SOLR-8813: Add test for MultiValued fields being returned in the correct order

This commit is contained in:
Erick Erickson 2016-03-09 11:40:44 -08:00
parent dee8b5e40a
commit 540e8010c3
2 changed files with 113 additions and 52 deletions

View File

@ -35,70 +35,73 @@
1.6: useDocValuesAsStored defaults to true. 1.6: useDocValuesAsStored defaults to true.
--> -->
<types>
<!-- field type definitions... note that the "name" attribute is <!-- field type definitions... note that the "name" attribute is
just a label to be used by field definitions. The "class" just a label to be used by field definitions. The "class"
attribute and any other attributes determine the real type and attribute and any other attributes determine the real type and
behavior of the fieldType. behavior of the fieldType.
--> -->
<fieldType name="int" class="solr.TrieIntField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/> <fieldType name="int" class="solr.TrieIntField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
<fieldType name="float" class="solr.TrieFloatField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/> <fieldType name="float" class="solr.TrieFloatField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
<fieldType name="long" class="solr.TrieLongField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/> <fieldType name="long" class="solr.TrieLongField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
<fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/> <fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
<fieldType name="tint" class="solr.TrieIntField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/> <fieldType name="tint" class="solr.TrieIntField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/>
<fieldType name="tfloat" class="solr.TrieFloatField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/> <fieldType name="tfloat" class="solr.TrieFloatField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/>
<fieldType name="tlong" class="solr.TrieLongField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/> <fieldType name="tlong" class="solr.TrieLongField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/>
<fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/> <fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" omitNorms="true" positionIncrementGap="0"/>
<fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/> <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/>
<fieldType name="string" class="solr.StrField" sortMissingLast="true"/> <fieldType name="string" class="solr.StrField" sortMissingLast="true"/>
<!-- format for date is 1995-12-31T23:59:59.999Z and only the fractional <!-- format for date is 1995-12-31T23:59:59.999Z and only the fractional
seconds part (.999) is optional. seconds part (.999) is optional.
--> -->
<fieldType name="date" class="solr.TrieDateField" precisionStep="0"/> <fieldType name="date" class="solr.TrieDateField" precisionStep="0"/>
<fieldType name="tdate" class="solr.TrieDateField" precisionStep="6"/> <fieldType name="tdate" class="solr.TrieDateField" precisionStep="6"/>
<fieldType name="tdatedv" class="solr.TrieDateField" precisionStep="6" docValues="true"/> <fieldType name="tdatedv" class="solr.TrieDateField" precisionStep="6" docValues="true"/>
<fieldType name="enumField" class="solr.EnumField" enumsConfig="enumsConfig.xml" enumName="severity"/> <fieldType name="enumField" class="solr.EnumField" enumsConfig="enumsConfig.xml" enumName="severity"/>
</types>
<fields>
<field name="id" type="string" indexed="true" stored="true" multiValued="false" required="false"/>
<field name="_version_" type="long" indexed="true" stored="true" docValues="true" multiValued="false"/> <field name="id" type="string" indexed="true" stored="true" multiValued="false" required="false"/>
<field name="nonstored_dv_str" type="string" indexed="true" stored="false" <field name="_version_" type="long" indexed="true" stored="true" docValues="true" multiValued="false"/>
docValues="true" useDocValuesAsStored="false" multiValued="false"/>
<field name="test_nonstored_dv_str" type="string" indexed="true" stored="false" docValues="true" multiValued="false"/> <field name="nonstored_dv_str" type="string" indexed="true" stored="false"
docValues="true" useDocValuesAsStored="false" multiValued="false"/>
<!-- single valued fields --> <field name="test_nonstored_dv_str" type="string" indexed="true" stored="false" docValues="true" multiValued="false"/>
<field name="enum_dvo" type="enumField" indexed="true" stored="false" multiValued="false" docValues="true"/>
<dynamicField name="*_s_dvo2" multiValued="false" type="string" docValues="true" indexed="false" stored="false"/> <field name="test_mvt_dvt_st_str" type="string" indexed="true" multiValued="true" docValues="true" stored="true"/>
<dynamicField name="*_s_dv" multiValued="false" type="string" docValues="true" indexed="true" stored="true"/> <field name="test_mvt_dvt_sf_str" type="string" indexed="true" multiValued="true" docValues="true" stored="false"/>
<dynamicField name="*_s_dvo" multiValued="false" type="string" docValues="true" indexed="true" stored="false"/> <field name="test_mvt_dvf_st_str" type="string" indexed="true" multiValued="true" docValues="false" stored="true"/>
<dynamicField name="*_i_dvo" multiValued="false" type="int" docValues="true" indexed="true" stored="false"/> <field name="test_mvt_dvu_st_str" type="string" indexed="true" multiValued="true" stored="true"/>
<dynamicField name="*_f_dvo" multiValued="false" type="float" docValues="true" indexed="true" stored="false"/>
<dynamicField name="*_d_dvo" multiValued="false" type="double" docValues="true" indexed="true" stored="false"/> <!-- single valued fields -->
<dynamicField name="*_l_dvo" multiValued="false" type="long" docValues="true" indexed="true" stored="false"/> <field name="enum_dvo" type="enumField" indexed="true" stored="false" multiValued="false" docValues="true"/>
<dynamicField name="*_dt_dvo" multiValued="false" type="date" docValues="true" indexed="true" stored="false"/> <dynamicField name="*_s_dvo2" multiValued="false" type="string" docValues="true" indexed="false" stored="false"/>
<dynamicField name="*_s_dv" multiValued="false" type="string" docValues="true" indexed="true" stored="true"/>
<dynamicField name="*_s_dvo" multiValued="false" type="string" docValues="true" indexed="true" stored="false"/>
<dynamicField name="*_i_dvo" multiValued="false" type="int" docValues="true" indexed="true" stored="false"/>
<dynamicField name="*_f_dvo" multiValued="false" type="float" docValues="true" indexed="true" stored="false"/>
<dynamicField name="*_d_dvo" multiValued="false" type="double" docValues="true" indexed="true" stored="false"/>
<dynamicField name="*_l_dvo" multiValued="false" type="long" docValues="true" indexed="true" stored="false"/>
<dynamicField name="*_dt_dvo" multiValued="false" type="date" docValues="true" indexed="true" stored="false"/>
<!-- multi valued fields -->
<field name="enums_dvo" type="enumField" indexed="true" stored="false" multiValued="true" docValues="true"/>
<dynamicField name="*_ss_dvo2" multiValued="true" type="string" docValues="true" indexed="false" stored="false"/>
<dynamicField name="*_ss_dv" multiValued="true" type="string" docValues="true" indexed="true" stored="true"/>
<dynamicField name="*_ss_dvo" multiValued="true" type="string" docValues="true" indexed="true" stored="false"/>
<dynamicField name="*_is_dvo" multiValued="true" type="int" docValues="true" indexed="true" stored="false"/>
<dynamicField name="*_fs_dvo" multiValued="true" type="float" docValues="true" indexed="true" stored="false"/>
<dynamicField name="*_ds_dvo" multiValued="true" type="double" docValues="true" indexed="true" stored="false"/>
<dynamicField name="*_ls_dvo" multiValued="true" type="long" docValues="true" indexed="true" stored="false"/>
<dynamicField name="*_dts_dvo" multiValued="true" type="date" docValues="true" indexed="true" stored="false"/>
<!-- multi valued fields -->
<field name="enums_dvo" type="enumField" indexed="true" stored="false" multiValued="true" docValues="true"/>
<dynamicField name="*_ss_dvo2" multiValued="true" type="string" docValues="true" indexed="false" stored="false"/>
<dynamicField name="*_ss_dv" multiValued="true" type="string" docValues="true" indexed="true" stored="true"/>
<dynamicField name="*_ss_dvo" multiValued="true" type="string" docValues="true" indexed="true" stored="false"/>
<dynamicField name="*_is_dvo" multiValued="true" type="int" docValues="true" indexed="true" stored="false"/>
<dynamicField name="*_fs_dvo" multiValued="true" type="float" docValues="true" indexed="true" stored="false"/>
<dynamicField name="*_ds_dvo" multiValued="true" type="double" docValues="true" indexed="true" stored="false"/>
<dynamicField name="*_ls_dvo" multiValued="true" type="long" docValues="true" indexed="true" stored="false"/>
<dynamicField name="*_dts_dvo" multiValued="true" type="date" docValues="true" indexed="true" stored="false"/>
</fields>
<uniqueKey>id</uniqueKey> <uniqueKey>id</uniqueKey>

