1 package org.apache.lucene.search; 2 3 18 19 import java.io.IOException ; 20 21 import org.apache.lucene.index.Term; 22 import org.apache.lucene.document.Document; 23 24 30 public abstract class Searcher implements Searchable { 31 32 35 public final Hits search(Query query) throws IOException { 36 return search(query, (Filter)null); 37 } 38 39 43 public Hits search(Query query, Filter filter) throws IOException { 44 return new Hits(this, query, filter); 45 } 46 47 51 public Hits search(Query query, Sort sort) 52 throws IOException { 53 return new Hits(this, query, null, sort); 54 } 55 56 60 public Hits search(Query query, Filter filter, Sort sort) 61 throws IOException { 62 return new Hits(this, query, filter, sort); 63 } 64 65 74 public TopFieldDocs search(Query query, Filter filter, int n, 75 Sort sort) throws IOException { 76 return search(createWeight(query), filter, n, sort); 77 } 78 79 93 public void search(Query query, HitCollector results) 94 throws IOException { 95 search(query, (Filter)null, results); 96 } 97 98 114 public void search(Query query, Filter filter, HitCollector results) 115 throws IOException { 116 search(createWeight(query), filter, results); 117 } 118 119 128 public TopDocs search(Query query, Filter filter, int n) 129 throws IOException { 130 return search(createWeight(query), filter, n); 131 } 132 133 141 public Explanation explain(Query query, int doc) throws IOException { 142 return explain(createWeight(query), doc); 143 } 144 145 146 private Similarity similarity = Similarity.getDefault(); 147 148 152 public void setSimilarity(Similarity similarity) { 153 this.similarity = similarity; 154 } 155 156 160 public Similarity getSimilarity() { 161 return this.similarity; 162 } 163 164 168 protected Weight createWeight(Query query) throws IOException { 169 return query.weight(this); 170 } 171 172 public int[] docFreqs(Term[] terms) throws IOException { 174 int[] result = new int[terms.length]; 175 for (int i = 0; i < terms.length; i++) { 176 result[i] = docFreq(terms[i]); 177 } 178 return result; 179 } 180 181 184 abstract public void search(Weight weight, Filter filter, HitCollector results) throws IOException ; 185 abstract public void close() throws IOException ; 186 abstract public int docFreq(Term term) throws IOException ; 187 abstract public int maxDoc() throws IOException ; 188 abstract public TopDocs search(Weight weight, Filter filter, int n) throws IOException ; 189 abstract public Document doc(int i) throws IOException ; 190 abstract public Query rewrite(Query query) throws IOException ; 191 abstract public Explanation explain(Weight weight, int doc) throws IOException ; 192 abstract public TopFieldDocs search(Weight weight, Filter filter, int n, Sort sort) throws IOException ; 193 194 } 195 | Popular Tags |