diff --git a/dev-tools/idea/lucene/suggest/suggest.iml b/dev-tools/idea/lucene/suggest/suggest.iml index 576ea8bff9b..5e58bc2000c 100644 --- a/dev-tools/idea/lucene/suggest/suggest.iml +++ b/dev-tools/idea/lucene/suggest/suggest.iml @@ -13,7 +13,6 @@ - diff --git a/lucene/core/src/java/org/apache/lucene/search/DoubleValuesSource.java b/lucene/core/src/java/org/apache/lucene/search/DoubleValuesSource.java index 4ac8fc164ac..d4be4e976d3 100644 --- a/lucene/core/src/java/org/apache/lucene/search/DoubleValuesSource.java +++ b/lucene/core/src/java/org/apache/lucene/search/DoubleValuesSource.java @@ -149,6 +149,33 @@ public abstract class DoubleValuesSource { } }; + /** + * Creates a DoubleValuesSource that always returns a constant value + */ + public static DoubleValuesSource constant(double value) { + return new DoubleValuesSource() { + @Override + public DoubleValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException { + return new DoubleValues() { + @Override + public double doubleValue() throws IOException { + return value; + } + + @Override + public boolean advanceExact(int doc) throws IOException { + return true; + } + }; + } + + @Override + public boolean needsScores() { + return false; + } + }; + } + /** * Returns a DoubleValues instance that wraps scores returned by a Scorer */ diff --git a/lucene/suggest/build.xml b/lucene/suggest/build.xml index 5babe064d18..bc4bed5f050 100644 --- a/lucene/suggest/build.xml +++ b/lucene/suggest/build.xml @@ -30,11 +30,10 @@ - - diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentValueSourceDictionary.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentValueSourceDictionary.java index 656dc04c57c..2291ac9436d 100644 --- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentValueSourceDictionary.java +++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentValueSourceDictionary.java @@ -23,7 +23,6 @@ import org.apache.lucene.document.Document; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.ReaderUtil; -import org.apache.lucene.queries.function.ValueSource; import org.apache.lucene.search.LongValues; import org.apache.lucene.search.LongValuesSource; @@ -63,21 +62,6 @@ import org.apache.lucene.search.LongValuesSource; public class DocumentValueSourceDictionary extends DocumentDictionary { private final LongValuesSource weightsValueSource; - - /** - * Creates a new dictionary with the contents of the fields named field - * for the terms, payload for the corresponding payloads, contexts - * for the associated contexts and uses the weightsValueSource supplied - * to determine the score. - * - * @deprecated Use {@link #DocumentValueSourceDictionary(IndexReader, String, LongValuesSource, String, String)} - */ - @Deprecated - public DocumentValueSourceDictionary(IndexReader reader, String field, - ValueSource weightsValueSource, String payload, String contexts) { - super(reader, field, null, payload, contexts); - this.weightsValueSource = weightsValueSource.asLongValuesSource(); - } /** * Creates a new dictionary with the contents of the fields named field @@ -91,21 +75,6 @@ public class DocumentValueSourceDictionary extends DocumentDictionary { this.weightsValueSource = weightsValueSource; } - /** - * Creates a new dictionary with the contents of the fields named field - * for the terms, payloadField for the corresponding payloads - * and uses the weightsValueSource supplied to determine the - * score. - * - * @deprecated Use {@link #DocumentValueSourceDictionary(IndexReader, String, LongValuesSource, String)} - */ - @Deprecated - public DocumentValueSourceDictionary(IndexReader reader, String field, - ValueSource weightsValueSource, String payload) { - super(reader, field, null, payload); - this.weightsValueSource = weightsValueSource.asLongValuesSource(); - } - /** * Creates a new dictionary with the contents of the fields named field * for the terms, payloadField for the corresponding payloads @@ -117,20 +86,6 @@ public class DocumentValueSourceDictionary extends DocumentDictionary { super(reader, field, null, payload); this.weightsValueSource = weightsValueSource; } - - /** - * Creates a new dictionary with the contents of the fields named field - * for the terms and uses the weightsValueSource supplied to determine the - * score. - * - * @deprecated Use {@link #DocumentValueSourceDictionary(IndexReader, String, LongValuesSource)} - */ - @Deprecated - public DocumentValueSourceDictionary(IndexReader reader, String field, - ValueSource weightsValueSource) { - super(reader, field, null, null); - this.weightsValueSource = weightsValueSource.asLongValuesSource(); - } /** * Creates a new dictionary with the contents of the fields named field diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentValueSourceDictionaryTest.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentValueSourceDictionaryTest.java index 92799cde63a..55970e483d6 100644 --- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentValueSourceDictionaryTest.java +++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentValueSourceDictionaryTest.java @@ -39,10 +39,6 @@ import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; -import org.apache.lucene.queries.function.ValueSource; -import org.apache.lucene.queries.function.valuesource.DoubleConstValueSource; -import org.apache.lucene.queries.function.valuesource.LongFieldSource; -import org.apache.lucene.queries.function.valuesource.SumFloatFunction; import org.apache.lucene.search.DoubleValues; import org.apache.lucene.search.LongValues; import org.apache.lucene.search.LongValuesSource; @@ -73,7 +69,7 @@ public class DocumentValueSourceDictionaryTest extends LuceneTestCase { writer.commit(); writer.close(); IndexReader ir = DirectoryReader.open(dir); - Dictionary dictionary = new DocumentValueSourceDictionary(ir, FIELD_NAME, new DoubleConstValueSource(10), PAYLOAD_FIELD_NAME); + Dictionary dictionary = new DocumentValueSourceDictionary(ir, FIELD_NAME, LongValuesSource.constant(10), PAYLOAD_FIELD_NAME); InputIterator inputIterator = dictionary.getEntryIterator(); assertNull(inputIterator.next()); @@ -119,8 +115,8 @@ public class DocumentValueSourceDictionaryTest extends LuceneTestCase { writer.close(); IndexReader ir = DirectoryReader.open(dir); - ValueSource[] toAdd = new ValueSource[] {new LongFieldSource(WEIGHT_FIELD_NAME_1), new LongFieldSource(WEIGHT_FIELD_NAME_2), new LongFieldSource(WEIGHT_FIELD_NAME_3)}; - Dictionary dictionary = new DocumentValueSourceDictionary(ir, FIELD_NAME, new SumFloatFunction(toAdd), PAYLOAD_FIELD_NAME); + LongValuesSource s = sum(WEIGHT_FIELD_NAME_1, WEIGHT_FIELD_NAME_2, WEIGHT_FIELD_NAME_3); + Dictionary dictionary = new DocumentValueSourceDictionary(ir, FIELD_NAME, s, PAYLOAD_FIELD_NAME); InputIterator inputIterator = dictionary.getEntryIterator(); BytesRef f; while((f = inputIterator.next())!=null) { @@ -227,8 +223,8 @@ public class DocumentValueSourceDictionaryTest extends LuceneTestCase { writer.close(); IndexReader ir = DirectoryReader.open(dir); - ValueSource[] toAdd = new ValueSource[] {new LongFieldSource(WEIGHT_FIELD_NAME_1), new LongFieldSource(WEIGHT_FIELD_NAME_2), new LongFieldSource(WEIGHT_FIELD_NAME_3)}; - Dictionary dictionary = new DocumentValueSourceDictionary(ir, FIELD_NAME, new SumFloatFunction(toAdd), PAYLOAD_FIELD_NAME, CONTEXTS_FIELD_NAME); + LongValuesSource s = sum(WEIGHT_FIELD_NAME_1, WEIGHT_FIELD_NAME_2, WEIGHT_FIELD_NAME_3); + Dictionary dictionary = new DocumentValueSourceDictionary(ir, FIELD_NAME, s, PAYLOAD_FIELD_NAME, CONTEXTS_FIELD_NAME); InputIterator inputIterator = dictionary.getEntryIterator(); BytesRef f; while((f = inputIterator.next())!=null) { @@ -305,8 +301,8 @@ public class DocumentValueSourceDictionaryTest extends LuceneTestCase { writer.close(); IndexReader ir = DirectoryReader.open(dir); - ValueSource[] toAdd = new ValueSource[] {new LongFieldSource(WEIGHT_FIELD_NAME_1), new LongFieldSource(WEIGHT_FIELD_NAME_2), new LongFieldSource(WEIGHT_FIELD_NAME_3)}; - Dictionary dictionary = new DocumentValueSourceDictionary(ir, FIELD_NAME, new SumFloatFunction(toAdd)); + LongValuesSource s = sum(WEIGHT_FIELD_NAME_1, WEIGHT_FIELD_NAME_2, WEIGHT_FIELD_NAME_3); + Dictionary dictionary = new DocumentValueSourceDictionary(ir, FIELD_NAME, s); InputIterator inputIterator = dictionary.getEntryIterator(); BytesRef f; while((f = inputIterator.next())!=null) { @@ -390,9 +386,8 @@ public class DocumentValueSourceDictionaryTest extends LuceneTestCase { IndexReader ir = DirectoryReader.open(dir); assertTrue("NumDocs should be > 0 but was " + ir.numDocs(), ir.numDocs() > 0); assertEquals(ir.numDocs(), docs.size()); - ValueSource[] toAdd = new ValueSource[] {new LongFieldSource(WEIGHT_FIELD_NAME_1), new LongFieldSource(WEIGHT_FIELD_NAME_2)}; - - Dictionary dictionary = new DocumentValueSourceDictionary(ir, FIELD_NAME, new SumFloatFunction(toAdd), PAYLOAD_FIELD_NAME); + LongValuesSource s = sum(WEIGHT_FIELD_NAME_1, WEIGHT_FIELD_NAME_2); + Dictionary dictionary = new DocumentValueSourceDictionary(ir, FIELD_NAME, s, PAYLOAD_FIELD_NAME); InputIterator inputIterator = dictionary.getEntryIterator(); BytesRef f; while((f = inputIterator.next())!=null) { @@ -478,7 +473,7 @@ public class DocumentValueSourceDictionaryTest extends LuceneTestCase { writer.close(); IndexReader ir = DirectoryReader.open(dir); - Dictionary dictionary = new DocumentValueSourceDictionary(ir, FIELD_NAME, new DoubleConstValueSource(10), PAYLOAD_FIELD_NAME); + Dictionary dictionary = new DocumentValueSourceDictionary(ir, FIELD_NAME, LongValuesSource.constant(10), PAYLOAD_FIELD_NAME); InputIterator inputIterator = dictionary.getEntryIterator(); BytesRef f; while((f = inputIterator.next())!=null) {