Search in sources :

Example 1 with EndResultTransformer

use of org.apache.solr.search.grouping.endresulttransformer.EndResultTransformer in project lucene-solr by apache.

the class QueryComponent method groupedFinishStage.

@SuppressWarnings("unchecked")
protected void groupedFinishStage(final ResponseBuilder rb) {
    // To have same response as non-distributed request.
    GroupingSpecification groupSpec = rb.getGroupingSpec();
    if (rb.mergedTopGroups.isEmpty()) {
        for (String field : groupSpec.getFields()) {
            rb.mergedTopGroups.put(field, new TopGroups(null, null, 0, 0, new GroupDocs[] {}, Float.NaN));
        }
        rb.resultIds = new HashMap<>();
    }
    EndResultTransformer.SolrDocumentSource solrDocumentSource = doc -> {
        ShardDoc solrDoc = (ShardDoc) doc;
        return rb.retrievedDocuments.get(solrDoc.id);
    };
    EndResultTransformer endResultTransformer;
    if (groupSpec.isMain()) {
        endResultTransformer = MAIN_END_RESULT_TRANSFORMER;
    } else if (Grouping.Format.grouped == groupSpec.getResponseFormat()) {
        endResultTransformer = new GroupedEndResultTransformer(rb.req.getSearcher());
    } else if (Grouping.Format.simple == groupSpec.getResponseFormat() && !groupSpec.isMain()) {
        endResultTransformer = SIMPLE_END_RESULT_TRANSFORMER;
    } else {
        return;
    }
    Map<String, Object> combinedMap = new LinkedHashMap<>();
    combinedMap.putAll(rb.mergedTopGroups);
    combinedMap.putAll(rb.mergedQueryCommandResults);
    endResultTransformer.transform(combinedMap, rb, solrDocumentSource);
}
Also used : Query(org.apache.lucene.search.Query) Arrays(java.util.Arrays) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) SolrDocumentList(org.apache.solr.common.SolrDocumentList) RankQuery(org.apache.solr.search.RankQuery) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) DocList(org.apache.solr.search.DocList) SolrPluginUtils(org.apache.solr.util.SolrPluginUtils) Term(org.apache.lucene.index.Term) LoggerFactory(org.slf4j.LoggerFactory) SearchGroupsFieldCommand(org.apache.solr.search.grouping.distributed.command.SearchGroupsFieldCommand) SolrParams(org.apache.solr.common.params.SolrParams) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrException(org.apache.solr.common.SolrException) QueryCommand(org.apache.solr.search.QueryCommand) Locale(java.util.Locale) Map(java.util.Map) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) SortField(org.apache.lucene.search.SortField) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) QParserPlugin(org.apache.solr.search.QParserPlugin) QueryResult(org.apache.solr.search.QueryResult) PrintWriter(java.io.PrintWriter) CursorMark(org.apache.solr.search.CursorMark) Scorer(org.apache.lucene.search.Scorer) ShardParams(org.apache.solr.common.params.ShardParams) StatsCache(org.apache.solr.search.stats.StatsCache) Sort(org.apache.lucene.search.Sort) BytesRef(org.apache.lucene.util.BytesRef) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) InPlaceMergeSorter(org.apache.lucene.util.InPlaceMergeSorter) BasicResultContext(org.apache.solr.response.BasicResultContext) ShardResponseProcessor(org.apache.solr.search.grouping.distributed.ShardResponseProcessor) LeafFieldComparator(org.apache.lucene.search.LeafFieldComparator) EndResultTransformer(org.apache.solr.search.grouping.endresulttransformer.EndResultTransformer) SearchGroupsResultTransformer(org.apache.solr.search.grouping.distributed.shardresultserializer.SearchGroupsResultTransformer) GroupDocs(org.apache.lucene.search.grouping.GroupDocs) List(java.util.List) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) TopGroupsResultTransformer(org.apache.solr.search.grouping.distributed.shardresultserializer.TopGroupsResultTransformer) Grouping(org.apache.solr.search.Grouping) DocSlice(org.apache.solr.search.DocSlice) TopGroupsShardResponseProcessor(org.apache.solr.search.grouping.distributed.responseprocessor.TopGroupsShardResponseProcessor) MainEndResultTransformer(org.apache.solr.search.grouping.endresulttransformer.MainEndResultTransformer) SimpleEndResultTransformer(org.apache.solr.search.grouping.endresulttransformer.SimpleEndResultTransformer) ReaderUtil(org.apache.lucene.index.ReaderUtil) QParser(org.apache.solr.search.QParser) SolrReturnFields(org.apache.solr.search.SolrReturnFields) StoredFieldsShardRequestFactory(org.apache.solr.search.grouping.distributed.requestfactory.StoredFieldsShardRequestFactory) StoredFieldsShardResponseProcessor(org.apache.solr.search.grouping.distributed.responseprocessor.StoredFieldsShardResponseProcessor) FieldType(org.apache.solr.schema.FieldType) Weight(org.apache.lucene.search.Weight) BytesRefBuilder(org.apache.lucene.util.BytesRefBuilder) DocListAndSet(org.apache.solr.search.DocListAndSet) GroupingSpecification(org.apache.solr.search.grouping.GroupingSpecification) HashMap(java.util.HashMap) FieldComparator(org.apache.lucene.search.FieldComparator) CursorMarkParams(org.apache.solr.common.params.CursorMarkParams) TopGroupsShardRequestFactory(org.apache.solr.search.grouping.distributed.requestfactory.TopGroupsShardRequestFactory) StrUtils(org.apache.solr.common.util.StrUtils) SearchGroupShardResponseProcessor(org.apache.solr.search.grouping.distributed.responseprocessor.SearchGroupShardResponseProcessor) ArrayList(java.util.ArrayList) SortSpec(org.apache.solr.search.SortSpec) LinkedHashMap(java.util.LinkedHashMap) SchemaField(org.apache.solr.schema.SchemaField) SyntaxError(org.apache.solr.search.SyntaxError) TopGroups(org.apache.lucene.search.grouping.TopGroups) GroupParams(org.apache.solr.common.params.GroupParams) SearchGroup(org.apache.lucene.search.grouping.SearchGroup) DocIdSetIterator(org.apache.lucene.search.DocIdSetIterator) QueryParsing(org.apache.solr.search.QueryParsing) CommandHandler(org.apache.solr.search.grouping.CommandHandler) GroupedEndResultTransformer(org.apache.solr.search.grouping.endresulttransformer.GroupedEndResultTransformer) DocIterator(org.apache.solr.search.DocIterator) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) SearchGroupsRequestFactory(org.apache.solr.search.grouping.distributed.requestfactory.SearchGroupsRequestFactory) StringWriter(java.io.StringWriter) IOException(java.io.IOException) ShardRequestFactory(org.apache.solr.search.grouping.distributed.ShardRequestFactory) ReturnFields(org.apache.solr.search.ReturnFields) NamedList(org.apache.solr.common.util.NamedList) IndexSchema(org.apache.solr.schema.IndexSchema) CommonParams(org.apache.solr.common.params.CommonParams) ResultContext(org.apache.solr.response.ResultContext) SolrDocument(org.apache.solr.common.SolrDocument) Builder(org.apache.solr.search.grouping.distributed.command.QueryCommand.Builder) TopGroupsFieldCommand(org.apache.solr.search.grouping.distributed.command.TopGroupsFieldCommand) SortSpecParsing(org.apache.solr.search.SortSpecParsing) Collections(java.util.Collections) IndexReaderContext(org.apache.lucene.index.IndexReaderContext) GroupedEndResultTransformer(org.apache.solr.search.grouping.endresulttransformer.GroupedEndResultTransformer) LinkedHashMap(java.util.LinkedHashMap) EndResultTransformer(org.apache.solr.search.grouping.endresulttransformer.EndResultTransformer) MainEndResultTransformer(org.apache.solr.search.grouping.endresulttransformer.MainEndResultTransformer) SimpleEndResultTransformer(org.apache.solr.search.grouping.endresulttransformer.SimpleEndResultTransformer) GroupedEndResultTransformer(org.apache.solr.search.grouping.endresulttransformer.GroupedEndResultTransformer) TopGroups(org.apache.lucene.search.grouping.TopGroups) GroupingSpecification(org.apache.solr.search.grouping.GroupingSpecification) GroupDocs(org.apache.lucene.search.grouping.GroupDocs)

Aggregations

IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 MethodHandles (java.lang.invoke.MethodHandles)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 IndexReaderContext (org.apache.lucene.index.IndexReaderContext)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 ReaderUtil (org.apache.lucene.index.ReaderUtil)1 Term (org.apache.lucene.index.Term)1 DocIdSetIterator (org.apache.lucene.search.DocIdSetIterator)1 FieldComparator (org.apache.lucene.search.FieldComparator)1