use of org.apache.solr.common.SolrDocument in project lucene-solr by apache.
the class RandomStream method read.
public Tuple read() throws IOException {
if (documentIterator.hasNext()) {
Map map = new HashMap();
SolrDocument doc = documentIterator.next();
for (String key : doc.keySet()) {
map.put(key, doc.get(key));
}
return new Tuple(map);
} else {
Map fields = new HashMap();
fields.put("EOF", true);
Tuple tuple = new Tuple(fields);
return tuple;
}
}
use of org.apache.solr.common.SolrDocument in project lucene-solr by apache.
the class AbstractFullDistribZkTestBase method doQuery.
void doQuery(String expectedDocs, String... queryParams) throws Exception {
Set<String> expectedIds = new HashSet<>(StrUtils.splitSmart(expectedDocs, ",", true));
QueryResponse rsp = cloudClient.query(params(queryParams));
Set<String> obtainedIds = new HashSet<>();
for (SolrDocument doc : rsp.getResults()) {
obtainedIds.add((String) doc.get("id"));
}
assertEquals(expectedIds, obtainedIds);
}
use of org.apache.solr.common.SolrDocument in project lucene-solr by apache.
the class BaseDistributedSearchTestCase method compare.
public static String compare(SolrDocumentList a, SolrDocumentList b, int flags, Map<String, Integer> handle) {
boolean ordered = (flags & UNORDERED) == 0;
String cmp;
int f = flags(handle, "maxScore");
if (f == 0) {
cmp = compare(a.getMaxScore(), b.getMaxScore(), 0, handle);
if (cmp != null)
return ".maxScore" + cmp;
} else if ((f & SKIP) == 0) {
// so we skip val but otherwise both should be present
assert (f & SKIPVAL) != 0;
if (b.getMaxScore() != null) {
if (a.getMaxScore() == null) {
return ".maxScore missing";
}
}
}
cmp = compare(a.getNumFound(), b.getNumFound(), 0, handle);
if (cmp != null)
return ".numFound" + cmp;
cmp = compare(a.getStart(), b.getStart(), 0, handle);
if (cmp != null)
return ".start" + cmp;
cmp = compare(a.size(), b.size(), 0, handle);
if (cmp != null)
return ".size()" + cmp;
// only for completely ordered results (ties might be in a different order)
if (ordered) {
for (int i = 0; i < a.size(); i++) {
cmp = compare(a.get(i), b.get(i), 0, handle);
if (cmp != null)
return "[" + i + "]" + cmp;
}
return null;
}
// unordered case
for (int i = 0; i < a.size(); i++) {
SolrDocument doc = a.get(i);
Object key = doc.getFirstValue("id");
SolrDocument docb = null;
if (key == null) {
// no id field to correlate... must compare ordered
docb = b.get(i);
} else {
for (int j = 0; j < b.size(); j++) {
docb = b.get(j);
if (key.equals(docb.getFirstValue("id")))
break;
}
}
// if (docb == null) return "[id="+key+"]";
cmp = compare(doc, docb, 0, handle);
if (cmp != null)
return "[id=" + key + "]" + cmp;
}
return null;
}
use of org.apache.solr.common.SolrDocument in project lucene-solr by apache.
the class DistributedVersionInfoTest method assertDocExists.
/**
* Query the real-time get handler for a specific doc by ID to verify it
* exists in the provided server, using distrib=false so it doesn't route to another replica.
*/
@SuppressWarnings("rawtypes")
protected Long assertDocExists(HttpSolrClient solr, String coll, String docId, Long expVers) throws Exception {
QueryRequest qr = new QueryRequest(params("qt", "/get", "id", docId, "distrib", "false", "fl", "id,_version_"));
NamedList rsp = solr.request(qr);
SolrDocument doc = (SolrDocument) rsp.get("doc");
String match = JSONTestUtil.matchObj("/id", doc, docId);
assertTrue("Doc with id=" + docId + " not found in " + solr.getBaseURL() + " due to: " + match + "; rsp=" + rsp, match == null);
Long vers = (Long) doc.getFirstValue("_version_");
assertNotNull(vers);
if (expVers != null)
assertEquals("expected version of doc " + docId + " to be " + expVers, expVers, vers);
return vers;
}
use of org.apache.solr.common.SolrDocument in project lucene-solr by apache.
the class TestCloudPseudoReturnFields method testGlobsRTG.
public void testGlobsRTG() throws Exception {
// behavior shouldn't matter if we are committed or uncommitted
for (String id : Arrays.asList("42", "99")) {
SolrDocument doc = getRandClient(random()).getById(id, params("fl", "val_*"));
String msg = id + ": fl=val_* => " + doc;
assertEquals(msg, 1, doc.size());
assertTrue(msg, doc.getFieldValue("val_i") instanceof Integer);
assertEquals(msg, 1, doc.getFieldValue("val_i"));
for (SolrParams p : Arrays.asList(params("fl", "val_*,subj*,ss*"), params("fl", "val_*", "fl", "subj*,ss*"))) {
doc = getRandClient(random()).getById(id, p);
msg = id + ": " + p + " => " + doc;
assertEquals(msg, 3, doc.size());
assertTrue(msg, doc.getFieldValue("val_i") instanceof Integer);
assertEquals(msg, 1, doc.getFieldValue("val_i"));
assertTrue(msg, doc.getFieldValue("subject") instanceof String);
// NOTE: 'subject' is diff between two docs
// TODO: val_ss: List<String>
assertTrue(msg, doc.getFieldValue("ssto") instanceof String);
assertEquals(msg, "X", doc.getFieldValue("ssto"));
}
}
}
Aggregations