diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 80d9b32efc0..2e81f1fac9c 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -250,6 +250,9 @@ Other Changes * SOLR-4511: Add new test for 'repeater' replication node. (Mark Miller) +* SOLR-4458: Sort directions (asc, desc) are now case insensitive + (Shawn Heisey via hossman) + ================== 4.1.0 ================== Versions of Major Components diff --git a/solr/core/src/java/org/apache/solr/search/QueryParsing.java b/solr/core/src/java/org/apache/solr/search/QueryParsing.java index cb6c930e5fb..1cdb4c4e3f7 100644 --- a/solr/core/src/java/org/apache/solr/search/QueryParsing.java +++ b/solr/core/src/java/org/apache/solr/search/QueryParsing.java @@ -46,6 +46,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; /** @@ -788,7 +789,7 @@ public class QueryParsing { } /** - * Sort direction or null if current position does not inidcate a + * Sort direction or null if current position does not indicate a * sort direction. (True is desc, False is asc). * Position is advanced to after the comma (or end) when result is non null */ @@ -799,9 +800,10 @@ public class QueryParsing { Boolean top = null; if (null != order) { - if ("desc".equals(order) || "top".equals(order)) { + final String orderLowerCase = order.toLowerCase(Locale.ROOT); + if ("desc".equals(orderLowerCase) || "top".equals(orderLowerCase)) { top = true; - } else if ("asc".equals(order) || "bottom".equals(order)) { + } else if ("asc".equals(orderLowerCase) || "bottom".equals(orderLowerCase)) { top = false; } diff --git a/solr/core/src/test/org/apache/solr/search/QueryParsingTest.java b/solr/core/src/test/org/apache/solr/search/QueryParsingTest.java index 6e13ce2dc0b..f4bdf18b247 100644 --- a/solr/core/src/test/org/apache/solr/search/QueryParsingTest.java +++ b/solr/core/src/test/org/apache/solr/search/QueryParsingTest.java @@ -79,17 +79,18 @@ public class QueryParsingTest extends SolrTestCaseJ4 { sort = QueryParsing.parseSort("score desc", req); assertNull("sort", sort);//only 1 thing in the list, no Sort specified - sort = QueryParsing.parseSort("score asc", req); + // SOLR-4458 - using different case variations of asc and desc + sort = QueryParsing.parseSort("score aSc", req); SortField[] flds = sort.getSort(); assertEquals(flds[0].getType(), SortField.Type.SCORE); assertTrue(flds[0].getReverse()); - sort = QueryParsing.parseSort("weight desc", req); + sort = QueryParsing.parseSort("weight dEsC", req); flds = sort.getSort(); assertEquals(flds[0].getType(), SortField.Type.FLOAT); assertEquals(flds[0].getField(), "weight"); assertEquals(flds[0].getReverse(), true); - sort = QueryParsing.parseSort("weight desc,bday asc", req); + sort = QueryParsing.parseSort("weight desc,bday ASC", req); flds = sort.getSort(); assertEquals(flds[0].getType(), SortField.Type.FLOAT); assertEquals(flds[0].getField(), "weight"); @@ -116,7 +117,7 @@ public class QueryParsingTest extends SolrTestCaseJ4 { assertEquals(flds[1].getReverse(), false); //test weird spacing - sort = QueryParsing.parseSort("weight desc, bday asc", req); + sort = QueryParsing.parseSort("weight DESC, bday asc", req); flds = sort.getSort(); assertEquals(flds[0].getType(), SortField.Type.FLOAT); assertEquals(flds[0].getField(), "weight");