mirror of https://github.com/apache/lucene.git
LUCENE-9258: DocTermsIndexDocValues' range scorer didn't support multi-valued fields
This commit is contained in:
parent
5286098ac5
commit
b1ec1cd9e0
|
@ -127,6 +127,9 @@ Bug Fixes
|
|||
|
||||
* LUCENE-8849: DocValuesRewriteMethod.visit wasn't visiting its embedded query (Michele Palmia, David Smiley)
|
||||
|
||||
* LUCENE-9258: DocTermsIndexDocValues assumed it was operating on a SortedDocValues (single valued) field when
|
||||
it could be multi-valued used with a SortedSetSelector (Michele Palmia)
|
||||
|
||||
Other
|
||||
---------------------
|
||||
|
||||
|
|
|
@ -40,15 +40,13 @@ public abstract class DocTermsIndexDocValues extends FunctionValues {
|
|||
protected final ValueSource vs;
|
||||
protected final MutableValueStr val = new MutableValueStr();
|
||||
protected final CharsRefBuilder spareChars = new CharsRefBuilder();
|
||||
private final String field;
|
||||
private int lastDocID;
|
||||
|
||||
public DocTermsIndexDocValues(ValueSource vs, LeafReaderContext context, String field) throws IOException {
|
||||
this(field, vs, open(context, field));
|
||||
this(vs, open(context, field));
|
||||
}
|
||||
|
||||
protected DocTermsIndexDocValues(String field, ValueSource vs, SortedDocValues termsIndex) {
|
||||
this.field = field;
|
||||
|
||||
protected DocTermsIndexDocValues(ValueSource vs, SortedDocValues termsIndex) {
|
||||
this.vs = vs;
|
||||
this.termsIndex = termsIndex;
|
||||
}
|
||||
|
@ -145,23 +143,11 @@ public abstract class DocTermsIndexDocValues extends FunctionValues {
|
|||
final int uu = upper;
|
||||
|
||||
return new ValueSourceScorer(weight, readerContext, this) {
|
||||
final SortedDocValues values = readerContext.reader().getSortedDocValues(field);
|
||||
private int lastDocID;
|
||||
|
||||
@Override
|
||||
public boolean matches(int doc) throws IOException {
|
||||
if (doc < lastDocID) {
|
||||
throw new IllegalArgumentException("docs were sent out-of-order: lastDocID=" + lastDocID + " vs docID=" + doc);
|
||||
}
|
||||
if (doc > values.docID()) {
|
||||
values.advance(doc);
|
||||
}
|
||||
if (doc == values.docID()) {
|
||||
int ord = values.ordValue();
|
||||
return ord >= ll && ord <= uu;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (!exists(doc)) return false;
|
||||
float docVal = ordVal(doc);
|
||||
return docVal >= ll && docVal <= uu;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ public class SortedSetFieldSource extends FieldCacheSource {
|
|||
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
|
||||
SortedSetDocValues sortedSet = DocValues.getSortedSet(readerContext.reader(), field);
|
||||
SortedDocValues view = SortedSetSelector.wrap(sortedSet, selector);
|
||||
return new DocTermsIndexDocValues(this.field, this, view) {
|
||||
return new DocTermsIndexDocValues(this, view) {
|
||||
@Override
|
||||
protected String toTerm(String readableValue) {
|
||||
return readableValue;
|
||||
|
|
|
@ -25,9 +25,7 @@ import org.apache.lucene.index.LeafReader;
|
|||
import org.apache.lucene.index.DirectoryReader;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.queries.function.valuesource.SortedSetFieldSource;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.SortField;
|
||||
import org.apache.lucene.search.SortedSetSortField;
|
||||
import org.apache.lucene.search.*;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
|
@ -66,7 +64,16 @@ public class TestSortedSetFieldSource extends LuceneTestCase {
|
|||
vssf = vssf.rewrite(searcher);
|
||||
sf = sf.rewrite(searcher);
|
||||
assertEquals(sf, vssf);
|
||||
|
||||
|
||||
// test scorer
|
||||
vs = new SortedSetFieldSource("value");
|
||||
values = vs.getValues(Collections.emptyMap(), ar.getContext());
|
||||
ValueSourceScorer vss = values.getRangeScorer(new MatchAllDocsQuery().createWeight(searcher, ScoreMode.TOP_SCORES, 1), ar.getContext(), "a", "z", true, true);
|
||||
|
||||
DocIdSetIterator iterator = vss.iterator();
|
||||
assertEquals("baz", values.strVal(iterator.nextDoc()));
|
||||
assertEquals("bar", values.strVal(iterator.nextDoc()));
|
||||
|
||||
ir.close();
|
||||
dir.close();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue