mirror of https://github.com/apache/lucene.git
SOLR-10394: a few more essentially non-public sortWithinGroup to withinGroupSort renames
This commit is contained in:
parent
f9ca49a8d5
commit
323c972922
|
@ -47,7 +47,7 @@ public class TopGroupsFieldCommand implements Command<TopGroups<BytesRef>> {
|
|||
|
||||
private SchemaField field;
|
||||
private Sort groupSort;
|
||||
private Sort sortWithinGroup;
|
||||
private Sort withinGroupSort;
|
||||
private Collection<SearchGroup<BytesRef>> firstPhaseGroups;
|
||||
private Integer maxDocPerGroup;
|
||||
private boolean needScores = false;
|
||||
|
@ -63,8 +63,8 @@ public class TopGroupsFieldCommand implements Command<TopGroups<BytesRef>> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder setSortWithinGroup(Sort sortWithinGroup) {
|
||||
this.sortWithinGroup = sortWithinGroup;
|
||||
public Builder setSortWithinGroup(Sort withinGroupSort) {
|
||||
this.withinGroupSort = withinGroupSort;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -89,19 +89,19 @@ public class TopGroupsFieldCommand implements Command<TopGroups<BytesRef>> {
|
|||
}
|
||||
|
||||
public TopGroupsFieldCommand build() {
|
||||
if (field == null || groupSort == null || sortWithinGroup == null || firstPhaseGroups == null ||
|
||||
if (field == null || groupSort == null || withinGroupSort == null || firstPhaseGroups == null ||
|
||||
maxDocPerGroup == null) {
|
||||
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 Sort groupSort;
|
||||
private final Sort sortWithinGroup;
|
||||
private final Sort withinGroupSort;
|
||||
private final Collection<SearchGroup<BytesRef>> firstPhaseGroups;
|
||||
private final int maxDocPerGroup;
|
||||
private final boolean needScores;
|
||||
|
@ -110,14 +110,14 @@ public class TopGroupsFieldCommand implements Command<TopGroups<BytesRef>> {
|
|||
|
||||
private TopGroupsFieldCommand(SchemaField field,
|
||||
Sort groupSort,
|
||||
Sort sortWithinGroup,
|
||||
Sort withinGroupSort,
|
||||
Collection<SearchGroup<BytesRef>> firstPhaseGroups,
|
||||
int maxDocPerGroup,
|
||||
boolean needScores,
|
||||
boolean needMaxScore) {
|
||||
this.field = field;
|
||||
this.groupSort = groupSort;
|
||||
this.sortWithinGroup = sortWithinGroup;
|
||||
this.withinGroupSort = withinGroupSort;
|
||||
this.firstPhaseGroups = firstPhaseGroups;
|
||||
this.maxDocPerGroup = maxDocPerGroup;
|
||||
this.needScores = needScores;
|
||||
|
@ -136,11 +136,11 @@ public class TopGroupsFieldCommand implements Command<TopGroups<BytesRef>> {
|
|||
ValueSource vs = fieldType.getValueSource(field, null);
|
||||
Collection<SearchGroup<MutableValue>> v = GroupConverter.toMutable(field, firstPhaseGroups);
|
||||
secondPassCollector = new TopGroupsCollector<>(new ValueSourceGroupSelector(vs, new HashMap<>()),
|
||||
v, groupSort, sortWithinGroup, maxDocPerGroup, needScores, needMaxScore, true
|
||||
v, groupSort, withinGroupSort, maxDocPerGroup, needScores, needMaxScore, true
|
||||
);
|
||||
} else {
|
||||
secondPassCollector = new TopGroupsCollector<>(new TermGroupSelector(field.getName()),
|
||||
firstPhaseGroups, groupSort, sortWithinGroup, maxDocPerGroup, needScores, needMaxScore, true
|
||||
firstPhaseGroups, groupSort, withinGroupSort, maxDocPerGroup, needScores, needMaxScore, true
|
||||
);
|
||||
}
|
||||
collectors.add(secondPassCollector);
|
||||
|
@ -151,7 +151,7 @@ public class TopGroupsFieldCommand implements Command<TopGroups<BytesRef>> {
|
|||
@SuppressWarnings("unchecked")
|
||||
public TopGroups<BytesRef> result() {
|
||||
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();
|
||||
|
@ -174,6 +174,6 @@ public class TopGroupsFieldCommand implements Command<TopGroups<BytesRef>> {
|
|||
|
||||
@Override
|
||||
public Sort getWithinGroupSort() {
|
||||
return sortWithinGroup;
|
||||
return withinGroupSort;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,8 +55,8 @@ public class SearchGroupShardResponseProcessor implements ShardResponseProcessor
|
|||
SortSpec ss = rb.getSortSpec();
|
||||
Sort groupSort = rb.getGroupingSpec().getGroupSort();
|
||||
final String[] fields = rb.getGroupingSpec().getFields();
|
||||
Sort sortWithinGroup = rb.getGroupingSpec().getSortWithinGroup();
|
||||
assert sortWithinGroup != null;
|
||||
Sort withinGroupSort = rb.getGroupingSpec().getSortWithinGroup();
|
||||
assert withinGroupSort != null;
|
||||
|
||||
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);
|
||||
|
@ -111,7 +111,7 @@ public class SearchGroupShardResponseProcessor implements ShardResponseProcessor
|
|||
maxElapsedTime = (int) Math.max(maxElapsedTime, srsp.getSolrResponse().getElapsedTime());
|
||||
@SuppressWarnings("unchecked")
|
||||
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()) {
|
||||
final SearchGroupsFieldCommandResult firstPhaseCommandResult = result.get(field);
|
||||
|
||||
|
|
|
@ -58,8 +58,8 @@ public class TopGroupsShardResponseProcessor implements ShardResponseProcessor {
|
|||
Sort groupSort = rb.getGroupingSpec().getGroupSort();
|
||||
String[] fields = rb.getGroupingSpec().getFields();
|
||||
String[] queries = rb.getGroupingSpec().getQueries();
|
||||
Sort sortWithinGroup = rb.getGroupingSpec().getSortWithinGroup();
|
||||
assert sortWithinGroup != null;
|
||||
Sort withinGroupSort = rb.getGroupingSpec().getSortWithinGroup();
|
||||
assert withinGroupSort != null;
|
||||
|
||||
// If group.format=simple group.offset doesn't make sense
|
||||
int groupOffsetDefault;
|
||||
|
@ -122,7 +122,7 @@ public class TopGroupsShardResponseProcessor implements ShardResponseProcessor {
|
|||
NamedList<NamedList> secondPhaseResult = (NamedList<NamedList>) srsp.getSolrResponse().getResponse().get("secondPhase");
|
||||
if(secondPhaseResult == null)
|
||||
continue;
|
||||
Map<String, ?> result = serializer.transformToNative(secondPhaseResult, groupSort, sortWithinGroup, srsp.getShard());
|
||||
Map<String, ?> result = serializer.transformToNative(secondPhaseResult, groupSort, withinGroupSort, srsp.getShard());
|
||||
int numFound = 0;
|
||||
float maxScore = Float.NaN;
|
||||
for (String field : commandTopGroups.keySet()) {
|
||||
|
@ -164,7 +164,7 @@ public class TopGroupsShardResponseProcessor implements ShardResponseProcessor {
|
|||
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()) {
|
||||
|
@ -178,10 +178,10 @@ public class TopGroupsShardResponseProcessor implements ShardResponseProcessor {
|
|||
|
||||
int topN = rb.getGroupingSpec().getOffset() + rb.getGroupingSpec().getLimit();
|
||||
final TopDocs mergedTopDocs;
|
||||
if (sortWithinGroup.equals(Sort.RELEVANCE)) {
|
||||
if (withinGroupSort.equals(Sort.RELEVANCE)) {
|
||||
mergedTopDocs = TopDocs.merge(topN, topDocs.toArray(new TopDocs[topDocs.size()]));
|
||||
} 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));
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ public class SearchGroupsResultTransformer implements ShardResultTransformer<Lis
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@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());
|
||||
for (Map.Entry<String, NamedList> command : shardResponse) {
|
||||
List<SearchGroup<BytesRef>> searchGroups = new ArrayList<>();
|
||||
|
|
|
@ -44,10 +44,10 @@ public interface ShardResultTransformer<T, R> {
|
|||
*
|
||||
* @param shardResponse The shard response containing data in a {@link NamedList} structure
|
||||
* @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
|
||||
* @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);
|
||||
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ public class TopGroupsResultTransformer implements ShardResultTransformer<List<C
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@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<>();
|
||||
|
||||
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");
|
||||
ScoreDoc[] scoreDocs = transformToNativeShardDoc(documents, groupSort, shard, schema);
|
||||
final TopDocs topDocs;
|
||||
if (sortWithinGroup.equals(Sort.RELEVANCE)) {
|
||||
if (withinGroupSort.equals(Sort.RELEVANCE)) {
|
||||
topDocs = new TopDocs(totalHits, scoreDocs, maxScore);
|
||||
} else {
|
||||
topDocs = new TopFieldDocs(totalHits, scoreDocs, sortWithinGroup.getSort(), maxScore);
|
||||
topDocs = new TopFieldDocs(totalHits, scoreDocs, withinGroupSort.getSort(), maxScore);
|
||||
}
|
||||
result.put(key, new QueryCommandResult(topDocs, matches));
|
||||
continue;
|
||||
|
@ -137,7 +137,7 @@ public class TopGroupsResultTransformer implements ShardResultTransformer<List<C
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
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;
|
||||
groupDocs.add(new GroupDocs<>(Float.NaN, maxScore, totalGroupHits, scoreDocs, groupValueRef, null));
|
||||
|
@ -146,7 +146,7 @@ public class TopGroupsResultTransformer implements ShardResultTransformer<List<C
|
|||
@SuppressWarnings("unchecked")
|
||||
GroupDocs<BytesRef>[] groupDocsArr = groupDocs.toArray(new GroupDocs[groupDocs.size()]);
|
||||
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);
|
||||
|
@ -222,8 +222,8 @@ 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 sortWithinGroup = rb.getGroupingSpec().getSortWithinGroup();
|
||||
SchemaField field = sortWithinGroup.getSort()[j].getField() != null ? schema.getFieldOrNull(sortWithinGroup.getSort()[j].getField()) : null;
|
||||
Sort withinGroupSort = rb.getGroupingSpec().getSortWithinGroup();
|
||||
SchemaField field = withinGroupSort.getSort()[j].getField() != null ? schema.getFieldOrNull(withinGroupSort.getSort()[j].getField()) : null;
|
||||
if (field != null) {
|
||||
FieldType fieldType = field.getType();
|
||||
if (sortValue != null) {
|
||||
|
|
Loading…
Reference in New Issue