From 4145656bb58466abfce6dc250d85d3b232094d6d Mon Sep 17 00:00:00 2001 From: Erick Erickson Date: Sun, 13 Nov 2011 19:29:17 +0000 Subject: [PATCH] Adding date tests to SOLR-2134 git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1201484 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 3 + .../test-files/solr/conf/schema-numeric.xml | 20 +- .../apache/solr/schema/NumericFieldsTest.java | 188 ++++++++++-------- solr/example/solr/conf/schema.xml | 10 +- 4 files changed, 130 insertions(+), 91 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 3af96bb8e8f..59cb58fac63 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -183,6 +183,9 @@ New Features LMDirichletSimilarity: LM with Dirichlet smoothing LMJelinekMercerSimilarity: 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.xml index 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 @@ - + + - + + - + + - + - + + - + + - + + diff --git a/solr/core/src/test/org/apache/solr/schema/NumericFieldsTest.java b/solr/core/src/test/org/apache/solr/schema/NumericFieldsTest.java index 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 { @BeforeClass public 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 0 String 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 = true suffix = "_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 = true suffix = "_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.xml index b17500aea7a..c073c27f2a7 100755 --- a/solr/example/solr/conf/schema.xml +++ b/solr/example/solr/conf/schema.xml @@ -74,8 +74,11 @@ -