diegoceccarelli 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_r320017542
########## File path: solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/SearchGroupsResultTransformer.java ########## @@ -142,4 +150,58 @@ private NamedList serializeSearchGroup(Collection<SearchGroup<BytesRef>> data, S return result; } + public static class SkipSecondStepSearchResultResultTransformer extends SearchGroupsResultTransformer { + + private static final String TOP_DOC_SOLR_ID_KEY = "topDocSolrId"; + private static final String TOP_DOC_SCORE_KEY = "topDocScore"; + private static final String SORTVALUES_KEY = "sortValues"; + + private final SchemaField uniqueField; + + public SkipSecondStepSearchResultResultTransformer(SolrIndexSearcher searcher) { + super(searcher); + this.uniqueField = searcher.getSchema().getUniqueKeyField(); + } + + @Override + protected Object[] getSortValues(Object groupDocs) { + NamedList<Object> groupInfo = (NamedList) groupDocs; + final ArrayList<?> sortValues = (ArrayList<?>) groupInfo.get(SORTVALUES_KEY); + return sortValues.toArray(new Comparable[sortValues.size()]); + } + + @Override + protected SearchGroup<BytesRef> deserializeOneSearchGroup(SchemaField groupField, String groupValue, + SortField[] groupSortField, Object rawSearchGroupData) { + SearchGroup<BytesRef> searchGroup = super.deserializeOneSearchGroup(groupField, groupValue, groupSortField, rawSearchGroupData); + NamedList<Object> groupInfo = (NamedList) rawSearchGroupData; + searchGroup.topDocLuceneId = DocIdSetIterator.NO_MORE_DOCS; + searchGroup.topDocScore = (float) groupInfo.get(TOP_DOC_SCORE_KEY); + searchGroup.topDocSolrId = groupInfo.get(TOP_DOC_SOLR_ID_KEY); + return searchGroup; + } + + @Override + protected Object serializeOneSearchGroup(SortField[] groupSortField, SearchGroup<BytesRef> searchGroup) { + Document luceneDoc = null; + /** Use the lucene id to get the unique solr id so that it can be sent to the federator. + * The lucene id of a document is not unique across all shards i.e. different documents + * in different shards could have the same lucene id, whereas the solr id is guaranteed + * to be unique so this is what we need to return to the federator + **/ + try { + luceneDoc = searcher.doc(searchGroup.topDocLuceneId, Collections.singleton(uniqueField.getName())); Review comment: Looks good, merged ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org