1 5 package org.exoplatform.services.indexing; 6 7 import java.util.Date ; 8 import org.apache.lucene.analysis.Analyzer; 9 import org.apache.lucene.document.DateField; 10 import org.apache.lucene.index.Term ; 11 import org.apache.lucene.search.* ; 12 17 public class RangeFieldSearchInput implements SearchInput { 18 19 private String field_ ; 20 private String lowerTerm_ ; 21 private String upperTerm_ ; 22 private boolean inclusive_ = true ; 23 24 public RangeFieldSearchInput(String field, Date lowerTerm, Date upperTerm) { 25 field_ = field ; 26 if(lowerTerm != null) 27 lowerTerm_ = DateField.dateToString(lowerTerm) ; 28 if(upperTerm != null) 29 upperTerm_ = DateField.dateToString(upperTerm) ; 30 } 31 32 public RangeFieldSearchInput(String field, String lowerTerm, String upperTerm) { 33 field_ = field ; 34 lowerTerm_ = lowerTerm ; 35 upperTerm_ = upperTerm ; 36 } 37 38 public String getField() { return field_ ; } 39 40 public void setInclusive(boolean b) { inclusive_ = b ; } 41 42 public boolean hasTerm() { 43 return (upperTerm_ != null && upperTerm_.length() > 0) || lowerTerm_ != null && lowerTerm_.length() > 0; 44 } 45 46 public Query getQuery(Analyzer analyzer) throws Exception { 47 Term lower = null ; 48 if(lowerTerm_ != null)lower = new Term(field_, lowerTerm_) ; 49 Term upper = null ; 50 if(upperTerm_ != null) upper = new Term(field_, upperTerm_) ; 51 return new RangeQuery(lower, upper, inclusive_) ; 52 } 53 } | Popular Tags |