mirror of https://github.com/apache/lucene.git
Fix FieldExistsQuery rewrite when all docs have vectors (#986)
Before we were checking the number of vectors in the segment against the total number of documents in IndexReader. This meant FieldExistsQuery would not rewrite to MatchAllDocsQuery when there were multiple segments.
This commit is contained in:
parent
03846b468e
commit
7b58088bd5
|
@ -131,6 +131,8 @@ Bug Fixes
|
||||||
|
|
||||||
* LUCENE-10607: Fix potential integer overflow in maxArcs computions (Tang Donghai)
|
* LUCENE-10607: Fix potential integer overflow in maxArcs computions (Tang Donghai)
|
||||||
|
|
||||||
|
* GITHUB#986: Fix FieldExistsQuery rewrite when all docs have vectors. (Julie Tibshirani)
|
||||||
|
|
||||||
Other
|
Other
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ public class FieldExistsQuery extends Query {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (fieldInfo.getVectorDimension() != 0) { // the field indexes vectors
|
} else if (fieldInfo.getVectorDimension() != 0) { // the field indexes vectors
|
||||||
if (leaf.getVectorValues(field).size() != reader.maxDoc()) {
|
if (leaf.getVectorValues(field).size() != leaf.maxDoc()) {
|
||||||
allReadersRewritable = false;
|
allReadersRewritable = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -626,13 +626,18 @@ public class TestFieldExistsQuery extends LuceneTestCase {
|
||||||
public void testKnnVectorAllDocsHaveField() throws IOException {
|
public void testKnnVectorAllDocsHaveField() throws IOException {
|
||||||
try (Directory dir = newDirectory();
|
try (Directory dir = newDirectory();
|
||||||
RandomIndexWriter iw = new RandomIndexWriter(random(), dir)) {
|
RandomIndexWriter iw = new RandomIndexWriter(random(), dir)) {
|
||||||
Document doc = new Document();
|
for (int i = 0; i < 100; ++i) {
|
||||||
doc.add(new KnnVectorField("vector", randomVector(3)));
|
Document doc = new Document();
|
||||||
iw.addDocument(doc);
|
doc.add(new KnnVectorField("vector", randomVector(5)));
|
||||||
|
iw.addDocument(doc);
|
||||||
|
}
|
||||||
iw.commit();
|
iw.commit();
|
||||||
|
|
||||||
try (IndexReader reader = iw.getReader()) {
|
try (IndexReader reader = iw.getReader()) {
|
||||||
IndexSearcher searcher = newSearcher(reader);
|
IndexSearcher searcher = newSearcher(reader);
|
||||||
assertEquals(1, searcher.count(new FieldExistsQuery("vector")));
|
Query query = new FieldExistsQuery("vector");
|
||||||
|
assertTrue(searcher.rewrite(query) instanceof MatchAllDocsQuery);
|
||||||
|
assertEquals(100, searcher.count(query));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue