1 2 3 4 package net.nutch.searcher; 5 6 import org.apache.lucene.search.BooleanQuery; 7 import org.apache.lucene.search.TermQuery; 8 import org.apache.lucene.index.Term; 9 10 import net.nutch.searcher.Query.Clause; 11 12 14 public abstract class RawFieldQueryFilter implements QueryFilter { 15 private String field; 16 private boolean lowerCase; 17 private float boost; 18 19 20 protected RawFieldQueryFilter(String field) { 21 this(field, true); 22 } 23 24 25 protected RawFieldQueryFilter(String field, float boost) { 26 this(field, true, boost); 27 } 28 29 30 protected RawFieldQueryFilter(String field, boolean lowerCase) { 31 this(field, lowerCase, 0.0f); 32 } 33 34 35 protected RawFieldQueryFilter(String field, boolean lowerCase, float boost) { 36 this.field = field; 37 this.lowerCase = lowerCase; 38 this.boost = boost; 39 } 40 41 public BooleanQuery filter(Query input, BooleanQuery output) 42 throws QueryException { 43 44 Clause[] clauses = input.getClauses(); 46 for (int i = 0; i < clauses.length; i++) { 47 Clause c = clauses[i]; 48 49 if (!c.getField().equals(field)) 51 continue; 52 53 String value = c.getTerm().toString(); 56 if (lowerCase) 57 value = value.toLowerCase(); 58 59 TermQuery clause = new TermQuery(new Term(field, value)); 61 clause.setBoost(boost); 63 output.add(clause, c.isRequired(), c.isProhibited()); 65 } 66 67 return output; 69 } 70 } 71 | Popular Tags |