lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dnh...@apache.org
Subject lucene-solr:master: LUCENE-8472: Always rewrite soft-deletes retention query
Date Mon, 03 Sep 2018 15:22:34 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/master a1ec716e1 -> b8dfb7e91


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.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/b8dfb7e9
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/b8dfb7e9
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/b8dfb7e9

Branch: refs/heads/master
Commit: b8dfb7e911e68dd89741675c70e0f7b6745b4502
Parents: a1ec716
Author: Nhat Nguyen <nhat.nguyen@elastic.co>
Authored: Mon Sep 3 11:13:42 2018 -0400
Committer: Nhat Nguyen <nhat.nguyen@elastic.co>
Committed: Mon Sep 3 11:19:40 2018 -0400

----------------------------------------------------------------------
 lucene/CHANGES.txt                              |  2 ++
 .../index/SoftDeletesRetentionMergePolicy.java  |  2 +-
 .../TestSoftDeletesRetentionMergePolicy.java    | 27 ++++++++++++++++++++
 3 files changed, 30 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b8dfb7e9/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 5120f28..a2d88cd 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -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

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b8dfb7e9/lucene/core/src/java/org/apache/lucene/index/SoftDeletesRetentionMergePolicy.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/index/SoftDeletesRetentionMergePolicy.java
b/lucene/core/src/java/org/apache/lucene/index/SoftDeletesRetentionMergePolicy.java
index a309b7a..9097a03 100644
--- a/lucene/core/src/java/org/apache/lucene/index/SoftDeletesRetentionMergePolicy.java
+++ b/lucene/core/src/java/org/apache/lucene/index/SoftDeletesRetentionMergePolicy.java
@@ -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());
   }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b8dfb7e9/lucene/core/src/test/org/apache/lucene/index/TestSoftDeletesRetentionMergePolicy.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestSoftDeletesRetentionMergePolicy.java
b/lucene/core/src/test/org/apache/lucene/index/TestSoftDeletesRetentionMergePolicy.java
index bc50fe5..fed2d19 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestSoftDeletesRetentionMergePolicy.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestSoftDeletesRetentionMergePolicy.java
@@ -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


Mime
View raw message