use of org.apache.solr.search.SolrCache in project lucene-solr by apache.
the class TestNestedDocsSort method testCachehits.
public void testCachehits() {
final SolrQueryRequest req = req();
try {
final SolrCache cache = req.getSearcher().getCache("perSegFilter");
assertNotNull(cache);
final Map<String, Object> state = cache.getMetricsSnapshot();
String lookupsKey = null;
for (String key : state.keySet()) {
if (key.endsWith(".lookups")) {
lookupsKey = key;
break;
}
}
Number before = (Number) state.get(lookupsKey);
parse("childfield(name_s1,$q) asc");
Number after = (Number) cache.getMetricsSnapshot().get(lookupsKey);
assertEquals("parsing bjq lookups parent filter," + "parsing sort spec lookups parent and child filters, " + "hopefully for the purpose", 3, after.intValue() - before.intValue());
} finally {
req.close();
}
}
use of org.apache.solr.search.SolrCache in project lucene-solr by apache.
the class TestScoreJoinQPScore method testCacheHit.
public void testCacheHit() throws Exception {
indexDataForScorring();
Map<String, Metric> metrics = h.getCoreContainer().getMetricManager().registry(h.getCore().getCoreMetricManager().getRegistryName()).getMetrics();
MetricsMap mm = (MetricsMap) metrics.get("CACHE.searcher.queryResultCache");
{
Map<String, Object> statPre = mm.getValue();
h.query(req("q", "{!join from=movieId_s to=id score=Avg}title:first", "fl", "id", "omitHeader", "true"));
assertHitOrInsert(mm.getValue(), statPre);
}
{
Map<String, Object> statPre = mm.getValue();
h.query(req("q", "{!join from=movieId_s to=id score=Avg}title:first", "fl", "id", "omitHeader", "true"));
assertHit(mm.getValue(), statPre);
}
{
Map<String, Object> statPre = mm.getValue();
Random r = random();
boolean changed = false;
boolean x = false;
String from = (x = r.nextBoolean()) ? "id" : "movieId_s";
changed |= x;
String to = (x = r.nextBoolean()) ? "movieId_s" : "id";
changed |= x;
String score = (x = r.nextBoolean()) ? not(ScoreMode.Avg).name() : "Avg";
changed |= x;
/* till SOLR-7814
* String boost = (x = r.nextBoolean()) ? "23" : "1";
changed |= x; */
String q = (!changed) ? (r.nextBoolean() ? "title:first^67" : "title:night") : "title:first";
final String resp = h.query(req("q", "{!join from=" + from + " to=" + to + " score=" + score + //" b=" + boost +
"}" + q, "fl", "id", "omitHeader", "true"));
assertInsert(mm.getValue(), statPre);
statPre = mm.getValue();
final String repeat = h.query(req("q", "{!join from=" + from + " to=" + to + " score=" + score.toLowerCase(Locale.ROOT) + //" b=" + boost
"}" + q, "fl", "id", "omitHeader", "true"));
assertHit(mm.getValue(), statPre);
assertEquals("lowercase shouldn't change anything", resp, repeat);
final String aMod = score.substring(0, score.length() - 1);
assertQEx("exception on " + aMod, "ScoreMode", req("q", "{!join from=" + from + " to=" + to + " score=" + aMod + "}" + q, "fl", "id", "omitHeader", "true"), SolrException.ErrorCode.BAD_REQUEST);
}
// this queries are not overlap, with other in this test case.
// however it might be better to extract this method into the separate suite
// for a while let's nuke a cache content, in case of repetitions
SolrCache cache = (SolrCache) h.getCore().getInfoRegistry().get("queryResultCache");
cache.clear();
}
use of org.apache.solr.search.SolrCache in project lucene-solr by apache.
the class BlockJoinParentQParser method getCachedFilter.
static BitDocIdSetFilterWrapper getCachedFilter(final SolrQueryRequest request, Query parentList) {
SolrCache parentCache = request.getSearcher().getCache(CACHE_NAME);
// lazily retrieve from solr cache
Filter filter = null;
if (parentCache != null) {
filter = (Filter) parentCache.get(parentList);
}
BitDocIdSetFilterWrapper result;
if (filter instanceof BitDocIdSetFilterWrapper) {
result = (BitDocIdSetFilterWrapper) filter;
} else {
result = new BitDocIdSetFilterWrapper(createParentFilter(parentList));
if (parentCache != null) {
parentCache.put(parentList, result);
}
}
return result;
}
Aggregations