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);
}
}
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));
}
}
}
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;
}
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);
}
}
}
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;
}
Aggregations