Search in sources :

Example 6 with MetricsMap

use of org.apache.solr.metrics.MetricsMap in project lucene-solr by apache.

the class LRUCache method initializeMetrics.

@Override
public void initializeMetrics(SolrMetricManager manager, String registryName, String scope) {
    registry = manager.registry(registryName);
    cacheMap = new MetricsMap((detailed, res) -> {
        synchronized (map) {
            res.put("lookups", lookups);
            res.put("hits", hits);
            res.put("hitratio", calcHitRatio(lookups, hits));
            res.put("inserts", inserts);
            res.put("evictions", evictions);
            res.put("size", map.size());
            if (maxRamBytes != Long.MAX_VALUE) {
                res.put("maxRamMB", maxRamBytes / 1024L / 1024L);
                res.put("ramBytesUsed", ramBytesUsed());
                res.put("evictionsRamUsage", evictionsRamUsage);
            }
        }
        res.put("warmupTime", warmupTime);
        long clookups = stats.lookups.longValue();
        long chits = stats.hits.longValue();
        res.put("cumulative_lookups", clookups);
        res.put("cumulative_hits", chits);
        res.put("cumulative_hitratio", calcHitRatio(clookups, chits));
        res.put("cumulative_inserts", stats.inserts.longValue());
        res.put("cumulative_evictions", stats.evictions.longValue());
        if (maxRamBytes != Long.MAX_VALUE) {
            res.put("cumulative_evictionsRamUsage", stats.evictionsRamUsage.longValue());
        }
    });
    manager.registerGauge(this, registryName, cacheMap, true, scope, getCategory().toString());
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) MetricsMap(org.apache.solr.metrics.MetricsMap) Accountables(org.apache.lucene.util.Accountables) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) TimeUnit(java.util.concurrent.TimeUnit) RamUsageEstimator(org.apache.lucene.util.RamUsageEstimator) SolrException(org.apache.solr.common.SolrException) Map(java.util.Map) Accountable(org.apache.lucene.util.Accountable) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) Collections(java.util.Collections) MetricsMap(org.apache.solr.metrics.MetricsMap)

Example 7 with MetricsMap

use of org.apache.solr.metrics.MetricsMap in project lucene-solr by apache.

the class Metrics method initializeMetrics.

@Override
public void initializeMetrics(SolrMetricManager manager, String registryName, String scope) {
    registry = manager.registry(registryName);
    metricsMap = new MetricsMap((detailed, map) -> {
        long now = System.nanoTime();
        long delta = Math.max(now - previous, 1);
        double seconds = delta / 1000000000.0;
        long hits_total = blockCacheHit.get();
        long hits_delta = hits_total - blockCacheHit_last.get();
        blockCacheHit_last.set(hits_total);
        long miss_total = blockCacheMiss.get();
        long miss_delta = miss_total - blockCacheMiss_last.get();
        blockCacheMiss_last.set(miss_total);
        long evict_total = blockCacheEviction.get();
        long evict_delta = evict_total - blockCacheEviction_last.get();
        blockCacheEviction_last.set(evict_total);
        long storeFail_total = blockCacheStoreFail.get();
        long storeFail_delta = storeFail_total - blockCacheStoreFail_last.get();
        blockCacheStoreFail_last.set(storeFail_total);
        long lookups_delta = hits_delta + miss_delta;
        long lookups_total = hits_total + miss_total;
        map.put("size", blockCacheSize.get());
        map.put("lookups", lookups_total);
        map.put("hits", hits_total);
        map.put("evictions", evict_total);
        map.put("storeFails", storeFail_total);
        // hit ratio since the last call
        map.put("hitratio_current", calcHitRatio(lookups_delta, hits_delta));
        // lookups per second since the last call
        map.put("lookups_persec", getPerSecond(lookups_delta, seconds));
        // hits per second since the last call
        map.put("hits_persec", getPerSecond(hits_delta, seconds));
        // evictions per second since the last call
        map.put("evictions_persec", getPerSecond(evict_delta, seconds));
        // evictions per second since the last call
        map.put("storeFails_persec", getPerSecond(storeFail_delta, seconds));
        // seconds since last call
        map.put("time_delta", seconds);
        // TODO: these aren't really related to the BlockCache
        map.put("buffercache.allocations", getPerSecond(shardBuffercacheAllocate.getAndSet(0), seconds));
        map.put("buffercache.lost", getPerSecond(shardBuffercacheLost.getAndSet(0), seconds));
        previous = now;
    });
    manager.registerGauge(this, registryName, metricsMap, true, getName(), getCategory().toString(), scope);
}
Also used : HashSet(java.util.HashSet) AtomicLong(java.util.concurrent.atomic.AtomicLong) MetricRegistry(com.codahale.metrics.MetricRegistry) SolrInfoBean(org.apache.solr.core.SolrInfoBean) Set(java.util.Set) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) MetricsMap(org.apache.solr.metrics.MetricsMap) SolrMetricProducer(org.apache.solr.metrics.SolrMetricProducer) SolrCacheBase(org.apache.solr.search.SolrCacheBase) MetricsMap(org.apache.solr.metrics.MetricsMap)

Example 8 with MetricsMap

use of org.apache.solr.metrics.MetricsMap in project lucene-solr by apache.

the class CursorPagingTest method testCacheImpacts.

/**
   * test that our assumptions about how caches are affected hold true
   */
public void testCacheImpacts() throws Exception {
    // cursor queryies can't live in the queryResultCache, but independent filters
    // should still be cached & reused
    // don't add in order of any field to ensure we aren't inadvertantly 
    // counting on internal docid ordering
    assertU(adoc("id", "9", "str", "c", "float", "-3.2", "int", "42"));
    assertU(adoc("id", "7", "str", "c", "float", "-3.2", "int", "-1976"));
    assertU(adoc("id", "2", "str", "c", "float", "-3.2", "int", "666"));
    assertU(adoc("id", "0", "str", "b", "float", "64.5", "int", "-42"));
    assertU(adoc("id", "5", "str", "b", "float", "64.5", "int", "2001"));
    assertU(adoc("id", "8", "str", "b", "float", "64.5", "int", "4055"));
    assertU(adoc("id", "6", "str", "a", "float", "64.5", "int", "7"));
    assertU(adoc("id", "1", "str", "a", "float", "64.5", "int", "7"));
    assertU(adoc("id", "4", "str", "a", "float", "11.1", "int", "6"));
    assertU(adoc("id", "3", "str", "a", "float", "11.1", "int", "3"));
    assertU(commit());
    final Collection<String> allFieldNames = getAllSortFieldNames();
    final MetricsMap filterCacheStats = (MetricsMap) h.getCore().getCoreMetricManager().getRegistry().getMetrics().get("CACHE.searcher.filterCache");
    assertNotNull(filterCacheStats);
    final MetricsMap queryCacheStats = (MetricsMap) h.getCore().getCoreMetricManager().getRegistry().getMetrics().get("CACHE.searcher.queryResultCache");
    assertNotNull(queryCacheStats);
    final long preQcIn = (Long) queryCacheStats.getValue().get("inserts");
    final long preFcIn = (Long) filterCacheStats.getValue().get("inserts");
    final long preFcHits = (Long) filterCacheStats.getValue().get("hits");
    SentinelIntSet ids = assertFullWalkNoDups(10, params("q", "*:*", "rows", "" + TestUtil.nextInt(random(), 1, 11), "fq", "-id:[1 TO 2]", "fq", "-id:[6 TO 7]", "fl", "id", "sort", buildRandomSort(allFieldNames)));
    assertEquals(6, ids.size());
    final long postQcIn = (Long) queryCacheStats.getValue().get("inserts");
    final long postFcIn = (Long) filterCacheStats.getValue().get("inserts");
    final long postFcHits = (Long) filterCacheStats.getValue().get("hits");
    assertEquals("query cache inserts changed", preQcIn, postQcIn);
    // NOTE: use of pure negative filters causees "*:* to be tracked in filterCache
    assertEquals("filter cache did not grow correctly", 3, postFcIn - preFcIn);
    assertTrue("filter cache did not have any new cache hits", 0 < postFcHits - preFcHits);
}
Also used : MetricsMap(org.apache.solr.metrics.MetricsMap) SentinelIntSet(org.apache.lucene.util.SentinelIntSet)

Example 9 with MetricsMap

use of org.apache.solr.metrics.MetricsMap in project lucene-solr by apache.

