You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by mk...@apache.org on 2023/03/04 08:00:50 UTC

[solr] branch branch_9x updated: SOLR-16585: examples test for match all paging (#1378) (#1430)

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

mkhl pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new 7e47929a97b SOLR-16585: examples test for match all paging (#1378) (#1430)
7e47929a97b is described below

commit 7e47929a97bc82be0d3d63dc94c36e67f7756421
Author: Mikhail Khludnev <mk...@users.noreply.github.com>
AuthorDate: Sat Mar 4 11:00:45 2023 +0300

    SOLR-16585: examples test for match all paging (#1378) (#1430)
    
    Co-authored-by: Christine Poerschke <cp...@apache.org>
---
 .../apache/solr/client/solrj/SolrExampleTests.java | 74 ++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
index 4f7d41f4fbc..3f5f82658de 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
@@ -32,6 +32,7 @@ import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
@@ -571,6 +572,79 @@ public abstract class SolrExampleTests extends SolrExampleTestsBase {
     assertEquals(0, out.get(1).size());
   }
 
+  @Test
+  public void testMatchAllPaging() throws Exception {
+    SolrClient client = getSolrClient();
+
+    // Empty the database...
+    client.deleteByQuery("*:*"); // delete everything!
+    if (random().nextBoolean()) {
+      client.commit();
+    }
+    // Add eleven docs
+    List<SolrInputDocument> docs = new ArrayList<>();
+    final int docsTotal = CommonParams.ROWS_DEFAULT + 1;
+    for (int i = 0; i < docsTotal; i++) {
+      SolrInputDocument doc = new SolrInputDocument();
+      doc.addField("id", "id" + i);
+      doc.addField("name", "doc" + i);
+      doc.addField("price", "" + i);
+      docs.add(doc);
+      if (rarely()) {
+        client.add(docs);
+        client.commit();
+        docs.clear();
+      }
+    }
+    client.add(docs);
+    if (random().nextBoolean()) {
+      client.commit();
+    } else {
+      client.optimize();
+    }
+    final List<String> sorts = Arrays.asList("_docid_", "id", "name", "price", null);
+    Collections.shuffle(sorts, random());
+    final List<Integer> starts =
+        Arrays.asList(0, 1, 2, CommonParams.ROWS_DEFAULT, docsTotal, CommonParams.ROWS_DEFAULT + 2);
+    Collections.shuffle(starts, random());
+    final List<String> queries = Arrays.asList("*:*", "id:[* TO *]", "{!prefix f=name}doc");
+    Collections.shuffle(queries, random());
+    for (String queryVal : queries) {
+      for (String sort : sorts) {
+        if (rarely()) {
+          continue; // shortcut to run faster
+        }
+        for (int start : starts) {
+          final SolrQuery query = new SolrQuery(queryVal);
+          if (sort != null) {
+            query.setSort(
+                sort, random().nextBoolean() ? SolrQuery.ORDER.asc : SolrQuery.ORDER.desc);
+          }
+          if (start > 0 || random().nextBoolean()) {
+            query.setStart(start);
+          }
+          if (usually()) {
+            query.setRows(CommonParams.ROWS_DEFAULT);
+          }
+          SolrDocumentList results = client.query(query).getResults();
+          assertEquals(docsTotal, results.getNumFound());
+          assertEquals(
+              "page from " + start,
+              Math.max(Math.min(CommonParams.ROWS_DEFAULT, docsTotal - start), 0),
+              results.size());
+          for (SolrDocument doc : results) {
+            assertTrue(doc.containsKey("id"));
+            assertTrue(doc.containsKey("name"));
+            assertTrue(doc.containsKey("price"));
+          }
+          if (rarely()) {
+            break; // shortcut to run faster
+          }
+        }
+      }
+    }
+  }
+
   private String randomTestString(int maxLength) {
     // we can't just use _TestUtil.randomUnicodeString() or we might get 0xfffe etc
     // (considered invalid by XML)