You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2023/10/04 21:39:21 UTC

[couchdb] branch nouveau-store-seq created (now e7e1bd228)

This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a change to branch nouveau-store-seq
in repository https://gitbox.apache.org/repos/asf/couchdb.git


      at e7e1bd228 store update seq of docs

This branch includes the following new commits:

     new e7e1bd228 store update seq of docs

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[couchdb] 01/01: store update seq of docs

Posted by rn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch nouveau-store-seq
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit e7e1bd228237edc9ecad5a3587d2dc554b6c1941
Author: Robert Newson <rn...@apache.org>
AuthorDate: Wed Oct 4 22:36:35 2023 +0100

    store update seq of docs
---
 .../java/org/apache/couchdb/nouveau/api/SearchHit.java     | 14 ++++++++++++--
 .../org/apache/couchdb/nouveau/lucene9/Lucene9Index.java   |  8 ++++++--
 .../apache/couchdb/nouveau/lucene9/Lucene9IndexTest.java   | 13 ++++++++++++-
 3 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/nouveau/src/main/java/org/apache/couchdb/nouveau/api/SearchHit.java b/nouveau/src/main/java/org/apache/couchdb/nouveau/api/SearchHit.java
index 2e575fef1..2f8ef0b80 100644
--- a/nouveau/src/main/java/org/apache/couchdb/nouveau/api/SearchHit.java
+++ b/nouveau/src/main/java/org/apache/couchdb/nouveau/api/SearchHit.java
@@ -17,6 +17,7 @@ import com.fasterxml.jackson.databind.PropertyNamingStrategies;
 import com.fasterxml.jackson.databind.annotation.JsonNaming;
 import jakarta.validation.constraints.NotEmpty;
 import jakarta.validation.constraints.NotNull;
+import jakarta.validation.constraints.Positive;
 import java.util.Collection;
 import java.util.Objects;
 import org.apache.couchdb.nouveau.core.ser.PrimitiveWrapper;
@@ -27,6 +28,9 @@ public class SearchHit {
     @NotEmpty
     private String id;
 
+    @Positive
+    private long seq;
+
     @NotNull
     private PrimitiveWrapper<?>[] order;
 
@@ -35,8 +39,10 @@ public class SearchHit {
 
     public SearchHit() {}
 
-    public SearchHit(final String id, final PrimitiveWrapper<?>[] order, final Collection<StoredField> fields) {
+    public SearchHit(
+            final String id, final long seq, final PrimitiveWrapper<?>[] order, final Collection<StoredField> fields) {
         this.id = id;
+        this.seq = seq;
         this.order = Objects.requireNonNull(order);
         this.fields = Objects.requireNonNull(fields);
     }
@@ -45,6 +51,10 @@ public class SearchHit {
         return id;
     }
 
+    public long getSeq() {
+        return seq;
+    }
+
     public PrimitiveWrapper<?>[] getOrder() {
         return order;
     }
@@ -55,6 +65,6 @@ public class SearchHit {
 
     @Override
     public String toString() {
-        return "SearchHit [id=" + id + ", order=" + order + ", fields=" + fields + "]";
+        return "SearchHit [id=" + id + ", seq=" + seq + ", order=" + order + ", fields=" + fields + "]";
     }
 }
diff --git a/nouveau/src/main/java/org/apache/couchdb/nouveau/lucene9/Lucene9Index.java b/nouveau/src/main/java/org/apache/couchdb/nouveau/lucene9/Lucene9Index.java
index ce7f7d7ec..0794f3352 100644
--- a/nouveau/src/main/java/org/apache/couchdb/nouveau/lucene9/Lucene9Index.java
+++ b/nouveau/src/main/java/org/apache/couchdb/nouveau/lucene9/Lucene9Index.java
@@ -245,7 +245,7 @@ public class Lucene9Index extends Index {
             final List<StoredField> fields =
                     new ArrayList<StoredField>(doc.getFields().size());
             for (IndexableField field : doc.getFields()) {
-                if (field.name().equals("_id")) {
+                if (field.name().startsWith("_")) {
                     continue;
                 }
                 final StoredValue storedValue = field.storedValue();
@@ -265,7 +265,8 @@ public class Lucene9Index extends Index {
             }
 
             final PrimitiveWrapper<?>[] after = toAfter(((FieldDoc) scoreDoc));
-            hits.add(new SearchHit(doc.get("_id"), after, fields));
+            hits.add(new SearchHit(
+                    doc.get("_id"), doc.getField("_seq").numericValue().longValue(), after, fields));
         }
 
         searchResults.setTotalHits(topDocs.totalHits.value);
@@ -382,6 +383,9 @@ public class Lucene9Index extends Index {
         result.add(new org.apache.lucene.document.StringField("_id", docId, Store.YES));
         result.add(new SortedDocValuesField("_id", new BytesRef(docId)));
 
+        // seq
+        result.add(new org.apache.lucene.document.LongField("_seq", request.getSeq(), Store.YES));
+
         // partition (optional)
         if (request.hasPartition()) {
             result.add(new org.apache.lucene.document.StringField("_partition", request.getPartition(), Store.NO));
diff --git a/nouveau/src/test/java/org/apache/couchdb/nouveau/lucene9/Lucene9IndexTest.java b/nouveau/src/test/java/org/apache/couchdb/nouveau/lucene9/Lucene9IndexTest.java
index ece5fb36f..c43976110 100644
--- a/nouveau/src/test/java/org/apache/couchdb/nouveau/lucene9/Lucene9IndexTest.java
+++ b/nouveau/src/test/java/org/apache/couchdb/nouveau/lucene9/Lucene9IndexTest.java
@@ -18,6 +18,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import java.io.IOException;
 import java.nio.file.Path;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
@@ -74,15 +75,25 @@ public class Lucene9IndexTest {
         final Index index = setup(path);
         try {
             final int count = 100;
+            List<String> ids = new ArrayList<String>(count);
             for (int i = 1; i <= count; i++) {
                 final Collection<Field> fields = List.of(new StringField("foo", "bar", false));
                 final DocumentUpdateRequest request = new DocumentUpdateRequest(i - 1, i, null, fields);
-                index.update("doc" + i, request);
+                final String id = "doc" + i;
+                ids.add(id);
+                index.update(id, request);
             }
+            ids.sort(String::compareTo);
             final SearchRequest request = new SearchRequest();
             request.setQuery("*:*");
+            request.setLimit(count);
             final SearchResults results = index.search(request);
             assertThat(results.getTotalHits()).isEqualTo(count);
+            for (int i = 0; i < count; i++) {
+                var hit = results.getHits().get(i);
+                assertThat(hit.getId()).isEqualTo(ids.get(i));
+                assertThat(hit.getSeq()).isEqualTo(Long.parseLong(ids.get(i).substring(3)));
+            }
         } finally {
             cleanup(index);
         }