the class TestFastLRUCache method testPercentageAutowarm.

public void testPercentageAutowarm() throws IOException {
    FastLRUCache<Object, Object> fastCache = new FastLRUCache<>();
    fastCache.initializeMetrics(metricManager, registry, scope);
    MetricsMap metrics = fastCache.getMetricsMap();
    Map<String, String> params = new HashMap<>();
    params.put("size", "100");
    params.put("initialSize", "10");
    params.put("autowarmCount", "100%");
    CacheRegenerator cr = new NoOpRegenerator();
    Object o = fastCache.init(params, null, cr);
    fastCache.setState(SolrCache.State.LIVE);
    for (int i = 0; i < 101; i++) {
        fastCache.put(i + 1, "" + (i + 1));
    }
    assertEquals("25", fastCache.get(25));
    assertEquals(null, fastCache.get(110));
    Map<String, Object> nl = metrics.getValue();
    assertEquals(2L, nl.get("lookups"));
    assertEquals(1L, nl.get("hits"));
    assertEquals(101L, nl.get("inserts"));
    // first item put in should be the first out
    assertEquals(null, fastCache.get(1));
    FastLRUCache<Object, Object> fastCacheNew = new FastLRUCache<>();
    fastCacheNew.initializeMetrics(metricManager, registry, scope);
    metrics = fastCacheNew.getMetricsMap();
    fastCacheNew.init(params, o, cr);
    fastCacheNew.warm(null, fastCache);
    fastCacheNew.setState(SolrCache.State.LIVE);
    fastCache.close();
    fastCacheNew.put(103, "103");
    assertEquals("90", fastCacheNew.get(90));
    assertEquals("50", fastCacheNew.get(50));
    nl = metrics.getValue();
    assertEquals(2L, nl.get("lookups"));
    assertEquals(2L, nl.get("hits"));
    assertEquals(1L, nl.get("inserts"));
    assertEquals(0L, nl.get("evictions"));
    assertEquals(5L, nl.get("cumulative_lookups"));
    assertEquals(3L, nl.get("cumulative_hits"));
    assertEquals(102L, nl.get("cumulative_inserts"));
    fastCacheNew.close();
}
Also used : MetricsMap(org.apache.solr.metrics.MetricsMap) HashMap(java.util.HashMap)

Example 10 with MetricsMap

use of org.apache.solr.metrics.MetricsMap in project lucene-solr by apache.

the class TestReRankQParserPlugin method testReRankQueries.

