From bcc7efbee57b49e2c3e3f724334d31beb791cad2 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Wed, 13 Jul 2011 19:38:40 +0000 Subject: [PATCH] SOLR-2642: Fixed sorting by function when using grouping. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1146291 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 2 ++ .../handler/component/QueryComponent.java | 4 ++-- .../org/apache/solr/TestGroupingSearch.java | 20 +++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 26208ef78ab..f6f04d48e11 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -369,6 +369,8 @@ Bug Fixes * SOLR-2564: Fixed ArrayIndexOutOfBoundsException when using simple format and start > 0 +* SOLR-2642: Fixed sorting by function when using grouping. (Thomas Heigl, Martijn van Groningen) + Other Changes ---------------------- diff --git a/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java b/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java index 84cd42dfa86..db6ea101f6b 100644 --- a/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java +++ b/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java @@ -331,9 +331,9 @@ public class QueryComponent extends SearchComponent boolean includeTotalGroupCount = params.getBool(GroupParams.GROUP_TOTAL_COUNT, false); Grouping.TotalCount defaultTotalCount = includeTotalGroupCount ? Grouping.TotalCount.grouped : Grouping.TotalCount.ungrouped; - Sort sort = cmd.getSort(); + Sort sort = searcher.weightSort(cmd.getSort()); // groupSort defaults to sort - Sort groupSort = groupSortStr == null ? cmd.getSort() : QueryParsing.parseSort(groupSortStr, req); + Sort groupSort = groupSortStr == null ? sort : searcher.weightSort(QueryParsing.parseSort(groupSortStr, req)); int limitDefault = cmd.getLen(); // this is normally from "rows" int groupOffsetDefault = params.getInt(GroupParams.GROUP_OFFSET, 0); diff --git a/solr/core/src/test/org/apache/solr/TestGroupingSearch.java b/solr/core/src/test/org/apache/solr/TestGroupingSearch.java index d705e5bba71..caad8953bfa 100644 --- a/solr/core/src/test/org/apache/solr/TestGroupingSearch.java +++ b/solr/core/src/test/org/apache/solr/TestGroupingSearch.java @@ -214,6 +214,26 @@ public class TestGroupingSearch extends SolrTestCaseJ4 { ); } + @Test + public void testGroupingSortByFunction() throws Exception { + assertU(add(doc("id", "1", "value1_i", "1", "value2_i", "1", "store", "45.18014,-93.87742"))); + assertU(add(doc("id", "2", "value1_i", "1", "value2_i", "2", "store", "45.18014,-93.87743"))); + assertU(add(doc("id", "3", "value1_i", "1", "value2_i", "3", "store", "45.18014,-93.87744"))); + assertU(add(doc("id", "4", "value1_i", "1", "value2_i", "4", "store", "45.18014,-93.87745"))); + assertU(add(doc("id", "5", "value1_i", "1", "value2_i", "5", "store", "45.18014,-93.87746"))); + assertU(commit()); + + assertJQ( + req("q", "*:*", "sort", "sum(value1_i, value2_i) desc", "rows", "1", "group", "true", "group.field", "id", "fl", "id"), + "/grouped=={'id':{'matches':5,'groups':[{'groupValue':'5','doclist':{'numFound':1,'start':0,'docs':[{'id':'5'}]}}]}}" + ); + + assertJQ( + req("q", "*:*", "sort", "geodist(45.18014,-93.87742,store) asc", "rows", "1", "group", "true", "group.field", "id", "fl", "id"), + "/grouped=={'id':{'matches':5,'groups':[{'groupValue':'1','doclist':{'numFound':1,'start':0,'docs':[{'id':'1'}]}}]}}" + ); + } + static String f = "foo_i"; static String f2 = "foo2_i";