LUCENE-9258: DocTermsIndexDocValues' range scorer didn't support multi-valued fields

This commit is contained in:
Michele Palmia 2020-03-11 16:56:10 -04:00 committed by David Smiley
parent 5286098ac5
commit b1ec1cd9e0
No known key found for this signature in database
GPG Key ID: 6FDFF3BF6796FD4A
4 changed files with 21 additions and 25 deletions

View File

@ -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
---------------------

View File

@ -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;
}
};
}

View File

@ -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;

View File

@ -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();
}