io.zulia.util.ResultHelper Maven / Gradle / Ivy
package io.zulia.util;
import org.bson.Document;
import java.util.ArrayList;
import java.util.List;
import static io.zulia.message.ZuliaBase.ResultDocument;
import static io.zulia.message.ZuliaBase.ResultDocumentOrBuilder;
import static io.zulia.message.ZuliaQuery.ScoredResult;
/**
* Created by Matt Davis on 2/1/16.
*/
public class ResultHelper {
public static Document getDocumentFromScoredResult(ScoredResult scoredResult) {
if (scoredResult.hasResultDocument()) {
ResultDocument rd = scoredResult.getResultDocument();
return getDocumentFromResultDocument(rd);
}
return null;
}
public static Document getDocumentFromResultDocument(ResultDocumentOrBuilder rd) {
if (rd.getDocument() != null) {
return ZuliaUtil.byteArrayToMongoDocument(rd.getDocument().toByteArray());
}
return null;
}
public static Object getValueFromMongoDocument(org.bson.Document mongoDocument, String storedFieldName) {
Object o;
if (storedFieldName.contains(".")) {
o = mongoDocument;
String[] fields = storedFieldName.split("\\.");
for (String field : fields) {
if (o instanceof List) {
List> list = (List>) o;
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy