SOLR-9992: Add support for grouping with PointFIelds

This commit is contained in:
Cao Manh Dat 2017-03-20 15:21:36 +07:00 committed by Shalin Shekhar Mangar
parent 83918532dc
commit 832bc3dbf5
8 changed files with 29 additions and 24 deletions

View File

@ -49,6 +49,7 @@ import org.apache.lucene.search.grouping.GroupDocs;
import org.apache.lucene.search.grouping.SearchGroup;
import org.apache.lucene.search.grouping.TopGroups;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefBuilder;
import org.apache.lucene.util.InPlaceMergeSorter;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.common.SolrDocument;
@ -445,7 +446,9 @@ public class QueryComponent extends SearchComponent
for (String topGroup : topGroupsParam) {
SearchGroup<BytesRef> searchGroup = new SearchGroup<>();
if (!topGroup.equals(TopGroupsShardRequestFactory.GROUP_NULL_VALUE)) {
searchGroup.groupValue = new BytesRef(schemaField.getType().readableToIndexed(topGroup));
BytesRefBuilder builder = new BytesRefBuilder();
schemaField.getType().readableToIndexed(topGroup, builder);
searchGroup.groupValue = builder.get();
}
topGroups.add(searchGroup);
}

View File

@ -19,6 +19,7 @@ package org.apache.solr.search.grouping.distributed.requestfactory;
import org.apache.lucene.analysis.reverse.ReverseStringFilter;
import org.apache.lucene.search.grouping.SearchGroup;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.CharsRefBuilder;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.GroupParams;
import org.apache.solr.common.params.ModifiableSolrParams;
@ -117,9 +118,8 @@ public class TopGroupsShardRequestFactory implements ShardRequestFactory {
for (SearchGroup<BytesRef> searchGroup : entry.getValue()) {
String groupValue;
if (searchGroup.groupValue != null) {
String rawGroupValue = searchGroup.groupValue.utf8ToString();
FieldType fieldType = schema.getField(entry.getKey()).getType();
groupValue = fieldType.indexedToReadable(rawGroupValue);
groupValue = fieldType.indexedToReadable(searchGroup.groupValue, new CharsRefBuilder()).toString();
} else {
groupValue = GROUP_NULL_VALUE;
}

View File

@ -19,6 +19,8 @@ package org.apache.solr.search.grouping.distributed.shardresultserializer;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.grouping.SearchGroup;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefBuilder;
import org.apache.lucene.util.CharsRefBuilder;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.search.SolrIndexSearcher;
@ -56,7 +58,7 @@ public class SearchGroupsResultTransformer implements ShardResultTransformer<Lis
final SearchGroupsFieldCommandResult fieldCommandResult = fieldCommand.result();
final Collection<SearchGroup<BytesRef>> searchGroups = fieldCommandResult.getSearchGroups();
if (searchGroups != null) {
commandResult.add(TOP_GROUPS, serializeSearchGroup(searchGroups, fieldCommand.getGroupSort()));
commandResult.add(TOP_GROUPS, serializeSearchGroup(searchGroups, fieldCommand));
}
final Integer groupedCount = fieldCommandResult.getGroupCount();
if (groupedCount != null) {
@ -85,7 +87,17 @@ public class SearchGroupsResultTransformer implements ShardResultTransformer<Lis
if (rawSearchGroups != null) {
for (Map.Entry<String, List<Comparable>> rawSearchGroup : rawSearchGroups){
SearchGroup<BytesRef> searchGroup = new SearchGroup<>();
searchGroup.groupValue = rawSearchGroup.getKey() != null ? new BytesRef(rawSearchGroup.getKey()) : null;
SchemaField groupField = rawSearchGroup.getKey() != null? searcher.getSchema().getFieldOrNull(command.getKey()) : null;
searchGroup.groupValue = null;
if (rawSearchGroup.getKey() != null) {
if (groupField != null) {
BytesRefBuilder builder = new BytesRefBuilder();
groupField.getType().readableToIndexed(rawSearchGroup.getKey(), builder);
searchGroup.groupValue = builder.get();
} else {
searchGroup.groupValue = new BytesRef(rawSearchGroup.getKey());
}
}
searchGroup.sortValues = rawSearchGroup.getValue().toArray(new Comparable[rawSearchGroup.getValue().size()]);
for (int i = 0; i < searchGroup.sortValues.length; i++) {
SchemaField field = groupSort.getSort()[i].getField() != null ? searcher.getSchema().getFieldOrNull(groupSort.getSort()[i].getField()) : null;
@ -101,17 +113,19 @@ public class SearchGroupsResultTransformer implements ShardResultTransformer<Lis
return result;
}
private NamedList serializeSearchGroup(Collection<SearchGroup<BytesRef>> data, Sort groupSort) {
private NamedList serializeSearchGroup(Collection<SearchGroup<BytesRef>> data, SearchGroupsFieldCommand command) {
final NamedList<Object[]> result = new NamedList<>(data.size());
for (SearchGroup<BytesRef> searchGroup : data) {
Object[] convertedSortValues = new Object[searchGroup.sortValues.length];
for (int i = 0; i < searchGroup.sortValues.length; i++) {
Object sortValue = searchGroup.sortValues[i];
SchemaField field = groupSort.getSort()[i].getField() != null ? searcher.getSchema().getFieldOrNull(groupSort.getSort()[i].getField()) : null;
SchemaField field = command.getGroupSort().getSort()[i].getField() != null ?
searcher.getSchema().getFieldOrNull(command.getGroupSort().getSort()[i].getField()) : null;
convertedSortValues[i] = ShardResultTransformerUtils.marshalSortValue(sortValue, field);
}
String groupValue = searchGroup.groupValue != null ? searchGroup.groupValue.utf8ToString() : null;
SchemaField field = searcher.getSchema().getFieldOrNull(command.getKey());
String groupValue = searchGroup.groupValue != null ? field.getType().indexedToReadable(searchGroup.groupValue, new CharsRefBuilder()).toString() : null;
result.add(groupValue, convertedSortValues);
}

View File

@ -33,6 +33,7 @@ import org.apache.lucene.search.TopFieldDocs;
import org.apache.lucene.search.grouping.GroupDocs;
import org.apache.lucene.search.grouping.TopGroups;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.CharsRefBuilder;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.handler.component.ShardDoc;
@ -232,7 +233,8 @@ public class TopGroupsResultTransformer implements ShardResultTransformer<List<C
document.add("sortValues", convertedSortValues);
}
groupResult.add("documents", documents);
String groupValue = searchGroup.groupValue != null ? groupField.getType().indexedToReadable(searchGroup.groupValue.utf8ToString()): null;
String groupValue = searchGroup.groupValue != null ?
groupField.getType().indexedToReadable(searchGroup.groupValue, new CharsRefBuilder()).toString(): null;
result.add(groupValue, groupResult);
}

View File

@ -20,7 +20,6 @@ import java.io.IOException;
import java.util.List;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.SolrTestCaseJ4.SuppressPointFields;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.QueryResponse;
@ -38,7 +37,6 @@ import org.junit.Test;
* @since solr 4.0
*/
@Slow
@SuppressPointFields
public class TestDistributedGrouping extends BaseDistributedSearchTestCase {
String t1="a_t";

View File

@ -50,7 +50,6 @@ import org.noggit.ObjectBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SolrTestCaseJ4.SuppressPointFields(bugUrl="https://issues.apache.org/jira/browse/SOLR-9992")
public class TestGroupingSearch extends SolrTestCaseJ4 {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@ -536,13 +535,6 @@ public class TestGroupingSearch extends SolrTestCaseJ4 {
,"/facet_counts/facet_fields/"+f+"==['1',3, '2',3, '3',2, '4',1, '5',1]"
);
// test that grouping works with highlighting
assertJQ(req("fq",filt, "q","{!func}"+f2, "group","true", "group.field",f, "fl","id"
,"hl","true", "hl.fl",f)
,"/grouped/"+f+"/matches==10"
,"/highlighting=={'_ORDERED_':'', '8':{},'3':{},'4':{},'1':{},'2':{}}"
);
// test that grouping works with debugging
assertJQ(req("fq",filt, "q","{!func}"+f2, "group","true", "group.field",f, "fl","id"
,"debugQuery","true")

View File

@ -22,7 +22,6 @@ import java.util.Map;
import java.util.Set;
import java.util.Random;
import org.apache.solr.SolrTestCaseJ4.SuppressPointFields;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.response.QueryResponse;
@ -32,8 +31,7 @@ import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ShardParams;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.response.SolrQueryResponse;
// This test uses grouping requests, which doesn't work yet with PointFields
@SuppressPointFields(bugUrl="https://issues.apache.org/jira/browse/SOLR-9992")
class SegmentTerminateEarlyTestState {
final String keyField = "id";

View File

@ -22,7 +22,6 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.lucene.util.TestUtil;
import org.apache.solr.SolrTestCaseJ4.SuppressPointFields;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.schema.SchemaRequest.Field;
@ -42,7 +41,6 @@ import org.junit.rules.TestName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressPointFields(bugUrl="https://issues.apache.org/jira/browse/SOLR-9992")
public class TestSegmentSorting extends SolrCloudTestCase {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());