Search in sources :

Example 1 with ShardDoc

use of org.apache.solr.handler.component.ShardDoc in project lucene-solr by apache.

the class StoredFieldsShardRequestFactory method mapShardToDocs.

private void mapShardToDocs(HashMap<String, Set<ShardDoc>> shardMap, ScoreDoc[] scoreDocs) {
    for (ScoreDoc scoreDoc : scoreDocs) {
        ShardDoc solrDoc = (ShardDoc) scoreDoc;
        Set<ShardDoc> shardDocs = shardMap.get(solrDoc.shard);
        if (shardDocs == null) {
            shardMap.put(solrDoc.shard, shardDocs = new HashSet<>());
        }
        shardDocs.add(solrDoc);
    }
}
Also used : ShardDoc(org.apache.solr.handler.component.ShardDoc) ScoreDoc(org.apache.lucene.search.ScoreDoc)

Example 2 with ShardDoc

use of org.apache.solr.handler.component.ShardDoc in project lucene-solr by apache.

the class SolrPluginUtils method copyNamedListIntoArrayByDocPosInResponse.

/** Copies the given {@code namedList} assumed to have doc uniqueKey keyed data into {@code destArr}
   * at the position of the document in the response.  destArr is assumed to be the same size as
   * {@code resultIds} is.  {@code resultIds} comes from {@link ResponseBuilder#resultIds}.  If the doc key
   * isn't in {@code resultIds} then it is ignored.
   * Note: most likely you will call {@link #removeNulls(Map.Entry[], NamedList)} sometime after calling this. */
public static void copyNamedListIntoArrayByDocPosInResponse(NamedList namedList, Map<Object, ShardDoc> resultIds, Map.Entry<String, Object>[] destArr) {
    assert resultIds.size() == destArr.length;
    for (int i = 0; i < namedList.size(); i++) {
        String id = namedList.getName(i);
        // TODO: lookup won't work for non-string ids... String vs Float
        ShardDoc sdoc = resultIds.get(id);
        if (sdoc != null) {
            // maybe null when rb.onePassDistributedQuery
            int idx = sdoc.positionInResponse;
            destArr[idx] = new NamedList.NamedListEntry<>(id, namedList.getVal(i));
        }
    }
}
Also used : NamedList(org.apache.solr.common.util.NamedList) ShardDoc(org.apache.solr.handler.component.ShardDoc)

Example 3 with ShardDoc

use of org.apache.solr.handler.component.ShardDoc in project lucene-solr by apache.

the class TopGroupsResultTransformer method transformToNativeShardDoc.

protected ScoreDoc[] transformToNativeShardDoc(List<NamedList<Object>> documents, Sort groupSort, String shard, IndexSchema schema) {
    ScoreDoc[] scoreDocs = new ScoreDoc[documents.size()];
    int j = 0;
    for (NamedList<Object> document : documents) {
        Object docId = document.get(ID);
        if (docId != null) {
            docId = docId.toString();
        } else {
            log.error("doc {} has null 'id'", document);
        }
        Float score = (Float) document.get("score");
        if (score == null) {
            score = Float.NaN;
        }
        Object[] sortValues = null;
        Object sortValuesVal = document.get("sortValues");
        if (sortValuesVal != null) {
            sortValues = ((List) sortValuesVal).toArray();
            for (int k = 0; k < sortValues.length; k++) {
                SchemaField field = groupSort.getSort()[k].getField() != null ? schema.getFieldOrNull(groupSort.getSort()[k].getField()) : null;
                sortValues[k] = ShardResultTransformerUtils.unmarshalSortValue(sortValues[k], field);
            }
        } else {
            log.debug("doc {} has null 'sortValues'", document);
        }
        scoreDocs[j++] = new ShardDoc(score, sortValues, docId, shard);
    }
    return scoreDocs;
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) ShardDoc(org.apache.solr.handler.component.ShardDoc) ScoreDoc(org.apache.lucene.search.ScoreDoc)

Example 4 with ShardDoc

use of org.apache.solr.handler.component.ShardDoc in project lucene-solr by apache.

the class StoredFieldsShardResponseProcessor method process.

/**
   * {@inheritDoc}
   */
