01 package gate.creole.annic.apache.lucene.search;
02
03 /**
04 * Copyright 2004 The Apache Software Foundation
05 *
06 * Licensed under the Apache License, Version 2.0 (the "License");
07 * you may not use this file except in compliance with the License.
08 * You may obtain a copy of the License at
09 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 import java.io.IOException;
20
21 /** An abstract base class for search implementations.
22 * Implements some common utility methods.
23 */
24 public abstract class Searcher implements Searchable {
25
26 /** Returns the documents matching <code>query</code>. */
27 public final Hits search(Query query) throws IOException {
28 return search(query, (Filter)null);
29 }
30
31 /** Returns the documents matching <code>query</code> and
32 <code>filter</code>. */
33 public Hits search(Query query, Filter filter) throws IOException {
34 return new Hits(this, query, filter);
35 }
36
37 /** Returns documents matching <code>query</code> sorted by
38 * <code>sort</code>.
39 */
40 public Hits search(Query query, Sort sort)
41 throws IOException {
42 return new Hits(this, query, null, sort);
43 }
44
45 /** Returns documents matching <code>query</code> and <code>filter</code>,
46 * sorted by <code>sort</code>.
47 */
48 public Hits search(Query query, Filter filter, Sort sort)
49 throws IOException {
50 return new Hits(this, query, filter, sort);
51 }
52
53 /** Lower-level search API.
54 *
55 * <p>{@link HitCollector#collect(int,float)} is called for every non-zero
56 * scoring document.
57 *
58 * <p>Applications should only use this if they need <i>all</i> of the
59 * matching documents. The high-level search API ({@link
60 * Searcher#search(Query)}) is usually more efficient, as it skips
61 * non-high-scoring hits.
62 * <p>Note: The <code>score</code> passed to this method is a raw score.
63 * In other words, the score will not necessarily be a float whose value is
64 * between 0 and 1.
65 */
66 public void search(Query query, HitCollector results)
67 throws IOException {
68 search(query, (Filter)null, results);
69 }
70
71 /** The Similarity implementation used by this searcher. */
72 private Similarity similarity = Similarity.getDefault();
73
74 /** Expert: Set the Similarity implementation used by this Searcher.
75 *
76 * @see Similarity#setDefault(Similarity)
77 */
78 public void setSimilarity(Similarity similarity) {
79 this.similarity = similarity;
80 }
81
82 /** Expert: Return the Similarity implementation used by this Searcher.
83 *
84 * <p>This defaults to the current value of {@link Similarity#getDefault()}.
85 */
86 public Similarity getSimilarity() {
87 return this.similarity;
88 }
89 }
|