cpoerschke commented on a change in pull request #300: SOLR-11831: Skip second
grouping step if group.limit is 1 (aka Las Vegas Patch)
URL: https://github.com/apache/lucene-solr/pull/300#discussion_r293818890
##########
File path:
solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
##########
@@ -232,6 +233,47 @@ public void prepare(ResponseBuilder rb) throws IOException
}
}
+ // check if prefix is a prefix of the array
+ private static boolean isPrefix(SortField[] prefix, SortField[] array){
+ if (prefix == null || array == null) return false;
+ if (prefix.length > array.length) return false;
+ // if we are here, prefix.length <= array.length
+ for (int i = 0; i < prefix.length; i++){
+ // we check if the element at position i matches
+ if (! prefix[i].equals(array[i])){
+ // if not is not a prefix
+ return false;
+ }
+ }
+ //.. other it is
+ return true;
+ }
+
+ private boolean allowSkipSecondGroupingStep(final SortSpec
withinGroupSpecification, final SortSpec groupSort, final boolean isReranking) {
+ // Only possible if we only want one doc per group
+ final int limit = withinGroupSpecification.getCount();
+ final int offset = withinGroupSpecification.getOffset();
+ if ( limit != 1 || offset != 0 ) {
+ return false;
+ }
+
+ final SortField[] withinGroupSortFields =
withinGroupSpecification.getSort().getSort();
+ final SortField[] groupSortFields = groupSort.getSort().getSort();
+
+ // Within group sort must be the same as group sort because if we skip
second step no sorting within group will be done.
+ if (! isPrefix(withinGroupSortFields, groupSortFields)) {
+ System.out.println("Not prefix" +
Arrays.toString(withinGroupSortFields)+ " , "+Arrays.toString(groupSortFields)
);
Review comment:
Just FYI the latest `ant precommit` checks for print statements in
production code. Suggest to either remove this one or to replace it with
`log.info` equivalent. If logging here then perhaps the other `return false`
should also log?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]