You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by er...@apache.org on 2019/03/07 19:04:49 UTC

[lucene-solr] branch branch_8x updated: SOLR-13261: Make SortableTextField work with export/streaming, now requires useDocValuesAsStored='true'

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

erick pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/branch_8x by this push:
     new fc76b70  SOLR-13261: Make SortableTextField work with export/streaming, now requires useDocValuesAsStored='true'
fc76b70 is described below

commit fc76b70bd5555a9391e4a048de89db49a5921643
Author: Erick Erickson <Er...@gmail.com>
AuthorDate: Thu Mar 7 10:59:20 2019 -0800

    SOLR-13261: Make SortableTextField work with export/streaming, now requires useDocValuesAsStored='true'
    
    (cherry picked from commit 1e09268e781039b62e856cc696aba0e519079bbc)
---
 solr/CHANGES.txt                                   |  3 +-
 .../apache/solr/handler/export/ExportWriter.java   | 10 ++++++-
 .../collection1/conf/schema-sortingresponse.xml    |  3 ++
 .../solr/handler/export/TestExportWriter.java      | 34 +++++++++++++++++-----
 4 files changed, 40 insertions(+), 10 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 37bc10c..692b27f 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -40,7 +40,8 @@ New Features
 
 * SOLR-13171 : A true streaming parser for javabin payload/stream without creating any objects (noble)
 
-* SOLR-13261: Make SortableTextField work with export/streaming
+* SOLR-13261: Make SortableTextField work with export/streaming. NOTE: requires that the field have
+  useDocValuesAsStored=true (either explicit or as the default).
 
 * SOLR-10436: Add hashRollup Streaming Expression (Joel Bernstein)
 
diff --git a/solr/core/src/java/org/apache/solr/handler/export/ExportWriter.java b/solr/core/src/java/org/apache/solr/handler/export/ExportWriter.java
index c80cae3..e4d6da0 100644
--- a/solr/core/src/java/org/apache/solr/handler/export/ExportWriter.java
+++ b/solr/core/src/java/org/apache/solr/handler/export/ExportWriter.java
@@ -332,9 +332,13 @@ public class ExportWriter implements SolrCore.RawWriter, Closeable {
       if (!schemaField.hasDocValues()) {
         throw new IOException(schemaField + " must have DocValues to use this feature.");
       }
-
       boolean multiValued = schemaField.multiValued();
       FieldType fieldType = schemaField.getType();
+
+      if (fieldType instanceof SortableTextField && schemaField.useDocValuesAsStored() == false) {
+        throw new IOException(schemaField + " Must have useDocValuesAsStored='true' to be used with export writer");
+      }
+
       if (fieldType instanceof IntValueFieldType) {
         if (multiValued) {
           writers[i] = new MultiFieldWriter(field, fieldType, schemaField, true);
@@ -398,6 +402,10 @@ public class ExportWriter implements SolrCore.RawWriter, Closeable {
         throw new IOException(field + " must have DocValues to use this feature.");
       }
 
+      if (ft instanceof SortableTextField && schemaField.useDocValuesAsStored() == false) {
+        throw new IOException(schemaField + " Must have useDocValuesAsStored='true' to be used with export writer");
+      }
+
       if (ft instanceof IntValueFieldType) {
         if (reverse) {
           sortValues[i] = new IntValue(field, new IntDesc());
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-sortingresponse.xml b/solr/core/src/test-files/solr/collection1/conf/schema-sortingresponse.xml
index 281e698..9fb224b 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema-sortingresponse.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema-sortingresponse.xml
@@ -69,6 +69,8 @@
   <field name="datedv_m" type="date" indexed="false" stored="false" docValues="true" multiValued="true"/>
   <field name="stringdv_m" type="string" indexed="false" stored="false" docValues="true" multiValued="true"/>
   <field name="sortabledv_m" type="text_gen_sort" indexed="true" stored="true" multiValued="true" />
+  <field name="sortabledv_m_udvas" type="text_gen_sort" indexed="true" stored="true" multiValued="true" useDocValuesAsStored="true"/>
+
 
   <field name="floatdv" type="float" indexed="false" stored="false" docValues="true"/>
   <field name="intdv" type="int" indexed="false" stored="false" docValues="true"/>
@@ -78,6 +80,7 @@
   <field name="stringdv" type="string" indexed="false" stored="false" docValues="true"/>
   <field name="booleandv" type="boolean" indexed="false" stored="false" docValues="true" />
   <field name="sortabledv" type="text_gen_sort" indexed="true" stored="true" multiValued="false" />
+  <field name="sortabledv_udvas" type="text_gen_sort" indexed="true" stored="true" multiValued="false" useDocValuesAsStored="true" />
 
   <dynamicField name="*_s_dv"   type="string"    indexed="true"  stored="true" docValues="true" multiValued="false"/>
 
diff --git a/solr/core/src/test/org/apache/solr/handler/export/TestExportWriter.java b/solr/core/src/test/org/apache/solr/handler/export/TestExportWriter.java
index 4cebb12..b37ece9 100644
--- a/solr/core/src/test/org/apache/solr/handler/export/TestExportWriter.java
+++ b/solr/core/src/test/org/apache/solr/handler/export/TestExportWriter.java
@@ -132,7 +132,10 @@ public class TestExportWriter extends SolrTestCaseJ4 {
                  "datedv_m", "2017-06-16T04:00:00Z",
                  "sortabledv_m", "this is some text one_1",
                  "sortabledv_m", "this is some text two_1",
-                 "sortabledv_m", "this is some text three_1"));
+                 "sortabledv_m", "this is some text three_1",
+                 "sortabledv_m_udvas", "this is some text one_1",
+                 "sortabledv_m_udvas", "this is some text two_1",
+                 "sortabledv_m_udvas", "this is some text three_1"));
 
     assertU(adoc("id","7",
         "floatdv","2.1",
@@ -170,7 +173,8 @@ public class TestExportWriter extends SolrTestCaseJ4 {
         "int_is_t", "1",
         "int_is_t", "1",
         "int_is_t", "1",
-        "sortabledv", "this is some text_1"));
+        "sortabledv", "this is some text_1",
+        "sortabledv_udvas", "this is some text_1"));
     assertU(commit());
     assertU(adoc("id","8",
         "floatdv","2.1",
@@ -197,9 +201,14 @@ public class TestExportWriter extends SolrTestCaseJ4 {
         "int_is_p", "1",
         "int_is_p", "1",
         "sortabledv", "this is some text_2",
+        "sortabledv_udvas", "this is some text_2",
         "sortabledv_m", "this is some text one_2",
         "sortabledv_m", "this is some text two_2",
-        "sortabledv_m", "this is some text three_2"));
+        "sortabledv_m", "this is some text three_2",
+        "sortabledv_m_udvas", "this is some text one_2",
+        "sortabledv_m_udvas", "this is some text two_2",
+        "sortabledv_m_udvas", "this is some text three_2"
+    ));
     assertU(commit());
 
 
