From d1203a28aabf99f16ba3891bc387261c92a7b9ae Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Tue, 12 Jul 2011 21:37:19 +0000 Subject: [PATCH] LUCENE-3299: refactoring of Similarity.sloppyFreq and scorePayload git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1145781 13f79535-47bb-0310-9956-ffa450edef68 --- lucene/CHANGES.txt | 2 +- lucene/MIGRATE.txt | 2 + .../lucene/search/DefaultSimilarity.java | 9 +++- .../lucene/search/MultiPhraseQuery.java | 3 +- .../org/apache/lucene/search/PhraseQuery.java | 2 +- .../org/apache/lucene/search/Similarity.java | 47 +++---------------- .../lucene/search/SloppyPhraseScorer.java | 6 +-- .../apache/lucene/search/TFIDFSimilarity.java | 39 +++++++++++++++ .../search/payloads/PayloadNearQuery.java | 22 ++++++--- .../search/payloads/PayloadTermQuery.java | 30 +++++------- .../lucene/search/spans/SpanScorer.java | 6 +-- .../lucene/search/spans/SpanWeight.java | 2 +- .../org/apache/lucene/index/TestOmitTf.java | 2 + .../lucene/search/JustCompileSearch.java | 5 -- .../lucene/search/TestDocValuesScoring.java | 16 +++++-- .../lucene/search/TestSimilarityProvider.java | 11 +++++ .../search/payloads/TestPayloadNearQuery.java | 5 +- .../search/payloads/TestPayloadTermQuery.java | 5 +- .../search/spans/JustCompileSearchSpans.java | 4 +- 19 files changed, 123 insertions(+), 95 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 041053935d1..7acde2d4522 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -156,7 +156,7 @@ Changes in backwards compatibility policy the queries module and can be found at o.a.l.queries.function. See MIGRATE.txt for more information (Chris Male) -* LUCENE-2392: Decoupled vector space scoring from Query/Weight/Scorer. If you +* LUCENE-2392, LUCENE-3299: Decoupled vector space scoring from Query/Weight/Scorer. If you extended Similarity directly before, you should extend TFIDFSimilarity instead. Similarity is now a lower-level API to implement other scoring algorithms. See MIGRATE.txt for more details. diff --git a/lucene/MIGRATE.txt b/lucene/MIGRATE.txt index 988293150d4..50bdbab51b0 100644 --- a/lucene/MIGRATE.txt +++ b/lucene/MIGRATE.txt @@ -393,6 +393,8 @@ LUCENE-1458, LUCENE-2111: Flexible Indexing the outer boost (topLevelBoost) and the norm. Weight.sumOfSquaredWeights has been renamed to Weight.getValueForNormalization(). + The scorePayload method now takes a BytesRef. It is never null. + * LUCENE-3283: Lucene's core o.a.l.queryParser QueryParsers have been consolidated into module/queryparser, where other QueryParsers from the codebase will also be placed. The following classes were moved: - o.a.l.queryParser.CharStream -> o.a.l.queryparser.classic.CharStream diff --git a/lucene/src/java/org/apache/lucene/search/DefaultSimilarity.java b/lucene/src/java/org/apache/lucene/search/DefaultSimilarity.java index 5e0ab442da4..bd0a90dcc97 100644 --- a/lucene/src/java/org/apache/lucene/search/DefaultSimilarity.java +++ b/lucene/src/java/org/apache/lucene/search/DefaultSimilarity.java @@ -1,6 +1,7 @@ package org.apache.lucene.search; import org.apache.lucene.index.FieldInvertState; +import org.apache.lucene.util.BytesRef; /** * Licensed to the Apache Software Foundation (ASF) under one or more @@ -51,7 +52,13 @@ public class DefaultSimilarity extends TFIDFSimilarity { public float sloppyFreq(int distance) { return 1.0f / (distance + 1); } - + + /** The default implementation returns 1 */ + @Override + public float scorePayload(int doc, int start, int end, BytesRef payload) { + return 1; + } + /** Implemented as log(numDocs/(docFreq+1)) + 1. */ @Override public float idf(int docFreq, int numDocs) { diff --git a/lucene/src/java/org/apache/lucene/search/MultiPhraseQuery.java b/lucene/src/java/org/apache/lucene/search/MultiPhraseQuery.java index 944f4c4a97f..1a65b65ee31 100644 --- a/lucene/src/java/org/apache/lucene/search/MultiPhraseQuery.java +++ b/lucene/src/java/org/apache/lucene/search/MultiPhraseQuery.java @@ -221,8 +221,7 @@ public class MultiPhraseQuery extends Query { return s; } } else { - return new SloppyPhraseScorer(this, postingsFreqs, similarity, - slop, similarity.sloppyDocScorer(stats, field, context)); + return new SloppyPhraseScorer(this, postingsFreqs, slop, similarity.sloppyDocScorer(stats, field, context)); } } diff --git a/lucene/src/java/org/apache/lucene/search/PhraseQuery.java b/lucene/src/java/org/apache/lucene/search/PhraseQuery.java index 696d6d372fb..73c054da02e 100644 --- a/lucene/src/java/org/apache/lucene/search/PhraseQuery.java +++ b/lucene/src/java/org/apache/lucene/search/PhraseQuery.java @@ -251,7 +251,7 @@ public class PhraseQuery extends Query { } } else { return - new SloppyPhraseScorer(this, postingsFreqs, similarity, slop, similarity.sloppyDocScorer(stats, field, context)); + new SloppyPhraseScorer(this, postingsFreqs, slop, similarity.sloppyDocScorer(stats, field, context)); } } diff --git a/lucene/src/java/org/apache/lucene/search/Similarity.java b/lucene/src/java/org/apache/lucene/search/Similarity.java index 5a907fcb1be..fe184be66c8 100644 --- a/lucene/src/java/org/apache/lucene/search/Similarity.java +++ b/lucene/src/java/org/apache/lucene/search/Similarity.java @@ -26,6 +26,7 @@ import org.apache.lucene.index.IndexReader; // javadoc import org.apache.lucene.index.IndexReader.AtomicReaderContext; import org.apache.lucene.index.Terms; // javadoc import org.apache.lucene.search.spans.SpanQuery; // javadoc +import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.SmallFloat; // javadoc import org.apache.lucene.util.TermContext; @@ -100,9 +101,6 @@ import org.apache.lucene.util.TermContext; * @lucene.experimental */ public abstract class Similarity { - - public static final int NO_DOC_ID_PROVIDED = -1; - /** * Computes the normalization value for a field, given the accumulated * state of term processing for this field (see {@link FieldInvertState}). @@ -120,43 +118,6 @@ public abstract class Similarity { * @return the calculated byte norm */ public abstract byte computeNorm(FieldInvertState state); - - /** Computes the amount of a sloppy phrase match, based on an edit distance. - * This value is summed for each sloppy phrase match in a document to form - * the frequency to be used in scoring instead of the exact term count. - * - *

