1 5 package org.exoplatform.services.indexing; 6 7 import java.util.* ; 8 import org.apache.lucene.analysis.Analyzer; 9 import org.apache.lucene.queryParser.QueryParser ; 10 import org.apache.lucene.search.* ; 11 16 public class MultipleFieldSearchInput implements SearchInput { 17 private List field_ ; 18 private String term_ ; 19 private boolean matchAllFields_ = false ; 20 21 public MultipleFieldSearchInput(List field) { 22 field_ = field ; 23 } 24 25 public List getField() { return field_ ; } 26 public void setField(List field) { field_ = field ; } 27 28 public String getTerm() { return term_ ; } 29 public void setTerm(String term) { term_ = term ; } 30 31 public boolean isMatchAllFields() { return matchAllFields_ ; } 32 public void setMatchAllFields(boolean b) { matchAllFields_ = b ; } 33 34 public boolean hasTerm() { 35 return term_ != null && term_.length() > 0; 36 } 37 38 39 public Query getQuery(Analyzer analyzer) throws Exception { 40 BooleanQuery bquery = new BooleanQuery() ; 41 for(int i = 0; i < field_.size(); i++) { 42 String field = (String )field_.get(i) ; 43 Query fieldquery = QueryParser.parse(term_ , field , analyzer) ; 44 bquery.add(fieldquery, matchAllFields_, false) ; 45 } 46 return bquery ; 47 } 48 } | Popular Tags |