SOLR-13603: remove deprecated groupSpec methods usage

This is precursor to removing deprecated methods
This commit is contained in:
Munendra S N 2019-07-03 19:19:12 +05:30
parent 717afb11fc
commit e3d247f288
9 changed files with 34 additions and 25 deletions

View File

@ -235,6 +235,8 @@ Other Changes
* SOLR-12364: Add test cases for edismax boost (David Smiley, Munendra S N)
* SOLR-13603: Remove usage of GroupingSpecification's deprecated methods (Munendra S N)
================== 8.1.2 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

View File

@ -1306,7 +1306,7 @@ public class QueryComponent extends SearchComponent
for (String field : groupingSpec.getFields()) {
topsGroupsActionBuilder.addCommandField(new SearchGroupsFieldCommand.Builder()
.setField(schema.getField(field))
.setGroupSort(groupingSpec.getGroupSort())
.setGroupSort(groupingSpec.getGroupSortSpec().getSort())
.setTopNGroups(cmd.getOffset() + cmd.getLen())
.setIncludeGroupCount(groupingSpec.isIncludeGroupCount())
.build()
@ -1342,7 +1342,8 @@ public class QueryComponent extends SearchComponent
.setTruncateGroups(groupingSpec.isTruncateGroups() && groupingSpec.getFields().length > 0)
.setSearcher(searcher);
int docsToCollect = Grouping.getMax(groupingSpec.getWithinGroupOffset(), groupingSpec.getWithinGroupLimit(), searcher.maxDoc());
SortSpec withinGroupSortSpec = groupingSpec.getWithinGroupSortSpec();
int docsToCollect = Grouping.getMax(withinGroupSortSpec.getOffset(), withinGroupSortSpec.getCount(), searcher.maxDoc());
docsToCollect = Math.max(docsToCollect, 1);
for (String field : groupingSpec.getFields()) {
@ -1367,8 +1368,8 @@ public class QueryComponent extends SearchComponent
new TopGroupsFieldCommand.Builder()
.setQuery(cmd.getQuery())
.setField(schemaField)
.setGroupSort(groupingSpec.getGroupSort())
.setSortWithinGroup(groupingSpec.getSortWithinGroup())
.setGroupSort(groupingSpec.getGroupSortSpec().getSort())
.setSortWithinGroup(withinGroupSortSpec.getSort())
.setFirstPhaseGroups(topGroups)
.setMaxDocPerGroup(docsToCollect)
.setNeedScores(needScores)
@ -1420,13 +1421,15 @@ public class QueryComponent extends SearchComponent
int limitDefault = cmd.getLen(); // this is normally from "rows"
Grouping grouping =
new Grouping(searcher, result, cmd, cacheSecondPassSearch, maxDocsPercentageToCache, groupingSpec.isMain());
grouping.setGroupSort(groupingSpec.getGroupSort())
.setWithinGroupSort(groupingSpec.getSortWithinGroup())
SortSpec withinGroupSortSpec = groupingSpec.getWithinGroupSortSpec();
grouping.setGroupSort(groupingSpec.getGroupSortSpec().getSort())
.setWithinGroupSort(withinGroupSortSpec.getSort())
.setDefaultFormat(groupingSpec.getResponseFormat())
.setLimitDefault(limitDefault)
.setDefaultTotalCount(defaultTotalCount)
.setDocsPerGroupDefault(groupingSpec.getWithinGroupLimit())
.setGroupOffsetDefault(groupingSpec.getWithinGroupOffset())
.setDocsPerGroupDefault(withinGroupSortSpec.getCount())
.setGroupOffsetDefault(withinGroupSortSpec.getOffset())
.setGetGroupedDocSet(groupingSpec.isTruncateGroups());
if (groupingSpec.getFields() != null) {

View File

@ -261,7 +261,7 @@ public class SimpleFacets {
DocSet base = searcher.getDocSet(qlist);
if (rb.grouping() && rb.getGroupingSpec().isTruncateGroups()) {
Grouping grouping = new Grouping(searcher, null, rb.createQueryCommand(), false, 0, false);
grouping.setWithinGroupSort(rb.getGroupingSpec().getSortWithinGroup());
grouping.setWithinGroupSort(rb.getGroupingSpec().getWithinGroupSortSpec().getSort());
if (rb.getGroupingSpec().getFields().length > 0) {
grouping.addFieldCommand(rb.getGroupingSpec().getFields()[0], req);
} else if (rb.getGroupingSpec().getFunctions().length > 0) {

View File

@ -50,9 +50,9 @@ public class SearchGroupShardResponseProcessor implements ShardResponseProcessor
@Override
public void process(ResponseBuilder rb, ShardRequest shardRequest) {
SortSpec groupSortSpec = rb.getGroupingSpec().getGroupSortSpec();
Sort groupSort = rb.getGroupingSpec().getGroupSort();
Sort groupSort = rb.getGroupingSpec().getGroupSortSpec().getSort();
final String[] fields = rb.getGroupingSpec().getFields();
Sort withinGroupSort = rb.getGroupingSpec().getSortWithinGroup();
Sort withinGroupSort = rb.getGroupingSpec().getWithinGroupSortSpec().getSort();
assert withinGroupSort != null;
final Map<String, List<Collection<SearchGroup<BytesRef>>>> commandSearchGroups = new HashMap<>(fields.length, 1.0f);

View File

@ -40,6 +40,7 @@ import org.apache.solr.handler.component.ShardRequest;
import org.apache.solr.handler.component.ShardResponse;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.search.Grouping;
import org.apache.solr.search.SortSpec;
import org.apache.solr.search.grouping.distributed.ShardResponseProcessor;
import org.apache.solr.search.grouping.distributed.command.QueryCommandResult;
import org.apache.solr.search.grouping.distributed.shardresultserializer.TopGroupsResultTransformer;
@ -52,10 +53,11 @@ public class TopGroupsShardResponseProcessor implements ShardResponseProcessor {
@Override
@SuppressWarnings("unchecked")
public void process(ResponseBuilder rb, ShardRequest shardRequest) {
Sort groupSort = rb.getGroupingSpec().getGroupSort();
Sort groupSort = rb.getGroupingSpec().getGroupSortSpec().getSort();
String[] fields = rb.getGroupingSpec().getFields();
String[] queries = rb.getGroupingSpec().getQueries();
Sort withinGroupSort = rb.getGroupingSpec().getSortWithinGroup();
SortSpec withinGroupSortSpec = rb.getGroupingSpec().getWithinGroupSortSpec();
Sort withinGroupSort = withinGroupSortSpec.getSort();
assert withinGroupSort != null;
boolean simpleOrMain = rb.getGroupingSpec().getResponseFormat() == Grouping.Format.simple ||
@ -66,18 +68,18 @@ public class TopGroupsShardResponseProcessor implements ShardResponseProcessor {
if (simpleOrMain) {
groupOffsetDefault = 0;
} else {
groupOffsetDefault = rb.getGroupingSpec().getWithinGroupOffset();
groupOffsetDefault = withinGroupSortSpec.getOffset();
}
int docsPerGroupDefault = rb.getGroupingSpec().getWithinGroupLimit();
int docsPerGroupDefault = withinGroupSortSpec.getCount();
Map<String, List<TopGroups<BytesRef>>> commandTopGroups = new HashMap<>();
for (String field : fields) {
commandTopGroups.put(field, new ArrayList<TopGroups<BytesRef>>());
commandTopGroups.put(field, new ArrayList<>());
}
Map<String, List<QueryCommandResult>> commandTopDocs = new HashMap<>();
for (String query : queries) {
commandTopDocs.put(query, new ArrayList<QueryCommandResult>());
commandTopDocs.put(query, new ArrayList<>());
}
TopGroupsResultTransformer serializer = new TopGroupsResultTransformer(rb);

View File

@ -218,7 +218,7 @@ public class TopGroupsResultTransformer implements ShardResultTransformer<List<C
Object[] convertedSortValues = new Object[fieldDoc.fields.length];
for (int j = 0; j < fieldDoc.fields.length; j++) {
Object sortValue = fieldDoc.fields[j];
Sort withinGroupSort = rb.getGroupingSpec().getSortWithinGroup();
Sort withinGroupSort = rb.getGroupingSpec().getWithinGroupSortSpec().getSort();
SchemaField field = withinGroupSort.getSort()[j].getField() != null ? schema.getFieldOrNull(withinGroupSort.getSort()[j].getField()) : null;
if (field != null) {
FieldType fieldType = field.getType();
@ -271,7 +271,7 @@ public class TopGroupsResultTransformer implements ShardResultTransformer<List<C
Object[] convertedSortValues = new Object[fieldDoc.fields.length];
for (int j = 0; j < fieldDoc.fields.length; j++) {
Object sortValue = fieldDoc.fields[j];
Sort groupSort = rb.getGroupingSpec().getGroupSort();
Sort groupSort = rb.getGroupingSpec().getGroupSortSpec().getSort();
SchemaField field = groupSort.getSort()[j].getField() != null
? schema.getFieldOrNull(groupSort.getSort()[j].getField()) : null;
convertedSortValues[j] = ShardResultTransformerUtils.marshalSortValue(sortValue, field);

View File

@ -38,6 +38,7 @@ import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.schema.FieldType;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.search.SolrIndexSearcher;
import org.apache.solr.search.SortSpec;
import org.apache.solr.search.grouping.distributed.command.QueryCommandResult;
/**
@ -54,6 +55,7 @@ public class GroupedEndResultTransformer implements EndResultTransformer {
@Override
public void transform(Map<String, ?> result, ResponseBuilder rb, SolrDocumentSource solrDocumentSource) {
NamedList<Object> commands = new SimpleOrderedMap<>();
SortSpec withinGroupSortSpec = rb.getGroupingSpec().getWithinGroupSortSpec();
for (Map.Entry<String, ?> entry : result.entrySet()) {
Object value = entry.getValue();
if (TopGroups.class.isInstance(value)) {
@ -90,7 +92,7 @@ public class GroupedEndResultTransformer implements EndResultTransformer {
if (!Float.isNaN(group.maxScore)) {
docList.setMaxScore(group.maxScore);
}
docList.setStart(rb.getGroupingSpec().getWithinGroupOffset());
docList.setStart(withinGroupSortSpec.getOffset());
retrieveAndAdd(docList, solrDocumentSource, group.scoreDocs);
groupResult.add("doclist", docList);
groups.add(groupResult);
@ -108,7 +110,7 @@ public class GroupedEndResultTransformer implements EndResultTransformer {
if (!Float.isNaN(queryCommandResult.getMaxScore())) {
docList.setMaxScore(queryCommandResult.getMaxScore());
}
docList.setStart(rb.getGroupingSpec().getWithinGroupOffset());
docList.setStart(withinGroupSortSpec.getOffset());
retrieveAndAdd(docList, solrDocumentSource, queryCommandResult.getTopDocs().scoreDocs);
command.add("doclist", docList);
commands.add(entry.getKey(), command);

View File

@ -53,7 +53,7 @@ public class MainEndResultTransformer implements EndResultTransformer {
@SuppressWarnings("unchecked")
TopGroups<BytesRef> topGroups = (TopGroups<BytesRef>) value;
SolrDocumentList docList = new SolrDocumentList();
docList.setStart(rb.getGroupingSpec().getOffset());
docList.setStart(rb.getGroupingSpec().getGroupSortSpec().getOffset());
docList.setNumFound(rb.totalHitCount);
float maxScore = Float.NEGATIVE_INFINITY;
@ -77,7 +77,7 @@ public class MainEndResultTransformer implements EndResultTransformer {
SolrDocumentList docList = new SolrDocumentList();
TopDocs topDocs = queryCommandResult.getTopDocs();
docList.setStart(rb.getGroupingSpec().getOffset());
docList.setStart(rb.getGroupingSpec().getGroupSortSpec().getOffset());
docList.setNumFound(topDocs.totalHits.value);
if (!Float.isNaN(queryCommandResult.getMaxScore())) {
docList.setMaxScore(queryCommandResult.getMaxScore());

View File

@ -49,7 +49,7 @@ public class SimpleEndResultTransformer implements EndResultTransformer {
command.add("ngroups", topGroups.totalGroupCount);
}
SolrDocumentList docList = new SolrDocumentList();
docList.setStart(rb.getGroupingSpec().getOffset());
docList.setStart(rb.getGroupingSpec().getGroupSortSpec().getOffset());
docList.setNumFound(topGroups.totalHitCount);
float maxScore = Float.NEGATIVE_INFINITY;
@ -76,7 +76,7 @@ public class SimpleEndResultTransformer implements EndResultTransformer {
TopDocs topDocs = queryCommandResult.getTopDocs();
SolrDocumentList docList = new SolrDocumentList();
docList.setStart(rb.getGroupingSpec().getOffset());
docList.setStart(rb.getGroupingSpec().getGroupSortSpec().getOffset());
docList.setNumFound(topDocs.totalHits.value);
if (!Float.isNaN(queryCommandResult.getMaxScore())) {