mirror of https://github.com/apache/lucene.git
LUCENE-7611: Remove queries dependency from suggester module
This commit is contained in:
parent
ce8b678ba1
commit
8f4fee3ad1
|
@ -13,7 +13,6 @@
|
|||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" scope="TEST" name="JUnit" level="project" />
|
||||
<orderEntry type="module" scope="TEST" module-name="lucene-test-framework" />
|
||||
<orderEntry type="module" module-name="queries" />
|
||||
<orderEntry type="module" module-name="analysis-common" />
|
||||
<orderEntry type="module" module-name="lucene-core" />
|
||||
</component>
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -30,11 +30,10 @@
|
|||
|
||||
<path id="classpath">
|
||||
<pathelement path="${analyzers-common.jar}"/>
|
||||
<pathelement path="${queries.jar}"/>
|
||||
<path refid="base.classpath"/>
|
||||
</path>
|
||||
|
||||
<target name="javadocs" depends="javadocs-queries,compile-core,check-javadocs-uptodate"
|
||||
<target name="javadocs" depends="compile-core,check-javadocs-uptodate"
|
||||
unless="javadocs-uptodate-${name}">
|
||||
<invoke-module-javadoc>
|
||||
<links>
|
||||
|
|
|
@ -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 <code>field</code>
|
||||
* for the terms, <code>payload</code> for the corresponding payloads, <code>contexts</code>
|
||||
* for the associated contexts and uses the <code>weightsValueSource</code> 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 <code>field</code>
|
||||
|
@ -91,21 +75,6 @@ public class DocumentValueSourceDictionary extends DocumentDictionary {
|
|||
this.weightsValueSource = weightsValueSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new dictionary with the contents of the fields named <code>field</code>
|
||||
* for the terms, <code>payloadField</code> for the corresponding payloads
|
||||
* and uses the <code>weightsValueSource</code> 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 <code>field</code>
|
||||
* for the terms, <code>payloadField</code> 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 <code>field</code>
|
||||
* for the terms and uses the <code>weightsValueSource</code> 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 <code>field</code>
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue