Index: D:/Programme/eclipse/workspace/lucene/src/test/org/apache/lucene/search/TestSort.java =================================================================== --- D:/Programme/eclipse/workspace/lucene/src/test/org/apache/lucene/search/TestSort.java (revision 164009) +++ D:/Programme/eclipse/workspace/lucene/src/test/org/apache/lucene/search/TestSort.java (working copy) @@ -344,12 +344,8 @@ HashMap scoresA = getScores (full.search (queryA)); // we'll test searching locally, remote and multi - // note: the multi test depends on each separate index containing - // the same documents as our local index, so the computed normalization - // will be the same. so we make a multi searcher over two equal document - // sets - not realistic, but necessary for testing. MultiSearcher remote = new MultiSearcher (new Searchable[] { getRemote() }); - MultiSearcher multi = new MultiSearcher (new Searchable[] { full, full }); + MultiSearcher multi = new MultiSearcher (new Searchable[] { searchX, searchY }); // change sorting and make sure relevancy stays the same Index: D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/RemoteSearchable.java =================================================================== --- D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/RemoteSearchable.java (revision 164009) +++ D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/RemoteSearchable.java (working copy) @@ -39,6 +39,8 @@ this.local = local; } + // this implementation should be removed when the deprecated + // Searchable#search(Query,Filter,HitCollector) is removed public void search(Query query, Filter filter, HitCollector results) throws IOException { local.search(query, filter, results); @@ -66,6 +68,8 @@ return local.maxDoc(); } + // this implementation should be removed when the deprecated + // Searchable#search(Query,Filter,int) is removed public TopDocs search(Query query, Filter filter, int n) throws IOException { return local.search(query, filter, n); } @@ -74,6 +78,8 @@ return local.search(weight, filter, n); } + // this implementation should be removed when the deprecated + // Searchable#search(Query,Filter,int,Sort) is removed public TopFieldDocs search (Query query, Filter filter, int n, Sort sort) throws IOException { return local.search (query, filter, n, sort); @@ -92,6 +98,8 @@ return local.rewrite(original); } + // this implementation should be removed when the deprecated + // Searchable#explain(Query,int) is removed public Explanation explain(Query query, int doc) throws IOException { return local.explain(query, doc); } Index: D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/Searcher.java =================================================================== --- D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/Searcher.java (revision 164178) +++ D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/Searcher.java (working copy) @@ -58,6 +58,20 @@ return new Hits(this, query, filter, sort); } + /** Expert: Low-level search implementation with arbitrary sorting. Finds + * the top n hits for query, applying + * filter if non-null, and sorting the hits by the criteria in + * sort. + * + *

