Apache Lucene open-source search software
Adding date tests to SOLR-2134
Erick Erickson4145656bb584
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 3af96bb8e8f..59cb58fac63 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -183,6 +183,9 @@ New FeaturesLMDirichletSimilarity: LM with Dirichlet smoothingLMJelinekMercerSimilarity: LM with Jelinek-Mercer smoothing(David Mark Nemeskey, Robert Muir)++* SOLR-2134 Trie* fields should support sortMissingLast=true, and deprecate Sortable* Field Types+ (Ryan McKinley, Mike McCandless, Uwe Schindler, Erick Erickson)Optimizations----------------------diff --git a/solr/core/src/test-files/solr/conf/schema-numeric.xml b/solr/core/src/test-files/solr/conf/schema-numeric.xmlindex e52e4b95441..0a12736702d 100644--- a/solr/core/src/test-files/solr/conf/schema-numeric.xml+++ b/solr/core/src/test-files/solr/conf/schema-numeric.xml@@ -35,36 +35,42 @@<fieldType name="int" class="solr.TrieIntField" precisionStep="0" sortMissingLast="false" omitNorms="true" positionIncrementGap="0"/><fieldType name="float" class="solr.TrieFloatField" precisionStep="0" sortMissingLast="false" omitNorms="true" positionIncrementGap="0"/><fieldType name="long" class="solr.TrieLongField" precisionStep="0" sortMissingLast="false" omitNorms="true" positionIncrementGap="0"/>- <fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" sortMissingLast="false" omitNorms="true" positionIncrementGap="0"/>+ <fieldType name="date" class="solr.TrieDateField" precisionStep="0" sortMissingLast="false" omitNorms="true" positionIncrementGap="0"/>+ <fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" sortMissingLast="false" omitNorms="true" positionIncrementGap="0"/><fieldType name="int_last" class="solr.TrieIntField" precisionStep="0" sortMissingLast="true" omitNorms="true" positionIncrementGap="0"/><fieldType name="float_last" class="solr.TrieFloatField" precisionStep="0" sortMissingLast="true" omitNorms="true" positionIncrementGap="0"/><fieldType name="long_last" class="solr.TrieLongField" precisionStep="0" sortMissingLast="true" omitNorms="true" positionIncrementGap="0"/>- <fieldType name="double_last" class="solr.TrieDoubleField" precisionStep="0" sortMissingLast="true" omitNorms="true" positionIncrementGap="0"/>+ <fieldType name="date_last" class="solr.TrieDateField" precisionStep="0" sortMissingLast="true" omitNorms="true" positionIncrementGap="0"/>+ <fieldType name="double_last" class="solr.TrieDoubleField" precisionStep="0" sortMissingLast="true" omitNorms="true" positionIncrementGap="0"/><fieldType name="int_first" class="solr.TrieIntField" precisionStep="0" sortMissingFirst="true" omitNorms="true" positionIncrementGap="0"/><fieldType name="float_first" class="solr.TrieFloatField" precisionStep="0" sortMissingFirst="true" omitNorms="true" positionIncrementGap="0"/><fieldType name="long_first" class="solr.TrieLongField" precisionStep="0" sortMissingFirst="true" omitNorms="true" positionIncrementGap="0"/>- <fieldType name="double_first" class="solr.TrieDoubleField" precisionStep="0" sortMissingFirst="true" omitNorms="true" positionIncrementGap="0"/>+ <fieldType name="date_first" class="solr.TrieDateField" precisionStep="0" sortMissingFirst="true" omitNorms="true" positionIncrementGap="0"/>+ <fieldType name="double_first" class="solr.TrieDoubleField" precisionStep="0" sortMissingFirst="true" omitNorms="true" positionIncrementGap="0"/></types>-+<fields><field name="id" type="string" indexed="true" stored="true" multiValued="false" required="true"/>-+<field name="int" type="int" indexed="true" stored="true" multiValued="false"/><field name="float" type="float" indexed="true" stored="true" multiValued="false"/><field name="long" type="long" indexed="true" stored="true" multiValued="false"/>+ <field name="date" type="date" indexed="true" stored="true" multiValued="false"/><field name="double" type="double" indexed="true" stored="true" multiValued="false"/>-+<field name="int_last" type="int_last" indexed="true" stored="true" multiValued="false"/><field name="float_last" type="float_last" indexed="true" stored="true" multiValued="false"/><field name="long_last" type="long_last" indexed="true" stored="true" multiValued="false"/>+ <field name="date_last" type="date_last" indexed="true" stored="true" multiValued="false"/><field name="double_last" type="double_last" indexed="true" stored="true" multiValued="false"/>-+<field name="int_first" type="int_first" indexed="true" stored="true" multiValued="false"/><field name="float_first" type="float_first" indexed="true" stored="true" multiValued="false"/><field name="long_first" type="long_first" indexed="true" stored="true" multiValued="false"/>+ <field name="date_first" type="date_first" indexed="true" stored="true" multiValued="false"/><field name="double_first" type="double_first" indexed="true" stored="true" multiValued="false"/></fields>diff --git a/solr/core/src/test/org/apache/solr/schema/NumericFieldsTest.java b/solr/core/src/test/org/apache/solr/schema/NumericFieldsTest.javaindex 56a467e85a3..43cd7b19ff5 100644--- a/solr/core/src/test/org/apache/solr/schema/NumericFieldsTest.java+++ b/solr/core/src/test/org/apache/solr/schema/NumericFieldsTest.java@@ -26,107 +26,133 @@ import org.junit.Test;public class NumericFieldsTest extends SolrTestCaseJ4 {@BeforeClasspublic static void beforeClass() throws Exception {- initCore("solrconfig-master.xml","schema-numeric.xml");- }-- static String[] types = new String[] { "int", "long", "float", "double" };-- public static SolrInputDocument getDoc( String id, Integer number )- {+ initCore("solrconfig-master.xml", "schema-numeric.xml");+ }++ static String[] types = new String[]{"int", "long", "float", "double", "date"};++ public static SolrInputDocument getDoc(String id, Integer number, String date) {SolrInputDocument doc = new SolrInputDocument();- doc.addField( "id", id );- for( String t : types ) {- doc.addField( t, number );- doc.addField( t+"_last", number );- doc.addField( t+"_first", number );+ doc.addField("id", id);+ for (String t : types) {+ if ("date".equals(t)) {+ doc.addField(t, date);+ doc.addField(t + "_last", date);+ doc.addField(t + "_first", date);+ } else {+ doc.addField(t, number);+ doc.addField(t + "_last", number);+ doc.addField(t + "_first", number);+ }}return doc;}@Test- public void testSortMissingFirstLast()- {+ public void testSortMissingFirstLast() {clearIndex();-- assertU(adoc("id", "M1" ));- assertU(adoc( getDoc( "+4", 4 ) ));- assertU(adoc( getDoc( "+5", 5 ) ));- assertU(adoc( getDoc( "-3", -3 ) ));- assertU(adoc("id", "M2" ));- assertU(commit());+ assertU(adoc("id", "M1"));+ assertU(adoc(getDoc("+4", 4, "2011-04-04T00:00:00Z")));+ assertU(adoc(getDoc("+5", 5, "2011-05-05T00:00:00Z")));+ assertU(adoc(getDoc("-3", -3, "2011-01-01T00:00:00Z")));+ assertU(adoc("id", "M2"));+ assertU(commit());// 'normal' sorting. Missing Values are 0String suffix = "";- for( String t : types ) {- assertQ( "Sorting Asc: "+t+suffix,- req("fl", "id", "q", "*:*", "sort", (t+suffix)+" asc" ),- "//*[@numFound='5']",- "//result/doc[1]/str[@name='id'][.='-3']",- "//result/doc[2]/str[@name='id'][.='M1']",- "//result/doc[3]/str[@name='id'][.='M2']",- "//result/doc[4]/str[@name='id'][.='+4']",- "//result/doc[5]/str[@name='id'][.='+5']"- );-- assertQ( "Sorting Desc: "+t+suffix,- req("fl", "id", "q", "*:*", "sort", (t+suffix)+" desc" ),- "//*[@numFound='5']",- "//result/doc[1]/str[@name='id'][.='+5']",- "//result/doc[2]/str[@name='id'][.='+4']",- "//result/doc[3]/str[@name='id'][.='M1']",- "//result/doc[4]/str[@name='id'][.='M2']",- "//result/doc[5]/str[@name='id'][.='-3']"- );+ for (String t : types) {+ if ("date".equals(t)) {+ assertQ("Sorting Asc: " + t + suffix,+ req("fl", "id", "q", "*:*", "sort", (t + suffix) + " asc"),+ "//*[@numFound='5']",+ "//result/doc[1]/str[@name='id'][.='M1']",+ "//result/doc[2]/str[@name='id'][.='M2']",+ "//result/doc[3]/str[@name='id'][.='-3']",+ "//result/doc[4]/str[@name='id'][.='+4']",+ "//result/doc[5]/str[@name='id'][.='+5']"+ );++ assertQ("Sorting Desc: " + t + suffix,+ req("fl", "id", "q", "*:*", "sort", (t + suffix) + " desc"),+ "//*[@numFound='5']",+ "//result/doc[1]/str[@name='id'][.='+5']",+ "//result/doc[2]/str[@name='id'][.='+4']",+ "//result/doc[3]/str[@name='id'][.='-3']",+ "//result/doc[4]/str[@name='id'][.='M1']",+ "//result/doc[5]/str[@name='id'][.='M2']"+ );+ } else {+ assertQ("Sorting Asc: " + t + suffix,+ req("fl", "id", "q", "*:*", "sort", (t + suffix) + " asc"),+ "//*[@numFound='5']",+ "//result/doc[1]/str[@name='id'][.='-3']",+ "//result/doc[2]/str[@name='id'][.='M1']",+ "//result/doc[3]/str[@name='id'][.='M2']",+ "//result/doc[4]/str[@name='id'][.='+4']",+ "//result/doc[5]/str[@name='id'][.='+5']"+ );++ assertQ("Sorting Desc: " + t + suffix,+ req("fl", "id", "q", "*:*", "sort", (t + suffix) + " desc"),+ "//*[@numFound='5']",+ "//result/doc[1]/str[@name='id'][.='+5']",+ "//result/doc[2]/str[@name='id'][.='+4']",+ "//result/doc[3]/str[@name='id'][.='M1']",+ "//result/doc[4]/str[@name='id'][.='M2']",+ "//result/doc[5]/str[@name='id'][.='-3']"+ );++ }}--- // sortMissingLast = true+++ // sortMissingLast = truesuffix = "_last";- for( String t : types ) {- assertQ( "Sorting Asc: "+t+suffix,- req("fl", "id", "q", "*:*", "sort", (t+suffix)+" asc" ),- "//*[@numFound='5']",- "//result/doc[1]/str[@name='id'][.='-3']",- "//result/doc[2]/str[@name='id'][.='+4']",- "//result/doc[3]/str[@name='id'][.='+5']",- "//result/doc[4]/str[@name='id'][.='M1']",- "//result/doc[5]/str[@name='id'][.='M2']"+ for (String t : types) {+ assertQ("Sorting Asc: " + t + suffix,+ req("fl", "id", "q", "*:*", "sort", (t + suffix) + " asc"),+ "//*[@numFound='5']",+ "//result/doc[1]/str[@name='id'][.='-3']",+ "//result/doc[2]/str[@name='id'][.='+4']",+ "//result/doc[3]/str[@name='id'][.='+5']",+ "//result/doc[4]/str[@name='id'][.='M1']",+ "//result/doc[5]/str[@name='id'][.='M2']");-+// This does not match- assertQ( "Sorting Desc: "+t+suffix,- req("fl", "id", "q", "*:*", "sort", (t+suffix)+" desc", "indent", "on" ),- "//*[@numFound='5']",- "//result/doc[1]/str[@name='id'][.='+5']",- "//result/doc[2]/str[@name='id'][.='+4']",- "//result/doc[3]/str[@name='id'][.='-3']",- "//result/doc[4]/str[@name='id'][.='M1']",- "//result/doc[5]/str[@name='id'][.='M2']"+ assertQ("Sorting Desc: " + t + suffix,+ req("fl", "id", "q", "*:*", "sort", (t + suffix) + " desc", "indent", "on"),+ "//*[@numFound='5']",+ "//result/doc[1]/str[@name='id'][.='+5']",+ "//result/doc[2]/str[@name='id'][.='+4']",+ "//result/doc[3]/str[@name='id'][.='-3']",+ "//result/doc[4]/str[@name='id'][.='M1']",+ "//result/doc[5]/str[@name='id'][.='M2']");}- // sortMissingFirst = true+ // sortMissingFirst = truesuffix = "_first";- for( String t : types ) {- assertQ( "Sorting Asc: "+t+suffix,- req("fl", "id", "q", "*:*", "sort", (t+suffix)+" asc", "indent", "on" ),- "//*[@numFound='5']",- "//result/doc[1]/str[@name='id'][.='M1']",- "//result/doc[2]/str[@name='id'][.='M2']",- "//result/doc[3]/str[@name='id'][.='-3']",- "//result/doc[4]/str[@name='id'][.='+4']",- "//result/doc[5]/str[@name='id'][.='+5']"+ for (String t : types) {+ assertQ("Sorting Asc: " + t + suffix,+ req("fl", "id", "q", "*:*", "sort", (t + suffix) + " asc", "indent", "on"),+ "//*[@numFound='5']",+ "//result/doc[1]/str[@name='id'][.='M1']",+ "//result/doc[2]/str[@name='id'][.='M2']",+ "//result/doc[3]/str[@name='id'][.='-3']",+ "//result/doc[4]/str[@name='id'][.='+4']",+ "//result/doc[5]/str[@name='id'][.='+5']");-+// This does not match- assertQ( "Sorting Desc: "+t+suffix,- req("fl", "id", "q", "*:*", "sort", (t+suffix)+" desc", "indent", "on" ),- "//*[@numFound='5']",- "//result/doc[1]/str[@name='id'][.='M1']",- "//result/doc[2]/str[@name='id'][.='M2']",- "//result/doc[3]/str[@name='id'][.='+5']",- "//result/doc[4]/str[@name='id'][.='+4']",- "//result/doc[5]/str[@name='id'][.='-3']"+ assertQ("Sorting Desc: " + t + suffix,+ req("fl", "id", "q", "*:*", "sort", (t + suffix) + " desc", "indent", "on"),+ "//*[@numFound='5']",+ "//result/doc[1]/str[@name='id'][.='M1']",+ "//result/doc[2]/str[@name='id'][.='M2']",+ "//result/doc[3]/str[@name='id'][.='+5']",+ "//result/doc[4]/str[@name='id'][.='+4']",+ "//result/doc[5]/str[@name='id'][.='-3']");}}diff --git a/solr/example/solr/conf/schema.xml b/solr/example/solr/conf/schema.xmlindex b17500aea7a..c073c27f2a7 100755--- a/solr/example/solr/conf/schema.xml+++ b/solr/example/solr/conf/schema.xml@@ -74,8 +74,11 @@<!--Binary data type. The data should be sent/retrieved in as Base64 encoded Strings --><fieldtype name="binary" class="solr.BinaryField"/>- <!-- sortMissingLast and sortMissingFirst attributes are optional attributes- that control how fields are sorted when values are missing.+ <!-- sortMissingLast and sortMissingFirst attributes are optional attributes are+ currently supported on types that are sorted internally as strings+ and on numeric types.+ This includes "string","boolean", and, as of 3.5 (and 4.x),+ int, float, long, date, double, including the "Trie" variants.- If sortMissingLast="true", then a sort on this field will cause documentswithout the field to come after documents with the field,regardless of the requested sort order (asc or desc).@@ -141,7 +144,8 @@<!--Note:These should only be used for compatibility with existing indexes (created with lucene or older Solr versions).-+ Use Trie based fields instead. As of Solr 3.5 and 4.x, Trie based fields support sortMissingFirst/Last+Plain numeric field types that store and index the textvalue verbatim (and hence don't correctly support range queries, since thelexicographic ordering isn't equal to the numeric ordering)