@@ -501,22 +510,31 @@ public class TestExportWriter extends SolrTestCaseJ4 {
     assertJsonEquals(s, "{\"responseHeader\": {\"status\": 0}, \"response\":{\"numFound\":1, \"docs\":[{\"stringdv\":\"chello \\\"world\\\"\"}]}}");
 
     // Test sortable text fields:
-    s =  h.query(req("q", "id:(1 OR 3 OR 8)", "qt", "/export", "fl", "sortabledv_m,sortabledv", "sort", "sortabledv asc"));
+    s =  h.query(req("q", "id:(1 OR 3 OR 8)", "qt", "/export", "fl", "sortabledv_m_udvas,sortabledv_udvas", "sort", "sortabledv_udvas asc"));
     assertJsonEquals(s, "{\n" +
         "  \"responseHeader\":{\"status\":0},\n" +
         "  \"response\":{\n" +
         "    \"numFound\":3,\n" +
         "    \"docs\":[{\n" +
-        "        \"sortabledv_m\":[\"this is some text one_1\"\n" +
+        "        \"sortabledv_m_udvas\":[\"this is some text one_1\"\n" +
         "          ,\"this is some text three_1\"\n" +
         "          ,\"this is some text two_1\"]}\n" +
         "      ,{\n" +
-        "        \"sortabledv\":\"this is some text_1\"}\n" +
+        "        \"sortabledv_udvas\":\"this is some text_1\"}\n" +
         "      ,{\n" +
-        "        \"sortabledv_m\":[\"this is some text one_2\"\n" +
+        "        \"sortabledv_m_udvas\":[\"this is some text one_2\"\n" +
         "          ,\"this is some text three_2\"\n" +
         "          ,\"this is some text two_2\"],\n" +
-        "        \"sortabledv\":\"this is some text_2\"}]}}");
+        "        \"sortabledv_udvas\":\"this is some text_2\"}]}}");
+
+    s =  h.query(req("q", "id:(1 OR 3 OR 8)", "qt", "/export", "fl", "sortabledv_m", "sort", "sortabledv_udvas asc"));
+    assertTrue("Should have 400 status when exporting sortabledv_m, it does not have useDocValuesAsStored='true'", s.contains("\"status\":400}"));
+    assertTrue("Should have a cause when exporting sortabledv_m, it does not have useDocValuesAsStored='true'", s.contains("Must have useDocValuesAsStored='true' to be used with export writer"));
+
+    s =  h.query(req("q", "id:(1 OR 3 OR 8)", "qt", "/export", "fl", "sortabledv", "sort", "sortabledv_udvas asc"));
+    assertTrue("Should have 400 status when exporting sortabledv, it does not have useDocValuesAsStored='true'", s.contains("\"status\":400}"));
+    assertTrue("Should have a cause when exporting sortabledv, it does not have useDocValuesAsStored='true'", s.contains("Must have useDocValuesAsStored='true' to be used with export writer"));
+
   }
 
   private void assertJsonEquals(String actual, String expected) {