@Test
public void testReRankQueries() throws Exception {
    assertU(delQ("*:*"));
    assertU(commit());
    String[] doc = { "id", "1", "term_s", "YYYY", "group_s", "group1", "test_ti", "5", "test_tl", "10", "test_tf", "2000" };
    assertU(adoc(doc));
    assertU(commit());
    String[] doc1 = { "id", "2", "term_s", "YYYY", "group_s", "group1", "test_ti", "50", "test_tl", "100", "test_tf", "200" };
    assertU(adoc(doc1));
    String[] doc2 = { "id", "3", "term_s", "YYYY", "test_ti", "5000", "test_tl", "100", "test_tf", "200" };
    assertU(adoc(doc2));
    assertU(commit());
    String[] doc3 = { "id", "4", "term_s", "YYYY", "test_ti", "500", "test_tl", "1000", "test_tf", "2000" };
    assertU(adoc(doc3));
    String[] doc4 = { "id", "5", "term_s", "YYYY", "group_s", "group2", "test_ti", "4", "test_tl", "10", "test_tf", "2000" };
    assertU(adoc(doc4));
    assertU(commit());
    String[] doc5 = { "id", "6", "term_s", "YYYY", "group_s", "group2", "test_ti", "10", "test_tl", "100", "test_tf", "200" };
    assertU(adoc(doc5));
    assertU(commit());
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=200}");
    params.add("q", "term_s:YYYY");
    params.add("rqq", "{!edismax bf=$bff}*:*");
    params.add("bff", "field(test_ti)");
    params.add("start", "0");
    params.add("rows", "6");
    params.add("df", "text");
    assertQ(req(params), "*[count(//doc)=6]", "//result/doc[1]/float[@name='id'][.='3.0']", "//result/doc[2]/float[@name='id'][.='4.0']", "//result/doc[3]/float[@name='id'][.='2.0']", "//result/doc[4]/float[@name='id'][.='6.0']", "//result/doc[5]/float[@name='id'][.='1.0']", "//result/doc[6]/float[@name='id'][.='5.0']");
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "{!edismax bq=$bqq2}*:*");
    params.add("bqq2", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "10");
    params.add("df", "text");
    assertQ(req(params), "*[count(//doc)=6]", "//result/doc[1]/float[@name='id'][.='2.0']", "//result/doc[2]/float[@name='id'][.='6.0']", "//result/doc[3]/float[@name='id'][.='5.0']", "//result/doc[4]/float[@name='id'][.='4.0']", "//result/doc[5]/float[@name='id'][.='3.0']", "//result/doc[6]/float[@name='id'][.='1.0']");
    //Test with sort by score.
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "{!edismax bq=$bqq2}*:*");
    params.add("bqq2", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "10");
    params.add("sort", "score desc");
    params.add("df", "text");
    assertQ(req(params), "*[count(//doc)=6]", "//result/doc[1]/float[@name='id'][.='2.0']", "//result/doc[2]/float[@name='id'][.='6.0']", "//result/doc[3]/float[@name='id'][.='5.0']", "//result/doc[4]/float[@name='id'][.='4.0']", "//result/doc[5]/float[@name='id'][.='3.0']", "//result/doc[6]/float[@name='id'][.='1.0']");
    //Test with compound sort.
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "{!edismax bq=$bqq2}*:*");
    params.add("bqq2", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "10");
    params.add("sort", "score desc,test_ti asc");
    params.add("df", "text");
    assertQ(req(params), "*[count(//doc)=6]", "//result/doc[1]/float[@name='id'][.='2.0']", "//result/doc[2]/float[@name='id'][.='6.0']", "//result/doc[3]/float[@name='id'][.='5.0']", "//result/doc[4]/float[@name='id'][.='4.0']", "//result/doc[5]/float[@name='id'][.='3.0']", "//result/doc[6]/float[@name='id'][.='1.0']");
    //Test with elevation
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6 " + ReRankQParserPlugin.RERANK_WEIGHT + "=50}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "{!edismax bq=$bqq2}*:*");
    params.add("bqq2", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "10");
    params.add("qt", "/elevate");
    params.add("elevateIds", "1");
    assertQ(req(params), "*[count(//doc)=6]", "//result/doc[1]/float[@name='id'][.='1.0']", "//result/doc[2]/float[@name='id'][.='2.0']", "//result/doc[3]/float[@name='id'][.='6.0']", "//result/doc[4]/float[@name='id'][.='5.0']", "//result/doc[5]/float[@name='id'][.='4.0']", "//result/doc[6]/float[@name='id'][.='3.0']");
    //Test TermQuery rqq
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "10");
    params.add("df", "text");
    assertQ(req(params), "*[count(//doc)=6]", "//result/doc[1]/float[@name='id'][.='2.0']", "//result/doc[2]/float[@name='id'][.='6.0']", "//result/doc[3]/float[@name='id'][.='5.0']", "//result/doc[4]/float[@name='id'][.='4.0']", "//result/doc[5]/float[@name='id'][.='3.0']", "//result/doc[6]/float[@name='id'][.='1.0']");
    //Test Elevation
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "10");
    params.add("qt", "/elevate");
    params.add("elevateIds", "1,4");
    assertQ(req(params), "*[count(//doc)=6]", //Elevated
    "//result/doc[1]/float[@name='id'][.='1.0']", //Elevated
    "//result/doc[2]/float[@name='id'][.='4.0']", //Boosted during rerank.
    "//result/doc[3]/float[@name='id'][.='2.0']", "//result/doc[4]/float[@name='id'][.='6.0']", "//result/doc[5]/float[@name='id'][.='5.0']", "//result/doc[6]/float[@name='id'][.='3.0']");
    //Test Elevation swapped
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "10");
    params.add("qt", "/elevate");
    params.add("elevateIds", "4,1");
    assertQ(req(params), "*[count(//doc)=6]", //Elevated
    "//result/doc[1]/float[@name='id'][.='4.0']", //Elevated
    "//result/doc[2]/float[@name='id'][.='1.0']", //Boosted during rerank.
    "//result/doc[3]/float[@name='id'][.='2.0']", "//result/doc[4]/float[@name='id'][.='6.0']", "//result/doc[5]/float[@name='id'][.='5.0']", "//result/doc[6]/float[@name='id'][.='3.0']");
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=4 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "10");
    params.add("qt", "/elevate");
    params.add("elevateIds", "4,1");
    assertQ(req(params), "*[count(//doc)=6]", //Elevated
    "//result/doc[1]/float[@name='id'][.='4.0']", //Elevated
    "//result/doc[2]/float[@name='id'][.='1.0']", "//result/doc[3]/float[@name='id'][.='6.0']", "//result/doc[4]/float[@name='id'][.='5.0']", "//result/doc[5]/float[@name='id'][.='3.0']", //Not in reRankeDocs
    "//result/doc[6]/float[@name='id'][.='2.0']");
    //Test Elevation with start beyond the rerank docs
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=3 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "4");
    params.add("rows", "10");
    params.add("qt", "/elevate");
    params.add("elevateIds", "4,1");
    assertQ(req(params), "*[count(//doc)=2]", "//result/doc[1]/float[@name='id'][.='3.0']", //Was not in reRankDocs
    "//result/doc[2]/float[@name='id'][.='2.0']");
    //Test Elevation with zero results
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=3 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "{!edismax bq=$bqq1}nada");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "4");
    params.add("rows", "10");
    params.add("qt", "/elevate");
    params.add("elevateIds", "4,1");
    assertQ(req(params), "*[count(//doc)=0]");
    //Pass in reRankDocs lower then the length being collected.
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=1 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "10");
    assertQ(req(params), "*[count(//doc)=6]", "//result/doc[1]/float[@name='id'][.='6.0']", "//result/doc[2]/float[@name='id'][.='5.0']", "//result/doc[3]/float[@name='id'][.='4.0']", "//result/doc[4]/float[@name='id'][.='3.0']", "//result/doc[5]/float[@name='id'][.='2.0']", "//result/doc[6]/float[@name='id'][.='1.0']");
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=0 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "10");
    assertQ(req(params), "*[count(//doc)=6]", "//result/doc[1]/float[@name='id'][.='6.0']", "//result/doc[2]/float[@name='id'][.='5.0']", "//result/doc[3]/float[@name='id'][.='4.0']", "//result/doc[4]/float[@name='id'][.='3.0']", "//result/doc[5]/float[@name='id'][.='2.0']", "//result/doc[6]/float[@name='id'][.='1.0']");
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=2 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "test_ti:4^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "10");
    assertQ(req(params), "*[count(//doc)=6]", "//result/doc[1]/float[@name='id'][.='5.0']", "//result/doc[2]/float[@name='id'][.='6.0']", "//result/doc[3]/float[@name='id'][.='4.0']", "//result/doc[4]/float[@name='id'][.='3.0']", "//result/doc[5]/float[@name='id'][.='2.0']", "//result/doc[6]/float[@name='id'][.='1.0']");
    //Test reRankWeight of 0, reranking will have no effect.
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6 " + ReRankQParserPlugin.RERANK_WEIGHT + "=0}");
    params.add("q", "{!edismax bq=$bqq1}*:*");
    params.add("bqq1", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "test_ti:50^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "5");
    assertQ(req(params), "*[count(//doc)=5]", "//result/doc[1]/float[@name='id'][.='6.0']", "//result/doc[2]/float[@name='id'][.='5.0']", "//result/doc[3]/float[@name='id'][.='4.0']", "//result/doc[4]/float[@name='id'][.='3.0']", "//result/doc[5]/float[@name='id'][.='2.0']");
    MetricsMap metrics = (MetricsMap) h.getCore().getCoreMetricManager().getRegistry().getMetrics().get("CACHE.searcher.queryResultCache");
    Map<String, Object> stats = metrics.getValue();
    long inserts = (Long) stats.get("inserts");
    assertTrue(inserts > 0);
    //Test range query
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6}");
    params.add("q", "test_ti:[0 TO 2000]");
    params.add("rqq", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "6");
    assertQ(req(params), "*[count(//doc)=5]", "//result/doc[1]/float[@name='id'][.='6.0']", "//result/doc[2]/float[@name='id'][.='5.0']", "//result/doc[3]/float[@name='id'][.='4.0']", "//result/doc[4]/float[@name='id'][.='2.0']", "//result/doc[5]/float[@name='id'][.='1.0']");
    stats = metrics.getValue();
    long inserts1 = (Long) stats.get("inserts");
    //Last query was added to the cache
    assertTrue(inserts1 > inserts);
    //Run same query and see if it was cached. This tests the query result cache hit with rewritten queries
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6}");
    params.add("q", "test_ti:[0 TO 2000]");
    params.add("rqq", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "6");
    assertQ(req(params), "*[count(//doc)=5]", "//result/doc[1]/float[@name='id'][.='6.0']", "//result/doc[2]/float[@name='id'][.='5.0']", "//result/doc[3]/float[@name='id'][.='4.0']", "//result/doc[4]/float[@name='id'][.='2.0']", "//result/doc[5]/float[@name='id'][.='1.0']");
    stats = metrics.getValue();
    long inserts2 = (Long) stats.get("inserts");
    //Last query was NOT added to the cache
    assertTrue(inserts1 == inserts2);
    //Test range query embedded in larger query
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6}");
    // function query for predictible scores (relative to id) independent of similarity
    params.add("q", "{!func}id");
    // constant score for each clause (unique per doc) for predictible scores independent of similarity
    // NOTE: biased in favor of doc id == 2
    params.add("rqq", "id:1^=10 id:2^=40 id:3^=30 id:4^=40 id:5^=50 id:6^=60");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "6");
    assertQ(req(params), "*[count(//doc)=6]", "//result/doc[1]/float[@name='id'][.='6.0']", "//result/doc[2]/float[@name='id'][.='5.0']", "//result/doc[3]/float[@name='id'][.='4.0']", // reranked out of orig order
    "//result/doc[4]/float[@name='id'][.='2.0']", "//result/doc[5]/float[@name='id'][.='3.0']", "//result/doc[6]/float[@name='id'][.='1.0']");
    //Test with start beyond reRankDocs
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=3 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50 id:6^60");
    params.add("rqq", "id:1^1000");
    params.add("fl", "id,score");
    params.add("start", "4");
    params.add("rows", "5");
    assertQ(req(params), "*[count(//doc)=2]", "//result/doc[1]/float[@name='id'][.='2.0']", "//result/doc[2]/float[@name='id'][.='1.0']");
    //Test ReRankDocs > docs returned
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=6 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "id:1^10 id:2^20 id:3^30 id:4^40 id:5^50");
    params.add("rqq", "id:1^1000");
    params.add("fl", "id,score");
    params.add("start", "0");
    params.add("rows", "1");
    assertQ(req(params), "*[count(//doc)=1]", "//result/doc[1]/float[@name='id'][.='1.0']");
    //Test with zero results
    params = new ModifiableSolrParams();
    params.add("rq", "{!" + ReRankQParserPlugin.NAME + " " + ReRankQParserPlugin.RERANK_QUERY + "=$rqq " + ReRankQParserPlugin.RERANK_DOCS + "=3 " + ReRankQParserPlugin.RERANK_WEIGHT + "=2}");
    params.add("q", "term_s:NNNN");
    params.add("rqq", "id:1^1000");
    params.add("fl", "id,score");
    params.add("start", "4");
    params.add("rows", "5");
    assertQ(req(params), "*[count(//doc)=0]");
}
Also used : MetricsMap(org.apache.solr.metrics.MetricsMap) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test)

Aggregations

MetricsMap (org.apache.solr.metrics.MetricsMap)26 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)10 Map (java.util.Map)8 Test (org.junit.Test)7 MetricRegistry (com.codahale.metrics.MetricRegistry)5 MethodHandles (java.lang.invoke.MethodHandles)5 HashSet (java.util.HashSet)5 Set (java.util.Set)5 SolrException (org.apache.solr.common.SolrException)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 HashMap (java.util.HashMap)4 Random (java.util.Random)4 List (java.util.List)3 TimeUnit (java.util.concurrent.TimeUnit)3 IOException (java.io.IOException)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)2 Gauge (com.codahale.metrics.Gauge)1 JmxReporter (com.codahale.metrics.JmxReporter)1