SOLR-10394: a few more essentially non-public sortWithinGroup to withinGroupSort renames

This commit is contained in:
Christine Poerschke 2017-04-19 11:50:24 +01:00
parent f9ca49a8d5
commit 323c972922
6 changed files with 31 additions and 31 deletions

View File

@ -47,7 +47,7 @@ public class TopGroupsFieldCommand implements Command<TopGroups<BytesRef>> {
private SchemaField field; private SchemaField field;
private Sort groupSort; private Sort groupSort;
private Sort sortWithinGroup; private Sort withinGroupSort;
private Collection<SearchGroup<BytesRef>> firstPhaseGroups; private Collection<SearchGroup<BytesRef>> firstPhaseGroups;
private Integer maxDocPerGroup; private Integer maxDocPerGroup;
private boolean needScores = false; private boolean needScores = false;
@ -63,8 +63,8 @@ public class TopGroupsFieldCommand implements Command<TopGroups<BytesRef>> {
return this; return this;
} }
public Builder setSortWithinGroup(Sort sortWithinGroup) { public Builder setSortWithinGroup(Sort withinGroupSort) {
this.sortWithinGroup = sortWithinGroup; this.withinGroupSort = withinGroupSort;
return this; return this;
} }
@ -89,19 +89,19 @@ public class TopGroupsFieldCommand implements Command<TopGroups<BytesRef>> {
} }
public TopGroupsFieldCommand build() { public TopGroupsFieldCommand build() {
if (field == null || groupSort == null || sortWithinGroup == null || firstPhaseGroups == null || if (field == null || groupSort == null || withinGroupSort == null || firstPhaseGroups == null ||
maxDocPerGroup == null) { maxDocPerGroup == null) {
throw new IllegalStateException("All required fields must be set"); throw new IllegalStateException("All required fields must be set");
} }
return new TopGroupsFieldCommand(field, groupSort, sortWithinGroup, firstPhaseGroups, maxDocPerGroup, needScores, needMaxScore); return new TopGroupsFieldCommand(field, groupSort, withinGroupSort, firstPhaseGroups, maxDocPerGroup, needScores, needMaxScore);
} }
} }
private final SchemaField field; private final SchemaField field;
private final Sort groupSort; private final Sort groupSort;
private final Sort sortWithinGroup; private final Sort withinGroupSort;
private final Collection<SearchGroup<BytesRef>> firstPhaseGroups; private final Collection<SearchGroup<BytesRef>> firstPhaseGroups;
private final int maxDocPerGroup; private final int maxDocPerGroup;
private final boolean needScores; private final boolean needScores;
@ -110,14 +110,14 @@ public class TopGroupsFieldCommand implements Command<TopGroups<BytesRef>> {
private TopGroupsFieldCommand(SchemaField field, private TopGroupsFieldCommand(SchemaField field,
Sort groupSort, Sort groupSort,
Sort sortWithinGroup, Sort withinGroupSort,
Collection<SearchGroup<BytesRef>> firstPhaseGroups, Collection<SearchGroup<BytesRef>> firstPhaseGroups,
int maxDocPerGroup, int maxDocPerGroup,
boolean needScores, boolean needScores,
boolean needMaxScore) { boolean needMaxScore) {
this.field = field; this.field = field;
this.groupSort = groupSort; this.groupSort = groupSort;
this.sortWithinGroup = sortWithinGroup; this.withinGroupSort = withinGroupSort;
this.firstPhaseGroups = firstPhaseGroups; this.firstPhaseGroups = firstPhaseGroups;
this.maxDocPerGroup = maxDocPerGroup; this.maxDocPerGroup = maxDocPerGroup;
this.needScores = needScores; this.needScores = needScores;
@ -136,11 +136,11 @@ public class TopGroupsFieldCommand implements Command<TopGroups<BytesRef>> {
ValueSource vs = fieldType.getValueSource(field, null); ValueSource vs = fieldType.getValueSource(field, null);
Collection<SearchGroup<MutableValue>> v = GroupConverter.toMutable(field, firstPhaseGroups); Collection<SearchGroup<MutableValue>> v = GroupConverter.toMutable(field, firstPhaseGroups);
secondPassCollector = new TopGroupsCollector<>(new ValueSourceGroupSelector(vs, new HashMap<>()), secondPassCollector = new TopGroupsCollector<>(new ValueSourceGroupSelector(vs, new HashMap<>()),
v, groupSort, sortWithinGroup, maxDocPerGroup, needScores, needMaxScore, true v, groupSort, withinGroupSort, maxDocPerGroup, needScores, needMaxScore, true
); );
} else { } else {
secondPassCollector = new TopGroupsCollector<>(new TermGroupSelector(field.getName()), secondPassCollector = new TopGroupsCollector<>(new TermGroupSelector(field.getName()),
firstPhaseGroups, groupSort, sortWithinGroup, maxDocPerGroup, needScores, needMaxScore, true firstPhaseGroups, groupSort, withinGroupSort, maxDocPerGroup, needScores, needMaxScore, true
); );
} }
collectors.add(secondPassCollector); collectors.add(secondPassCollector);
@ -151,7 +151,7 @@ public class TopGroupsFieldCommand implements Command<TopGroups<BytesRef>> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public TopGroups<BytesRef> result() { public TopGroups<BytesRef> result() {
if (firstPhaseGroups.isEmpty()) { if (firstPhaseGroups.isEmpty()) {
return new TopGroups<>(groupSort.getSort(), sortWithinGroup.getSort(), 0, 0, new GroupDocs[0], Float.NaN); return new TopGroups<>(groupSort.getSort(), withinGroupSort.getSort(), 0, 0, new GroupDocs[0], Float.NaN);
} }
FieldType fieldType = field.getType(); FieldType fieldType = field.getType();
@ -174,6 +174,6 @@ public class TopGroupsFieldCommand implements Command<TopGroups<BytesRef>> {
@Override @Override
public Sort getWithinGroupSort() { public Sort getWithinGroupSort() {
return sortWithinGroup; return withinGroupSort;
} }
} }

View File

@ -55,8 +55,8 @@ public class SearchGroupShardResponseProcessor implements ShardResponseProcessor
SortSpec ss = rb.getSortSpec(); SortSpec ss = rb.getSortSpec();
Sort groupSort = rb.getGroupingSpec().getGroupSort(); Sort groupSort = rb.getGroupingSpec().getGroupSort();
final String[] fields = rb.getGroupingSpec().getFields(); final String[] fields = rb.getGroupingSpec().getFields();
Sort sortWithinGroup = rb.getGroupingSpec().getSortWithinGroup(); Sort withinGroupSort = rb.getGroupingSpec().getSortWithinGroup();
assert sortWithinGroup != null; assert withinGroupSort != null;
final Map<String, List<Collection<SearchGroup<BytesRef>>>> commandSearchGroups = new HashMap<>(fields.length, 1.0f); final Map<String, List<Collection<SearchGroup<BytesRef>>>> commandSearchGroups = new HashMap<>(fields.length, 1.0f);
final Map<String, Map<SearchGroup<BytesRef>, Set<String>>> tempSearchGroupToShards = new HashMap<>(fields.length, 1.0f); final Map<String, Map<SearchGroup<BytesRef>, Set<String>>> tempSearchGroupToShards = new HashMap<>(fields.length, 1.0f);
@ -111,7 +111,7 @@ public class SearchGroupShardResponseProcessor implements ShardResponseProcessor
maxElapsedTime = (int) Math.max(maxElapsedTime, srsp.getSolrResponse().getElapsedTime()); maxElapsedTime = (int) Math.max(maxElapsedTime, srsp.getSolrResponse().getElapsedTime());
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
NamedList<NamedList> firstPhaseResult = (NamedList<NamedList>) srsp.getSolrResponse().getResponse().get("firstPhase"); NamedList<NamedList> firstPhaseResult = (NamedList<NamedList>) srsp.getSolrResponse().getResponse().get("firstPhase");
final Map<String, SearchGroupsFieldCommandResult> result = serializer.transformToNative(firstPhaseResult, groupSort, sortWithinGroup, srsp.getShard()); final Map<String, SearchGroupsFieldCommandResult> result = serializer.transformToNative(firstPhaseResult, groupSort, withinGroupSort, srsp.getShard());
for (String field : commandSearchGroups.keySet()) { for (String field : commandSearchGroups.keySet()) {
final SearchGroupsFieldCommandResult firstPhaseCommandResult = result.get(field); final SearchGroupsFieldCommandResult firstPhaseCommandResult = result.get(field);

View File

@ -58,8 +58,8 @@ public class TopGroupsShardResponseProcessor implements ShardResponseProcessor {
Sort groupSort = rb.getGroupingSpec().getGroupSort(); Sort groupSort = rb.getGroupingSpec().getGroupSort();
String[] fields = rb.getGroupingSpec().getFields(); String[] fields = rb.getGroupingSpec().getFields();
String[] queries = rb.getGroupingSpec().getQueries(); String[] queries = rb.getGroupingSpec().getQueries();
Sort sortWithinGroup = rb.getGroupingSpec().getSortWithinGroup(); Sort withinGroupSort = rb.getGroupingSpec().getSortWithinGroup();
assert sortWithinGroup != null; assert withinGroupSort != null;
// If group.format=simple group.offset doesn't make sense // If group.format=simple group.offset doesn't make sense
int groupOffsetDefault; int groupOffsetDefault;
@ -122,7 +122,7 @@ public class TopGroupsShardResponseProcessor implements ShardResponseProcessor {
NamedList<NamedList> secondPhaseResult = (NamedList<NamedList>) srsp.getSolrResponse().getResponse().get("secondPhase"); NamedList<NamedList> secondPhaseResult = (NamedList<NamedList>) srsp.getSolrResponse().getResponse().get("secondPhase");
if(secondPhaseResult == null) if(secondPhaseResult == null)
continue; continue;
Map<String, ?> result = serializer.transformToNative(secondPhaseResult, groupSort, sortWithinGroup, srsp.getShard()); Map<String, ?> result = serializer.transformToNative(secondPhaseResult, groupSort, withinGroupSort, srsp.getShard());
int numFound = 0; int numFound = 0;
float maxScore = Float.NaN; float maxScore = Float.NaN;
for (String field : commandTopGroups.keySet()) { for (String field : commandTopGroups.keySet()) {
@ -164,7 +164,7 @@ public class TopGroupsShardResponseProcessor implements ShardResponseProcessor {
docsPerGroup += subTopGroups.totalGroupedHitCount; docsPerGroup += subTopGroups.totalGroupedHitCount;
} }
} }
rb.mergedTopGroups.put(groupField, TopGroups.merge(topGroups.toArray(topGroupsArr), groupSort, sortWithinGroup, groupOffsetDefault, docsPerGroup, TopGroups.ScoreMergeMode.None)); rb.mergedTopGroups.put(groupField, TopGroups.merge(topGroups.toArray(topGroupsArr), groupSort, withinGroupSort, groupOffsetDefault, docsPerGroup, TopGroups.ScoreMergeMode.None));
} }
for (String query : commandTopDocs.keySet()) { for (String query : commandTopDocs.keySet()) {
@ -178,10 +178,10 @@ public class TopGroupsShardResponseProcessor implements ShardResponseProcessor {
int topN = rb.getGroupingSpec().getOffset() + rb.getGroupingSpec().getLimit(); int topN = rb.getGroupingSpec().getOffset() + rb.getGroupingSpec().getLimit();
final TopDocs mergedTopDocs; final TopDocs mergedTopDocs;
if (sortWithinGroup.equals(Sort.RELEVANCE)) { if (withinGroupSort.equals(Sort.RELEVANCE)) {
mergedTopDocs = TopDocs.merge(topN, topDocs.toArray(new TopDocs[topDocs.size()])); mergedTopDocs = TopDocs.merge(topN, topDocs.toArray(new TopDocs[topDocs.size()]));
} else { } else {
mergedTopDocs = TopDocs.merge(sortWithinGroup, topN, topDocs.toArray(new TopFieldDocs[topDocs.size()])); mergedTopDocs = TopDocs.merge(withinGroupSort, topN, topDocs.toArray(new TopFieldDocs[topDocs.size()]));
} }
rb.mergedQueryCommandResults.put(query, new QueryCommandResult(mergedTopDocs, mergedMatches)); rb.mergedQueryCommandResults.put(query, new QueryCommandResult(mergedTopDocs, mergedMatches));
} }

View File

@ -77,7 +77,7 @@ public class SearchGroupsResultTransformer implements ShardResultTransformer<Lis
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Map<String, SearchGroupsFieldCommandResult> transformToNative(NamedList<NamedList> shardResponse, Sort groupSort, Sort sortWithinGroup, String shard) { public Map<String, SearchGroupsFieldCommandResult> transformToNative(NamedList<NamedList> shardResponse, Sort groupSort, Sort withinGroupSort, String shard) {
final Map<String, SearchGroupsFieldCommandResult> result = new HashMap<>(shardResponse.size()); final Map<String, SearchGroupsFieldCommandResult> result = new HashMap<>(shardResponse.size());
for (Map.Entry<String, NamedList> command : shardResponse) { for (Map.Entry<String, NamedList> command : shardResponse) {
List<SearchGroup<BytesRef>> searchGroups = new ArrayList<>(); List<SearchGroup<BytesRef>> searchGroups = new ArrayList<>();

View File

@ -44,10 +44,10 @@ public interface ShardResultTransformer<T, R> {
* *
* @param shardResponse The shard response containing data in a {@link NamedList} structure * @param shardResponse The shard response containing data in a {@link NamedList} structure
* @param groupSort The group sort * @param groupSort The group sort
* @param sortWithinGroup The sort inside a group * @param withinGroupSort The sort inside a group
* @param shard The shard address where the response originated from * @param shard The shard address where the response originated from
* @return native structure of the data * @return native structure of the data
*/ */
R transformToNative(NamedList<NamedList> shardResponse, Sort groupSort, Sort sortWithinGroup, String shard); R transformToNative(NamedList<NamedList> shardResponse, Sort groupSort, Sort withinGroupSort, String shard);
} }

View File

@ -92,7 +92,7 @@ public class TopGroupsResultTransformer implements ShardResultTransformer<List<C
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Map<String, ?> transformToNative(NamedList<NamedList> shardResponse, Sort groupSort, Sort sortWithinGroup, String shard) { public Map<String, ?> transformToNative(NamedList<NamedList> shardResponse, Sort groupSort, Sort withinGroupSort, String shard) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
final IndexSchema schema = rb.req.getSearcher().getSchema(); final IndexSchema schema = rb.req.getSearcher().getSchema();
@ -113,10 +113,10 @@ public class TopGroupsResultTransformer implements ShardResultTransformer<List<C
List<NamedList<Object>> documents = (List<NamedList<Object>>) commandResult.get("documents"); List<NamedList<Object>> documents = (List<NamedList<Object>>) commandResult.get("documents");
ScoreDoc[] scoreDocs = transformToNativeShardDoc(documents, groupSort, shard, schema); ScoreDoc[] scoreDocs = transformToNativeShardDoc(documents, groupSort, shard, schema);
final TopDocs topDocs; final TopDocs topDocs;
if (sortWithinGroup.equals(Sort.RELEVANCE)) { if (withinGroupSort.equals(Sort.RELEVANCE)) {
topDocs = new TopDocs(totalHits, scoreDocs, maxScore); topDocs = new TopDocs(totalHits, scoreDocs, maxScore);
} else { } else {
topDocs = new TopFieldDocs(totalHits, scoreDocs, sortWithinGroup.getSort(), maxScore); topDocs = new TopFieldDocs(totalHits, scoreDocs, withinGroupSort.getSort(), maxScore);
} }
result.put(key, new QueryCommandResult(topDocs, matches)); result.put(key, new QueryCommandResult(topDocs, matches));
continue; continue;
@ -137,7 +137,7 @@ public class TopGroupsResultTransformer implements ShardResultTransformer<List<C
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<NamedList<Object>> documents = (List<NamedList<Object>>) groupResult.get("documents"); List<NamedList<Object>> documents = (List<NamedList<Object>>) groupResult.get("documents");
ScoreDoc[] scoreDocs = transformToNativeShardDoc(documents, sortWithinGroup, shard, schema); ScoreDoc[] scoreDocs = transformToNativeShardDoc(documents, withinGroupSort, shard, schema);
BytesRef groupValueRef = groupValue != null ? new BytesRef(groupValue) : null; BytesRef groupValueRef = groupValue != null ? new BytesRef(groupValue) : null;
groupDocs.add(new GroupDocs<>(Float.NaN, maxScore, totalGroupHits, scoreDocs, groupValueRef, null)); groupDocs.add(new GroupDocs<>(Float.NaN, maxScore, totalGroupHits, scoreDocs, groupValueRef, null));
@ -146,7 +146,7 @@ public class TopGroupsResultTransformer implements ShardResultTransformer<List<C
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
GroupDocs<BytesRef>[] groupDocsArr = groupDocs.toArray(new GroupDocs[groupDocs.size()]); GroupDocs<BytesRef>[] groupDocsArr = groupDocs.toArray(new GroupDocs[groupDocs.size()]);
TopGroups<BytesRef> topGroups = new TopGroups<>( TopGroups<BytesRef> topGroups = new TopGroups<>(
groupSort.getSort(), sortWithinGroup.getSort(), totalHitCount, totalGroupedHitCount, groupDocsArr, Float.NaN groupSort.getSort(), withinGroupSort.getSort(), totalHitCount, totalGroupedHitCount, groupDocsArr, Float.NaN
); );
result.put(key, topGroups); result.put(key, topGroups);
@ -222,8 +222,8 @@ public class TopGroupsResultTransformer implements ShardResultTransformer<List<C
Object[] convertedSortValues = new Object[fieldDoc.fields.length]; Object[] convertedSortValues = new Object[fieldDoc.fields.length];
for (int j = 0; j < fieldDoc.fields.length; j++) { for (int j = 0; j < fieldDoc.fields.length; j++) {
Object sortValue = fieldDoc.fields[j]; Object sortValue = fieldDoc.fields[j];
Sort sortWithinGroup = rb.getGroupingSpec().getSortWithinGroup(); Sort withinGroupSort = rb.getGroupingSpec().getSortWithinGroup();
SchemaField field = sortWithinGroup.getSort()[j].getField() != null ? schema.getFieldOrNull(sortWithinGroup.getSort()[j].getField()) : null; SchemaField field = withinGroupSort.getSort()[j].getField() != null ? schema.getFieldOrNull(withinGroupSort.getSort()[j].getField()) : null;
if (field != null) { if (field != null) {
FieldType fieldType = field.getType(); FieldType fieldType = field.getType();
if (sortValue != null) { if (sortValue != null) {