mirror of
https://github.com/apache/lucene.git
synced 2025-02-23 18:55:50 +00:00
LUCENE-8472: Always rewrite soft-deletes retention query
This change ensures that we always rewrite the soft-deletes merge retention policy before passing it into `createWeight` as some Query does not support `createWeight` directly.
This commit is contained in:
parent
a1ec716e10
commit
b8dfb7e911
@ -312,6 +312,8 @@ Bug Fixes:
|
||||
* LUCENE-8384: Fix missing advance docValues generation while handling docValues
|
||||
update in PendingSoftDeletes. (Simon Willnauer, Nhat Nguyen)
|
||||
|
||||
* LUCENE-8472: Always rewrite the soft-deletes merge retention query. (Adrien Grand, Nhat Nguyen)
|
||||
|
||||
======================= Lucene 7.4.0 =======================
|
||||
|
||||
Upgrading
|
||||
|
@ -124,7 +124,7 @@ public final class SoftDeletesRetentionMergePolicy extends OneMergeWrappingMerge
|
||||
private static Scorer getScorer(Query query, CodecReader reader) throws IOException {
|
||||
IndexSearcher s = new IndexSearcher(reader);
|
||||
s.setQueryCache(null);
|
||||
Weight weight = s.createWeight(query, ScoreMode.COMPLETE_NO_SCORES, 1.0f);
|
||||
Weight weight = s.createWeight(s.rewrite(query), ScoreMode.COMPLETE_NO_SCORES, 1.0f);
|
||||
return weight.scorer(reader.getContext());
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@ import org.apache.lucene.search.DocValuesFieldExistsQuery;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.MatchAllDocsQuery;
|
||||
import org.apache.lucene.search.MatchNoDocsQuery;
|
||||
import org.apache.lucene.search.PrefixQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.SearcherFactory;
|
||||
import org.apache.lucene.search.SearcherManager;
|
||||
@ -678,6 +679,32 @@ public class TestSoftDeletesRetentionMergePolicy extends LuceneTestCase {
|
||||
IOUtils.close(writer, dir);
|
||||
}
|
||||
|
||||
public void testRewriteRetentionQuery() throws Exception {
|
||||
Directory dir = newDirectory();
|
||||
IndexWriterConfig config = newIndexWriterConfig().setSoftDeletesField("soft_deletes")
|
||||
.setMergePolicy(new SoftDeletesRetentionMergePolicy("soft_deletes",
|
||||
() -> new PrefixQuery(new Term("id", "foo")), newMergePolicy()));
|
||||
IndexWriter writer = new IndexWriter(dir, config);
|
||||
|
||||
Document d = new Document();
|
||||
d.add(new StringField("id", "foo-1", Field.Store.YES));
|
||||
writer.addDocument(d);
|
||||
d = new Document();
|
||||
d.add(new StringField("id", "foo-2", Field.Store.YES));
|
||||
writer.softUpdateDocument(new Term("id", "foo-1"), d, new NumericDocValuesField("soft_deletes", 1));
|
||||
|
||||
d = new Document();
|
||||
d.add(new StringField("id", "bar-1", Field.Store.YES));
|
||||
writer.addDocument(d);
|
||||
d.add(new StringField("id", "bar-2", Field.Store.YES));
|
||||
writer.softUpdateDocument(new Term("id", "bar-1"), d, new NumericDocValuesField("soft_deletes", 1));
|
||||
|
||||
writer.forceMerge(1);
|
||||
assertEquals(2, writer.numDocs()); // foo-2, bar-2
|
||||
assertEquals(3, writer.maxDoc()); // foo-1, foo-2, bar-2
|
||||
IOUtils.close(writer, dir);
|
||||
}
|
||||
|
||||
static void doUpdate(Term doc, IndexWriter writer, Field... fields) throws IOException {
|
||||
long seqId = -1;
|
||||
do { // retry if we just committing a merge
|
||||
|
Loading…
x
Reference in New Issue
Block a user