use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.
the class TestCloudJSONFacetJoinDomain method assertFacetCountsAreCorrect.
/**
* Recursive Helper method that walks the actual facet response, comparing the counts to the expected output
* based on the equivilent filters generated from the original TermFacet.
*/
private void assertFacetCountsAreCorrect(Map<String, TermFacet> expected, SolrParams baseParams, NamedList actualFacetResponse) throws SolrServerException, IOException {
for (Map.Entry<String, TermFacet> entry : expected.entrySet()) {
final String facetKey = entry.getKey();
final TermFacet facet = entry.getValue();
final NamedList results = (NamedList) actualFacetResponse.get(facetKey);
assertNotNull(facetKey + " key missing from: " + actualFacetResponse, results);
final List<NamedList> buckets = (List<NamedList>) results.get("buckets");
assertNotNull(facetKey + " has null buckets: " + actualFacetResponse, buckets);
for (NamedList bucket : buckets) {
final long count = ((Number) bucket.get("count")).longValue();
// int or stringified int
final String fieldVal = bucket.get("val").toString();
// change our query to filter on the fieldVal, and wrap in the facet domain (if any)
final SolrParams verifyParams = facet.applyValueConstraintAndDomain(baseParams, facetKey, fieldVal);
// check the count for this bucket
assertEquals(facetKey + ": " + verifyParams, count, getRandClient(random()).query(verifyParams).getResults().getNumFound());
// recursively check subFacets
if (!facet.subFacets.isEmpty()) {
assertFacetCountsAreCorrect(facet.subFacets, verifyParams, bucket);
}
}
}
assertTrue("facets have unexpeted keys left over: " + actualFacetResponse, // should alwasy be a count, maybe a 'val' if we're a subfacet
(actualFacetResponse.size() == expected.size() + 1) || (actualFacetResponse.size() == expected.size() + 2));
}
use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.
the class TestCloudPseudoReturnFields method testGlobs.
public void testGlobs() throws Exception {
SolrDocumentList docs = assertSearch(params("q", "*:*", "rows", "10", "fl", "val_*"));
assertEquals(5, docs.getNumFound());
// shouldn't matter what doc we pick...
for (SolrDocument doc : docs) {
assertEquals(doc.toString(), 1, doc.size());
assertTrue(doc.toString(), doc.getFieldValue("val_i") instanceof Integer);
}
for (SolrParams p : Arrays.asList(params("q", "*:*", "rows", "10", "fl", "val_*,subj*,ss*"), params("q", "*:*", "rows", "10", "fl", "val_*", "fl", "subj*,ss*"), params("q", "*:*", "rows", "10", "fl", "val_*", "fl", "subj*", "fl", "ss*"))) {
docs = assertSearch(p);
// shouldn't matter what doc we pick...
for (SolrDocument doc : docs) {
String msg = p + " => " + doc;
assertEquals(msg, 3, doc.size());
assertTrue(msg, doc.getFieldValue("val_i") instanceof Integer);
assertTrue(msg, doc.getFieldValue("subject") instanceof String);
// TODO: val_ss: List<String>
assertTrue(msg, doc.getFieldValue("ssto") instanceof String);
assertEquals(msg, "X", doc.getFieldValue("ssto"));
}
}
}
use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.
the class TestCloudPseudoReturnFields method testGlobsAndExplicitRTG.
public void testGlobsAndExplicitRTG() 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_*,id"));
String msg = id + ": fl=val_*,id => " + doc;
assertEquals(msg, 2, doc.size());
assertTrue(msg, doc.getFieldValue("id") instanceof String);
assertTrue(msg, doc.getFieldValue("val_i") instanceof Integer);
assertEquals(msg, 1, doc.getFieldValue("val_i"));
for (SolrParams p : Arrays.asList(params("fl", "val_*,subj*,id"), params("fl", "val_*", "fl", "subj*", "fl", "id"), params("fl", "val_*", "fl", "subj*,id"))) {
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);
assertTrue(msg, doc.getFieldValue("id") instanceof String);
}
}
}
use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.
the class TestCloudPseudoReturnFields method testAugmentersGlobsExplicitAndScoreOhMyRTG.
public void testAugmentersGlobsExplicitAndScoreOhMyRTG() throws Exception {
Random random = random();
// NOTE: 'ssto' is the missing one
final List<String> fl = Arrays.asList("id", "[docid]", "[explain]", "score", "val_*", "subj*");
final int iters = atLeast(random, 10);
for (int i = 0; i < iters; i++) {
Collections.shuffle(fl, random);
final SolrParams singleFl = params("fl", StringUtils.join(fl.toArray(), ','));
final ModifiableSolrParams multiFl = params();
for (String item : fl) {
multiFl.add("fl", item);
}
// RTG behavior should be consistent, (committed or otherwise)
for (String id : Arrays.asList("42", "99")) {
for (SolrParams params : Arrays.asList(singleFl, multiFl)) {
SolrDocument doc = getRandClient(random()).getById(id, params);
String msg = id + ": " + params + " => " + doc;
assertEquals(msg, 4, doc.size());
assertTrue(msg, doc.getFieldValue("id") instanceof String);
assertTrue(msg, doc.getFieldValue("val_i") instanceof Integer);
assertEquals(msg, 1, doc.getFieldValue("val_i"));
assertTrue(msg, doc.getFieldValue("subject") instanceof String);
assertTrue(msg, doc.getFieldValue("[docid]") instanceof Integer);
assertTrue(msg, -1 <= ((Integer) doc.getFieldValue("[docid]")).intValue());
// RTG: [explain] and score should be missing (ignored)
}
}
}
}
use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.
the class TestCloudPseudoReturnFields method testGlobsAndScore.
public void testGlobsAndScore() throws Exception {
SolrDocumentList docs = assertSearch(params("q", "*:*", "rows", "10", "fl", "val_*,score"));
assertEquals(5, docs.getNumFound());
// shouldn't matter what doc we pick...
for (SolrDocument doc : docs) {
assertEquals(doc.toString(), 2, doc.size());
assertTrue(doc.toString(), doc.getFieldValue("val_i") instanceof Integer);
assertTrue(doc.toString(), doc.getFieldValue("score") instanceof Float);
}
for (SolrParams p : Arrays.asList(params("q", "*:*", "rows", "10", "fl", "val_*,subj*,score"), params("q", "*:*", "rows", "10", "fl", "val_*", "fl", "subj*", "fl", "score"), params("q", "*:*", "rows", "10", "fl", "val_*", "fl", "subj*,score"))) {
docs = assertSearch(p);
assertEquals(p + " => " + docs, 5, docs.getNumFound());
// shouldn't matter what doc we pick...
for (SolrDocument doc : docs) {
String msg = p + " => " + doc;
assertEquals(msg, 3, doc.size());
assertTrue(msg, doc.getFieldValue("val_i") instanceof Integer);
assertTrue(msg, doc.getFieldValue("subject") instanceof String);
assertTrue(msg, doc.getFieldValue("score") instanceof Float);
}
}
}
Aggregations