View File

@ -76,7 +76,7 @@ public class TestUseDocValuesAsStored extends AbstractBadConfigTestBase {
@Test @Test
public void testOnEmptyIndex() throws Exception { public void testOnEmptyIndex() throws Exception {
assertU(delQ("*:*")); clearIndex();
assertU(commit()); assertU(commit());
assertJQ(req("q", "*:*"), "/response/numFound==0"); assertJQ(req("q", "*:*"), "/response/numFound==0");
assertJQ(req("q", "*:*", "fl", "*"), "/response/numFound==0"); assertJQ(req("q", "*:*", "fl", "*"), "/response/numFound==0");
@ -238,4 +238,62 @@ public class TestUseDocValuesAsStored extends AbstractBadConfigTestBase {
assertQ(desc + ": " + fl, req("q", "*:*", "fl", fl), xpaths); assertQ(desc + ": " + fl, req("q", "*:*", "fl", fl), xpaths);
} }
// See SOLR-8740 for a discussion. This test is here to make sure we consciously change behavior of multiValued
// fields given that we can now return docValues fields. The behavior we've guaranteed in the past is that if
// multiValued fields are stored, they're returned in the document in the order they were added.
// There are four new fieldTypes added:
// <field name="test_mvt_dvt_st_str" type="string" indexed="true" multiValued="true" docValues="true" stored="true"/>
// <field name="test_mvt_dvt_sf_str" type="string" indexed="true" multiValued="true" docValues="true" stored="false"/>
// <field name="test_mvt_dvf_st_str" type="string" indexed="true" multiValued="true" docValues="false" stored="true"/>
// <field name="test_mvt_dvu_st_str" type="string" indexed="true" multiValued="true" stored="true"/>
//
// If any of these tests break as a result of returning DocValues rather than stored values, make sure we reach some
// consensus that any breaks on back-compat are A Good Thing and that that behavior is carefully documented!
@Test
public void testMultivaluedOrdering() throws Exception {
clearIndex();
// multiValued=true, docValues=true, stored=true. Should return in original order
assertU(adoc("id", "1", "test_mvt_dvt_st_str", "cccc", "test_mvt_dvt_st_str", "aaaa", "test_mvt_dvt_st_str", "bbbb"));
// multiValued=true, docValues=true, stored=false. Should return in sorted order
assertU(adoc("id", "2", "test_mvt_dvt_sf_str", "cccc", "test_mvt_dvt_sf_str", "aaaa", "test_mvt_dvt_sf_str", "bbbb"));
// multiValued=true, docValues=false, stored=true. Should return in original order
assertU(adoc("id", "3", "test_mvt_dvf_st_str", "cccc", "test_mvt_dvf_st_str", "aaaa", "test_mvt_dvf_st_str", "bbbb"));
// multiValued=true, docValues=not specified, stored=true. Should return in original order
assertU(adoc("id", "4", "test_mvt_dvu_st_str", "cccc", "test_mvt_dvu_st_str", "aaaa", "test_mvt_dvu_st_str", "bbbb"));
assertU(commit());
assertJQ(req("q", "id:1", "fl", "test_mvt_dvt_st_str"),
"/response/docs/[0]/test_mvt_dvt_st_str/[0]==cccc",
"/response/docs/[0]/test_mvt_dvt_st_str/[1]==aaaa",
"/response/docs/[0]/test_mvt_dvt_st_str/[2]==bbbb");
// Currently, this test fails since stored=false. When SOLR-8740 is committed, it should not throw an exception
// and should succeed, returning the field in sorted order.
try {
assertJQ(req("q", "id:2", "fl", "test_mvt_dvt_sf_str"),
"/response/docs/[0]/test_mvt_dvt_sf_str/[0]==aaaa",
"/response/docs/[0]/test_mvt_dvt_sf_str/[1]==bbbb",
"/response/docs/[0]/test_mvt_dvt_sf_str/[2]==cccc");
} catch (Exception e) {
// do nothing until SOLR-8740 is committed. At that point this should not throw an exception.
// NOTE: I think the test is correct after 8740 so just remove the try/catch
}
assertJQ(req("q", "id:3", "fl", "test_mvt_dvf_st_str"),
"/response/docs/[0]/test_mvt_dvf_st_str/[0]==cccc",
"/response/docs/[0]/test_mvt_dvf_st_str/[1]==aaaa",
"/response/docs/[0]/test_mvt_dvf_st_str/[2]==bbbb");
assertJQ(req("q", "id:4", "fl", "test_mvt_dvu_st_str"),
"/response/docs/[0]/test_mvt_dvu_st_str/[0]==cccc",
"/response/docs/[0]/test_mvt_dvu_st_str/[1]==aaaa",
"/response/docs/[0]/test_mvt_dvu_st_str/[2]==bbbb");
}
} }