Index: contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
===================================================================
--- contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java (revision 824730)
+++ contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java (working copy)
@@ -43,10 +43,11 @@
import org.apache.lucene.index.TermPositions;
import org.apache.lucene.index.TermVectorMapper;
import org.apache.lucene.index.FieldInvertState;
-import org.apache.lucene.search.HitCollector;
+import org.apache.lucene.search.Collector;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Searcher;
+import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Similarity;
/**
@@ -414,10 +415,22 @@
Searcher searcher = createSearcher();
try {
final float[] scores = new float[1]; // inits to 0.0f (no match)
- searcher.search(query, new HitCollector() {
- public void collect(int doc, float score) {
- scores[0] = score;
+ searcher.search(query, new Collector() {
+ private Scorer scorer;
+
+ public void collect(int doc) throws IOException {
+ scores[0] = scorer.score();
}
+
+ public void setScorer(Scorer scorer) throws IOException {
+ this.scorer = scorer;
+ }
+
+ public boolean acceptsDocsOutOfOrder() {
+ return true;
+ }
+
+ public void setNextReader(IndexReader reader, int docBase) { }
});
float score = scores[0];
return score;
Index: contrib/memory/src/test/org/apache/lucene/index/memory/MemoryIndexTest.java
===================================================================
--- contrib/memory/src/test/org/apache/lucene/index/memory/MemoryIndexTest.java (revision 824730)
+++ contrib/memory/src/test/org/apache/lucene/index/memory/MemoryIndexTest.java (working copy)
@@ -42,11 +42,13 @@
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexReader;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.search.HitCollector;
+import org.apache.lucene.search.Collector;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
+import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Searcher;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
@@ -424,11 +426,23 @@
else
searcher = ((MemoryIndex) index).createSearcher();
- final float[] scores = new float[1]; // inits to 0.0f
- searcher.search(query, new HitCollector() {
- public void collect(int doc, float score) {
- scores[0] = score;
+ final float[] scores = new float[1]; // inits to 0.0f (no match)
+ searcher.search(query, new Collector() {
+ private Scorer scorer;
+
+ public void collect(int doc) throws IOException {
+ scores[0] = scorer.score();
}
+
+ public void setScorer(Scorer scorer) throws IOException {
+ this.scorer = scorer;
+ }
+
+ public boolean acceptsDocsOutOfOrder() {
+ return true;
+ }
+
+ public void setNextReader(IndexReader reader, int docBase) { }
});
float score = scores[0];
// Hits hits = searcher.search(query);
Index: contrib/remote/src/java/org/apache/lucene/search/RemoteSearchable.java
===================================================================
--- contrib/remote/src/java/org/apache/lucene/search/RemoteSearchable.java (revision 824730)
+++ contrib/remote/src/java/org/apache/lucene/search/RemoteSearchable.java (working copy)
@@ -44,13 +44,6 @@
super();
this.local = local;
}
-
- /** @deprecated use {@link #search(Weight, Filter, Collector)} instead. */
- public void search(Weight weight, Filter filter, HitCollector results)
- throws IOException {
- local.search(weight, filter, results);
- }
-
public void search(Weight weight, Filter filter, Collector results)
throws IOException {
local.search(weight, filter, results);
Index: contrib/surround/src/test/org/apache/lucene/queryParser/surround/query/BooleanQueryTst.java
===================================================================
--- contrib/surround/src/test/org/apache/lucene/queryParser/surround/query/BooleanQueryTst.java (revision 824730)
+++ contrib/surround/src/test/org/apache/lucene/queryParser/surround/query/BooleanQueryTst.java (working copy)
@@ -17,10 +17,14 @@
* limitations under the License.
*/
+import java.io.IOException;
+
+import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Searcher;
+import org.apache.lucene.search.Collector;
+import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Query;
-import org.apache.lucene.search.HitCollector;
import org.apache.lucene.queryParser.surround.parser.QueryParser;
@@ -52,16 +56,32 @@
public void setVerbose(boolean verbose) {this.verbose = verbose;}
- class TestCollector extends HitCollector { // FIXME: use check hits from Lucene tests
+ class TestCollector extends Collector { // FIXME: use check hits from Lucene tests
int totalMatched;
boolean[] encountered;
+ private Scorer scorer = null;
+ private int docBase = 0;
TestCollector() {
totalMatched = 0;
encountered = new boolean[expectedDocNrs.length];
}
- public void collect(int docNr, float score) {
+ public void setScorer(Scorer scorer) throws IOException {
+ this.scorer = scorer;
+ }
+
+ public boolean acceptsDocsOutOfOrder() {
+ return true;
+ }
+
+ public void setNextReader(IndexReader reader, int docBase) throws IOException {
+ this.docBase = docBase;
+ }
+
+ public void collect(int docNr) throws IOException {
+ float score = scorer.score();
+ docNr += docBase;
/* System.out.println(docNr + " '" + dBase.getDocs()[docNr] + "': " + score); */
TestCase.assertTrue(queryText + ": positive score", score > 0.0);
TestCase.assertTrue(queryText + ": too many hits", totalMatched < expectedDocNrs.length);
Index: src/java/org/apache/lucene/search/BooleanScorer.java
===================================================================
--- src/java/org/apache/lucene/search/BooleanScorer.java (revision 824730)
+++ src/java/org/apache/lucene/search/BooleanScorer.java (working copy)
@@ -270,11 +270,6 @@
return false;
}
-
- /** @deprecated use {@link #score(Collector, int, int)} instead. */
- protected boolean score(HitCollector hc, int max) throws IOException {
- return score(new HitCollectorWrapper(hc), max, docID());
- }
public int advance(int target) throws IOException {
throw new UnsupportedOperationException();
@@ -328,11 +323,6 @@
public void score(Collector collector) throws IOException {
score(collector, Integer.MAX_VALUE, nextDoc());
}
-
- /** @deprecated use {@link #score(Collector)} instead. */
- public void score(HitCollector hc) throws IOException {
- score(new HitCollectorWrapper(hc));
- }
public String toString() {
StringBuilder buffer = new StringBuilder();
Index: src/java/org/apache/lucene/search/BooleanScorer2.java
===================================================================
--- src/java/org/apache/lucene/search/BooleanScorer2.java (revision 824730)
+++ src/java/org/apache/lucene/search/BooleanScorer2.java (working copy)
@@ -261,16 +261,6 @@
}
/** Scores and collects all matching documents.
- * @param hc The collector to which all matching documents are passed through
- * {@link HitCollector#collect(int, float)}.
- *
When this method is used the {@link #explain(int)} method should not be used.
- * @deprecated use {@link #score(Collector)} instead.
- */
- public void score(HitCollector hc) throws IOException {
- score(new HitCollectorWrapper(hc));
- }
-
- /** Scores and collects all matching documents.
* @param collector The collector to which all matching documents are passed through.
*
When this method is used the {@link #explain(int)} method should not be used.
*/
@@ -280,19 +270,6 @@
collector.collect(doc);
}
}
-
- /** Expert: Collects matching documents in a range.
- *
Note that {@link #next()} must be called once before this method is
- * called for the first time.
- * @param hc The collector to which all matching documents are passed through
- * {@link HitCollector#collect(int, float)}.
- * @param max Do not score documents past this.
- * @return true if more matching documents may remain.
- * @deprecated use {@link #score(Collector, int, int)} instead.
- */
- protected boolean score(HitCollector hc, int max) throws IOException {
- return score(new HitCollectorWrapper(hc), max, docID());
- }
protected boolean score(Collector collector, int max, int firstDocID) throws IOException {
doc = firstDocID;
Index: src/java/org/apache/lucene/search/Collector.java
===================================================================
--- src/java/org/apache/lucene/search/Collector.java (revision 824730)
+++ src/java/org/apache/lucene/search/Collector.java (working copy)
@@ -26,13 +26,6 @@
* gather raw results from a search, and implement sorting
* or custom result filtering, collation, etc.
As of 2.9, this class replaces the deprecated - * HitCollector, and offers an API for efficient collection - * of hits across sequential {@link IndexReader}s. {@link - * IndexSearcher} advances the collector through each of the - * sub readers, in an arbitrary order. This results in a - * higher performance means of collection.
- * *Lucene's core collectors are derived from Collector. * Likely your application can use one of these classes, or * subclass {@link TopDocsCollector}, instead of @@ -60,8 +53,7 @@ * *
ConjunctionScorer.
* This Scorer implements {@link Scorer#skipTo(int)} and uses skipTo() on the given Scorers.
- * TODO: Implement score(HitCollector, int).
*/
class DisjunctionSumScorer extends Scorer {
/** The number of subscorers. */
@@ -109,16 +108,6 @@
}
/** Scores and collects all matching documents.
- * @param hc The collector to which all matching documents are passed through
- * {@link HitCollector#collect(int, float)}.
- * If, for example, an application wished to collect all of the hits for a - * query in a BitSet, then it might:
- * Searcher searcher = new IndexSearcher(indexReader);
- * final BitSet bits = new BitSet(indexReader.maxDoc());
- * searcher.search(query, new HitCollector() {
- * public void collect(int doc, float score) {
- * bits.set(doc);
- * }
- * });
- *
- *
- * Note: This is called in an inner search loop. For good search - * performance, implementations of this method should not call - * {@link Searcher#doc(int)} or - * {@link org.apache.lucene.index.IndexReader#document(int)} on every - * document number encountered. Doing so can slow searches by an order - * of magnitude or more. - *
Note: The score passed to this method is a raw score.
- * In other words, the score will not necessarily be a float whose value is
- * between 0 and 1.
- */
- public abstract void collect(int doc, float score);
-}
Index: src/java/org/apache/lucene/search/HitCollectorWrapper.java
===================================================================
--- src/java/org/apache/lucene/search/HitCollectorWrapper.java (revision 824730)
+++ src/java/org/apache/lucene/search/HitCollectorWrapper.java (working copy)
@@ -1,57 +0,0 @@
-package org.apache.lucene.search;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.IOException;
-
-import org.apache.lucene.index.IndexReader;
-
-/**
- * Wrapper for ({@link HitCollector}) implementations, which simply re-bases the
- * incoming docID before calling {@link HitCollector#collect}.
- *
- * @deprecated Please migrate custom HitCollectors to the new {@link Collector}
- * class. This class will be removed when {@link HitCollector} is
- * removed.
- */
-public class HitCollectorWrapper extends Collector {
- private HitCollector collector;
- private int base = 0;
- private Scorer scorer = null;
-
- public HitCollectorWrapper(HitCollector collector) {
- this.collector = collector;
- }
-
- public void setNextReader(IndexReader reader, int docBase) {
- base = docBase;
- }
-
- public void collect(int doc) throws IOException {
- collector.collect(doc + base, scorer.score());
- }
-
- public void setScorer(Scorer scorer) throws IOException {
- this.scorer = scorer;
- }
-
- public boolean acceptsDocsOutOfOrder() {
- return false;
- }
-
-}
Index: src/java/org/apache/lucene/search/Scorer.java
===================================================================
--- src/java/org/apache/lucene/search/Scorer.java (revision 824730)
+++ src/java/org/apache/lucene/search/Scorer.java (working copy)
@@ -55,16 +55,6 @@
}
/** Scores and collects all matching documents.
- * @param hc The collector to which all matching documents are passed through
- * {@link HitCollector#collect(int, float)}.
- *
When this method is used the {@link #explain(int)} method should not be used.
- * @deprecated use {@link #score(Collector)} instead.
- */
- public void score(HitCollector hc) throws IOException {
- score(new HitCollectorWrapper(hc));
- }
-
- /** Scores and collects all matching documents.
* @param collector The collector to which all matching documents are passed.
*
When this method is used the {@link #explain(int)} method should not be used.
*/
@@ -76,19 +66,6 @@
}
}
- /** Expert: Collects matching documents in a range. Hook for optimization.
- * Note that {@link #next()} must be called once before this method is called
- * for the first time.
- * @param hc The collector to which all matching documents are passed through
- * {@link HitCollector#collect(int, float)}.
- * @param max Do not score documents past this.
- * @return true if more matching documents may remain.
- * @deprecated use {@link #score(Collector, int, int)} instead.
- */
- protected boolean score(HitCollector hc, int max) throws IOException {
- return score(new HitCollectorWrapper(hc), max, docID());
- }
-
/**
* Expert: Collects matching documents in a range. Hook for optimization.
* Note, firstDocID is added to ensure that {@link #nextDoc()}
Index: src/java/org/apache/lucene/search/Searchable.java
===================================================================
--- src/java/org/apache/lucene/search/Searchable.java (revision 824730)
+++ src/java/org/apache/lucene/search/Searchable.java (working copy)
@@ -43,26 +43,6 @@
*/
public interface Searchable {
- /** Lower-level search API.
- *
- *
{@link HitCollector#collect(int,float)} is called for every non-zero
- * scoring document.
- *
HitCollector-based access to remote indexes is discouraged.
- *
- *
Applications should only use this if they need all of the - * matching documents. The high-level search API ({@link - * Searcher#search(Query)}) is usually more efficient, as it skips - * non-high-scoring hits. - * - * @param weight to match documents - * @param filter if non-null, used to permit documents to be collected. - * @param results to receive hits - * @throws BooleanQuery.TooManyClauses - * @deprecated use {@link #search(Weight, Filter, Collector)} instead. - */ - void search(Weight weight, Filter filter, HitCollector results) - throws IOException; - /** * Lower-level search API. * @@ -115,7 +95,6 @@ *
Applications should usually call {@link Searcher#search(Query)} or * {@link Searcher#search(Query,Filter)} instead. * @throws BooleanQuery.TooManyClauses - * @deprecated use {@link #search(Weight, Filter, int)} instead. */ TopDocs search(Weight weight, Filter filter, int n) throws IOException; Index: src/java/org/apache/lucene/search/Searcher.java =================================================================== --- src/java/org/apache/lucene/search/Searcher.java (revision 824730) +++ src/java/org/apache/lucene/search/Searcher.java (working copy) @@ -51,26 +51,6 @@ } /** Lower-level search API. - * - *
{@link HitCollector#collect(int,float)} is called for every matching - * document. - * - *
Applications should only use this if they need all of the - * matching documents. The high-level search API ({@link - * Searcher#search(Query)}) is usually more efficient, as it skips - * non-high-scoring hits. - *
Note: The score passed to this method is a raw score.
- * In other words, the score will not necessarily be a float whose value is
- * between 0 and 1.
- * @throws BooleanQuery.TooManyClauses
- * @deprecated use {@link #search(Query, Collector)} instead.
- */
- public void search(Query query, HitCollector results)
- throws IOException {
- search(createWeight(query), null, new HitCollectorWrapper(results));
- }
-
- /** Lower-level search API.
*
*
{@link Collector#collect(int)} is called for every matching document. * @@ -90,28 +70,6 @@ /** Lower-level search API. * - *
{@link HitCollector#collect(int,float)} is called for every matching
- * document.
- *
HitCollector-based access to remote indexes is discouraged.
- *
- *
Applications should only use this if they need all of the - * matching documents. The high-level search API ({@link - * Searcher#search(Query, Filter, int)}) is usually more efficient, as it skips - * non-high-scoring hits. - * - * @param query to match documents - * @param filter if non-null, used to permit documents to be collected. - * @param results to receive hits - * @throws BooleanQuery.TooManyClauses - * @deprecated use {@link #search(Query, Filter, Collector)} instead. - */ - public void search(Query query, Filter filter, HitCollector results) - throws IOException { - search(createWeight(query), filter, new HitCollectorWrapper(results)); - } - - /** Lower-level search API. - * *
{@link Collector#collect(int)} is called for every matching
* document.
*
Collector-based access to remote indexes is discouraged.
@@ -199,15 +157,6 @@
return result;
}
- /* The following abstract methods were added as a workaround for GCJ bug #15411.
- * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15411
- */
- /**
- * @deprecated use {@link #search(Weight, Filter, Collector)} instead.
- */
- public void search(Weight weight, Filter filter, HitCollector results) throws IOException {
- search(weight, filter, new HitCollectorWrapper(results));
- }
abstract public void search(Weight weight, Filter filter, Collector results) throws IOException;
abstract public void close() throws IOException;
abstract public int docFreq(Term term) throws IOException;
Index: src/java/org/apache/lucene/search/TermScorer.java
===================================================================
--- src/java/org/apache/lucene/search/TermScorer.java (revision 824730)
+++ src/java/org/apache/lucene/search/TermScorer.java (working copy)
@@ -65,20 +65,10 @@
scoreCache[i] = getSimilarity().tf(i) * weightValue;
}
- /** @deprecated use {@link #score(Collector)} instead. */
- public void score(HitCollector hc) throws IOException {
- score(new HitCollectorWrapper(hc));
- }
-
public void score(Collector c) throws IOException {
score(c, Integer.MAX_VALUE, nextDoc());
}
- /** @deprecated use {@link #score(Collector, int, int)} instead. */
- protected boolean score(HitCollector c, int end) throws IOException {
- return score(new HitCollectorWrapper(c), end, doc);
- }
-
// firstDocID is ignored since nextDoc() sets 'doc'
protected boolean score(Collector c, int end, int firstDocID) throws IOException {
c.setScorer(this);
@@ -166,8 +156,6 @@
}
/** Returns an explanation of the score for a document.
- *
When this method is used, the {@link #next()} method
- * and the {@link #score(HitCollector)} method should not be used.
* @param doc The document number for the explanation.
*/
public Explanation explain(int doc) throws IOException {
Index: src/java/org/apache/lucene/search/TimeLimitedCollector.java
===================================================================
--- src/java/org/apache/lucene/search/TimeLimitedCollector.java (revision 824730)
+++ src/java/org/apache/lucene/search/TimeLimitedCollector.java (working copy)
@@ -1,217 +0,0 @@
-package org.apache.lucene.search;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
-*/
-
-/**
- *
- * The TimeLimitedCollector is used to timeout search requests that take longer - * than the maximum allowed search time limit. After this time is exceeded, the - * search thread is stopped by throwing a TimeExceeded Exception. - *
- * - * @deprecated Use {@link TimeLimitingCollector} instead, which extends the new - * {@link Collector}. This class will be removed in 3.0. - */ -public class TimeLimitedCollector extends HitCollector { - - /** - * Default timer resolution. - * @see #setResolution(long) - */ - public static final int DEFAULT_RESOLUTION = 20; - - /** - * Default for {@link #isGreedy()}. - * @see #isGreedy() - */ - public boolean DEFAULT_GREEDY = false; - - private static long resolution = DEFAULT_RESOLUTION; - - private boolean greedy = DEFAULT_GREEDY ; - - private static class TimerThread extends Thread { - - // NOTE: we can avoid explicit synchronization here for several reasons: - // * updates to volatile long variables are atomic - // * only single thread modifies this value - // * use of volatile keyword ensures that it does not reside in - // a register, but in main memory (so that changes are visible to - // other threads). - // * visibility of changes does not need to be instantaneous, we can - // afford losing a tick or two. - // - // See section 17 of the Java Language Specification for details. - private volatile long time = 0; - - /** - * TimerThread provides a pseudo-clock service to all searching - * threads, so that they can count elapsed time with less overhead - * than repeatedly calling System.currentTimeMillis. A single - * thread should be created to be used for all searches. - */ - private TimerThread() { - super("TimeLimitedCollector timer thread"); - this.setDaemon( true ); - } - - public void run() { - while( true ) { - // TODO: Use System.nanoTime() when Lucene moves to Java SE 5. - time += resolution; - try { - Thread.sleep( resolution ); - } catch (InterruptedException ie) { - Thread.currentThread().interrupt(); - throw new RuntimeException(ie); - } - } - } - - /** - * Get the timer value in milliseconds. - */ - public long getMilliseconds() { - return time; - } - } - - /** - * Thrown when elapsed search time exceeds allowed search time. - */ - public static class TimeExceededException extends RuntimeException { - private long timeAllowed; - private long timeElapsed; - private int lastDocCollected; - private TimeExceededException(long timeAllowed, long timeElapsed, int lastDocCollected) { - super("Elapsed time: " + timeElapsed + "Exceeded allowed search time: " + timeAllowed + " ms."); - this.timeAllowed = timeAllowed; - this.timeElapsed = timeElapsed; - this.lastDocCollected = lastDocCollected; - } - /** - * Returns allowed time (milliseconds). - */ - public long getTimeAllowed() { - return timeAllowed; - } - /** - * Returns elapsed time (milliseconds). - */ - public long getTimeElapsed() { - return timeElapsed; - } - /** - * Returns last doc that was collected when the search time exceeded. - */ - public int getLastDocCollected() { - return lastDocCollected; - } - } - - // Declare and initialize a single static timer thread to be used by - // all TimeLimitedCollector instances. The JVM assures that - // this only happens once. - private final static TimerThread TIMER_THREAD = new TimerThread(); - - static { - TIMER_THREAD.start(); - } - - private final long t0; - private final long timeout; - private final HitCollector hc; - - /** - * Create a TimeLimitedCollector wrapper over another HitCollector with a specified timeout. - * @param hc the wrapped HitCollector - * @param timeAllowed max time allowed for collecting hits after which {@link TimeExceededException} is thrown - */ - public TimeLimitedCollector(final HitCollector hc, final long timeAllowed) { - this.hc = hc; - t0 = TIMER_THREAD.getMilliseconds(); - this.timeout = t0 + timeAllowed; - } - - /** - * Calls collect() on the decorated HitCollector. - * - * @throws TimeExceededException if the time allowed has been exceeded. - */ - public void collect( final int doc, final float score ) { - long time = TIMER_THREAD.getMilliseconds(); - if( timeout < time) { - if (greedy) { - //System.out.println(this+" greedy: before failing, collecting doc: "+doc+" "+(time-t0)); - hc.collect( doc, score ); - } - //System.out.println(this+" failing on: "+doc+" "+(time-t0)); - throw new TimeExceededException( timeout-t0, time-t0, doc ); - } - //System.out.println(this+" collecting: "+doc+" "+(time-t0)); - hc.collect( doc, score ); - } - - /** - * Return the timer resolution. - * @see #setResolution(long) - */ - public static long getResolution() { - return resolution; - } - - /** - * Set the timer resolution. - * The default timer resolution is 20 milliseconds. - * This means that a search required to take no longer than - * 800 milliseconds may be stopped after 780 to 820 milliseconds. - *