use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.
the class GetByIdTest method testGetIdWithParams.
@Test
public void testGetIdWithParams() throws Exception {
final SolrParams ID_FL_ONLY = params(CommonParams.FL, "id");
SolrDocument rsp = getSolrClient().getById("0", ID_FL_ONLY);
assertNull(rsp);
rsp = getSolrClient().getById("1", ID_FL_ONLY);
assertEquals("1", rsp.get("id"));
assertNull("This field should have been removed from the response.", rsp.get("term_s"));
assertNull("This field should have been removed from the response.", rsp.get("term2_s"));
rsp = getSolrClient().getById("2", ID_FL_ONLY);
assertEquals("2", rsp.get("id"));
assertNull("This field should have been removed from the response.", rsp.get("term_s"));
assertNull("This field should have been removed from the response.", rsp.get("term2_s"));
}
use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.
the class DistribCursorPagingTest method assertFullWalkNoDups.
/**
* <p>
* Given a set of params, executes a cursor query using {@link CursorMarkParams#CURSOR_MARK_START}
* and then continuously walks the results using {@link CursorMarkParams#CURSOR_MARK_START} as long
* as a non-0 number of docs ar returned. This method records the the set of all id's
* (must be positive ints) encountered and throws an assertion failure if any id is
* encountered more then once, or if the set grows above maxSize
* </p>
*
* <p>
* Note that this method explicitly uses the "cloudClient" for executing the queries,
* instead of relying on the test infrastructure to execute the queries redundently
* against both the cloud client as well as a control client. This is because term stat
* differences in a sharded setup can result in different scores for documents compared
* to the control index -- which can affect the sorting in some cases and cause false
* negatives in the response comparisons (even if we don't include "score" in the "fl")
* </p>
*/
public SentinelIntSet assertFullWalkNoDups(int maxSize, SolrParams params) throws Exception {
SentinelIntSet ids = new SentinelIntSet(maxSize, -1);
String cursorMark = CURSOR_MARK_START;
int docsOnThisPage = Integer.MAX_VALUE;
while (0 < docsOnThisPage) {
final SolrParams p = p(params, CURSOR_MARK_PARAM, cursorMark);
QueryResponse rsp = cloudClient.query(p);
String nextCursorMark = assertHashNextCursorMark(rsp);
SolrDocumentList docs = extractDocList(rsp);
docsOnThisPage = docs.size();
if (null != params.getInt(CommonParams.ROWS)) {
int rows = params.getInt(CommonParams.ROWS);
assertTrue("Too many docs on this page: " + rows + " < " + docsOnThisPage, docsOnThisPage <= rows);
}
if (0 == docsOnThisPage) {
assertEquals("no more docs, but " + CURSOR_MARK_NEXT + " isn't same", cursorMark, nextCursorMark);
}
for (SolrDocument doc : docs) {
int id = ((Integer) doc.get("id")).intValue();
if (ids.exists(id)) {
String msg = "(" + p + ") walk already seen: " + id;
try {
queryAndCompareShards(params("distrib", "false", "q", "id:" + id));
} catch (AssertionError ae) {
throw new AssertionError(msg + ", found shard inconsistency that would explain it...", ae);
}
rsp = cloudClient.query(params("q", "id:" + id));
throw new AssertionError(msg + ", don't know why; q=id:" + id + " gives: " + rsp.toString());
}
ids.put(id);
assertFalse("id set bigger then max allowed (" + maxSize + "): " + ids.size(), maxSize < ids.size());
}
cursorMark = nextCursorMark;
}
return ids;
}
use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.
the class TestCloudPivotFacet method assertPivotCountsAreCorrect.
/**
* Given some query params, executes the request against the cloudClient and
* then walks the pivot facet values in the response, treating each one as a
* filter query to assert the pivot counts are correct.
*/
private void assertPivotCountsAreCorrect(SolrParams baseParams, SolrParams pivotParams) throws SolrServerException {
SolrParams initParams = SolrParams.wrapAppended(pivotParams, baseParams);
log.info("Doing full run: {}", initParams);
countNumFoundChecks = 0;
NamedList<List<PivotField>> pivots = null;
try {
QueryResponse initResponse = cloudClient.query(initParams);
pivots = initResponse.getFacetPivot();
assertNotNull(initParams + " has null pivots?", pivots);
assertEquals(initParams + " num pivots", initParams.getParams("facet.pivot").length, pivots.size());
} catch (Exception e) {
throw new RuntimeException("init query failed: " + initParams + ": " + e.getMessage(), e);
}
try {
for (Map.Entry<String, List<PivotField>> pivot : pivots) {
final String pivotKey = pivot.getKey();
// :HACK: for counting the max possible pivot depth
final int maxDepth = 1 + pivotKey.length() - pivotKey.replace(",", "").length();
assertTraceOk(pivotKey, baseParams, pivot.getValue());
// will catch it.
for (PivotField constraint : pivot.getValue()) {
int depth = assertPivotCountsAreCorrect(pivotKey, baseParams, constraint);
// we can't assert that the depth reached is the same as the depth requested
// because the fq and/or mincount may have pruned the tree too much
assertTrue("went too deep: " + depth + ": " + pivotKey + " ==> " + pivot, depth <= maxDepth);
}
}
} catch (AssertionError e) {
throw new AssertionError(initParams + " ==> " + e.getMessage(), e);
} finally {
log.info("Ending full run (countNumFoundChecks={}): {}", countNumFoundChecks, initParams);
}
}
use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.
the class TestCloudPseudoReturnFields method testFunctionsRTG.
public void testFunctionsRTG() throws Exception {
// if we use RTG (committed or otherwise) functions should behave the same
for (String id : Arrays.asList("42", "99")) {
for (SolrParams p : Arrays.asList(params("fl", "log(val_i),abs(val_i)"), params("fl", "log(val_i)", "fl", "abs(val_i)"))) {
SolrDocument doc = getRandClient(random()).getById(id, p);
String msg = id + "," + p + " => " + doc;
assertEquals(msg, 2, doc.size());
assertTrue(msg, doc.getFieldValue("log(val_i)") instanceof Double);
assertTrue(msg, doc.getFieldValue("abs(val_i)") instanceof Float);
// true for both these specific docs
assertEquals(msg, 0.0D, doc.getFieldValue("log(val_i)"));
assertEquals(msg, 1.0F, doc.getFieldValue("abs(val_i)"));
}
}
}
use of org.apache.solr.common.params.SolrParams in project lucene-solr by apache.
the class TestCloudPseudoReturnFields method testFilterAndOneRealFieldRTG.
public void testFilterAndOneRealFieldRTG() throws Exception {
SolrParams params = params("fl", "id,val_i", "fq", "{!field f='subject' v=$my_var}", "my_var", "uncommitted");
SolrDocumentList docs = getRandClient(random()).getById(Arrays.asList("42", "99"), params);
final String msg = params + " => " + docs;
assertEquals(msg, 1, docs.size());
assertEquals(msg, 1, docs.getNumFound());
SolrDocument doc = docs.get(0);
assertEquals(msg, 2, doc.size());
assertEquals(msg, "99", doc.getFieldValue("id"));
assertEquals(msg, 1, doc.getFieldValue("val_i"));
}
Aggregations