From dc16b7efea3084d76d3db1fb03eae5d89b9e465f Mon Sep 17 00:00:00 2001 From: "Chris M. Hostetter" Date: Thu, 3 Feb 2011 23:21:44 +0000 Subject: [PATCH] SOLR-2339: Fix sorting to explicitly generate an error if you attempt to sort on a multiValued field. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1067030 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 11 + .../org/apache/solr/schema/BoolField.java | 1 + .../org/apache/solr/schema/ByteField.java | 3 +- .../org/apache/solr/schema/DoubleField.java | 1 + .../org/apache/solr/schema/FieldType.java | 6 +- .../org/apache/solr/schema/FloatField.java | 1 + .../java/org/apache/solr/schema/IntField.java | 1 + .../org/apache/solr/schema/LongField.java | 2 +- .../org/apache/solr/schema/SchemaField.java | 28 +++ .../org/apache/solr/schema/ShortField.java | 2 +- .../org/apache/solr/schema/TextField.java | 1 + .../org/apache/solr/schema/TrieDateField.java | 1 + .../org/apache/solr/schema/TrieField.java | 2 + .../org/apache/solr/search/QueryParsing.java | 11 +- solr/src/test-files/solr/conf/schema.xml | 21 +- solr/src/test-files/solr/conf/schema12.xml | 2 + .../solr/BaseDistributedSearchTestCase.java | 5 +- .../apache/solr/BasicFunctionalityTest.java | 37 ++++ .../org/apache/solr/ConvertedLegacyTest.java | 192 +++++++++--------- .../test/org/apache/solr/SolrTestCaseJ4.java | 8 + .../apache/solr/TestDistributedSearch.java | 6 +- .../org/apache/solr/TestGroupingSearch.java | 40 ++-- .../solr/cloud/BasicDistributedZkTest.java | 6 +- .../handler/StandardRequestHandlerTest.java | 16 +- .../QueryElevationComponentTest.java | 14 +- .../search/function/SortByFunctionTest.java | 14 +- 26 files changed, 271 insertions(+), 161 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index a40d288259b..7e6506702f7 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -53,6 +53,15 @@ Upgrading from Solr 3.1-dev legacy behavior should set a default value for the 'mm' param in their solrconfig.xml file. +* In previous releases, sorting on fields that are "multiValued" + (either by explicit declaration in schema.xml or by implict behavior + because the "version" attribute on the schema was less then 1.2) did + not generally work, but it would sometimes silently act as if it + succeeded and order the docs arbitrarily. Solr will now fail on any + attempt to sort on a multivalued field + + + Detailed Change List ---------------------- @@ -170,6 +179,8 @@ Bug Fixes * SOLR-1940: Fix SolrDispatchFilter behavior when Content-Type is unknown (Lance Norskog and hossman) +* SOLR-2339: Fix sorting to explicitly generate an error if you + attempt to sort on a multiValued field. (hossman) Other Changes ---------------------- diff --git a/solr/src/java/org/apache/solr/schema/BoolField.java b/solr/src/java/org/apache/solr/schema/BoolField.java index 0694e4c4c13..19fb3620dd3 100644 --- a/solr/src/java/org/apache/solr/schema/BoolField.java +++ b/solr/src/java/org/apache/solr/schema/BoolField.java @@ -43,6 +43,7 @@ public class BoolField extends FieldType { @Override public SortField getSortField(SchemaField field,boolean reverse) { + field.checkSortability(); return getStringSort(field,reverse); } diff --git a/solr/src/java/org/apache/solr/schema/ByteField.java b/solr/src/java/org/apache/solr/schema/ByteField.java index 204bce94836..dba71d86680 100644 --- a/solr/src/java/org/apache/solr/schema/ByteField.java +++ b/solr/src/java/org/apache/solr/schema/ByteField.java @@ -41,6 +41,7 @@ public class ByteField extends FieldType { ///////////////////////////////////////////////////////////// @Override public SortField getSortField(SchemaField field, boolean reverse) { + field.checkSortability(); return new SortField(field.name, SortField.BYTE, reverse); } @@ -78,4 +79,4 @@ public class ByteField extends FieldType { public Byte toObject(Fieldable f) { return Byte.valueOf(toExternal(f)); } -} \ No newline at end of file +} diff --git a/solr/src/java/org/apache/solr/schema/DoubleField.java b/solr/src/java/org/apache/solr/schema/DoubleField.java index 62e34e7ab82..c668c2a1647 100644 --- a/solr/src/java/org/apache/solr/schema/DoubleField.java +++ b/solr/src/java/org/apache/solr/schema/DoubleField.java @@ -41,6 +41,7 @@ public class DoubleField extends FieldType { ///////////////////////////////////////////////////////////// @Override public SortField getSortField(SchemaField field, boolean reverse) { + field.checkSortability(); return new SortField(field.name, SortField.DOUBLE, reverse); } diff --git a/solr/src/java/org/apache/solr/schema/FieldType.java b/solr/src/java/org/apache/solr/schema/FieldType.java index 712c22519f7..30e0a3130ac 100644 --- a/solr/src/java/org/apache/solr/schema/FieldType.java +++ b/solr/src/java/org/apache/solr/schema/FieldType.java @@ -478,13 +478,17 @@ public abstract class FieldType extends FieldProperties { /** * Returns the SortField instance that should be used to sort fields * of this type. + * @see SchemaField#checkSortability */ public abstract SortField getSortField(SchemaField field, boolean top); /** - * Utility usable by subclasses when they want to get basic String sorting. + * Utility usable by subclasses when they want to get basic String sorting + * using common checks. + * @see SchemaField#checkSortability */ protected SortField getStringSort(SchemaField field, boolean reverse) { + field.checkSortability(); return Sorting.getStringSortField(field.name, reverse, field.sortMissingLast(),field.sortMissingFirst()); } diff --git a/solr/src/java/org/apache/solr/schema/FloatField.java b/solr/src/java/org/apache/solr/schema/FloatField.java index 2df5ec9c345..51c7b646c30 100644 --- a/solr/src/java/org/apache/solr/schema/FloatField.java +++ b/solr/src/java/org/apache/solr/schema/FloatField.java @@ -39,6 +39,7 @@ public class FloatField extends FieldType { @Override public SortField getSortField(SchemaField field,boolean reverse) { + field.checkSortability(); return new SortField(field.name,SortField.FLOAT, reverse); } diff --git a/solr/src/java/org/apache/solr/schema/IntField.java b/solr/src/java/org/apache/solr/schema/IntField.java index 5d8182d52ae..73ff10a02c0 100644 --- a/solr/src/java/org/apache/solr/schema/IntField.java +++ b/solr/src/java/org/apache/solr/schema/IntField.java @@ -39,6 +39,7 @@ public class IntField extends FieldType { @Override public SortField getSortField(SchemaField field,boolean reverse) { + field.checkSortability(); return new SortField(field.name,SortField.INT, reverse); } diff --git a/solr/src/java/org/apache/solr/schema/LongField.java b/solr/src/java/org/apache/solr/schema/LongField.java index f1189b6adb7..a6a6dd01432 100644 --- a/solr/src/java/org/apache/solr/schema/LongField.java +++ b/solr/src/java/org/apache/solr/schema/LongField.java @@ -41,7 +41,7 @@ public class LongField extends FieldType { @Override public SortField getSortField(SchemaField field,boolean reverse) { - + field.checkSortability(); return new SortField(field.name,SortField.LONG, reverse); } diff --git a/solr/src/java/org/apache/solr/schema/SchemaField.java b/solr/src/java/org/apache/solr/schema/SchemaField.java index 2618fa987b3..5b9e417c411 100644 --- a/solr/src/java/org/apache/solr/schema/SchemaField.java +++ b/solr/src/java/org/apache/solr/schema/SchemaField.java @@ -17,9 +17,12 @@ package org.apache.solr.schema; +import org.apache.solr.common.SolrException; +import org.apache.solr.common.SolrException.ErrorCode; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; import org.apache.lucene.search.SortField; + import org.apache.solr.response.TextResponseWriter; import java.util.Map; @@ -120,10 +123,35 @@ public final class SchemaField extends FieldProperties { type.write(writer,name,val); } + /** + * Delegates to the FieldType for this field + * @see FieldType#getSortField + */ public SortField getSortField(boolean top) { return type.getSortField(this, top); } + /** + * Sanity checks that the properties of this field type are plausible + * for a field that may be used in sorting, throwing an appropraite + * exception (including hte field name) if it is not. FieldType subclasses + * can choose to call this method in their getSortField implementation + * @see FieldType#getSortField + */ + public void checkSortability() throws SolrException { + if (! indexed() ) { + throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, + "can not sort on unindexed field: " + + getName()); + } + if ( multiValued() ) { + throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, + "can not sort on multivalued field: " + + getName()); + } + + } + static SchemaField create(String name, FieldType ft, Map props) { diff --git a/solr/src/java/org/apache/solr/schema/ShortField.java b/solr/src/java/org/apache/solr/schema/ShortField.java index 2db6861ccc0..8283ffb0f89 100644 --- a/solr/src/java/org/apache/solr/schema/ShortField.java +++ b/solr/src/java/org/apache/solr/schema/ShortField.java @@ -44,7 +44,7 @@ public class ShortField extends FieldType { @Override public SortField getSortField(SchemaField field, boolean reverse) { - + field.checkSortability(); return new SortField(field.name, SortField.SHORT, reverse); } diff --git a/solr/src/java/org/apache/solr/schema/TextField.java b/solr/src/java/org/apache/solr/schema/TextField.java index d43cf54efa6..a30bbfe2a54 100644 --- a/solr/src/java/org/apache/solr/schema/TextField.java +++ b/solr/src/java/org/apache/solr/schema/TextField.java @@ -65,6 +65,7 @@ public class TextField extends FieldType { @Override public SortField getSortField(SchemaField field, boolean reverse) { + /* :TODO: maybe warn if isTokenized(), but doesn't use LimitTokenCountFilter in it's chain? */ return getStringSort(field, reverse); } diff --git a/solr/src/java/org/apache/solr/schema/TrieDateField.java b/solr/src/java/org/apache/solr/schema/TrieDateField.java index 7f118704f56..74db2991aaf 100755 --- a/solr/src/java/org/apache/solr/schema/TrieDateField.java +++ b/solr/src/java/org/apache/solr/schema/TrieDateField.java @@ -78,6 +78,7 @@ public class TrieDateField extends DateField { @Override public SortField getSortField(SchemaField field, boolean top) { + field.checkSortability(); return new SortField(new LongValuesCreator( field.getName(), FieldCache.NUMERIC_UTILS_LONG_PARSER, CachedArrayCreator.CACHE_VALUES_AND_BITS ), top); } diff --git a/solr/src/java/org/apache/solr/schema/TrieField.java b/solr/src/java/org/apache/solr/schema/TrieField.java index 6f6d01c7023..7f980283230 100644 --- a/solr/src/java/org/apache/solr/schema/TrieField.java +++ b/solr/src/java/org/apache/solr/schema/TrieField.java @@ -123,6 +123,8 @@ public class TrieField extends FieldType { @Override public SortField getSortField(SchemaField field, boolean top) { + field.checkSortability(); + int flags = CachedArrayCreator.CACHE_VALUES_AND_BITS; Object missingValue = null; boolean sortMissingLast = on( SORT_MISSING_LAST, properties ); diff --git a/solr/src/java/org/apache/solr/search/QueryParsing.java b/solr/src/java/org/apache/solr/search/QueryParsing.java index 1ffbdefb828..1c9a5826428 100644 --- a/solr/src/java/org/apache/solr/search/QueryParsing.java +++ b/solr/src/java/org/apache/solr/search/QueryParsing.java @@ -330,16 +330,9 @@ public class QueryParsing { } throw new SolrException (SolrException.ErrorCode.BAD_REQUEST, - "sort param fiedl can't be found: " + field); + "sort param field can't be found: " + field); } - - // TODO: remove this - it should be up to the FieldType - if (!sf.indexed()) { - throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, - "can not sort on unindexed field: " - + field); - } - lst.add(sf.getType().getSortField(sf, top)); + lst.add(sf.getSortField(top)); } } diff --git a/solr/src/test-files/solr/conf/schema.xml b/solr/src/test-files/solr/conf/schema.xml index 6590e20cc95..490bfc75b05 100644 --- a/solr/src/test-files/solr/conf/schema.xml +++ b/solr/src/test-files/solr/conf/schema.xml @@ -402,8 +402,8 @@ - - + + @@ -480,7 +480,7 @@ - + @@ -508,27 +508,40 @@ both match, the first appearing in the schema will be used. --> + + + + + + + + + + + - + + + diff --git a/solr/src/test-files/solr/conf/schema12.xml b/solr/src/test-files/solr/conf/schema12.xml index eadcfdc4a12..c8a60840ee1 100755 --- a/solr/src/test-files/solr/conf/schema12.xml +++ b/solr/src/test-files/solr/conf/schema12.xml @@ -545,6 +545,8 @@ + + diff --git a/solr/src/test/org/apache/solr/BaseDistributedSearchTestCase.java b/solr/src/test/org/apache/solr/BaseDistributedSearchTestCase.java index 1934bf7cd31..b1ea44c5de2 100644 --- a/solr/src/test/org/apache/solr/BaseDistributedSearchTestCase.java +++ b/solr/src/test/org/apache/solr/BaseDistributedSearchTestCase.java @@ -134,7 +134,7 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 { */ public abstract void doTest() throws Exception; - public static String[] fieldNames = new String[]{"n_ti", "n_f", "n_tf", "n_d", "n_td", "n_l", "n_tl", "n_dt", "n_tdt"}; + public static String[] fieldNames = new String[]{"n_ti1", "n_f1", "n_tf1", "n_d1", "n_td1", "n_l1", "n_tl1", "n_dt1", "n_tdt1"}; public static RandVal[] randVals = new RandVal[]{rint, rfloat, rfloat, rdouble, rdouble, rlong, rlong, rdate, rdate}; protected String[] getFieldNames() { @@ -580,7 +580,8 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 { String cmp; cmp = compare(a.getResponse(), b.getResponse(), flags, handle); if (cmp != null) { - log.info("Mismatched responses:\n" + a + "\n" + b); + //log.info("Mismatched responses:\n" + a + "\n" + b); + System.err.println("Mismatched responses:\n" + a + "\n" + b); // :nocommit: TestCase.fail(cmp); } } diff --git a/solr/src/test/org/apache/solr/BasicFunctionalityTest.java b/solr/src/test/org/apache/solr/BasicFunctionalityTest.java index 3847825c7a5..a69fe52c927 100644 --- a/solr/src/test/org/apache/solr/BasicFunctionalityTest.java +++ b/solr/src/test/org/apache/solr/BasicFunctionalityTest.java @@ -29,6 +29,8 @@ import javax.xml.parsers.DocumentBuilderFactory; import org.apache.lucene.document.Field; import org.apache.lucene.document.Fieldable; import org.apache.lucene.index.LogMergePolicy; +import org.apache.solr.common.SolrException; +import org.apache.solr.common.SolrException.ErrorCode; import org.apache.solr.common.params.AppendedSolrParams; import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.DefaultSolrParams; @@ -47,6 +49,8 @@ import org.apache.solr.schema.SchemaField; import org.apache.solr.search.DocIterator; import org.apache.solr.search.DocList; import org.apache.solr.update.SolrIndexWriter; + + import org.junit.BeforeClass; import org.junit.Test; @@ -658,6 +662,39 @@ public class BasicFunctionalityTest extends SolrTestCaseJ4 { "*[count(//doc)=1]"); } + @Test + public void testAbuseOfSort() { + + assertU(adoc("id", "9999991", + "sortabuse_b", "true", + "sortabuse_t", "zzz xxx ccc vvv bbb nnn aaa sss ddd fff ggg")); + assertU(adoc("id", "9999992", + "sortabuse_b", "true", + "sortabuse_t", "zzz xxx ccc vvv bbb nnn qqq www eee rrr ttt")); + + assertU(commit()); + + try { + assertQ("sort on something that shouldn't work", + req("q", "sortabuse_b:true", + "sort", "sortabuse_t asc"), + "*[count(//doc)=2]"); + fail("no error encountered when sorting on sortabuse_t"); + } catch (Exception outer) { + // EXPECTED + Throwable root = getRootCause(outer); + assertEquals("sort exception root cause", + SolrException.class, root.getClass()); + SolrException e = (SolrException) root; + assertEquals("incorrect error type", + SolrException.ErrorCode.BAD_REQUEST, + SolrException.ErrorCode.getErrorCode(e.code())); + assertTrue("exception doesn't contain field name", + -1 != e.getMessage().indexOf("sortabuse_t")); + } + } + + // /** this doesn't work, but if it did, this is how we'd test it. */ // public void testOverwriteFalse() { diff --git a/solr/src/test/org/apache/solr/ConvertedLegacyTest.java b/solr/src/test/org/apache/solr/ConvertedLegacyTest.java index f6f9d1b0c14..96dd599d172 100644 --- a/solr/src/test/org/apache/solr/ConvertedLegacyTest.java +++ b/solr/src/test/org/apache/solr/ConvertedLegacyTest.java @@ -123,9 +123,9 @@ public class ConvertedLegacyTest extends SolrTestCaseJ4 { // test range assertU("44"); - assertU("44apple"); - assertU("44banana"); - assertU("44pear"); + assertU("44appleapple"); + assertU("44bananabanana"); + assertU("44pearpear"); assertU(""); assertQ(req("val_s:[a TO z]") ,"//*[@numFound='3'] " @@ -228,7 +228,7 @@ public class ConvertedLegacyTest extends SolrTestCaseJ4 { args = new HashMap(); args.put("version","2.0"); args.put("defType","lucenePlusSort"); - req = new LocalSolrQueryRequest(h.getCore(), "val_s:[a TO z];val_s asc", + req = new LocalSolrQueryRequest(h.getCore(), "val_s:[a TO z];val_s1 asc", "standard", 0, 0 , args); assertQ(req ,"//*[@numFound='3'] " @@ -237,7 +237,7 @@ public class ConvertedLegacyTest extends SolrTestCaseJ4 { args = new HashMap(); args.put("version","2.0"); args.put("defType","lucenePlusSort"); - req = new LocalSolrQueryRequest(h.getCore(), "val_s:[a TO z];val_s desc", + req = new LocalSolrQueryRequest(h.getCore(), "val_s:[a TO z];val_s1 desc", "standard", 0, 0 , args); assertQ(req ,"//*[@numFound='3'] " @@ -509,133 +509,133 @@ public class ConvertedLegacyTest extends SolrTestCaseJ4 { // test integer ranges and sorting assertU("44"); - assertU("441234567890"); - assertU("4410"); - assertU("441"); - assertU("442"); - assertU("4415"); - assertU("44-1"); - assertU("44-987654321"); - assertU("442147483647"); - assertU("44-2147483648"); - assertU("440"); + assertU("441234567890"); + assertU("4410"); + assertU("441"); + assertU("442"); + assertU("4415"); + assertU("44-1"); + assertU("44-987654321"); + assertU("442147483647"); + assertU("44-2147483648"); + assertU("440"); assertU(""); assertQ(req("id:44") ,"*[count(//doc)=10]" ); - assertQ(req("num_i:2147483647") + assertQ(req("num_i1:2147483647") ,"//@numFound[.='1'] " ,"//int[.='2147483647']" ); - assertQ(req("num_i:\"-2147483648\"") + assertQ(req("num_i1:\"-2147483648\"") ,"//@numFound[.='1'] " ,"//int[.='-2147483648']" ); - assertQ(req("id:44;num_i asc;") + assertQ(req("id:44;num_i1 asc;") ,"//doc[1]/int[.='-2147483648'] " ,"//doc[last()]/int[.='2147483647']" ); - assertQ(req("id:44;num_i desc;") + assertQ(req("id:44;num_i1 desc;") ,"//doc[1]/int[.='2147483647'] " ,"//doc[last()]/int[.='-2147483648']" ); - assertQ(req("num_i:[0 TO 9]") + assertQ(req("num_i1:[0 TO 9]") ,"*[count(//doc)=3]" ); - assertQ(req("num_i:[-2147483648 TO 2147483647]") + assertQ(req("num_i1:[-2147483648 TO 2147483647]") ,"*[count(//doc)=10]" ); - assertQ(req("num_i:[-10 TO -1]") + assertQ(req("num_i1:[-10 TO -1]") ,"*[count(//doc)=1]" ); // test long ranges and sorting assertU("44"); - assertU("441234567890"); - assertU("4410"); - assertU("441"); - assertU("442"); - assertU("4415"); - assertU("44-1"); - assertU("44-987654321"); - assertU("449223372036854775807"); - assertU("44-9223372036854775808"); - assertU("440"); + assertU("441234567890"); + assertU("4410"); + assertU("441"); + assertU("442"); + assertU("4415"); + assertU("44-1"); + assertU("44-987654321"); + assertU("449223372036854775807"); + assertU("44-9223372036854775808"); + assertU("440"); assertU(""); assertQ(req("id:44") ,"*[count(//doc)=10]" ); - assertQ(req("num_l:9223372036854775807") + assertQ(req("num_l1:9223372036854775807") ,"//@numFound[.='1'] " ,"//long[.='9223372036854775807']" ); - assertQ(req("num_l:\"-9223372036854775808\"") + assertQ(req("num_l1:\"-9223372036854775808\"") ,"//@numFound[.='1'] " ,"//long[.='-9223372036854775808']" ); - assertQ(req("id:44;num_l asc;") + assertQ(req("id:44;num_l1 asc;") ,"//doc[1]/long[.='-9223372036854775808'] " ,"//doc[last()]/long[.='9223372036854775807']" ); - assertQ(req("id:44;num_l desc;") + assertQ(req("id:44;num_l1 desc;") ,"//doc[1]/long[.='9223372036854775807'] " ,"//doc[last()]/long[.='-9223372036854775808']" ); - assertQ(req("num_l:[-1 TO 9]") + assertQ(req("num_l1:[-1 TO 9]") ,"*[count(//doc)=4]" ); - assertQ(req("num_l:[-9223372036854775808 TO 9223372036854775807]") + assertQ(req("num_l1:[-9223372036854775808 TO 9223372036854775807]") ,"*[count(//doc)=10]" ); - assertQ(req("num_l:[-10 TO -1]") + assertQ(req("num_l1:[-10 TO -1]") ,"*[count(//doc)=1]" ); // test binary float ranges and sorting assertU("44"); - assertU("441.4142135"); - assertU("44Infinity"); - assertU("44-Infinity"); - assertU("44NaN"); - assertU("442"); - assertU("44-1"); - assertU("44-987654321"); - assertU("44-999999.99"); - assertU("44-1e20"); - assertU("440"); + assertU("441.4142135"); + assertU("44Infinity"); + assertU("44-Infinity"); + assertU("44NaN"); + assertU("442"); + assertU("44-1"); + assertU("44-987654321"); + assertU("44-999999.99"); + assertU("44-1e20"); + assertU("440"); assertU(""); assertQ(req("id:44") ,"*[count(//doc)=10]" ); - assertQ(req("num_sf:Infinity") + assertQ(req("num_sf1:Infinity") ,"//@numFound[.='1'] " ,"//float[.='Infinity']" ); - assertQ(req("num_sf:\"-Infinity\"") + assertQ(req("num_sf1:\"-Infinity\"") ,"//@numFound[.='1'] " ,"//float[.='-Infinity']" ); - assertQ(req("num_sf:\"NaN\"") + assertQ(req("num_sf1:\"NaN\"") ,"//@numFound[.='1'] " ,"//float[.='NaN']" ); - assertQ(req("num_sf:\"-1e20\"") + assertQ(req("num_sf1:\"-1e20\"") ,"//@numFound[.='1']" ); - assertQ(req("id:44;num_sf asc;") + assertQ(req("id:44;num_sf1 asc;") ,"//doc[1]/float[.='-Infinity'] " ,"//doc[last()]/float[.='NaN']" ); - assertQ(req("id:44;num_sf desc;") + assertQ(req("id:44;num_sf1 desc;") ,"//doc[1]/float[.='NaN'] " ,"//doc[last()]/float[.='-Infinity']" ); - assertQ(req("num_sf:[-1 TO 2]") + assertQ(req("num_sf1:[-1 TO 2]") ,"*[count(//doc)=4]" ); - assertQ(req("num_sf:[-Infinity TO Infinity]") + assertQ(req("num_sf1:[-Infinity TO Infinity]") ,"*[count(//doc)=9]" ); @@ -644,50 +644,50 @@ public class ConvertedLegacyTest extends SolrTestCaseJ4 { // test binary double ranges and sorting assertU("44"); - assertU("441.4142135"); - assertU("44Infinity"); - assertU("44-Infinity"); - assertU("44NaN"); - assertU("442"); - assertU("44-1"); - assertU("441e-100"); - assertU("44-999999.99"); - assertU("44-1e100"); - assertU("440"); + assertU("441.4142135"); + assertU("44Infinity"); + assertU("44-Infinity"); + assertU("44NaN"); + assertU("442"); + assertU("44-1"); + assertU("441e-100"); + assertU("44-999999.99"); + assertU("44-1e100"); + assertU("440"); assertU(""); assertQ(req("id:44") ,"*[count(//doc)=10]" ); - assertQ(req("num_sd:Infinity") + assertQ(req("num_sd1:Infinity") ,"//@numFound[.='1'] " ,"//double[.='Infinity']" ); - assertQ(req("num_sd:\"-Infinity\"") + assertQ(req("num_sd1:\"-Infinity\"") ,"//@numFound[.='1'] " ,"//double[.='-Infinity']" ); - assertQ(req("num_sd:\"NaN\"") + assertQ(req("num_sd1:\"NaN\"") ,"//@numFound[.='1'] " ,"//double[.='NaN']" ); - assertQ(req("num_sd:\"-1e100\"") + assertQ(req("num_sd1:\"-1e100\"") ,"//@numFound[.='1']" ); - assertQ(req("num_sd:\"1e-100\"") + assertQ(req("num_sd1:\"1e-100\"") ,"//@numFound[.='1']" ); - assertQ(req("id:44;num_sd asc;") + assertQ(req("id:44;num_sd1 asc;") ,"//doc[1]/double[.='-Infinity'] " ,"//doc[last()]/double[.='NaN']" ); - assertQ(req("id:44;num_sd desc;") + assertQ(req("id:44;num_sd1 desc;") ,"//doc[1]/double[.='NaN'] " ,"//doc[last()]/double[.='-Infinity']" ); - assertQ(req("num_sd:[-1 TO 2]") + assertQ(req("num_sd1:[-1 TO 2]") ,"*[count(//doc)=5]" ); - assertQ(req("num_sd:[-Infinity TO Infinity]") + assertQ(req("num_sd1:[-Infinity TO Infinity]") ,"*[count(//doc)=9]" ); @@ -695,38 +695,38 @@ public class ConvertedLegacyTest extends SolrTestCaseJ4 { // test sorting on multiple fields assertU("44"); - assertU("4410"); - assertU("441100"); - assertU("44-1"); - assertU("4415"); - assertU("44150"); - assertU("440"); + assertU("4410"); + assertU("441100"); + assertU("44-1"); + assertU("4415"); + assertU("44150"); + assertU("440"); assertU(""); assertQ(req("id:44") ,"*[count(//doc)=6]" ); - assertQ(req("id:44; a_i asc,b_i desc") + assertQ(req("id:44; a_i1 asc,b_i1 desc") ,"*[count(//doc)=6] " ,"//doc[3]/int[.='100'] " ,"//doc[4]/int[.='50']" ); - assertQ(req("id:44;a_i asc , b_i asc;") + assertQ(req("id:44;a_i1 asc , b_i1 asc;") ,"*[count(//doc)=6] " ,"//doc[3]/int[.='50'] " ,"//doc[4]/int[.='100']" ); - assertQ(req("id:44;a_i asc;") + assertQ(req("id:44;a_i1 asc;") ,"*[count(//doc)=6] " ,"//doc[1]/int[.='-1'] " ,"//doc[last()]/int[.='15']" ); - assertQ(req("id:44;a_i asc , score top;") + assertQ(req("id:44;a_i1 asc , score top;") ,"*[count(//doc)=6] " ,"//doc[1]/int[.='-1'] " ,"//doc[last()]/int[.='15']" ); - assertQ(req("id:44; score top , a_i top, b_i bottom ;") + assertQ(req("id:44; score top , a_i1 top, b_i1 bottom ;") ,"*[count(//doc)=6] " ,"//doc[last()]/int[.='-1'] " ,"//doc[1]/int[.='15'] " @@ -738,13 +738,13 @@ public class ConvertedLegacyTest extends SolrTestCaseJ4 { // test sorting with some docs missing the sort field assertU("id_i:[1000 TO 1010]"); - assertU("10001Z"); - assertU("100110A"); - assertU("10021100"); - assertU("1003-1"); - assertU("100415"); - assertU("1005150"); - assertU("10060"); + assertU("10001Z"); + assertU("100110A"); + assertU("10021100"); + assertU("1003-1"); + assertU("100415"); + assertU("1005150"); + assertU("10060"); assertU(""); assertQ(req("id_i:[1000 TO 1010]") ,"*[count(//doc)=7]" @@ -759,13 +759,13 @@ public class ConvertedLegacyTest extends SolrTestCaseJ4 { ,"//doc[1]/int[.='100'] " ,"//doc[2]/int[.='50']" ); - assertQ(req("id_i:[1000 TO 1010]; a_i asc,b_si desc") + assertQ(req("id_i:[1000 TO 1010]; a_i1 asc,b_si desc") ,"*[count(//doc)=7] " ,"//doc[3]/int[.='100'] " ,"//doc[4]/int[.='50'] " ,"//doc[5]/int[.='1000']" ); - assertQ(req("id_i:[1000 TO 1010]; a_i asc,b_si asc") + assertQ(req("id_i:[1000 TO 1010]; a_i1 asc,b_si asc") ,"*[count(//doc)=7] " ,"//doc[3]/int[.='50'] " ,"//doc[4]/int[.='100'] " diff --git a/solr/src/test/org/apache/solr/SolrTestCaseJ4.java b/solr/src/test/org/apache/solr/SolrTestCaseJ4.java index 17269d477d3..ecbe82f4382 100755 --- a/solr/src/test/org/apache/solr/SolrTestCaseJ4.java +++ b/solr/src/test/org/apache/solr/SolrTestCaseJ4.java @@ -1073,4 +1073,12 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase { } return new File(base, "solr/").getAbsolutePath(); } + + public static Throwable getRootCause(Throwable t) { + Throwable result = t; + for (Throwable cause = t; null != cause; cause = cause.getCause()) { + result = cause; + } + return result; + } } diff --git a/solr/src/test/org/apache/solr/TestDistributedSearch.java b/solr/src/test/org/apache/solr/TestDistributedSearch.java index d1cd535941d..5151564fedd 100755 --- a/solr/src/test/org/apache/solr/TestDistributedSearch.java +++ b/solr/src/test/org/apache/solr/TestDistributedSearch.java @@ -38,7 +38,7 @@ public class TestDistributedSearch extends BaseDistributedSearchTestCase { String ndouble = "n_d"; String tdouble = "n_td"; String nlong = "n_l"; - String tlong = "n_tl"; + String tlong = "other_tl1"; String ndate = "n_dt"; String tdate = "n_tdt"; @@ -98,8 +98,8 @@ public class TestDistributedSearch extends BaseDistributedSearchTestCase { query("q","*:*", "sort","{!func}add("+i1+",5)"+" desc"); query("q","*:*", "sort",i1+" asc"); query("q","*:*", "sort",i1+" desc", "fl","*,score"); - query("q","*:*", "sort",tlong+" asc", "fl","score"); // test legacy behavior - "score"=="*,score" - query("q","*:*", "sort",tlong+" desc"); + query("q","*:*", "sort","n_tl1 asc", "fl","score"); // test legacy behavior - "score"=="*,score" + query("q","*:*", "sort","n_tl1 desc"); handle.put("maxScore", SKIPVAL); query("q","{!func}"+i1);// does not expect maxScore. So if it comes ,ignore it. JavaBinCodec.writeSolrDocumentList() //is agnostic of request params. diff --git a/solr/src/test/org/apache/solr/TestGroupingSearch.java b/solr/src/test/org/apache/solr/TestGroupingSearch.java index 2f4775ebdb0..f0b53bc32fe 100644 --- a/solr/src/test/org/apache/solr/TestGroupingSearch.java +++ b/solr/src/test/org/apache/solr/TestGroupingSearch.java @@ -30,6 +30,10 @@ import java.util.*; public class TestGroupingSearch extends SolrTestCaseJ4 { + public static final String FOO_STRING_FIELD = "foo_s1"; + public static final String SMALL_STRING_FIELD = "small_s1"; + public static final String SMALL_INT_FIELD = "small_i"; + @BeforeClass public static void beforeTests() throws Exception { initCore("solrconfig.xml","schema12.xml"); @@ -376,9 +380,9 @@ public class TestGroupingSearch extends SolrTestCaseJ4 { types.add(new FldType("id",ONE_ONE, new SVal('A','Z',4,4))); types.add(new FldType("score_f",ONE_ONE, new FVal(1,100))); // field used to score types.add(new FldType("foo_i",ZERO_ONE, new IRange(0,indexSize))); - types.add(new FldType("foo_s",ZERO_ONE, new SVal('a','z',1,2))); - types.add(new FldType("small_s",ZERO_ONE, new SVal('a',(char)('c'+indexSize/10),1,1))); - types.add(new FldType("small_i",ZERO_ONE, new IRange(0,5+indexSize/10))); + types.add(new FldType(FOO_STRING_FIELD,ZERO_ONE, new SVal('a','z',1,2))); + types.add(new FldType(SMALL_STRING_FIELD,ZERO_ONE, new SVal('a',(char)('c'+indexSize/10),1,1))); + types.add(new FldType(SMALL_INT_FIELD,ZERO_ONE, new IRange(0,5+indexSize/10))); clearIndex(); Map model = indexDocs(types, null, indexSize); @@ -389,36 +393,36 @@ public class TestGroupingSearch extends SolrTestCaseJ4 { clearIndex(); model.clear(); Doc d1 = createDoc(types); - d1.getValues("small_s").set(0,"c"); - d1.getValues("small_i").set(0,5); + d1.getValues(SMALL_STRING_FIELD).set(0,"c"); + d1.getValues(SMALL_INT_FIELD).set(0,5); d1.order = 0; updateJ(toJSON(d1), params("commit","true")); model.put(d1.id, d1); d1 = createDoc(types); - d1.getValues("small_s").set(0,"b"); - d1.getValues("small_i").set(0,5); + d1.getValues(SMALL_STRING_FIELD).set(0,"b"); + d1.getValues(SMALL_INT_FIELD).set(0,5); d1.order = 1; updateJ(toJSON(d1), params("commit","false")); model.put(d1.id, d1); d1 = createDoc(types); - d1.getValues("small_s").set(0,"c"); - d1.getValues("small_i").set(0,5); + d1.getValues(SMALL_STRING_FIELD).set(0,"c"); + d1.getValues(SMALL_INT_FIELD).set(0,5); d1.order = 2; updateJ(toJSON(d1), params("commit","false")); model.put(d1.id, d1); d1 = createDoc(types); - d1.getValues("small_s").set(0,"c"); - d1.getValues("small_i").set(0,5); + d1.getValues(SMALL_STRING_FIELD).set(0,"c"); + d1.getValues(SMALL_INT_FIELD).set(0,5); d1.order = 3; updateJ(toJSON(d1), params("commit","false")); model.put(d1.id, d1); d1 = createDoc(types); - d1.getValues("small_s").set(0,"b"); - d1.getValues("small_i").set(0,2); + d1.getValues(SMALL_STRING_FIELD).set(0,"b"); + d1.getValues(SMALL_INT_FIELD).set(0,2); d1.order = 4; updateJ(toJSON(d1), params("commit","true")); model.put(d1.id, d1); @@ -447,11 +451,11 @@ public class TestGroupingSearch extends SolrTestCaseJ4 { // Test specific case if (false) { - groupField="small_i"; - sortComparator=createComparator(Arrays.asList(createComparator("small_s", true, true, false, true))); - sortStr = "small_s asc"; - groupComparator = createComparator(Arrays.asList(createComparator("small_s", true, true, false, false))); - groupSortStr = "small_s asc"; + groupField=SMALL_INT_FIELD; + sortComparator=createComparator(Arrays.asList(createComparator(SMALL_STRING_FIELD, true, true, false, true))); + sortStr = SMALL_STRING_FIELD + " asc"; + groupComparator = createComparator(Arrays.asList(createComparator(SMALL_STRING_FIELD, true, true, false, false))); + groupSortStr = SMALL_STRING_FIELD + " asc"; rows=1; start=0; group_offset=1; group_limit=1; } diff --git a/solr/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java b/solr/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java index 35d86e0ac5c..2452a90f498 100644 --- a/solr/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java +++ b/solr/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java @@ -43,7 +43,7 @@ public class BasicDistributedZkTest extends AbstractDistributedZkTestCase { String ndouble = "n_d"; String tdouble = "n_td"; String nlong = "n_l"; - String tlong = "n_tl"; + String tlong = "other_tl1"; String ndate = "n_dt"; String tdate = "n_tdt"; @@ -133,8 +133,8 @@ public class BasicDistributedZkTest extends AbstractDistributedZkTestCase { query("q","*:*", "sort",i1+" desc"); query("q","*:*", "sort",i1+" asc"); query("q","*:*", "sort",i1+" desc", "fl","*,score"); - query("q","*:*", "sort",tlong+" asc", "fl","score"); // test legacy behavior - "score"=="*,score" - query("q","*:*", "sort",tlong+" desc"); + query("q","*:*", "sort","n_tl1 asc", "fl","score"); // test legacy behavior - "score"=="*,score" + query("q","*:*", "sort","n_tl1 desc"); handle.put("maxScore", SKIPVAL); query("q","{!func}"+i1);// does not expect maxScore. So if it comes ,ignore it. JavaBinCodec.writeSolrDocumentList() //is agnostic of request params. diff --git a/solr/src/test/org/apache/solr/handler/StandardRequestHandlerTest.java b/solr/src/test/org/apache/solr/handler/StandardRequestHandlerTest.java index e9dd455da55..1cb930f94d6 100644 --- a/solr/src/test/org/apache/solr/handler/StandardRequestHandlerTest.java +++ b/solr/src/test/org/apache/solr/handler/StandardRequestHandlerTest.java @@ -43,9 +43,9 @@ public class StandardRequestHandlerTest extends AbstractSolrTestCase { public void testSorting() throws Exception { SolrCore core = h.getCore(); - assertU(adoc("id", "10", "title", "test", "val_s", "aaa")); - assertU(adoc("id", "11", "title", "test", "val_s", "bbb")); - assertU(adoc("id", "12", "title", "test", "val_s", "ccc")); + assertU(adoc("id", "10", "title", "test", "val_s1", "aaa")); + assertU(adoc("id", "11", "title", "test", "val_s1", "bbb")); + assertU(adoc("id", "12", "title", "test", "val_s1", "ccc")); assertU(commit()); Map args = new HashMap(); @@ -58,7 +58,7 @@ public class StandardRequestHandlerTest extends AbstractSolrTestCase { ,"//*[@numFound='3']" ); - args.put( CommonParams.SORT, "val_s asc" ); + args.put( CommonParams.SORT, "val_s1 asc" ); assertQ("with sort param [asc]", req ,"//*[@numFound='3']" ,"//result/doc[1]/int[@name='id'][.='10']" @@ -66,7 +66,7 @@ public class StandardRequestHandlerTest extends AbstractSolrTestCase { ,"//result/doc[3]/int[@name='id'][.='12']" ); - args.put( CommonParams.SORT, "val_s desc" ); + args.put( CommonParams.SORT, "val_s1 desc" ); assertQ("with sort param [desc]", req ,"//*[@numFound='3']" ,"//result/doc[1]/int[@name='id'][.='12']" @@ -84,7 +84,7 @@ public class StandardRequestHandlerTest extends AbstractSolrTestCase { // Using legacy ';' param args.remove( CommonParams.SORT ); args.put( QueryParsing.DEFTYPE, "lucenePlusSort" ); - args.put( CommonParams.Q, "title:test; val_s desc" ); + args.put( CommonParams.Q, "title:test; val_s1 desc" ); assertQ("with sort param [desc]", req ,"//*[@numFound='3']" ,"//result/doc[1]/int[@name='id'][.='12']" @@ -92,8 +92,8 @@ public class StandardRequestHandlerTest extends AbstractSolrTestCase { ,"//result/doc[3]/int[@name='id'][.='10']" ); - args.put( CommonParams.Q, "title:test; val_s asc" ); - assertQ("with sort param [desc]", req + args.put( CommonParams.Q, "title:test; val_s1 asc" ); + assertQ("with sort param [asc]", req ,"//*[@numFound='3']" ,"//result/doc[1]/int[@name='id'][.='10']" ,"//result/doc[2]/int[@name='id'][.='11']" diff --git a/solr/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java b/solr/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java index 349521d0901..821c838af7c 100644 --- a/solr/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java +++ b/solr/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java @@ -120,13 +120,13 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 { @Test public void testSorting() throws IOException { - assertU(adoc("id", "a", "title", "ipod", "str_s", "a" )); - assertU(adoc("id", "b", "title", "ipod ipod", "str_s", "b" )); - assertU(adoc("id", "c", "title", "ipod ipod ipod", "str_s", "c" )); + assertU(adoc("id", "a", "title", "ipod", "str_s1", "a" )); + assertU(adoc("id", "b", "title", "ipod ipod", "str_s1", "b" )); + assertU(adoc("id", "c", "title", "ipod ipod ipod", "str_s1", "c" )); - assertU(adoc("id", "x", "title", "boosted", "str_s", "x" )); - assertU(adoc("id", "y", "title", "boosted boosted", "str_s", "y" )); - assertU(adoc("id", "z", "title", "boosted boosted boosted", "str_s", "z" )); + assertU(adoc("id", "x", "title", "boosted", "str_s1", "x" )); + assertU(adoc("id", "y", "title", "boosted boosted", "str_s1", "y" )); + assertU(adoc("id", "z", "title", "boosted boosted boosted", "str_s1", "z" )); assertU(commit()); String query = "title:ipod"; @@ -188,7 +188,7 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 { // Try normal sort by 'id' // default 'forceBoost' should be false assertEquals( false, booster.forceElevation ); - args.put( CommonParams.SORT, "str_s asc" ); + args.put( CommonParams.SORT, "str_s1 asc" ); assertQ( null, req ,"//*[@numFound='4']" ,"//result/doc[1]/str[@name='id'][.='a']" diff --git a/solr/src/test/org/apache/solr/search/function/SortByFunctionTest.java b/solr/src/test/org/apache/solr/search/function/SortByFunctionTest.java index cd06c5077ee..48d160af9d4 100644 --- a/solr/src/test/org/apache/solr/search/function/SortByFunctionTest.java +++ b/solr/src/test/org/apache/solr/search/function/SortByFunctionTest.java @@ -35,10 +35,10 @@ public class SortByFunctionTest extends AbstractSolrTestCase { } public void test() throws Exception { - assertU(adoc("id", "1", "x_td", "0", "y_td", "2", "w_td", "25", "z_td", "5", "f_t", "ipod")); - assertU(adoc("id", "2", "x_td", "2", "y_td", "2", "w_td", "15", "z_td", "5", "f_t", "ipod ipod ipod ipod ipod")); - assertU(adoc("id", "3", "x_td", "3", "y_td", "2", "w_td", "55", "z_td", "5", "f_t", "ipod ipod ipod ipod ipod ipod ipod ipod ipod")); - assertU(adoc("id", "4", "x_td", "4", "y_td", "2", "w_td", "45", "z_td", "5", "f_t", "ipod ipod ipod ipod ipod ipod ipod")); + assertU(adoc("id", "1", "x_td", "0", "y_td", "2", "w_td1", "25", "z_td", "5", "f_t", "ipod")); + assertU(adoc("id", "2", "x_td", "2", "y_td", "2", "w_td1", "15", "z_td", "5", "f_t", "ipod ipod ipod ipod ipod")); + assertU(adoc("id", "3", "x_td", "3", "y_td", "2", "w_td1", "55", "z_td", "5", "f_t", "ipod ipod ipod ipod ipod ipod ipod ipod ipod")); + assertU(adoc("id", "4", "x_td", "4", "y_td", "2", "w_td1", "45", "z_td", "5", "f_t", "ipod ipod ipod ipod ipod ipod ipod")); assertU(commit()); assertQ(req("fl", "*,score", "q", "*:*"), @@ -82,8 +82,8 @@ public class SortByFunctionTest extends AbstractSolrTestCase { "//result/doc[3]/int[@name='id'][.='3']", "//result/doc[4]/int[@name='id'][.='4']" ); - //the function is equal, w_td separates - assertQ(req("q", "*:*", "fl", "id", "sort", "sum(z_td, y_td) asc, w_td asc"), + //the function is equal, w_td1 separates + assertQ(req("q", "*:*", "fl", "id", "sort", "sum(z_td, y_td) asc, w_td1 asc"), "//*[@numFound='4']", "//result/doc[1]/int[@name='id'][.='2']", "//result/doc[2]/int[@name='id'][.='1']", @@ -127,4 +127,4 @@ public class SortByFunctionTest extends AbstractSolrTestCase { /* 0931.0442muLti-Default2009-12-12T12:59:46.412Z4.02.01.0342muLti-Default2009-12-12T12:59:46.409Z3.02.01.0242muLti-Default2009-12-12T12:59:46.406Z2.02.01.0142muLti-Default2009-12-12T12:59:46.361Z0.02.0 -*/ \ No newline at end of file +*/