Index: solr/src/java/org/apache/solr/schema/LatLonType.java =================================================================== --- solr/src/java/org/apache/solr/schema/LatLonType.java (revision 1061067) +++ solr/src/java/org/apache/solr/schema/LatLonType.java (working copy) @@ -371,7 +371,7 @@ @Override public Scorer scorer(AtomicReaderContext context, ScorerContext scorerContext) throws IOException { - return new SpatialScorer(searcher.getSimilarity(), context, this); + return new SpatialScorer(context, this); } @Override @@ -404,8 +404,8 @@ int lastDistDoc; double lastDist; - public SpatialScorer(Similarity similarity, AtomicReaderContext readerContext, SpatialWeight w) throws IOException { - super(similarity); + public SpatialScorer(AtomicReaderContext readerContext, SpatialWeight w) throws IOException { + super(w); this.weight = w; this.qWeight = w.getValue(); this.reader = readerContext.reader; Index: solr/src/java/org/apache/solr/search/function/FunctionQuery.java =================================================================== --- solr/src/java/org/apache/solr/search/function/FunctionQuery.java (revision 1061067) +++ solr/src/java/org/apache/solr/search/function/FunctionQuery.java (working copy) @@ -95,7 +95,7 @@ @Override public Scorer scorer(AtomicReaderContext context, ScorerContext scorerContext) throws IOException { - return new AllScorer(searcher.getSimilarity(), context, this); + return new AllScorer(context, this); } @Override @@ -114,8 +114,8 @@ final boolean hasDeletions; final Bits delDocs; - public AllScorer(Similarity similarity, AtomicReaderContext context, FunctionWeight w) throws IOException { - super(similarity); + public AllScorer(AtomicReaderContext context, FunctionWeight w) throws IOException { + super(w); this.weight = w; this.qWeight = w.getValue(); this.reader = context.reader; Index: solr/src/java/org/apache/solr/search/function/BoostedQuery.java =================================================================== --- solr/src/java/org/apache/solr/search/function/BoostedQuery.java (revision 1061067) +++ solr/src/java/org/apache/solr/search/function/BoostedQuery.java (working copy) @@ -96,7 +96,7 @@ if(subQueryScorer == null) { return null; } - return new BoostedQuery.CustomScorer(searcher.getSimilarity(), context, this, subQueryScorer, boostVal); + return new BoostedQuery.CustomScorer(context, this, subQueryScorer, boostVal); } @Override @@ -123,9 +123,9 @@ private final DocValues vals; private final AtomicReaderContext readerContext; - private CustomScorer(Similarity similarity, AtomicReaderContext readerContext, BoostedQuery.BoostedWeight w, + private CustomScorer(AtomicReaderContext readerContext, BoostedQuery.BoostedWeight w, Scorer scorer, ValueSource vs) throws IOException { - super(similarity); + super(w); this.weight = w; this.qWeight = w.getValue(); this.scorer = scorer; Index: solr/src/java/org/apache/solr/search/SolrConstantScoreQuery.java =================================================================== --- solr/src/java/org/apache/solr/search/SolrConstantScoreQuery.java (revision 1061067) +++ solr/src/java/org/apache/solr/search/SolrConstantScoreQuery.java (working copy) @@ -91,13 +91,13 @@ @Override public Scorer scorer(AtomicReaderContext context, ScorerContext scorerContext) throws IOException { - return new ConstantScorer(similarity, context, this); + return new ConstantScorer(context, this); } @Override public Explanation explain(AtomicReaderContext context, int doc) throws IOException { - ConstantScorer cs = new ConstantScorer(similarity, context, this); + ConstantScorer cs = new ConstantScorer(context, this); boolean exists = cs.docIdSetIterator.advance(doc) == doc; ComplexExplanation result = new ComplexExplanation(); @@ -124,8 +124,8 @@ final float theScore; int doc = -1; - public ConstantScorer(Similarity similarity, AtomicReaderContext context, ConstantWeight w) throws IOException { - super(similarity); + public ConstantScorer(AtomicReaderContext context, ConstantWeight w) throws IOException { + super(w); theScore = w.getValue(); DocIdSet docIdSet = filter instanceof SolrFilter ? ((SolrFilter)filter).getDocIdSet(w.context, context) : filter.getDocIdSet(context); if (docIdSet == null) { Index: lucene/src/test/org/apache/lucene/search/TestBooleanScorer.java =================================================================== --- lucene/src/test/org/apache/lucene/search/TestBooleanScorer.java (revision 1061067) +++ lucene/src/test/org/apache/lucene/search/TestBooleanScorer.java (working copy) @@ -75,9 +75,8 @@ IndexReader ir = writer.getReader(); writer.close(); IndexSearcher searcher = new IndexSearcher(ir); - - Similarity sim = Similarity.getDefault(); - Scorer[] scorers = new Scorer[] {new Scorer(sim) { + BooleanWeight weight = (BooleanWeight) new BooleanQuery().createWeight(searcher); + Scorer[] scorers = new Scorer[] {new Scorer(weight) { private int doc = -1; @Override public float score() throws IOException { return 0; } @Override public int docID() { return doc; } @@ -91,7 +90,7 @@ } }}; - 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()); Index: lucene/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java =================================================================== --- lucene/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java (revision 1061067) +++ lucene/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java (working copy) @@ -19,7 +19,11 @@ import java.io.IOException; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.IndexReader.AtomicReaderContext; +import org.apache.lucene.index.Term; +import org.apache.lucene.store.Directory; import org.apache.lucene.util.LuceneTestCase; public class TestScoreCachingWrappingScorer extends LuceneTestCase { @@ -28,8 +32,8 @@ private int idx = 0; private int doc = -1; - public SimpleScorer() { - super(null); + public SimpleScorer(Weight weight) { + super(weight); } @Override public float score() throws IOException { @@ -95,8 +99,14 @@ 8.108544f, 4.961808f, 2.2423935f, 7.285586f, 4.6699767f }; public void testGetScores() throws Exception { - - Scorer s = new SimpleScorer(); + Directory directory = newDirectory(); + RandomIndexWriter writer = new RandomIndexWriter(random, directory); + writer.commit(); + IndexReader ir = writer.getReader(); + writer.close(); + IndexSearcher searcher = new IndexSearcher(ir); + Weight fake = new TermQuery(new Term("fake", "weight")).createWeight(searcher); + Scorer s = new SimpleScorer(fake); ScoreCachingCollector scc = new ScoreCachingCollector(scores.length); scc.setScorer(s); @@ -109,7 +119,9 @@ for (int i = 0; i < scores.length; i++) { assertEquals(scores[i], scc.mscores[i], 0f); } - + searcher.close(); + ir.close(); + directory.close(); } } Index: lucene/src/test/org/apache/lucene/search/JustCompileSearch.java =================================================================== --- lucene/src/test/org/apache/lucene/search/JustCompileSearch.java (revision 1061067) +++ lucene/src/test/org/apache/lucene/search/JustCompileSearch.java (working copy) @@ -210,8 +210,8 @@ static final class JustCompileScorer extends Scorer { - protected JustCompileScorer(Similarity similarity) { - super(similarity); + protected JustCompileScorer(Weight weight) { + super(weight); } @Override Index: lucene/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java =================================================================== --- lucene/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java (revision 1061067) +++ lucene/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java (working copy) @@ -19,6 +19,10 @@ import java.io.IOException; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.RandomIndexWriter; +import org.apache.lucene.index.Term; +import org.apache.lucene.store.Directory; import org.apache.lucene.util.LuceneTestCase; public class TestPositiveScoresOnlyCollector extends LuceneTestCase { @@ -26,8 +30,8 @@ private static final class SimpleScorer extends Scorer { private int idx = -1; - public SimpleScorer() { - super(null); + public SimpleScorer(Weight weight) { + super(weight); } @Override public float score() throws IOException { @@ -65,7 +69,14 @@ } } - Scorer s = new SimpleScorer(); + Directory directory = newDirectory(); + RandomIndexWriter writer = new RandomIndexWriter(random, directory); + writer.commit(); + IndexReader ir = writer.getReader(); + writer.close(); + IndexSearcher searcher = new IndexSearcher(ir); + Weight fake = new TermQuery(new Term("fake", "weight")).createWeight(searcher); + Scorer s = new SimpleScorer(fake); TopDocsCollector tdc = TopScoreDocCollector.create(scores.length, true); Collector c = new PositiveScoresOnlyCollector(tdc); c.setScorer(s); @@ -78,6 +89,9 @@ for (int i = 0; i < sd.length; i++) { assertTrue("only positive scores should return: " + sd[i].score, sd[i].score > 0); } + searcher.close(); + ir.close(); + directory.close(); } } Index: lucene/src/java/org/apache/lucene/search/ConstantScoreQuery.java =================================================================== --- lucene/src/java/org/apache/lucene/search/ConstantScoreQuery.java (revision 1061067) +++ lucene/src/java/org/apache/lucene/search/ConstantScoreQuery.java (working copy) @@ -97,12 +97,10 @@ protected class ConstantWeight extends Weight { private final Weight innerWeight; - private final Similarity similarity; private float queryNorm; private float queryWeight; public ConstantWeight(IndexSearcher searcher) throws IOException { - this.similarity = searcher.getSimilarity(); this.innerWeight = (query == null) ? null : query.createWeight(searcher); } @@ -148,7 +146,7 @@ } if (disi == null) return null; - return new ConstantScorer(similarity, disi, this); + return new ConstantScorer(disi, this); } @Override @@ -181,8 +179,8 @@ final DocIdSetIterator docIdSetIterator; final float theScore; - public ConstantScorer(Similarity similarity, DocIdSetIterator docIdSetIterator, Weight w) throws IOException { - super(similarity,w); + public ConstantScorer(DocIdSetIterator docIdSetIterator, Weight w) throws IOException { + super(w); theScore = w.getValue(); this.docIdSetIterator = docIdSetIterator; } @@ -212,8 +210,7 @@ @Override public void setScorer(Scorer scorer) throws IOException { // we must wrap again here, but using the scorer passed in as parameter: - collector.setScorer(new ConstantScorer(ConstantScorer.this.getSimilarity(), - scorer, ConstantScorer.this.weight)); + collector.setScorer(new ConstantScorer(scorer, ConstantScorer.this.weight)); } @Override Index: lucene/src/java/org/apache/lucene/search/BooleanScorer2.java =================================================================== --- lucene/src/java/org/apache/lucene/search/BooleanScorer2.java (revision 1061067) +++ lucene/src/java/org/apache/lucene/search/BooleanScorer2.java (working copy) @@ -83,7 +83,7 @@ */ public BooleanScorer2(BooleanWeight weight, boolean disableCoord, int minNrShouldMatch, List required, List prohibited, List optional, int maxCoord) throws IOException { - super(null, weight); // Similarity not used + super(weight); if (minNrShouldMatch < 0) { throw new IllegalArgumentException("Minimum number of optional scorers should not be negative"); } @@ -108,7 +108,7 @@ private float lastDocScore = Float.NaN; SingleMatchScorer(Scorer scorer) { - super(null); // No similarity used. + super(scorer.weight); this.scorer = scorer; } @@ -144,7 +144,7 @@ private Scorer countingDisjunctionSumScorer(final List scorers, int minNrShouldMatch) throws IOException { // each scorer from the list counted as a single matcher - return new DisjunctionSumScorer(scorers, minNrShouldMatch) { + return new DisjunctionSumScorer(weight, scorers, minNrShouldMatch) { private int lastScoredDoc = -1; // Save the score of lastScoredDoc, so that we don't compute it more than // once in score(). @@ -167,7 +167,7 @@ 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 : ((BooleanWeight)weight).coord(requiredScorers.size(), requiredScorers.size()), requiredScorers) { + return new ConjunctionScorer(weight, 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(). @@ -192,7 +192,7 @@ private Scorer dualConjunctionSumScorer(boolean disableCoord, Scorer req1, Scorer req2) throws IOException { // non counting. - return new ConjunctionScorer(disableCoord ? 1.0f : ((BooleanWeight)weight).coord(2, 2), req1, req2); + return new ConjunctionScorer(weight, 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 @@ -262,7 +262,7 @@ : new ReqExclScorer(requiredCountingSumScorer, ((prohibitedScorers.size() == 1) ? prohibitedScorers.get(0) - : new DisjunctionSumScorer(prohibitedScorers))); + : new DisjunctionSumScorer(weight, prohibitedScorers))); } /** Scores and collects all matching documents. Index: lucene/src/java/org/apache/lucene/search/MatchAllDocsQuery.java =================================================================== --- lucene/src/java/org/apache/lucene/search/MatchAllDocsQuery.java (revision 1061067) +++ lucene/src/java/org/apache/lucene/search/MatchAllDocsQuery.java (working copy) @@ -51,10 +51,12 @@ private int doc = -1; private final int maxDoc; private final Bits delDocs; + private final Similarity similarity; MatchAllScorer(IndexReader reader, Similarity similarity, Weight w, byte[] norms) throws IOException { - super(similarity,w); + super(w); + this.similarity = similarity; delDocs = reader.getDeletedDocs(); score = w.getValue(); maxDoc = reader.maxDoc(); @@ -80,7 +82,7 @@ @Override public float score() { - return norms == null ? score : score * getSimilarity().decodeNormValue(norms[docID()]); + return norms == null ? score : score * similarity.decodeNormValue(norms[docID()]); } @Override Index: lucene/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java =================================================================== --- lucene/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java (revision 1061067) +++ lucene/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java (working copy) @@ -95,15 +95,12 @@ * change suddenly in the next release.

*/ protected class DisjunctionMaxWeight extends Weight { - /** The Similarity implementation. */ - protected Similarity similarity; /** The Weights for our subqueries, in 1-1 correspondence with disjuncts */ protected ArrayList weights = new ArrayList(); // The Weight's for our subqueries, in 1-1 correspondence with disjuncts /* Construct the Weight for this Query searched by searcher. Recursively construct subquery weights. */ public DisjunctionMaxWeight(IndexSearcher searcher) throws IOException { - this.similarity = searcher.getSimilarity(); for (Query disjunctQuery : disjuncts) { weights.add(disjunctQuery.createWeight(searcher)); } @@ -152,7 +149,7 @@ } } if (idx == 0) return null; // all scorers did not have documents - DisjunctionMaxScorer result = new DisjunctionMaxScorer(tieBreakerMultiplier, similarity, scorers, idx); + DisjunctionMaxScorer result = new DisjunctionMaxScorer(this, tieBreakerMultiplier, scorers, idx); return result; } Index: lucene/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java =================================================================== --- lucene/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java (revision 1061067) +++ lucene/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java (working copy) @@ -153,7 +153,6 @@ Spans spans; protected float payloadScore; private int payloadsSeen; - Similarity similarity = getSimilarity(); protected PayloadNearSpanScorer(Spans spans, Weight weight, Similarity similarity, byte[] norms) throws IOException { @@ -211,7 +210,7 @@ payloadsSeen = 0; do { int matchLength = spans.end() - spans.start(); - freq += getSimilarity().sloppyFreq(matchLength); + freq += similarity.sloppyFreq(matchLength); Spans[] spansArr = new Spans[1]; spansArr[0] = spans; getPayloads(spansArr); Index: lucene/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java =================================================================== --- lucene/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java (revision 1061067) +++ lucene/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java (working copy) @@ -100,12 +100,11 @@ freq = 0.0f; payloadScore = 0; payloadsSeen = 0; - Similarity similarity1 = getSimilarity(); while (more && doc == spans.doc()) { int matchLength = spans.end() - spans.start(); - freq += similarity1.sloppyFreq(matchLength); - processPayload(similarity1); + freq += similarity.sloppyFreq(matchLength); + processPayload(similarity); more = spans.next();// this moves positions to the next match in this // document Index: lucene/src/java/org/apache/lucene/search/spans/SpanScorer.java =================================================================== --- lucene/src/java/org/apache/lucene/search/spans/SpanScorer.java (revision 1061067) +++ lucene/src/java/org/apache/lucene/search/spans/SpanScorer.java (working copy) @@ -36,10 +36,12 @@ protected int doc; protected float freq; - + protected final Similarity similarity; + protected SpanScorer(Spans spans, Weight weight, Similarity similarity, byte[] norms) throws IOException { - super(similarity, weight); + super(weight); + this.similarity = similarity; this.spans = spans; this.norms = norms; this.value = weight.getValue(); @@ -81,7 +83,7 @@ freq = 0.0f; do { int matchLength = spans.end() - spans.start(); - freq += getSimilarity().sloppyFreq(matchLength); + freq += similarity.sloppyFreq(matchLength); more = spans.next(); } while (more && (doc == spans.doc())); return true; @@ -92,8 +94,8 @@ @Override public float score() throws IOException { - float raw = getSimilarity().tf(freq) * value; // raw score - return norms == null? raw : raw * getSimilarity().decodeNormValue(norms[doc]); // normalize + float raw = similarity.tf(freq) * value; // raw score + return norms == null? raw : raw * similarity.decodeNormValue(norms[doc]); // normalize } @Override @@ -109,7 +111,7 @@ int expDoc = advance(doc); float phraseFreq = (expDoc == doc) ? freq : 0.0f; - tfExplanation.setValue(getSimilarity().tf(phraseFreq)); + tfExplanation.setValue(similarity.tf(phraseFreq)); tfExplanation.setDescription("tf(phraseFreq=" + phraseFreq + ")"); return tfExplanation; Index: lucene/src/java/org/apache/lucene/search/ConjunctionScorer.java =================================================================== --- lucene/src/java/org/apache/lucene/search/ConjunctionScorer.java (revision 1061067) +++ lucene/src/java/org/apache/lucene/search/ConjunctionScorer.java (working copy) @@ -29,12 +29,12 @@ private final float coord; private int lastDoc = -1; - public ConjunctionScorer(float coord, Collection scorers) throws IOException { - this(coord, scorers.toArray(new Scorer[scorers.size()])); + public ConjunctionScorer(Weight weight, float coord, Collection scorers) throws IOException { + this(weight, coord, scorers.toArray(new Scorer[scorers.size()])); } - public ConjunctionScorer(float coord, Scorer... scorers) throws IOException { - super(null); + public ConjunctionScorer(Weight weight, float coord, Scorer... scorers) throws IOException { + super(weight); this.scorers = scorers; this.coord = coord; Index: lucene/src/java/org/apache/lucene/search/SloppyPhraseScorer.java =================================================================== --- lucene/src/java/org/apache/lucene/search/SloppyPhraseScorer.java (revision 1061067) +++ lucene/src/java/org/apache/lucene/search/SloppyPhraseScorer.java (working copy) @@ -78,7 +78,7 @@ int matchLength = end - start; if (matchLength <= slop) - freq += getSimilarity().sloppyFreq(matchLength); // score match + freq += similarity.sloppyFreq(matchLength); // score match if (pp.position > end) end = pp.position; Index: lucene/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java =================================================================== --- lucene/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java (revision 1061067) +++ lucene/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java (working copy) @@ -43,19 +43,15 @@ * @param tieBreakerMultiplier * Multiplier applied to non-maximum-scoring subqueries for a * document as they are summed into the result. - * @param similarity - * -- not used since our definition involves neither coord nor terms - * directly * @param subScorers * The sub scorers this Scorer should iterate on * @param numScorers * The actual number of scorers to iterate on. Note that the array's * length may be larger than the actual number of scorers. */ - public DisjunctionMaxScorer(float tieBreakerMultiplier, - Similarity similarity, Scorer[] subScorers, int numScorers) throws IOException { - super(similarity); - + public DisjunctionMaxScorer(Weight weight, float tieBreakerMultiplier, + Scorer[] subScorers, int numScorers) throws IOException { + super(weight); this.tieBreakerMultiplier = tieBreakerMultiplier; // The passed subScorers array includes only scorers which have documents // (DisjunctionMaxQuery takes care of that), and their nextDoc() was already Index: lucene/src/java/org/apache/lucene/search/FilteredQuery.java =================================================================== --- lucene/src/java/org/apache/lucene/search/FilteredQuery.java (revision 1061067) +++ lucene/src/java/org/apache/lucene/search/FilteredQuery.java (working copy) @@ -62,7 +62,6 @@ @Override public Weight createWeight(final IndexSearcher searcher) throws IOException { final Weight weight = query.createWeight (searcher); - final Similarity similarity = searcher.getSimilarity(); return new Weight() { private float value; @@ -127,7 +126,7 @@ return null; } - return new Scorer(similarity, this) { + return new Scorer(this) { private int doc = -1; Index: lucene/src/java/org/apache/lucene/search/PhraseScorer.java =================================================================== --- lucene/src/java/org/apache/lucene/search/PhraseScorer.java (revision 1061067) +++ lucene/src/java/org/apache/lucene/search/PhraseScorer.java (working copy) @@ -40,9 +40,12 @@ private float freq; //phrase frequency in current doc as computed by phraseFreq(). + protected final Similarity similarity; + PhraseScorer(Weight weight, PhraseQuery.PostingsAndFreq[] postings, Similarity similarity, byte[] norms) { - super(similarity, weight); + super(weight); + this.similarity = similarity; this.norms = norms; this.value = weight.getValue(); @@ -105,8 +108,8 @@ @Override public float score() throws IOException { //System.out.println("scoring " + first.doc); - float raw = getSimilarity().tf(freq) * value; // raw score - return norms == null ? raw : raw * getSimilarity().decodeNormValue(norms[first.doc]); // normalize + float raw = similarity.tf(freq) * value; // raw score + return norms == null ? raw : raw * similarity.decodeNormValue(norms[first.doc]); // normalize } @Override Index: lucene/src/java/org/apache/lucene/search/function/ValueSourceQuery.java =================================================================== --- lucene/src/java/org/apache/lucene/search/function/ValueSourceQuery.java (revision 1061067) +++ lucene/src/java/org/apache/lucene/search/function/ValueSourceQuery.java (working copy) @@ -64,12 +64,10 @@ } class ValueSourceWeight extends Weight { - Similarity similarity; float queryNorm; float queryWeight; public ValueSourceWeight(IndexSearcher searcher) { - this.similarity = searcher.getSimilarity(); } /*(non-Javadoc) @see org.apache.lucene.search.Weight#getQuery() */ @@ -100,7 +98,7 @@ @Override public Scorer scorer(AtomicReaderContext context, ScorerContext scorerContext) throws IOException { - return new ValueSourceScorer(similarity, context, this); + return new ValueSourceScorer(context, this); } /*(non-Javadoc) @see org.apache.lucene.search.Weight#explain(org.apache.lucene.index.IndexReader, int) */ @@ -133,8 +131,8 @@ private int doc = -1; // constructor - private ValueSourceScorer(Similarity similarity, AtomicReaderContext context, ValueSourceWeight w) throws IOException { - super(similarity,w); + private ValueSourceScorer(AtomicReaderContext context, ValueSourceWeight w) throws IOException { + super(w); final IndexReader reader = context.reader; qWeight = w.getValue(); // this is when/where the values are first created. Index: lucene/src/java/org/apache/lucene/search/function/CustomScoreQuery.java =================================================================== --- lucene/src/java/org/apache/lucene/search/function/CustomScoreQuery.java (revision 1061067) +++ lucene/src/java/org/apache/lucene/search/function/CustomScoreQuery.java (working copy) @@ -183,13 +183,11 @@ //=========================== W E I G H T ============================ private class CustomWeight extends Weight { - Similarity similarity; Weight subQueryWeight; Weight[] valSrcWeights; boolean qStrict; public CustomWeight(IndexSearcher searcher) throws IOException { - this.similarity = searcher.getSimilarity(); this.subQueryWeight = subQuery.weight(searcher); this.valSrcWeights = new Weight[valSrcQueries.length]; for(int i = 0; i < valSrcQueries.length; i++) { @@ -254,7 +252,7 @@ for(int i = 0; i < valSrcScorers.length; i++) { valSrcScorers[i] = valSrcWeights[i].scorer(context, scorerContext.scoreDocsInOrder(true)); } - return new CustomScorer(similarity, context.reader, this, subQueryScorer, valSrcScorers); + return new CustomScorer(context.reader, this, subQueryScorer, valSrcScorers); } @Override @@ -303,9 +301,9 @@ private float vScores[]; // reused in score() to avoid allocating this array for each doc // constructor - private CustomScorer(Similarity similarity, IndexReader reader, CustomWeight w, + private CustomScorer(IndexReader reader, CustomWeight w, Scorer subQueryScorer, Scorer[] valSrcScorers) throws IOException { - super(similarity,w); + super(w); this.qWeight = w.getValue(); this.subQueryScorer = subQueryScorer; this.valSrcScorers = valSrcScorers; Index: lucene/src/java/org/apache/lucene/search/ReqOptSumScorer.java =================================================================== --- lucene/src/java/org/apache/lucene/search/ReqOptSumScorer.java (revision 1061067) +++ lucene/src/java/org/apache/lucene/search/ReqOptSumScorer.java (working copy) @@ -38,7 +38,7 @@ Scorer reqScorer, Scorer optScorer) { - super(null); // No similarity used. + super(reqScorer.weight); this.reqScorer = reqScorer; this.optScorer = optScorer; } Index: lucene/src/java/org/apache/lucene/search/DisjunctionSumScorer.java =================================================================== --- lucene/src/java/org/apache/lucene/search/DisjunctionSumScorer.java (revision 1061067) +++ lucene/src/java/org/apache/lucene/search/DisjunctionSumScorer.java (working copy) @@ -67,8 +67,8 @@ *
When minimumNrMatchers equals the number of subScorers, * it more efficient to use ConjunctionScorer. */ - public DisjunctionSumScorer( List subScorers, int minimumNrMatchers) throws IOException { - super(null); + public DisjunctionSumScorer(Weight weight, List subScorers, int minimumNrMatchers) throws IOException { + super(weight); nrScorers = subScorers.size(); @@ -88,8 +88,8 @@ /** Construct a DisjunctionScorer, using one as the minimum number * of matching subscorers. */ - public DisjunctionSumScorer(List subScorers) throws IOException { - this(subScorers, 1); + public DisjunctionSumScorer(Weight weight, List subScorers) throws IOException { + this(weight, subScorers, 1); } /** Called the first time nextDoc() or advance() is called to Index: lucene/src/java/org/apache/lucene/search/BooleanScorer.java =================================================================== --- lucene/src/java/org/apache/lucene/search/BooleanScorer.java (revision 1061067) +++ lucene/src/java/org/apache/lucene/search/BooleanScorer.java (working copy) @@ -119,7 +119,7 @@ int doc = NO_MORE_DOCS; int freq; - public BucketScorer() { super(null); } + public BucketScorer(Weight weight) { super(weight); } @Override public int advance(int target) throws IOException { return NO_MORE_DOCS; } @@ -200,7 +200,7 @@ BooleanScorer(BooleanWeight weight, boolean disableCoord, int minNrShouldMatch, List optionalScorers, List prohibitedScorers, int maxCoord) throws IOException { - super(null, weight); // Similarity not used + super(weight); this.minNrShouldMatch = minNrShouldMatch; if (optionalScorers != null && optionalScorers.size() > 0) { @@ -233,7 +233,7 @@ public boolean score(Collector collector, int max, int firstDocID) throws IOException { boolean more; Bucket tmp; - BucketScorer bs = new BucketScorer(); + BucketScorer bs = new BucketScorer(weight); // The internal loop will set the score and doc before calling collect. collector.setScorer(bs); do { Index: lucene/src/java/org/apache/lucene/search/Scorer.java =================================================================== --- lucene/src/java/org/apache/lucene/search/Scorer.java (revision 1061067) +++ lucene/src/java/org/apache/lucene/search/Scorer.java (working copy) @@ -40,31 +40,16 @@ * with these scores. */ public abstract class Scorer extends DocIdSetIterator { - private final Similarity similarity; protected final Weight weight; - /** Constructs a Scorer. - * @param similarity The Similarity implementation used by this scorer. - */ - protected Scorer(Similarity similarity) { - this(similarity, null); - } - /** * Constructs a Scorer - * @param similarity The Similarity implementation used by this scorer. - * @param weight The scorers Weight + * @param weight The scorers Weight. */ - protected Scorer(Similarity similarity, Weight weight) { - this.similarity = similarity; + protected Scorer(Weight weight) { this.weight = weight; } - /** Returns the Similarity implementation used by this scorer. */ - public Similarity getSimilarity() { - return this.similarity; - } - /** Scores and collects all matching documents. * @param collector The collector to which all matching documents are passed. */ @@ -172,7 +157,7 @@ *

* Note: this method will throw {@link UnsupportedOperationException} if no * associated {@link Weight} instance is provided to - * {@link #Scorer(Similarity, Weight)} + * {@link #Scorer(Weight)} *

* * @lucene.experimental Index: lucene/src/java/org/apache/lucene/search/ScoreCachingWrappingScorer.java =================================================================== --- lucene/src/java/org/apache/lucene/search/ScoreCachingWrappingScorer.java (revision 1061067) +++ lucene/src/java/org/apache/lucene/search/ScoreCachingWrappingScorer.java (working copy) @@ -38,7 +38,7 @@ /** Creates a new instance by wrapping the given scorer. */ public ScoreCachingWrappingScorer(Scorer scorer) { - super(scorer.getSimilarity()); + super(scorer.weight); this.scorer = scorer; } @@ -46,11 +46,6 @@ public boolean score(Collector collector, int max, int firstDocID) throws IOException { return scorer.score(collector, max, firstDocID); } - - @Override - public Similarity getSimilarity() { - return scorer.getSimilarity(); - } @Override public float score() throws IOException { Index: lucene/src/java/org/apache/lucene/search/ReqExclScorer.java =================================================================== --- lucene/src/java/org/apache/lucene/search/ReqExclScorer.java (revision 1061067) +++ lucene/src/java/org/apache/lucene/search/ReqExclScorer.java (working copy) @@ -36,7 +36,7 @@ * @param exclDisi indicates exclusion. */ public ReqExclScorer(Scorer reqScorer, DocIdSetIterator exclDisi) { - super(null); // No similarity used. + super(reqScorer.weight); this.reqScorer = reqScorer; this.exclDisi = exclDisi; } Index: lucene/src/java/org/apache/lucene/search/ExactPhraseScorer.java =================================================================== --- lucene/src/java/org/apache/lucene/search/ExactPhraseScorer.java (revision 1061067) +++ lucene/src/java/org/apache/lucene/search/ExactPhraseScorer.java (working copy) @@ -60,9 +60,12 @@ private int docID = -1; private int freq; + private final Similarity similarity; + ExactPhraseScorer(Weight weight, PhraseQuery.PostingsAndFreq[] postings, Similarity similarity, byte[] norms) throws IOException { - super(similarity, weight); + super(weight); + this.similarity = similarity; this.norms = norms; this.value = weight.getValue(); @@ -87,7 +90,7 @@ } for (int i = 0; i < SCORE_CACHE_SIZE; i++) { - scoreCache[i] = getSimilarity().tf((float) i) * value; + scoreCache[i] = similarity.tf((float) i) * value; } } @@ -207,9 +210,9 @@ if (freq < SCORE_CACHE_SIZE) { raw = scoreCache[freq]; } else { - raw = getSimilarity().tf((float) freq) * value; + raw = similarity.tf((float) freq) * value; } - return norms == null ? raw : raw * getSimilarity().decodeNormValue(norms[docID]); // normalize + return norms == null ? raw : raw * similarity.decodeNormValue(norms[docID]); // normalize } private int phraseFreq() throws IOException { Index: lucene/src/java/org/apache/lucene/search/TermScorer.java =================================================================== --- lucene/src/java/org/apache/lucene/search/TermScorer.java (revision 1061067) +++ lucene/src/java/org/apache/lucene/search/TermScorer.java (working copy) @@ -38,7 +38,8 @@ private int[] docs; private int[] freqs; private final DocsEnum.BulkReadResult bulkResult; - + private final Similarity similarity; + /** * Construct a TermScorer. * @@ -53,15 +54,15 @@ * The field norms of the document fields for the Term. */ TermScorer(Weight weight, DocsEnum td, Similarity similarity, byte[] norms) { - super(similarity, weight); - + super(weight); + this.similarity = similarity; this.docsEnum = td; this.norms = norms; this.weightValue = weight.getValue(); bulkResult = td.getBulkResult(); for (int i = 0; i < SCORE_CACHE_SIZE; i++) - scoreCache[i] = getSimilarity().tf(i) * weightValue; + scoreCache[i] = similarity.tf(i) * weightValue; } @Override @@ -136,9 +137,9 @@ float raw = // compute tf(f)*weight freq < SCORE_CACHE_SIZE // check cache ? scoreCache[freq] // cache hit - : getSimilarity().tf(freq)*weightValue; // cache miss + : similarity.tf(freq)*weightValue; // cache miss - return norms == null ? raw : raw * getSimilarity().decodeNormValue(norms[doc]); // normalize for field + return norms == null ? raw : raw * similarity.decodeNormValue(norms[doc]); // normalize for field } /**