You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "iprithv (via GitHub)" <gi...@apache.org> on 2026/05/22 18:41:04 UTC

[PR] Add count() to SortedSetDocValuesRangeQuery [lucene]

iprithv opened a new pull request, #16109:
URL: https://github.com/apache/lucene/pull/16109

   SortedNumericDocValuesRangeQuery has an efficient count() override (added in #15080) that uses DocValuesSkipper to avoid iterating docs for match-all and match-none cases. Its sibling SortedSetDocValuesRangeQuery has no count() override at all, despite having the same skipper-based logic already in scorerSupplier().


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Add count() to SortedSetDocValuesRangeQuery [lucene]

Posted by "iprithv (via GitHub)" <gi...@apache.org>.
iprithv commented on code in PR #16109:
URL: https://github.com/apache/lucene/pull/16109#discussion_r3333729435


##########
lucene/core/src/test/org/apache/lucene/search/TestDocValuesQueries.java:
##########
@@ -689,6 +689,153 @@ private void assertCount(IndexSearcher searcher, Query query, int expectedCount)
     assertEquals(expectedCount, w.count(searcher.reader.leaves().getFirst()));
   }
 
+  @Test
+  public void testSortedSetDocValuesRangeQueryCount() throws Exception {
+    try (Directory dir = newDirectory();
+        RandomIndexWriter iw = new RandomIndexWriter(random(), dir)) {
+      for (int i = 0; i < 100; i++) {
+        Document doc = new Document();
+        doc.add(SortedSetDocValuesField.indexedField("with_index", newBytesRef(i + "")));

Review Comment:
   sure, understood. changed it accordingly. thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Add count() to SortedSetDocValuesRangeQuery [lucene]

Posted by "shubhamsrkdev (via GitHub)" <gi...@apache.org>.
shubhamsrkdev commented on PR #16109:
URL: https://github.com/apache/lucene/pull/16109#issuecomment-4576953387

   nit: Do we have to wait for the next major version for this? I see #15080 was on a minor version maybe we can release this in 10.5.0?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Add count() to SortedSetDocValuesRangeQuery [lucene]

Posted by "iprithv (via GitHub)" <gi...@apache.org>.
iprithv commented on PR #16109:
URL: https://github.com/apache/lucene/pull/16109#issuecomment-4557263678

   @romseygeek could you please help review this? Thanks!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Add count() to SortedSetDocValuesRangeQuery [lucene]

Posted by "romseygeek (via GitHub)" <gi...@apache.org>.
romseygeek commented on code in PR #16109:
URL: https://github.com/apache/lucene/pull/16109#discussion_r3332560173


##########
lucene/core/src/test/org/apache/lucene/search/TestDocValuesQueries.java:
##########
@@ -689,6 +689,153 @@ private void assertCount(IndexSearcher searcher, Query query, int expectedCount)
     assertEquals(expectedCount, w.count(searcher.reader.leaves().getFirst()));
   }
 
+  @Test
+  public void testSortedSetDocValuesRangeQueryCount() throws Exception {
+    try (Directory dir = newDirectory();
+        RandomIndexWriter iw = new RandomIndexWriter(random(), dir)) {
+      for (int i = 0; i < 100; i++) {
+        Document doc = new Document();
+        doc.add(SortedSetDocValuesField.indexedField("with_index", newBytesRef(i + "")));

Review Comment:
   Can we use zero-padded number strings here?  Otherwise it gets very confusing as to what sorts where.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Add count() to SortedSetDocValuesRangeQuery [lucene]

Posted by "romseygeek (via GitHub)" <gi...@apache.org>.
romseygeek commented on code in PR #16109:
URL: https://github.com/apache/lucene/pull/16109#discussion_r3334132731


##########
lucene/core/src/test/org/apache/lucene/search/TestDocValuesQueries.java:
##########
@@ -689,6 +690,139 @@ private void assertCount(IndexSearcher searcher, Query query, int expectedCount)
     assertEquals(expectedCount, w.count(searcher.reader.leaves().getFirst()));
   }
 
+  @Test
+  public void testSortedSetDocValuesRangeQueryCount() throws Exception {
+    try (Directory dir = newDirectory();
+        RandomIndexWriter iw = new RandomIndexWriter(random(), dir)) {
+      for (int i = 0; i < 100; i++) {
+        String val = String.format(Locale.ROOT, "%03d", i);
+        Document doc = new Document();
+        doc.add(SortedSetDocValuesField.indexedField("with_index", newBytesRef(val)));
+        doc.add(new SortedSetDocValuesField("without_index", newBytesRef(val)));
+        if (i != 55) {
+          doc.add(SortedSetDocValuesField.indexedField("sparse", newBytesRef(val)));
+        }
+        iw.addDocument(doc);
+      }
+      iw.commit();
+      iw.forceMerge(1);
+
+      try (IndexReader reader = iw.getReader()) {
+        IndexSearcher searcher = new IndexSearcher(reader);
+
+        // Nonexistent field
+        assertCount(
+            searcher,
+            SortedSetDocValuesField.newSlowRangeQuery(
+                "nonexistent", newBytesRef("000"), newBytesRef("099"), true, true),
+            0);
+
+        // Below all values: range is entirely before "000"
+        assertCount(
+            searcher,
+            SortedSetDocValuesField.newSlowRangeQuery(
+                "with_index", newBytesRef("!"), newBytesRef("/"), true, true),
+            0);
+        assertCount(
+            searcher,
+            SortedSetDocValuesField.newSlowRangeQuery(
+                "without_index", newBytesRef("!"), newBytesRef("/"), true, true),
+            0);
+        assertCount(
+            searcher,
+            SortedSetDocValuesField.newSlowRangeQuery(
+                "sparse", newBytesRef("!"), newBytesRef("/"), true, true),
+            0);
+
+        // Match all values: "000" through "099"
+        assertCount(
+            searcher,
+            SortedSetDocValuesField.newSlowRangeQuery(
+                "with_index", newBytesRef("000"), newBytesRef("099"), true, true),
+            100);
+        assertCount(
+            searcher,
+            SortedSetDocValuesField.newSlowRangeQuery(
+                "without_index", newBytesRef("000"), newBytesRef("099"), true, true),
+            -1);
+        assertCount(
+            searcher,
+            SortedSetDocValuesField.newSlowRangeQuery(
+                "sparse", newBytesRef("000"), newBytesRef("099"), true, true),
+            -1);
+
+        // Partial match: "050" through "060" = 11 values
+        assertCount(

Review Comment:
   Let's add tests for partial matches against terms that aren't in the index, eg "0501" to "100"



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org


Re: [PR] Add count() to SortedSetDocValuesRangeQuery [lucene]

Posted by "romseygeek (via GitHub)" <gi...@apache.org>.
romseygeek merged PR #16109:
URL: https://github.com/apache/lucene/pull/16109


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org