Applications should usually call {@link + * Searcher#search(Query,Filter,Sort)} instead. + * @throws BooleanQuery.TooManyClauses + */ + public TopFieldDocs search(Query query, Filter filter, int n, + Sort sort) throws IOException { + return search(createWeight(query), filter, n, sort); + } + /** Lower-level search API. * *

{@link HitCollector#collect(int,float)} is called for every non-zero @@ -77,6 +91,53 @@ search(query, (Filter)null, results); } + /** 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 query to match documents + * @param filter if non-null, a bitset used to eliminate some documents + * @param results to receive hits + * @throws BooleanQuery.TooManyClauses + */ + public void search(Query query, Filter filter, HitCollector results) + throws IOException { + search(query.weight(this), filter, results); + } + + /** Expert: Low-level search implementation. Finds the top n + * hits for query, applying filter if non-null. + * + *

Called by {@link Hits}. + * + *

Applications should usually call {@link Searcher#search(Query)} or + * {@link Searcher#search(Query,Filter)} instead. + * @throws BooleanQuery.TooManyClauses + */ + public TopDocs search(Query query, Filter filter, int n) + throws IOException { + return search(createWeight(query), filter, n); + } + + /** Returns an Explanation that describes how doc scored against + * query. + * + *

This is intended to be used in developing Similarity implementations, + * and, for good performance, should not be displayed with every hit. + * Computing an explanation is as expensive as executing the query over the + * entire index. + */ + public Explanation explain(Query query, int doc) throws IOException { + return explain(query.weight(this), doc); + } + /** The Similarity implementation used by this searcher. */ private Similarity similarity = Similarity.getDefault(); @@ -95,8 +156,15 @@ public Similarity getSimilarity() { return this.similarity; } + + /** + * creates a weight for query + * @return new weight + */ + protected Weight createWeight(Query query) throws IOException { + return query.createWeight(this); + } - // inherit javadoc public int[] docFreqs(Term[] terms) throws IOException { int[] result = new int[terms.length]; @@ -105,5 +173,4 @@ } return result; } - } Index: D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/TopFieldDocs.java =================================================================== --- D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/TopFieldDocs.java (revision 164009) +++ D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/TopFieldDocs.java (working copy) @@ -25,7 +25,7 @@ * @author Tim Jones (Nacimiento Software) * @since lucene 1.4 * @version $Id$ - * @see Searchable#search(Query,Filter,int,Sort) + * @see Searcher#search(Query,Filter,int,Sort) */ public class TopFieldDocs extends TopDocs { Index: D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/Searchable.java =================================================================== --- D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/Searchable.java (revision 164009) +++ D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/Searchable.java (working copy) @@ -44,22 +44,19 @@ * Searcher#search(Query)}) is usually more efficient, as it skips * non-high-scoring hits. * - * @param query to match documents + * @param weight to match documents * @param filter if non-null, a bitset used to eliminate some documents * @param results to receive hits * @throws BooleanQuery.TooManyClauses - * - * @deprecated */ - void search(Query query, Filter filter, HitCollector results) - throws IOException; + void search(Weight weight, Filter filter, HitCollector results) + throws IOException; /** Expert: Low-level search implementation. - * Identical to {@link #search(Query, Filter, HitCollector)}, but takes - * a Weight instead of a query. + * @deprecated use {@link Searcher#search(Query, Filter, HitCollector)} instead. */ - void search(Weight weight, Filter filter, HitCollector results) - throws IOException; + void search(Query query, Filter filter, HitCollector results) + throws IOException; /** Frees resources associated with this Searcher. * Be careful not to call this method while you are still using objects @@ -93,16 +90,13 @@ *

Applications should usually call {@link Searcher#search(Query)} or * {@link Searcher#search(Query,Filter)} instead. * @throws BooleanQuery.TooManyClauses - * - * @deprecated */ - TopDocs search(Query query, Filter filter, int n) throws IOException; + TopDocs search(Weight weight, Filter filter, int n) throws IOException; /** Expert: Low-level search implementation. - * Identical to {@link #search(Query, Filter, int)}, but takes - * a Weight instead of a query. + * @deprecated use {@link Searcher#search(Query, Filter, int)} instead. */ - TopDocs search(Weight weight, Filter filter, int n) throws IOException; + TopDocs search(Query query, Filter filter, int n) throws IOException; /** Expert: Returns the stored fields of document i. * Called by {@link HitCollector} implementations. @@ -115,22 +109,23 @@ */ Query rewrite(Query query) throws IOException; - /** Returns an Explanation that describes how doc scored against - * query. + /** Expert: low-level implementation method + * Returns an Explanation that describes how doc scored against + * weight. * *

This is intended to be used in developing Similarity implementations, * and, for good performance, should not be displayed with every hit. * Computing an explanation is as expensive as executing the query over the * entire index. + *

Applications should call {@link Searcher#explain(Query, int)}. * @throws BooleanQuery.TooManyClauses */ - Explanation explain(Query query, int doc) throws IOException; + Explanation explain(Weight weight, int doc) throws IOException; /** - * Identical to {@link #search(Query, Filter, HitCollector)}, but takes - * a Weight instead of a query. + * @deprecated use {@link Searcher#explain(Query, int)} instead. */ - Explanation explain(Weight weight, int doc) throws IOException; + Explanation explain(Query query, int doc) throws IOException; /** Expert: Low-level search implementation with arbitrary sorting. Finds * the top n hits for query, applying @@ -140,16 +135,13 @@ *

Applications should usually call {@link * Searcher#search(Query,Filter,Sort)} instead. * @throws BooleanQuery.TooManyClauses - * - * @deprecated */ - TopFieldDocs search(Query query, Filter filter, int n, Sort sort) - throws IOException; + TopFieldDocs search(Weight weight, Filter filter, int n, Sort sort) + throws IOException; /** Expert: Low-level search implementation. - * Identical to {@link #search(Query, Filter, int, Sort)}, but takes - * a Weight instead of a query. + * @deprecated use {@link Searcher#search(Query, Filter, int, Sort)} instead. */ - TopFieldDocs search(Weight weight, Filter filter, int n, Sort sort) - throws IOException; + TopFieldDocs search(Query query, Filter filter, int n, Sort sort) + throws IOException; } Index: D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/FieldDoc.java =================================================================== --- D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/FieldDoc.java (revision 164009) +++ D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/FieldDoc.java (working copy) @@ -46,7 +46,7 @@ * Sort object. Each Object will be either an Integer, Float or String, * depending on the type of values in the terms of the original field. * @see Sort - * @see Searchable#search(Query,Filter,int,Sort) + * @see Searcher#search(Query,Filter,int,Sort) */ public Comparable[] fields; Index: D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/FieldSortedHitQueue.java =================================================================== --- D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/FieldSortedHitQueue.java (revision 164009) +++ D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/FieldSortedHitQueue.java (working copy) @@ -35,7 +35,7 @@ * @author Tim Jones (Nacimiento Software) * @since lucene 1.4 * @version $Id$ - * @see Searchable#search(Query,Filter,int,Sort) + * @see Searcher#search(Query,Filter,int,Sort) * @see FieldCache */ class FieldSortedHitQueue @@ -110,7 +110,7 @@ * by a MultiSearcher with other search hits. * @param doc The FieldDoc to store sort values into. * @return The same FieldDoc passed in. - * @see Searchable#search(Query,Filter,int,Sort) + * @see Searchable#search(Weight,Filter,int,Sort) */ FieldDoc fillFields (final FieldDoc doc) { final int n = comparators.length; Index: D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/MultiSearcher.java =================================================================== --- D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/MultiSearcher.java (revision 164009) +++ D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/MultiSearcher.java (working copy) @@ -84,34 +84,18 @@ throw new UnsupportedOperationException(); } - public Explanation explain(Query query,int doc) throws IOException{ - throw new UnsupportedOperationException(); - } - public Explanation explain(Weight weight,int doc) throws IOException { throw new UnsupportedOperationException(); } - public void search(Query query, Filter filter, HitCollector results) throws IOException { - throw new UnsupportedOperationException(); - } - public void search(Weight weight, Filter filter, HitCollector results) throws IOException { throw new UnsupportedOperationException(); } - public TopDocs search(Query query,Filter filter,int n) throws IOException { - throw new UnsupportedOperationException(); - } - public TopDocs search(Weight weight,Filter filter,int n) throws IOException { throw new UnsupportedOperationException(); } - public TopFieldDocs search(Query query,Filter filter,int n,Sort sort) throws IOException { - throw new UnsupportedOperationException(); - } - public TopFieldDocs search(Weight weight,Filter filter,int n,Sort sort) throws IOException { throw new UnsupportedOperationException(); } @@ -203,12 +187,6 @@ return maxDoc; } - public TopDocs search(Query query, Filter filter, int nDocs) - throws IOException { - Weight weight = prepareWeight(query); - return search(weight, filter, nDocs); - } - public TopDocs search(Weight weight, Filter filter, int nDocs) throws IOException { @@ -234,13 +212,6 @@ return new TopDocs(totalHits, scoreDocs); } - - public TopFieldDocs search (Query query, Filter filter, int n, Sort sort) - throws IOException { - Weight weight = prepareWeight(query); - return search(weight, filter, n, sort); - } - public TopFieldDocs search (Weight weight, Filter filter, int n, Sort sort) throws IOException { FieldDocSortedHitQueue hq = null; @@ -268,13 +239,6 @@ // inherit javadoc - public void search(Query query, Filter filter, final HitCollector results) - throws IOException { - Weight weight = prepareWeight(query); - search(weight, filter, results); - } - - // inherit javadoc public void search(Weight weight, Filter filter, final HitCollector results) throws IOException { for (int i = 0; i < searchables.length; i++) { @@ -298,12 +262,6 @@ return queries[0].combine(queries); } - public Explanation explain(Query query, int doc) throws IOException { - Weight weight = prepareWeight(query); - return explain(weight, doc); - } - - public Explanation explain(Weight weight, int doc) throws IOException { int i = subSearcher(doc); // find searcher index return searchables[i].explain(weight,doc-starts[i]); // dispatch to searcher @@ -322,7 +280,7 @@ * * @return rewritten queries */ - private Weight prepareWeight(Query original) throws IOException { + protected Weight createWeight(Query original) throws IOException { // step 1 Query rewrittenQuery = rewrite(original); Index: D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/ParallelMultiSearcher.java =================================================================== --- D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/ParallelMultiSearcher.java (revision 164009) +++ D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/ParallelMultiSearcher.java (working copy) @@ -158,13 +158,13 @@ * * TODO: parallelize this one too */ - public void search(Query query, Filter filter, final HitCollector results) + public void search(Weight weight, Filter filter, final HitCollector results) throws IOException { for (int i = 0; i < searchables.length; i++) { final int start = starts[i]; - searchables[i].search(query, filter, new HitCollector() { + searchables[i].search(weight, filter, new HitCollector() { public void collect(int doc, float score) { results.collect(doc + start, score); } Index: D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/IndexSearcher.java =================================================================== --- D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/IndexSearcher.java (revision 164009) +++ D:/Programme/eclipse/workspace/lucene/src/java/org/apache/lucene/search/IndexSearcher.java (working copy) @@ -86,12 +86,6 @@ } // inherit javadoc - public TopDocs search(Query query, Filter filter, final int nDocs) - throws IOException { - return search(query.weight(this), filter, nDocs); - } - - // inherit javadoc public TopDocs search(Weight weight, Filter filter, final int nDocs) throws IOException { @@ -127,13 +121,6 @@ } // inherit javadoc - public TopFieldDocs search(Query query, Filter filter, final int nDocs, - Sort sort) - throws IOException { - return search(query.weight(this), filter, nDocs, sort); - } - - // inherit javadoc public TopFieldDocs search(Weight weight, Filter filter, final int nDocs, Sort sort) throws IOException { @@ -162,14 +149,7 @@ return new TopFieldDocs(totalHits[0], scoreDocs, hq.getFields()); } - // inherit javadoc - public void search(Query query, Filter filter, - final HitCollector results) throws IOException { - search(query.weight(this), filter, results); - } - - // inherit javadoc public void search(Weight weight, Filter filter, final HitCollector results) throws IOException { HitCollector collector = results; @@ -199,10 +179,6 @@ return query; } - public Explanation explain(Query query, int doc) throws IOException { - return explain(query.weight(this), doc); - } - public Explanation explain(Weight weight, int doc) throws IOException { return weight.explain(reader, doc); }