Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-13261: Make SortableTextField work with export/streaming, now requires useDocValuesAsStored='true'

Erick Erickson1e09268e7810
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 3579e9d5874..6fdfac86bf4 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -62,7 +62,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 c80cae36787..e4d6da0a5bb 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 281e698eb4a..9fb224b34a3 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 4cebb12c8bc..b37ece975c9 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) {