A phrase match with a small edit distance to a document passage more - * closely matches the document, so implementations of this method usually - * return larger values when the edit distance is small and smaller values - * when it is large. - * - * @see PhraseQuery#setSlop(int) - * @param distance the edit distance of this sloppy phrase match - * @return the frequency increment for this match - */ - public abstract float sloppyFreq(int distance); - - /** - * Calculate a scoring factor based on the data in the payload. Overriding implementations - * are responsible for interpreting what is in the payload. Lucene makes no assumptions about - * what is in the byte array. - *

- * The default implementation returns 1. - * - * @param docId The docId currently being scored. If this value is {@link #NO_DOC_ID_PROVIDED}, then it should be assumed that the PayloadQuery implementation does not provide document information - * @param start The start position of the payload - * @param end The end position of the payload - * @param payload The payload byte array to be scored - * @param offset The offset into the payload array - * @param length The length in the array - * @return An implementation dependent float to be used as a scoring factor - * - */ - // TODO: maybe switch this API to BytesRef? - public float scorePayload(int docId, int start, int end, byte [] payload, int offset, int length) - { - return 1; - } /** * Compute any collection-level stats (e.g. IDF, average document length, etc) needed for scoring a query. @@ -216,6 +177,12 @@ public abstract class Similarity { * @return document's score */ public abstract float score(int doc, float freq); + + /** Computes the amount of a sloppy phrase match, based on an edit distance. */ + public abstract float computeSlopFactor(int distance); + + /** Calculate a scoring factor based on the data in the payload. */ + public abstract float computePayloadFactor(int doc, int start, int end, BytesRef payload); /** * Explain the score for a single document diff --git a/lucene/src/java/org/apache/lucene/search/SloppyPhraseScorer.java b/lucene/src/java/org/apache/lucene/search/SloppyPhraseScorer.java index 5252c5550b4..d13f5cb41e6 100644 --- a/lucene/src/java/org/apache/lucene/search/SloppyPhraseScorer.java +++ b/lucene/src/java/org/apache/lucene/search/SloppyPhraseScorer.java @@ -25,13 +25,11 @@ final class SloppyPhraseScorer extends PhraseScorer { private PhrasePositions repeats[]; private PhrasePositions tmpPos[]; // for flipping repeating pps. private boolean checkedRepeats; - private final Similarity similarity; - SloppyPhraseScorer(Weight weight, PhraseQuery.PostingsAndFreq[] postings, Similarity similarity, + SloppyPhraseScorer(Weight weight, PhraseQuery.PostingsAndFreq[] postings, int slop, Similarity.SloppyDocScorer docScorer) throws IOException { super(weight, postings, docScorer); this.slop = slop; - this.similarity = similarity; } /** @@ -80,7 +78,7 @@ final class SloppyPhraseScorer extends PhraseScorer { int matchLength = end - start; if (matchLength <= slop) - freq += similarity.sloppyFreq(matchLength); // score match + freq += docScorer.computeSlopFactor(matchLength); // score match if (pp.position > end) end = pp.position; diff --git a/lucene/src/java/org/apache/lucene/search/TFIDFSimilarity.java b/lucene/src/java/org/apache/lucene/search/TFIDFSimilarity.java index abc8e512064..3ae85bc4b47 100644 --- a/lucene/src/java/org/apache/lucene/search/TFIDFSimilarity.java +++ b/lucene/src/java/org/apache/lucene/search/TFIDFSimilarity.java @@ -22,6 +22,7 @@ import java.io.IOException; import org.apache.lucene.index.IndexReader.AtomicReaderContext; import org.apache.lucene.index.Term; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.TermContext; import org.apache.lucene.util.SmallFloat; @@ -666,6 +667,34 @@ public abstract class TFIDFSimilarity extends Similarity { return SmallFloat.floatToByte315(f); } + /** Computes the amount of a sloppy phrase match, based on an edit distance. + * This value is summed for each sloppy phrase match in a document to form + * the frequency to be used in scoring instead of the exact term count. + * + *

A phrase match with a small edit distance to a document passage more + * closely matches the document, so implementations of this method usually + * return larger values when the edit distance is small and smaller values + * when it is large. + * + * @see PhraseQuery#setSlop(int) + * @param distance the edit distance of this sloppy phrase match + * @return the frequency increment for this match + */ + public abstract float sloppyFreq(int distance); + + /** + * Calculate a scoring factor based on the data in the payload. Implementations + * are responsible for interpreting what is in the payload. Lucene makes no assumptions about + * what is in the byte array. + * + * @param doc The docId currently being scored. + * @param start The start position of the payload + * @param end The end position of the payload + * @param payload The payload byte array to be scored + * @return An implementation dependent float to be used as a scoring factor + */ + public abstract float scorePayload(int doc, int start, int end, BytesRef payload); + @Override public final Stats computeStats(IndexSearcher searcher, String fieldName, float queryBoost, TermContext... termContexts) throws IOException { @@ -736,6 +765,16 @@ public abstract class TFIDFSimilarity extends Similarity { return norms == null ? raw : raw * decodeNormValue(norms[doc]); // normalize for field } + @Override + public float computeSlopFactor(int distance) { + return sloppyFreq(distance); + } + + @Override + public float computePayloadFactor(int doc, int start, int end, BytesRef payload) { + return scorePayload(doc, start, end, payload); + } + @Override public Explanation explain(int doc, Explanation freq) { return explainScore(doc, freq, stats, norms); diff --git a/lucene/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java b/lucene/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java index ac2f5008cd3..c5f8900a4ff 100644 --- a/lucene/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java +++ b/lucene/src/java/org/apache/lucene/search/payloads/PayloadNearQuery.java @@ -23,6 +23,7 @@ import org.apache.lucene.search.Explanation; import org.apache.lucene.search.Scorer; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Similarity; +import org.apache.lucene.search.DefaultSimilarity; // javadocs only import org.apache.lucene.search.Weight; import org.apache.lucene.search.Similarity.SloppyDocScorer; import org.apache.lucene.search.spans.NearSpansOrdered; @@ -32,6 +33,7 @@ import org.apache.lucene.search.spans.SpanQuery; import org.apache.lucene.search.spans.SpanScorer; import org.apache.lucene.search.spans.SpanWeight; import org.apache.lucene.search.spans.Spans; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.ToStringUtils; import java.io.IOException; @@ -44,13 +46,13 @@ import java.util.Iterator; * in the value of the payloads located at each of the positions where the * {@link org.apache.lucene.search.spans.TermSpans} occurs. *

- * In order to take advantage of this, you must override - * {@link org.apache.lucene.search.Similarity#scorePayload} + * NOTE: In order to take advantage of this with the default scoring implementation + * ({@link DefaultSimilarity}), you must override {@link DefaultSimilarity#scorePayload(int, int, int, BytesRef)}, * which returns 1 by default. *

* Payload scores are aggregated using a pluggable {@link PayloadFunction}. * - * @see org.apache.lucene.search.Similarity#scorePayload + * @see org.apache.lucene.search.Similarity.SloppyDocScorer#computePayloadFactor(int, int, int, BytesRef) */ public class PayloadNearQuery extends SpanNearQuery { protected String fieldName; @@ -186,7 +188,7 @@ public class PayloadNearQuery extends SpanNearQuery { protected PayloadNearSpanScorer(Spans spans, Weight weight, Similarity similarity, Similarity.SloppyDocScorer docScorer) throws IOException { - super(spans, weight, similarity, docScorer); + super(spans, weight, docScorer); this.spans = spans; } @@ -209,6 +211,9 @@ public class PayloadNearQuery extends SpanNearQuery { } } + // TODO change the whole spans api to use bytesRef, or nuke spans + BytesRef scratch = new BytesRef(); + /** * By default, uses the {@link PayloadFunction} to score the payloads, but * can be overridden to do other things. @@ -221,9 +226,12 @@ public class PayloadNearQuery extends SpanNearQuery { */ protected void processPayloads(Collection payLoads, int start, int end) { for (final byte[] thePayload : payLoads) { + scratch.bytes = thePayload; + scratch.offset = 0; + scratch.length = thePayload.length; payloadScore = function.currentScore(doc, fieldName, start, end, - payloadsSeen, payloadScore, similarity.scorePayload(doc, - spans.start(), spans.end(), thePayload, 0, thePayload.length)); + payloadsSeen, payloadScore, docScorer.computePayloadFactor(doc, + spans.start(), spans.end(), scratch)); ++payloadsSeen; } } @@ -240,7 +248,7 @@ public class PayloadNearQuery extends SpanNearQuery { payloadsSeen = 0; do { int matchLength = spans.end() - spans.start(); - freq += similarity.sloppyFreq(matchLength); + freq += docScorer.computeSlopFactor(matchLength); Spans[] spansArr = new Spans[1]; spansArr[0] = spans; getPayloads(spansArr); diff --git a/lucene/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java b/lucene/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java index 9c697de1474..1a32ff0a25d 100644 --- a/lucene/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java +++ b/lucene/src/java/org/apache/lucene/search/payloads/PayloadTermQuery.java @@ -20,6 +20,7 @@ package org.apache.lucene.search.payloads; import org.apache.lucene.index.IndexReader.AtomicReaderContext; import org.apache.lucene.index.Term; import org.apache.lucene.index.DocsAndPositionsEnum; +import org.apache.lucene.search.DefaultSimilarity; // javadocs only import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Scorer; import org.apache.lucene.search.Weight; @@ -42,12 +43,13 @@ import java.io.IOException; * {@link org.apache.lucene.search.spans.SpanTermQuery} except that it factors * in the value of the payload located at each of the positions where the * {@link org.apache.lucene.index.Term} occurs. - *

- * In order to take advantage of this, you must override - * {@link org.apache.lucene.search.Similarity#scorePayload(int, int, int, byte[],int,int)} + *

+ * NOTE: In order to take advantage of this with the default scoring implementation + * ({@link DefaultSimilarity}), you must override {@link DefaultSimilarity#scorePayload(int, int, int, BytesRef)}, * which returns 1 by default. - *

+ *

* Payload scores are aggregated using a pluggable {@link PayloadFunction}. + * @see org.apache.lucene.search.Similarity.SloppyDocScorer#computePayloadFactor(int, int, int, BytesRef) **/ public class PayloadTermQuery extends SpanTermQuery { protected PayloadFunction function; @@ -79,7 +81,7 @@ public class PayloadTermQuery extends SpanTermQuery { @Override public Scorer scorer(AtomicReaderContext context, ScorerContext scorerContext) throws IOException { return new PayloadTermSpanScorer((TermSpans) query.getSpans(context), - this, similarity, similarity.sloppyDocScorer(stats, query.getField(), context)); + this, similarity.sloppyDocScorer(stats, query.getField(), context)); } protected class PayloadTermSpanScorer extends SpanScorer { @@ -88,9 +90,8 @@ public class PayloadTermQuery extends SpanTermQuery { protected int payloadsSeen; private final TermSpans termSpans; - public PayloadTermSpanScorer(TermSpans spans, Weight weight, - Similarity similarity, Similarity.SloppyDocScorer docScorer) throws IOException { - super(spans, weight, similarity, docScorer); + public PayloadTermSpanScorer(TermSpans spans, Weight weight, Similarity.SloppyDocScorer docScorer) throws IOException { + super(spans, weight, docScorer); termSpans = spans; } @@ -106,7 +107,7 @@ public class PayloadTermQuery extends SpanTermQuery { while (more && doc == spans.doc()) { int matchLength = spans.end() - spans.start(); - freq += similarity.sloppyFreq(matchLength); + freq += docScorer.computeSlopFactor(matchLength); processPayload(similarity); more = spans.next();// this moves positions to the next match in this @@ -122,17 +123,10 @@ public class PayloadTermQuery extends SpanTermQuery { if (payload != null) { payloadScore = function.currentScore(doc, term.field(), spans.start(), spans.end(), payloadsSeen, payloadScore, - similarity.scorePayload(doc, spans.start(), - spans.end(), payload.bytes, - payload.offset, - payload.length)); + docScorer.computePayloadFactor(doc, spans.start(), spans.end(), payload)); } else { payloadScore = function.currentScore(doc, term.field(), - spans.start(), spans.end(), payloadsSeen, payloadScore, - similarity.scorePayload(doc, spans.start(), - spans.end(), null, - 0, - 0)); + spans.start(), spans.end(), payloadsSeen, payloadScore, 1F); } payloadsSeen++; diff --git a/lucene/src/java/org/apache/lucene/search/spans/SpanScorer.java b/lucene/src/java/org/apache/lucene/search/spans/SpanScorer.java index 9cce1f45e4b..573c91baa5b 100644 --- a/lucene/src/java/org/apache/lucene/search/spans/SpanScorer.java +++ b/lucene/src/java/org/apache/lucene/search/spans/SpanScorer.java @@ -35,13 +35,11 @@ public class SpanScorer extends Scorer { protected int doc; protected float freq; - protected final Similarity similarity; protected final Similarity.SloppyDocScorer docScorer; - protected SpanScorer(Spans spans, Weight weight, Similarity similarity, Similarity.SloppyDocScorer docScorer) + protected SpanScorer(Spans spans, Weight weight, Similarity.SloppyDocScorer docScorer) throws IOException { super(weight); - this.similarity = similarity; this.docScorer = docScorer; this.spans = spans; @@ -83,7 +81,7 @@ public class SpanScorer extends Scorer { freq = 0.0f; do { int matchLength = spans.end() - spans.start(); - freq += similarity.sloppyFreq(matchLength); + freq += docScorer.computeSlopFactor(matchLength); more = spans.next(); } while (more && (doc == spans.doc())); return true; 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 cf8bf4e22a2..14dba75eb37 100644 --- a/lucene/src/java/org/apache/lucene/search/spans/SpanWeight.java +++ b/lucene/src/java/org/apache/lucene/search/spans/SpanWeight.java @@ -67,7 +67,7 @@ public class SpanWeight extends Weight { @Override public Scorer scorer(AtomicReaderContext context, ScorerContext scorerContext) throws IOException { - return new SpanScorer(query.getSpans(context), this, similarity, similarity.sloppyDocScorer(stats, query.getField(), context)); + return new SpanScorer(query.getSpans(context), this, similarity.sloppyDocScorer(stats, query.getField(), context)); } @Override diff --git a/lucene/src/test/org/apache/lucene/index/TestOmitTf.java b/lucene/src/test/org/apache/lucene/index/TestOmitTf.java index fd5d4ee8fdf..d9bae536231 100644 --- a/lucene/src/test/org/apache/lucene/index/TestOmitTf.java +++ b/lucene/src/test/org/apache/lucene/index/TestOmitTf.java @@ -19,6 +19,7 @@ package org.apache.lucene.index; import java.io.IOException; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TermContext; import org.apache.lucene.util._TestUtil; @@ -48,6 +49,7 @@ public class TestOmitTf extends LuceneTestCase { @Override public Explanation idfExplain(TermContext[] terms, IndexSearcher searcher) throws IOException { return new Explanation(1.0f, "Inexplicable"); } + @Override public float scorePayload(int doc, int start, int end, BytesRef payload) { return 1.0f; } }; } } diff --git a/lucene/src/test/org/apache/lucene/search/JustCompileSearch.java b/lucene/src/test/org/apache/lucene/search/JustCompileSearch.java index 167d10e696c..a76dbdc1958 100644 --- a/lucene/src/test/org/apache/lucene/search/JustCompileSearch.java +++ b/lucene/src/test/org/apache/lucene/search/JustCompileSearch.java @@ -265,11 +265,6 @@ final class JustCompileSearch { public byte computeNorm(FieldInvertState state) { throw new UnsupportedOperationException(UNSUPPORTED_MSG); } - - @Override - public float sloppyFreq(int distance) { - throw new UnsupportedOperationException(UNSUPPORTED_MSG); - } } static final class JustCompileSimilarityProvider implements SimilarityProvider { diff --git a/lucene/src/test/org/apache/lucene/search/TestDocValuesScoring.java b/lucene/src/test/org/apache/lucene/search/TestDocValuesScoring.java index 2281000eff3..fe642d1337f 100644 --- a/lucene/src/test/org/apache/lucene/search/TestDocValuesScoring.java +++ b/lucene/src/test/org/apache/lucene/search/TestDocValuesScoring.java @@ -30,6 +30,7 @@ import org.apache.lucene.index.IndexReader.AtomicReaderContext; import org.apache.lucene.index.codecs.CodecProvider; import org.apache.lucene.index.values.IndexDocValues.Source; import org.apache.lucene.store.Directory; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TermContext; @@ -144,11 +145,6 @@ public class TestDocValuesScoring extends LuceneTestCase { return sim.computeNorm(state); } - @Override - public float sloppyFreq(int distance) { - return sim.sloppyFreq(distance); - } - @Override public Stats computeStats(IndexSearcher searcher, String fieldName, float queryBoost, TermContext... termContexts) throws IOException { return sim.computeStats(searcher, fieldName, queryBoost, termContexts); @@ -188,6 +184,16 @@ public class TestDocValuesScoring extends LuceneTestCase { return (float) values.getFloat(doc) * sub.score(doc, freq); } + @Override + public float computeSlopFactor(int distance) { + return sub.computeSlopFactor(distance); + } + + @Override + public float computePayloadFactor(int doc, int start, int end, BytesRef payload) { + return sub.computePayloadFactor(doc, start, end, payload); + } + @Override public Explanation explain(int doc, Explanation freq) { Explanation boostExplanation = new Explanation((float) values.getFloat(doc), "indexDocValue(" + boostField + ")"); diff --git a/lucene/src/test/org/apache/lucene/search/TestSimilarityProvider.java b/lucene/src/test/org/apache/lucene/search/TestSimilarityProvider.java index 1bf30e3b773..42f50468b02 100644 --- a/lucene/src/test/org/apache/lucene/search/TestSimilarityProvider.java +++ b/lucene/src/test/org/apache/lucene/search/TestSimilarityProvider.java @@ -27,6 +27,7 @@ import org.apache.lucene.index.MultiNorms; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LuceneTestCase; public class TestSimilarityProvider extends LuceneTestCase { @@ -125,6 +126,11 @@ public class TestSimilarityProvider extends LuceneTestCase { public float idf(int docFreq, int numDocs) { return 1f; } + + @Override + public float scorePayload(int doc, int start, int end, BytesRef payload) { + return 1f; + } } private class Sim2 extends TFIDFSimilarity { @@ -147,5 +153,10 @@ public class TestSimilarityProvider extends LuceneTestCase { public float idf(int docFreq, int numDocs) { return 10f; } + + @Override + public float scorePayload(int doc, int start, int end, BytesRef payload) { + return 1f; + } } } diff --git a/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java b/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java index 962eab069c2..2e1da3af04f 100644 --- a/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java +++ b/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadNearQuery.java @@ -42,6 +42,7 @@ import org.apache.lucene.search.spans.SpanQuery; import org.apache.lucene.search.spans.SpanNearQuery; import org.apache.lucene.search.spans.SpanTermQuery; import org.apache.lucene.store.Directory; +import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.English; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TermContext; @@ -315,9 +316,9 @@ public class TestPayloadNearQuery extends LuceneTestCase { return new DefaultSimilarity() { @Override - public float scorePayload(int docId, int start, int end, byte[] payload, int offset, int length) { + public float scorePayload(int docId, int start, int end, BytesRef payload) { //we know it is size 4 here, so ignore the offset/length - return payload[offset]; + return payload.bytes[payload.offset]; } //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! diff --git a/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.java b/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.java index ea35f60cb56..0a4ad06783f 100644 --- a/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.java +++ b/lucene/src/test/org/apache/lucene/search/payloads/TestPayloadTermQuery.java @@ -16,6 +16,7 @@ package org.apache.lucene.search.payloads; * limitations under the License. */ +import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.English; import org.apache.lucene.search.DefaultSimilarityProvider; @@ -309,9 +310,9 @@ public class TestPayloadTermQuery extends LuceneTestCase { // TODO: Remove warning after API has been finalized @Override - public float scorePayload(int docId, int start, int end, byte[] payload, int offset, int length) { + public float scorePayload(int docId, int start, int end, BytesRef payload) { //we know it is size 4 here, so ignore the offset/length - return payload[offset]; + return payload.bytes[payload.offset]; } //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! diff --git a/lucene/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java b/lucene/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java index 4adceca1bb7..9b2ee4b5289 100644 --- a/lucene/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java +++ b/lucene/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java @@ -135,8 +135,8 @@ final class JustCompileSearchSpans { static final class JustCompileSpanScorer extends SpanScorer { protected JustCompileSpanScorer(Spans spans, Weight weight, - Similarity similarity, Similarity.SloppyDocScorer docScorer) throws IOException { - super(spans, weight, similarity, docScorer); + Similarity.SloppyDocScorer docScorer) throws IOException { + super(spans, weight, docScorer); } @Override