From ede75ff9ae4eea4b1106255f0280ce7c15f67550 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Wed, 19 Jan 2011 23:03:19 +0000 Subject: [PATCH] LUCENE-2869: remove Query.getSimilarity git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1061050 13f79535-47bb-0310-9956-ffa450edef68 --- lucene/CHANGES.txt | 4 +++ .../apache/lucene/search/BoostingQuery.java | 8 ++--- .../apache/lucene/search/BooleanQuery.java | 11 +++--- .../apache/lucene/search/BooleanScorer.java | 5 +-- .../apache/lucene/search/BooleanScorer2.java | 35 +++++++++---------- .../lucene/search/ConstantScoreQuery.java | 2 +- .../apache/lucene/search/FilteredQuery.java | 2 +- .../lucene/search/MultiPhraseQuery.java | 2 +- .../org/apache/lucene/search/PhraseQuery.java | 2 +- .../java/org/apache/lucene/search/Query.java | 11 +----- .../org/apache/lucene/search/TermQuery.java | 2 +- .../search/function/CustomScoreQuery.java | 2 +- .../search/function/ValueSourceQuery.java | 2 +- .../search/spans/FieldMaskingSpanQuery.java | 5 --- .../lucene/search/spans/SpanWeight.java | 2 +- .../lucene/search/TestBooleanScorer.java | 15 +++++++- .../apache/lucene/search/spans/TestSpans.java | 19 +++++----- .../org/apache/solr/schema/LatLonType.java | 2 +- .../solr/search/SolrConstantScoreQuery.java | 2 +- .../solr/search/function/BoostedQuery.java | 2 +- .../solr/search/function/FunctionQuery.java | 2 +- 21 files changed, 70 insertions(+), 67 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 42ba0ab6d49..d54d2ae0a02 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -410,6 +410,10 @@ Changes in backwards compatibility policy Similarity impls to cutover to the more general computeNorm (Robert Muir, Mike McCandless) +* LUCENE-2869: Deprecated Query.getSimilarity: instead of using + "runtime" subclassing/delegation, subclass the Weight instead. + (Robert Muir) + * LUCENE-2674: A new idfExplain method was added to Similarity, that accepts an incoming docFreq. If you subclass Similarity, make sure you also override this method on upgrade. (Robert Muir, Mike diff --git a/lucene/contrib/queries/src/java/org/apache/lucene/search/BoostingQuery.java b/lucene/contrib/queries/src/java/org/apache/lucene/search/BoostingQuery.java index 5a5fa0b388d..0b81cd6181a 100644 --- a/lucene/contrib/queries/src/java/org/apache/lucene/search/BoostingQuery.java +++ b/lucene/contrib/queries/src/java/org/apache/lucene/search/BoostingQuery.java @@ -21,10 +21,9 @@ import java.io.IOException; import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.DefaultSimilarity; import org.apache.lucene.search.Query; import org.apache.lucene.search.IndexSearcher; -import org.apache.lucene.search.Similarity; + /** * The BoostingQuery class can be used to effectively demote results that match a given query. * Unlike the "NOT" clause, this still selects documents that contain undesirable terms, @@ -56,10 +55,9 @@ public class BoostingQuery extends Query { @Override public Query rewrite(IndexReader reader) throws IOException { BooleanQuery result = new BooleanQuery() { - @Override - public Similarity getSimilarity(IndexSearcher searcher) { - return new DefaultSimilarity() { + public Weight createWeight(IndexSearcher searcher) throws IOException { + return new BooleanWeight(searcher, false) { @Override public float coord(int overlap, int max) { diff --git a/lucene/src/java/org/apache/lucene/search/BooleanQuery.java b/lucene/src/java/org/apache/lucene/search/BooleanQuery.java index e3a09e1cfe9..07e2aeca1e3 100644 --- a/lucene/src/java/org/apache/lucene/search/BooleanQuery.java +++ b/lucene/src/java/org/apache/lucene/search/BooleanQuery.java @@ -169,7 +169,7 @@ public class BooleanQuery extends Query implements Iterable { public BooleanWeight(IndexSearcher searcher, boolean disableCoord) throws IOException { - this.similarity = getSimilarity(searcher); + this.similarity = searcher.getSimilarity(); this.disableCoord = disableCoord; weights = new ArrayList(clauses.size()); for (int i = 0 ; i < clauses.size(); i++) { @@ -201,6 +201,9 @@ public class BooleanQuery extends Query implements Iterable { return sum ; } + public float coord(int overlap, int maxOverlap) { + return similarity.coord(overlap, maxOverlap); + } @Override public void normalize(float norm) { @@ -273,7 +276,7 @@ public class BooleanQuery extends Query implements Iterable { sumExpl.setMatch(0 < coord ? Boolean.TRUE : Boolean.FALSE); sumExpl.setValue(sum); - final float coordFactor = disableCoord ? 1.0f : similarity.coord(coord, maxCoord); + final float coordFactor = disableCoord ? 1.0f : coord(coord, maxCoord); if (coordFactor == 1.0f) { return sumExpl; // eliminate wrapper } else { @@ -312,7 +315,7 @@ public class BooleanQuery extends Query implements Iterable { // Check if we can return a BooleanScorer if (!scorerContext.scoreDocsInOrder && scorerContext.topScorer && required.size() == 0 && prohibited.size() < 32) { - return new BooleanScorer(this, disableCoord, similarity, minNrShouldMatch, optional, prohibited, maxCoord); + return new BooleanScorer(this, disableCoord, minNrShouldMatch, optional, prohibited, maxCoord); } if (required.size() == 0 && optional.size() == 0) { @@ -326,7 +329,7 @@ public class BooleanQuery extends Query implements Iterable { } // Return a BooleanScorer2 - return new BooleanScorer2(this, disableCoord, similarity, minNrShouldMatch, required, prohibited, optional, maxCoord); + return new BooleanScorer2(this, disableCoord, minNrShouldMatch, required, prohibited, optional, maxCoord); } @Override diff --git a/lucene/src/java/org/apache/lucene/search/BooleanScorer.java b/lucene/src/java/org/apache/lucene/search/BooleanScorer.java index 7b244b4eb3a..6faa7cc8e53 100644 --- a/lucene/src/java/org/apache/lucene/search/BooleanScorer.java +++ b/lucene/src/java/org/apache/lucene/search/BooleanScorer.java @@ -22,6 +22,7 @@ import java.util.List; import org.apache.lucene.index.IndexReader.AtomicReaderContext; import org.apache.lucene.search.BooleanClause.Occur; +import org.apache.lucene.search.BooleanQuery.BooleanWeight; /* Description from Doug Cutting (excerpted from * LUCENE-1483): @@ -197,7 +198,7 @@ final class BooleanScorer extends Scorer { private Bucket current; private int doc = -1; - BooleanScorer(Weight weight, boolean disableCoord, Similarity similarity, int minNrShouldMatch, + BooleanScorer(BooleanWeight weight, boolean disableCoord, int minNrShouldMatch, List optionalScorers, List prohibitedScorers, int maxCoord) throws IOException { super(null, weight); // Similarity not used this.minNrShouldMatch = minNrShouldMatch; @@ -223,7 +224,7 @@ final class BooleanScorer extends Scorer { coordFactors = new float[optionalScorers.size() + 1]; for (int i = 0; i < coordFactors.length; i++) { - coordFactors[i] = disableCoord ? 1.0f : similarity.coord(i, maxCoord); + coordFactors[i] = disableCoord ? 1.0f : weight.coord(i, maxCoord); } } diff --git a/lucene/src/java/org/apache/lucene/search/BooleanScorer2.java b/lucene/src/java/org/apache/lucene/search/BooleanScorer2.java index d1a7a6d38b7..c459dae1ade 100644 --- a/lucene/src/java/org/apache/lucene/search/BooleanScorer2.java +++ b/lucene/src/java/org/apache/lucene/search/BooleanScorer2.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.List; import org.apache.lucene.search.BooleanClause.Occur; +import org.apache.lucene.search.BooleanQuery.BooleanWeight; /* See the description in BooleanScorer.java, comparing * BooleanScorer & BooleanScorer2 */ @@ -42,10 +43,10 @@ class BooleanScorer2 extends Scorer { int maxCoord = 0; // to be increased for each non prohibited scorer int nrMatchers; // to be increased by score() of match counting scorers. - void init(Similarity sim, boolean disableCoord) { // use after all scorers have been added. + void init(boolean disableCoord) { // use after all scorers have been added. coordFactors = new float[optionalScorers.size() + requiredScorers.size() + 1]; for (int i = 0; i < coordFactors.length; i++) { - coordFactors[i] = disableCoord ? 1.0f : sim.coord(i, maxCoord); + coordFactors[i] = disableCoord ? 1.0f : ((BooleanWeight)weight).coord(i, maxCoord); } } } @@ -80,7 +81,7 @@ class BooleanScorer2 extends Scorer { * @param optional * the list of optional scorers. */ - public BooleanScorer2(Weight weight, boolean disableCoord, Similarity similarity, int minNrShouldMatch, + public BooleanScorer2(BooleanWeight weight, boolean disableCoord, int minNrShouldMatch, List required, List prohibited, List optional, int maxCoord) throws IOException { super(null, weight); // Similarity not used if (minNrShouldMatch < 0) { @@ -94,8 +95,8 @@ class BooleanScorer2 extends Scorer { requiredScorers = required; prohibitedScorers = prohibited; - coordinator.init(similarity, disableCoord); - countingSumScorer = makeCountingSumScorer(disableCoord, similarity); + coordinator.init(disableCoord); + countingSumScorer = makeCountingSumScorer(disableCoord); } /** Count a scorer as a single match. */ @@ -163,11 +164,10 @@ class BooleanScorer2 extends Scorer { } private Scorer countingConjunctionSumScorer(boolean disableCoord, - Similarity similarity, List requiredScorers) throws IOException { // each scorer from the list counted as a single matcher final int requiredNrMatchers = requiredScorers.size(); - return new ConjunctionScorer(disableCoord ? 1.0f : similarity.coord(requiredScorers.size(), requiredScorers.size()), requiredScorers) { + return new ConjunctionScorer(disableCoord ? 1.0f : ((BooleanWeight)weight).coord(requiredScorers.size(), requiredScorers.size()), requiredScorers) { private int lastScoredDoc = -1; // Save the score of lastScoredDoc, so that we don't compute it more than // once in score(). @@ -191,9 +191,8 @@ class BooleanScorer2 extends Scorer { } private Scorer dualConjunctionSumScorer(boolean disableCoord, - Similarity similarity, Scorer req1, Scorer req2) throws IOException { // non counting. - return new ConjunctionScorer(disableCoord ? 1.0f : similarity.coord(2, 2), req1, req2); + return new ConjunctionScorer(disableCoord ? 1.0f : ((BooleanWeight)weight).coord(2, 2), req1, req2); // All scorers match, so defaultSimilarity always has 1 as // the coordination factor. // Therefore the sum of the scores of two scorers @@ -203,14 +202,13 @@ class BooleanScorer2 extends Scorer { /** Returns the scorer to be used for match counting and score summing. * Uses requiredScorers, optionalScorers and prohibitedScorers. */ - private Scorer makeCountingSumScorer(boolean disableCoord, - Similarity similarity) throws IOException { // each scorer counted as a single matcher + private Scorer makeCountingSumScorer(boolean disableCoord) throws IOException { // each scorer counted as a single matcher return (requiredScorers.size() == 0) - ? makeCountingSumScorerNoReq(disableCoord, similarity) - : makeCountingSumScorerSomeReq(disableCoord, similarity); + ? makeCountingSumScorerNoReq(disableCoord) + : makeCountingSumScorerSomeReq(disableCoord); } - private Scorer makeCountingSumScorerNoReq(boolean disableCoord, Similarity similarity) throws IOException { // No required scorers + private Scorer makeCountingSumScorerNoReq(boolean disableCoord) throws IOException { // No required scorers // minNrShouldMatch optional scorers are required, but at least 1 int nrOptRequired = (minNrShouldMatch < 1) ? 1 : minNrShouldMatch; Scorer requiredCountingSumScorer; @@ -219,26 +217,25 @@ class BooleanScorer2 extends Scorer { else if (optionalScorers.size() == 1) requiredCountingSumScorer = new SingleMatchScorer(optionalScorers.get(0)); else { - requiredCountingSumScorer = countingConjunctionSumScorer(disableCoord, similarity, optionalScorers); + requiredCountingSumScorer = countingConjunctionSumScorer(disableCoord, optionalScorers); } return addProhibitedScorers(requiredCountingSumScorer); } - private Scorer makeCountingSumScorerSomeReq(boolean disableCoord, Similarity similarity) throws IOException { // At least one required scorer. + private Scorer makeCountingSumScorerSomeReq(boolean disableCoord) throws IOException { // At least one required scorer. if (optionalScorers.size() == minNrShouldMatch) { // all optional scorers also required. ArrayList allReq = new ArrayList(requiredScorers); allReq.addAll(optionalScorers); - return addProhibitedScorers(countingConjunctionSumScorer(disableCoord, similarity, allReq)); + return addProhibitedScorers(countingConjunctionSumScorer(disableCoord, allReq)); } else { // optionalScorers.size() > minNrShouldMatch, and at least one required scorer Scorer requiredCountingSumScorer = requiredScorers.size() == 1 ? new SingleMatchScorer(requiredScorers.get(0)) - : countingConjunctionSumScorer(disableCoord, similarity, requiredScorers); + : countingConjunctionSumScorer(disableCoord, requiredScorers); if (minNrShouldMatch > 0) { // use a required disjunction scorer over the optional scorers return addProhibitedScorers( dualConjunctionSumScorer( // non counting disableCoord, - similarity, requiredCountingSumScorer, countingDisjunctionSumScorer( optionalScorers, diff --git a/lucene/src/java/org/apache/lucene/search/ConstantScoreQuery.java b/lucene/src/java/org/apache/lucene/search/ConstantScoreQuery.java index 2e67f94cf3c..5aa78b4f1a4 100644 --- a/lucene/src/java/org/apache/lucene/search/ConstantScoreQuery.java +++ b/lucene/src/java/org/apache/lucene/search/ConstantScoreQuery.java @@ -102,7 +102,7 @@ public class ConstantScoreQuery extends Query { private float queryWeight; public ConstantWeight(IndexSearcher searcher) throws IOException { - this.similarity = getSimilarity(searcher); + this.similarity = searcher.getSimilarity(); this.innerWeight = (query == null) ? null : query.createWeight(searcher); } diff --git a/lucene/src/java/org/apache/lucene/search/FilteredQuery.java b/lucene/src/java/org/apache/lucene/search/FilteredQuery.java index f2559e67a36..e273d37e426 100644 --- a/lucene/src/java/org/apache/lucene/search/FilteredQuery.java +++ b/lucene/src/java/org/apache/lucene/search/FilteredQuery.java @@ -62,7 +62,7 @@ extends Query { @Override public Weight createWeight(final IndexSearcher searcher) throws IOException { final Weight weight = query.createWeight (searcher); - final Similarity similarity = query.getSimilarity(searcher); + final Similarity similarity = searcher.getSimilarity(); return new Weight() { private float value; diff --git a/lucene/src/java/org/apache/lucene/search/MultiPhraseQuery.java b/lucene/src/java/org/apache/lucene/search/MultiPhraseQuery.java index 79122c2c0a6..06a9d7bb91d 100644 --- a/lucene/src/java/org/apache/lucene/search/MultiPhraseQuery.java +++ b/lucene/src/java/org/apache/lucene/search/MultiPhraseQuery.java @@ -137,7 +137,7 @@ public class MultiPhraseQuery extends Query { public MultiPhraseWeight(IndexSearcher searcher) throws IOException { - this.similarity = getSimilarity(searcher); + this.similarity = searcher.getSimilarity(); // compute idf final int maxDoc = searcher.maxDoc(); diff --git a/lucene/src/java/org/apache/lucene/search/PhraseQuery.java b/lucene/src/java/org/apache/lucene/search/PhraseQuery.java index ce86931f5df..313bf7331fa 100644 --- a/lucene/src/java/org/apache/lucene/search/PhraseQuery.java +++ b/lucene/src/java/org/apache/lucene/search/PhraseQuery.java @@ -146,7 +146,7 @@ public class PhraseQuery extends Query { public PhraseWeight(IndexSearcher searcher) throws IOException { - this.similarity = getSimilarity(searcher); + this.similarity = searcher.getSimilarity(); idfExp = similarity.idfExplain(terms, searcher); idf = idfExp.getIdf(); diff --git a/lucene/src/java/org/apache/lucene/search/Query.java b/lucene/src/java/org/apache/lucene/search/Query.java index 8cffc52d2f4..6c8f9b8af8c 100644 --- a/lucene/src/java/org/apache/lucene/search/Query.java +++ b/lucene/src/java/org/apache/lucene/search/Query.java @@ -98,7 +98,7 @@ public abstract class Query implements java.io.Serializable, Cloneable { Query query = searcher.rewrite(this); Weight weight = query.createWeight(searcher); float sum = weight.sumOfSquaredWeights(); - float norm = getSimilarity(searcher).queryNorm(sum); + float norm = searcher.getSimilarity().queryNorm(sum); if (Float.isInfinite(norm) || Float.isNaN(norm)) norm = 1.0f; weight.normalize(norm); @@ -124,15 +124,6 @@ public abstract class Query implements java.io.Serializable, Cloneable { // needs to be implemented by query subclasses throw new UnsupportedOperationException(); } - - - /** Expert: Returns the Similarity implementation to be used for this query. - * Subclasses may override this method to specify their own Similarity - * implementation, perhaps one that delegates through that of the Searcher. - * By default the Searcher's Similarity implementation is returned.*/ - public Similarity getSimilarity(IndexSearcher searcher) { - return searcher.getSimilarity(); - } /** Returns a clone of this query. */ @Override diff --git a/lucene/src/java/org/apache/lucene/search/TermQuery.java b/lucene/src/java/org/apache/lucene/search/TermQuery.java index 798fcb082a7..5dc9514e5a0 100644 --- a/lucene/src/java/org/apache/lucene/search/TermQuery.java +++ b/lucene/src/java/org/apache/lucene/search/TermQuery.java @@ -54,7 +54,7 @@ public class TermQuery extends Query { throws IOException { assert termStates != null : "PerReaderTermState must not be null"; this.termStates = termStates; - this.similarity = getSimilarity(searcher); + this.similarity = searcher.getSimilarity(); if (docFreq != -1) { idfExp = similarity.idfExplain(term, searcher, docFreq); } else { diff --git a/lucene/src/java/org/apache/lucene/search/function/CustomScoreQuery.java b/lucene/src/java/org/apache/lucene/search/function/CustomScoreQuery.java index a775d040b33..7bd1b715f8b 100755 --- a/lucene/src/java/org/apache/lucene/search/function/CustomScoreQuery.java +++ b/lucene/src/java/org/apache/lucene/search/function/CustomScoreQuery.java @@ -189,7 +189,7 @@ public class CustomScoreQuery extends Query { boolean qStrict; public CustomWeight(IndexSearcher searcher) throws IOException { - this.similarity = getSimilarity(searcher); + this.similarity = searcher.getSimilarity(); this.subQueryWeight = subQuery.weight(searcher); this.valSrcWeights = new Weight[valSrcQueries.length]; for(int i = 0; i < valSrcQueries.length; i++) { diff --git a/lucene/src/java/org/apache/lucene/search/function/ValueSourceQuery.java b/lucene/src/java/org/apache/lucene/search/function/ValueSourceQuery.java index 22364163015..64971a7bc76 100644 --- a/lucene/src/java/org/apache/lucene/search/function/ValueSourceQuery.java +++ b/lucene/src/java/org/apache/lucene/search/function/ValueSourceQuery.java @@ -69,7 +69,7 @@ public class ValueSourceQuery extends Query { float queryWeight; public ValueSourceWeight(IndexSearcher searcher) { - this.similarity = getSimilarity(searcher); + this.similarity = searcher.getSimilarity(); } /*(non-Javadoc) @see org.apache.lucene.search.Weight#getQuery() */ diff --git a/lucene/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java b/lucene/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java index 16c88f30dee..be130bc4eb4 100644 --- a/lucene/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java +++ b/lucene/src/java/org/apache/lucene/search/spans/FieldMaskingSpanQuery.java @@ -106,11 +106,6 @@ public class FieldMaskingSpanQuery extends SpanQuery { return maskedQuery.createWeight(searcher); } - @Override - public Similarity getSimilarity(IndexSearcher searcher) { - return maskedQuery.getSimilarity(searcher); - } - @Override public Query rewrite(IndexReader reader) throws IOException { FieldMaskingSpanQuery clone = null; diff --git a/lucene/src/java/org/apache/lucene/search/spans/SpanWeight.java b/lucene/src/java/org/apache/lucene/search/spans/SpanWeight.java index f60564189da..427abfbbcb4 100644 --- a/lucene/src/java/org/apache/lucene/search/spans/SpanWeight.java +++ b/lucene/src/java/org/apache/lucene/search/spans/SpanWeight.java @@ -42,7 +42,7 @@ public class SpanWeight extends Weight { public SpanWeight(SpanQuery query, IndexSearcher searcher) throws IOException { - this.similarity = query.getSimilarity(searcher); + this.similarity = searcher.getSimilarity(); this.query = query; terms=new HashSet(); diff --git a/lucene/src/test/org/apache/lucene/search/TestBooleanScorer.java b/lucene/src/test/org/apache/lucene/search/TestBooleanScorer.java index 4628e911773..2e6c52a9b90 100644 --- a/lucene/src/test/org/apache/lucene/search/TestBooleanScorer.java +++ b/lucene/src/test/org/apache/lucene/search/TestBooleanScorer.java @@ -25,6 +25,7 @@ import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; +import org.apache.lucene.search.BooleanQuery.BooleanWeight; import org.apache.lucene.store.Directory; import org.apache.lucene.util.LuceneTestCase; @@ -68,6 +69,13 @@ public class TestBooleanScorer extends LuceneTestCase // 'more' variable to work properly, and this test ensures that if the logic // changes, we have a test to back it up. + Directory directory = newDirectory(); + RandomIndexWriter writer = new RandomIndexWriter(random, directory); + writer.commit(); + IndexReader ir = writer.getReader(); + writer.close(); + IndexSearcher searcher = new IndexSearcher(ir); + Similarity sim = Similarity.getDefault(); Scorer[] scorers = new Scorer[] {new Scorer(sim) { private int doc = -1; @@ -83,10 +91,15 @@ public class TestBooleanScorer extends LuceneTestCase } }}; - BooleanScorer bs = new BooleanScorer(null, false, sim, 1, Arrays.asList(scorers), null, scorers.length); + BooleanWeight weight = (BooleanWeight) new BooleanQuery().createWeight(searcher); + BooleanScorer bs = new BooleanScorer(weight, false, 1, Arrays.asList(scorers), null, scorers.length); assertEquals("should have received 3000", 3000, bs.nextDoc()); assertEquals("should have received NO_MORE_DOCS", DocIdSetIterator.NO_MORE_DOCS, bs.nextDoc()); + searcher.close(); + ir.close(); + directory.close(); + } } diff --git a/lucene/src/test/org/apache/lucene/search/spans/TestSpans.java b/lucene/src/test/org/apache/lucene/search/spans/TestSpans.java index 09fba717028..dfabb4f0e5d 100644 --- a/lucene/src/test/org/apache/lucene/search/spans/TestSpans.java +++ b/lucene/src/test/org/apache/lucene/search/spans/TestSpans.java @@ -410,20 +410,21 @@ public class TestSpans extends LuceneTestCase { } }; - SpanNearQuery snq = new SpanNearQuery( + final Similarity oldSim = searcher.getSimilarity(); + Scorer spanScorer; + try { + searcher.setSimilarity(sim); + SpanNearQuery snq = new SpanNearQuery( new SpanQuery[] { makeSpanTermQuery("t1"), makeSpanTermQuery("t2") }, slop, - ordered) { - @Override - public Similarity getSimilarity(IndexSearcher s) { - return sim; - } - }; - - Scorer spanScorer = snq.weight(searcher).scorer(new AtomicReaderContext(new SlowMultiReaderWrapper(searcher.getIndexReader())), ScorerContext.def()); + ordered); + spanScorer = snq.weight(searcher).scorer(new AtomicReaderContext(new SlowMultiReaderWrapper(searcher.getIndexReader())), ScorerContext.def()); + } finally { + searcher.setSimilarity(oldSim); + } assertTrue("first doc", spanScorer.nextDoc() != DocIdSetIterator.NO_MORE_DOCS); assertEquals("first doc number", spanScorer.docID(), 11); float score = spanScorer.score(); diff --git a/solr/src/java/org/apache/solr/schema/LatLonType.java b/solr/src/java/org/apache/solr/schema/LatLonType.java index 7ffdbf60524..9045d9e0619 100644 --- a/solr/src/java/org/apache/solr/schema/LatLonType.java +++ b/solr/src/java/org/apache/solr/schema/LatLonType.java @@ -371,7 +371,7 @@ class SpatialDistanceQuery extends Query { @Override public Scorer scorer(AtomicReaderContext context, ScorerContext scorerContext) throws IOException { - return new SpatialScorer(getSimilarity(searcher), context, this); + return new SpatialScorer(searcher.getSimilarity(), context, this); } @Override diff --git a/solr/src/java/org/apache/solr/search/SolrConstantScoreQuery.java b/solr/src/java/org/apache/solr/search/SolrConstantScoreQuery.java index 6e231f8f2f6..9df9bec0ac7 100755 --- a/solr/src/java/org/apache/solr/search/SolrConstantScoreQuery.java +++ b/solr/src/java/org/apache/solr/search/SolrConstantScoreQuery.java @@ -61,7 +61,7 @@ public class SolrConstantScoreQuery extends ConstantScoreQuery { private Map context; public ConstantWeight(IndexSearcher searcher) throws IOException { - this.similarity = getSimilarity(searcher); + this.similarity = searcher.getSimilarity(); this.context = ValueSource.newContext(searcher); if (filter instanceof SolrFilter) ((SolrFilter)filter).createWeight(context, searcher); diff --git a/solr/src/java/org/apache/solr/search/function/BoostedQuery.java b/solr/src/java/org/apache/solr/search/function/BoostedQuery.java index a8d4872b1e8..3564d9208c8 100755 --- a/solr/src/java/org/apache/solr/search/function/BoostedQuery.java +++ b/solr/src/java/org/apache/solr/search/function/BoostedQuery.java @@ -96,7 +96,7 @@ public class BoostedQuery extends Query { if(subQueryScorer == null) { return null; } - return new BoostedQuery.CustomScorer(getSimilarity(searcher), context, this, subQueryScorer, boostVal); + return new BoostedQuery.CustomScorer(searcher.getSimilarity(), context, this, subQueryScorer, boostVal); } @Override diff --git a/solr/src/java/org/apache/solr/search/function/FunctionQuery.java b/solr/src/java/org/apache/solr/search/function/FunctionQuery.java index b82ccaf21eb..44eb99ebc54 100644 --- a/solr/src/java/org/apache/solr/search/function/FunctionQuery.java +++ b/solr/src/java/org/apache/solr/search/function/FunctionQuery.java @@ -95,7 +95,7 @@ public class FunctionQuery extends Query { @Override public Scorer scorer(AtomicReaderContext context, ScorerContext scorerContext) throws IOException { - return new AllScorer(getSimilarity(searcher), context, this); + return new AllScorer(searcher.getSimilarity(), context, this); } @Override