[SOLR-4150] - added null checks (with log warnings in case of null) to TopGroupsResultTransformer#transformToNative

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1421164 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tommaso Teofili 2012-12-13 09:24:29 +00:00
parent 7e7bfe1f4d
commit 2e2f1fd713
1 changed files with 18 additions and 3 deletions

View File

@ -17,7 +17,6 @@ package org.apache.solr.search.grouping.distributed.shardresultserializer;
* limitations under the License. * limitations under the License.
*/ */
import org.apache.lucene.document.Document;
import org.apache.lucene.document.DocumentStoredFieldVisitor; import org.apache.lucene.document.DocumentStoredFieldVisitor;
import org.apache.lucene.index.StoredDocument; import org.apache.lucene.index.StoredDocument;
import org.apache.lucene.search.FieldDoc; import org.apache.lucene.search.FieldDoc;
@ -38,6 +37,8 @@ import org.apache.solr.search.grouping.Command;
import org.apache.solr.search.grouping.distributed.command.QueryCommand; import org.apache.solr.search.grouping.distributed.command.QueryCommand;
import org.apache.solr.search.grouping.distributed.command.QueryCommandResult; import org.apache.solr.search.grouping.distributed.command.QueryCommandResult;
import org.apache.solr.search.grouping.distributed.command.TopGroupsFieldCommand; import org.apache.solr.search.grouping.distributed.command.TopGroupsFieldCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -53,6 +54,8 @@ public class TopGroupsResultTransformer implements ShardResultTransformer<List<C
private final ResponseBuilder rb; private final ResponseBuilder rb;
private static final Logger log = LoggerFactory.getLogger(TopGroupsResultTransformer.class);
public TopGroupsResultTransformer(ResponseBuilder rb) { public TopGroupsResultTransformer(ResponseBuilder rb) {
this.rb = rb; this.rb = rb;
} }
@ -105,12 +108,24 @@ public class TopGroupsResultTransformer implements ShardResultTransformer<List<C
ScoreDoc[] scoreDocs = new ScoreDoc[documents.size()]; ScoreDoc[] scoreDocs = new ScoreDoc[documents.size()];
int j = 0; int j = 0;
for (NamedList<Object> document : documents) { for (NamedList<Object> document : documents) {
Object uniqueId = document.get("id").toString(); Object docId = document.get("id");
Object uniqueId = null;
if (docId != null)
uniqueId = docId.toString();
else
log.warn("doc {} has null 'id'", document);
Float score = (Float) document.get("score"); Float score = (Float) document.get("score");
if (score == null) { if (score == null) {
score = Float.NaN; score = Float.NaN;
} }
Object[] sortValues = ((List) document.get("sortValues")).toArray(); Object[] sortValues = null;
Object sortValuesVal = document.get("sortValues");
if (sortValuesVal != null) {
sortValues = ((List) sortValuesVal).toArray();
}
else {
log.warn("doc {} has null 'sortValues'", document);
}
scoreDocs[j++] = new ShardDoc(score, sortValues, uniqueId, shard); scoreDocs[j++] = new ShardDoc(score, sortValues, uniqueId, shard);
} }
result.put(key, new QueryCommandResult(new TopDocs(totalHits, scoreDocs, maxScore), matches)); result.put(key, new QueryCommandResult(new TopDocs(totalHits, scoreDocs, maxScore), matches));