01: package org.apache.lucene.search;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19:
20: /** Lower-level search API.
21: * <br>HitCollectors are primarily meant to be used to implement queries,
22: * sorting and filtering.
23: * @see Searcher#search(Query,HitCollector)
24: * @version $Id: HitCollector.java 596462 2007-11-19 22:03:22Z hossman $
25: */
26: public abstract class HitCollector {
27: /** Called once for every document matching a query, with the document
28: * number and its raw score.
29: *
30: * <P>If, for example, an application wished to collect all of the hits for a
31: * query in a BitSet, then it might:<pre>
32: * Searcher searcher = new IndexSearcher(indexReader);
33: * final BitSet bits = new BitSet(indexReader.maxDoc());
34: * searcher.search(query, new HitCollector() {
35: * public void collect(int doc, float score) {
36: * bits.set(doc);
37: * }
38: * });
39: * </pre>
40: *
41: * <p>Note: This is called in an inner search loop. For good search
42: * performance, implementations of this method should not call
43: * {@link Searcher#doc(int)} or
44: * {@link org.apache.lucene.index.IndexReader#document(int)} on every
45: * document number encountered. Doing so can slow searches by an order
46: * of magnitude or more.
47: * <p>Note: The <code>score</code> passed to this method is a raw score.
48: * In other words, the score will not necessarily be a float whose value is
49: * between 0 and 1.
50: */
51: public abstract void collect(int doc, float score);
52: }
|