@Override
public void process(ResponseBuilder rb, ShardRequest shardRequest) {
    boolean returnScores = (rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES) != 0;
    ShardResponse srsp = shardRequest.responses.get(0);
    SolrDocumentList docs = (SolrDocumentList) srsp.getSolrResponse().getResponse().get("response");
    String uniqueIdFieldName = rb.req.getSchema().getUniqueKeyField().getName();
    for (SolrDocument doc : docs) {
        Object id = doc.getFieldValue(uniqueIdFieldName).toString();
        ShardDoc shardDoc = rb.resultIds.get(id);
        FieldDoc fieldDoc = (FieldDoc) shardDoc;
        if (shardDoc != null) {
            if (returnScores && !Float.isNaN(fieldDoc.score)) {
                doc.setField("score", fieldDoc.score);
            }
            rb.retrievedDocuments.put(id, doc);
        }
    }
}
Also used : ShardResponse(org.apache.solr.handler.component.ShardResponse) SolrDocument(org.apache.solr.common.SolrDocument) FieldDoc(org.apache.lucene.search.FieldDoc) SolrDocumentList(org.apache.solr.common.SolrDocumentList) ShardDoc(org.apache.solr.handler.component.ShardDoc)

Example 5 with ShardDoc

use of org.apache.solr.handler.component.ShardDoc in project lucene-solr by apache.

the class StoredFieldsShardRequestFactory method constructRequest.

@Override
public ShardRequest[] constructRequest(ResponseBuilder rb) {
    HashMap<String, Set<ShardDoc>> shardMap = new HashMap<>();
    for (TopGroups<BytesRef> topGroups : rb.mergedTopGroups.values()) {
        for (GroupDocs<BytesRef> group : topGroups.groups) {
            mapShardToDocs(shardMap, group.scoreDocs);
        }
    }
    for (QueryCommandResult queryCommandResult : rb.mergedQueryCommandResults.values()) {
        mapShardToDocs(shardMap, queryCommandResult.getTopDocs().scoreDocs);
    }
    ShardRequest[] shardRequests = new ShardRequest[shardMap.size()];
    SchemaField uniqueField = rb.req.getSchema().getUniqueKeyField();
    int i = 0;
    for (Collection<ShardDoc> shardDocs : shardMap.values()) {
        ShardRequest sreq = new ShardRequest();
        sreq.purpose = ShardRequest.PURPOSE_GET_FIELDS;
        sreq.shards = new String[] { shardDocs.iterator().next().shard };
        sreq.params = new ModifiableSolrParams();
        sreq.params.add(rb.req.getParams());
        sreq.params.remove(GroupParams.GROUP);
        sreq.params.remove(CommonParams.SORT);
        sreq.params.remove(ResponseBuilder.FIELD_SORT_VALUES);
        String fl = sreq.params.get(CommonParams.FL);
        if (fl != null) {
            fl = fl.trim();
            // don't add "id" if the fl is empty or "score" or it would change the meaning.
            if (fl.length() != 0 && !"score".equals(fl) && !"*".equals(fl)) {
                sreq.params.set(CommonParams.FL, fl + ',' + uniqueField.getName());
            }
        }
        List<String> ids = new ArrayList<>(shardDocs.size());
        for (ShardDoc shardDoc : shardDocs) {
            ids.add(shardDoc.id.toString());
        }
        sreq.params.add(ShardParams.IDS, StrUtils.join(ids, ','));
        shardRequests[i++] = sreq;
    }
    return shardRequests;
}
Also used : QueryCommandResult(org.apache.solr.search.grouping.distributed.command.QueryCommandResult) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SchemaField(org.apache.solr.schema.SchemaField) ShardRequest(org.apache.solr.handler.component.ShardRequest) BytesRef(org.apache.lucene.util.BytesRef) ShardDoc(org.apache.solr.handler.component.ShardDoc)

Aggregations

ShardDoc (org.apache.solr.handler.component.ShardDoc)6 ScoreDoc (org.apache.lucene.search.ScoreDoc)3 BytesRef (org.apache.lucene.util.BytesRef)2 NamedList (org.apache.solr.common.util.NamedList)2 ShardResponse (org.apache.solr.handler.component.ShardResponse)2 SchemaField (org.apache.solr.schema.SchemaField)2 QueryCommandResult (org.apache.solr.search.grouping.distributed.command.QueryCommandResult)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 FieldDoc (org.apache.lucene.search.FieldDoc)1 Sort (org.apache.lucene.search.Sort)1 TopDocs (org.apache.lucene.search.TopDocs)1 TopGroups (org.apache.lucene.search.grouping.TopGroups)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 SolrDocument (org.apache.solr.common.SolrDocument)1 SolrDocumentList (org.apache.solr.common.SolrDocumentList)1 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)1