Search in sources :

Example 1 with Coverage

use of com.yahoo.search.result.Coverage in project vespa by vespa-engine.

the class VespaBackEndSearcher method addMetaInfo.

protected void addMetaInfo(Query query, QueryPacketData queryPacketData, QueryResultPacket resultPacket, Result result, boolean fromCache) {
    result.setTotalHitCount(resultPacket.getTotalDocumentCount());
    // Grouping
    if (resultPacket.getGroupData() != null) {
        byte[] data = resultPacket.getGroupData();
        ArrayList<Grouping> list = new ArrayList<>();
        BufferSerializer buf = new BufferSerializer(new GrowableByteBuffer(ByteBuffer.wrap(data)));
        int cnt = buf.getInt(null);
        for (int i = 0; i < cnt; i++) {
            Grouping g = new Grouping();
            g.deserialize(buf);
            list.add(g);
        }
        GroupingListHit hit = new GroupingListHit(list, getDocsumDefinitionSet(query));
        hit.setQuery(result.getQuery());
        hit.setSource(getName());
        hit.setSourceNumber(sourceNumber);
        hit.setQueryPacketData(queryPacketData);
        result.hits().add(hit);
    }
    if (resultPacket.getCoverageFeature()) {
        result.setCoverage(new Coverage(resultPacket.getCoverageDocs(), resultPacket.getActiveDocs(), resultPacket.getNodesReplied()).setSoonActive(resultPacket.getSoonActiveDocs()).setDegradedReason(resultPacket.getDegradedReason()).setNodesTried(resultPacket.getNodesQueried()));
    }
}
Also used : BufferSerializer(com.yahoo.vespa.objects.BufferSerializer) ArrayList(java.util.ArrayList) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Grouping(com.yahoo.searchlib.aggregation.Grouping) Coverage(com.yahoo.search.result.Coverage)

Example 2 with Coverage

use of com.yahoo.search.result.Coverage in project vespa by vespa-engine.

the class JsonRenderer method renderCoverage.

private void renderCoverage() throws IOException {
    Coverage c = getResult().getCoverage(false);
    if (c == null)
        return;
    generator.writeObjectFieldStart(COVERAGE);
    generator.writeNumberField(COVERAGE_COVERAGE, c.getResultPercentage());
    generator.writeNumberField(COVERAGE_DOCUMENTS, c.getDocs());
    if (c.isDegraded()) {
        generator.writeObjectFieldStart(COVERAGE_DEGRADE);
        generator.writeBooleanField(COVERAGE_DEGRADE_MATCHPHASE, c.isDegradedByMatchPhase());
        generator.writeBooleanField(COVERAGE_DEGRADE_TIMEOUT, c.isDegradedByTimeout());
        generator.writeBooleanField(COVERAGE_DEGRADE_ADAPTIVE_TIMEOUT, c.isDegradedByAdapativeTimeout());
        generator.writeBooleanField(COVERAGE_DEGRADED_NON_IDEAL_STATE, c.isDegradedByNonIdealState());
        generator.writeEndObject();
    }
    generator.writeBooleanField(COVERAGE_FULL, c.getFull());
    generator.writeNumberField(COVERAGE_NODES, c.getNodes());
    generator.writeNumberField(COVERAGE_RESULTS, c.getResultSets());
    generator.writeNumberField(COVERAGE_RESULTS_FULL, c.getFullResultSets());
    generator.writeEndObject();
}
Also used : Coverage(com.yahoo.search.result.Coverage)

Example 3 with Coverage

use of com.yahoo.search.result.Coverage in project vespa by vespa-engine.

the class JsonRendererTestCase method test.

@Test
public final void test() throws IOException, InterruptedException, ExecutionException, JSONException {
    String expected = "{\n" + "    \"root\": {\n" + "        \"children\": [\n" + "            {\n" + "                \"children\": [\n" + "                    {\n" + "                        \"fields\": {\n" + "                            \"c\": \"d\",\n" + "                            \"uri\": \"http://localhost/1\"\n" + "                        },\n" + "                        \"id\": \"http://localhost/1\",\n" + "                        \"relevance\": 0.9,\n" + "                        \"types\": [\n" + "                            \"summary\"\n" + "                        ]\n" + "                    }\n" + "                ],\n" + "                \"id\": \"usual\",\n" + "                \"relevance\": 1.0\n" + "            },\n" + "            {\n" + "                \"fields\": {\n" + "                    \"e\": \"f\"\n" + "                },\n" + "                \"id\": \"type grouphit\",\n" + "                \"relevance\": 1.0,\n" + "                \"types\": [\n" + "                    \"grouphit\"\n" + "                ]\n" + "            },\n" + "            {\n" + "                \"fields\": {\n" + "                    \"b\": \"foo\",\n" + "                    \"uri\": \"http://localhost/\"\n" + "                },\n" + "                \"id\": \"http://localhost/\",\n" + "                \"relevance\": 0.95,\n" + "                \"types\": [\n" + "                    \"summary\"\n" + "                ]\n" + "            }\n" + "        ],\n" + "        \"coverage\": {\n" + "            \"coverage\": 100,\n" + "            \"documents\": 500,\n" + "            \"full\": true,\n" + "            \"nodes\": 1,\n" + "            \"results\": 1,\n" + "            \"resultsFull\": 1\n" + "        },\n" + "        \"errors\": [\n" + "            {\n" + "                \"code\": 18,\n" + "                \"message\": \"boom\",\n" + "                \"summary\": \"Internal server error.\"\n" + "            }\n" + "        ],\n" + "        \"fields\": {\n" + "            \"totalCount\": 0\n" + "        },\n" + "        \"id\": \"toplevel\",\n" + "        \"relevance\": 1.0\n" + "    }\n" + "}";
    Query q = new Query("/?query=a&tracelevel=5&reportCoverage=true");
    Execution execution = new Execution(Execution.Context.createContextStub());
    Result r = new Result(q);
    r.setCoverage(new Coverage(500, 1, true));
    FastHit h = new FastHit("http://localhost/", .95);
    h.setField("$a", "Hello, world.");
    h.setField("b", "foo");
    r.hits().add(h);
    HitGroup g = new HitGroup("usual");
    h = new FastHit("http://localhost/1", .90);
    h.setField("c", "d");
    g.add(h);
    r.hits().add(g);
    HitGroup gg = new HitGroup("type grouphit");
    gg.types().add("grouphit");
    gg.setField("e", "f");
    r.hits().add(gg);
    r.hits().addError(ErrorMessage.createInternalServerError("boom"));
    String summary = render(execution, r);
    assertEqualJson(expected, summary);
}
Also used : Execution(com.yahoo.search.searchchain.Execution) FastHit(com.yahoo.prelude.fastsearch.FastHit) Query(com.yahoo.search.Query) Coverage(com.yahoo.search.result.Coverage) JSONString(com.yahoo.prelude.hitfield.JSONString) Result(com.yahoo.search.Result) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 4 with Coverage

use of com.yahoo.search.result.Coverage in project vespa by vespa-engine.

the class SyncDefaultRendererTestCase method testRenderWriterResult.

@SuppressWarnings("deprecation")
@Test
public final void testRenderWriterResult() throws IOException, InterruptedException, ExecutionException {
    Query q = new Query("/?query=a&tracelevel=5&reportCoverage=true");
    q.getPresentation().setTiming(true);
    Result r = new Result(q);
    r.setCoverage(new Coverage(500, 1, true));
    TimeTracker t = new TimeTracker(new Chain<Searcher>(new UselessSearcher("first"), new UselessSearcher("second"), new UselessSearcher("third")));
    ElapsedTimeTestCase.doInjectTimeSource(t, new CreativeTimeSource(new long[] { 1L, 2L, 3L, 4L, 5L, 6L, 7L }));
    t.sampleSearch(0, true);
    t.sampleSearch(1, true);
    t.sampleSearch(2, true);
    t.sampleSearch(3, true);
    t.sampleSearchReturn(2, true, null);
    t.sampleSearchReturn(1, true, null);
    t.sampleSearchReturn(0, true, null);
    r.getElapsedTime().add(t);
    r.getTemplating().setRenderer(d);
    FastHit h = new FastHit("http://localhost/", .95);
    h.setField("$a", "Hello, world.");
    h.setField("b", "foo");
    r.hits().add(h);
    HitGroup g = new HitGroup("usual");
    h = new FastHit("http://localhost/1", .90);
    h.setField("c", "d");
    g.add(h);
    r.hits().add(g);
    HitGroup gg = new HitGroup("type grouphit");
    gg.types().add("grouphit");
    gg.setField("e", "f");
    r.hits().add(gg);
    r.hits().addError(ErrorMessage.createInternalServerError("boom"));
    ByteArrayOutputStream bs = new ByteArrayOutputStream();
    ListenableFuture<Boolean> f = d.render(bs, r, null, null);
    assertTrue(f.get());
    String summary = Utf8.toString(bs.toByteArray());
    // TODO figure out a reasonably strict and reasonably flexible way to test
    assertTrue(summary.length() > 1000);
}
Also used : Query(com.yahoo.search.Query) CreativeTimeSource(com.yahoo.search.statistics.ElapsedTimeTestCase.CreativeTimeSource) Searcher(com.yahoo.search.Searcher) UselessSearcher(com.yahoo.search.statistics.ElapsedTimeTestCase.UselessSearcher) Coverage(com.yahoo.search.result.Coverage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Result(com.yahoo.search.Result) UselessSearcher(com.yahoo.search.statistics.ElapsedTimeTestCase.UselessSearcher) FastHit(com.yahoo.prelude.fastsearch.FastHit) TimeTracker(com.yahoo.search.statistics.TimeTracker) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 5 with Coverage

use of com.yahoo.search.result.Coverage in project vespa by vespa-engine.

the class StatisticsSearcher method search.

/**
 * Generate statistics for the query passing through this Searcher
 * 1) Add 1 to total query count
 * 2) Add response time to total response time (time from entry to return)
 * 3) .....
 */
public Result search(com.yahoo.search.Query query, Execution execution) {
    if (query.properties().getBoolean(IGNORE_QUERY, false)) {
        return execution.search(query);
    }
    Metric.Context metricContext = getChainMetricContext(execution.chain().getId().stringValue());
    incrQueryCount(metricContext);
    logQuery(query);
    // Start time, in millisecs.
    long start = System.currentTimeMillis();
    qps(metricContext);
    Result result;
    // handle exceptions thrown below in searchers
    try {
        // Pass on down the chain
        result = execution.search(query);
    } catch (Exception e) {
        incrErrorCount(null, metricContext);
        throw e;
    }
    // Start time, in millisecs.
    long end = System.currentTimeMillis();
    long latency = end - start;
    if (latency >= 0) {
        addLatency(latency, metricContext);
    } else {
        getLogger().log(LogLevel.WARNING, "Apparently negative latency measure, start: " + start + ", end: " + end + ", for query: " + query.toString());
    }
    if (result.hits().getError() != null) {
        incrErrorCount(result, metricContext);
        incrementStatePageOnlyErrors(result);
    }
    Coverage queryCoverage = result.getCoverage(false);
    if (queryCoverage != null) {
        if (queryCoverage.isDegraded()) {
            Metric.Context degradedContext = getDegradedMetricContext(execution.chain().getId().stringValue(), queryCoverage);
            metric.add(DEGRADED_METRIC, 1, degradedContext);
        }
        metric.set(COVERAGE_METRIC, (double) queryCoverage.getResultPercentage(), metricContext);
    }
    int hitCount = result.getConcreteHitCount();
    hitsPerQuery.put((double) hitCount);
    metric.set(HITS_PER_QUERY_METRIC, (double) hitCount, metricContext);
    metric.set(TOTALHITS_PER_QUERY_METRIC, (double) result.getTotalHitCount(), metricContext);
    if (hitCount == 0) {
        emptyResults.increment();
        metric.add(EMPTY_RESULTS_METRIC, 1, metricContext);
    }
    return result;
}
Also used : Metric(com.yahoo.jdisc.Metric) Coverage(com.yahoo.search.result.Coverage) Result(com.yahoo.search.Result)

Aggregations

Coverage (com.yahoo.search.result.Coverage)10 Result (com.yahoo.search.Result)6 Query (com.yahoo.search.Query)5 Test (org.junit.Test)4 FastHit (com.yahoo.prelude.fastsearch.FastHit)3 HitGroup (com.yahoo.search.result.HitGroup)3 JSONString (com.yahoo.prelude.hitfield.JSONString)2 Searcher (com.yahoo.search.Searcher)2 Execution (com.yahoo.search.searchchain.Execution)2 CreativeTimeSource (com.yahoo.search.statistics.ElapsedTimeTestCase.CreativeTimeSource)2 UselessSearcher (com.yahoo.search.statistics.ElapsedTimeTestCase.UselessSearcher)2 TimeTracker (com.yahoo.search.statistics.TimeTracker)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)1 Metric (com.yahoo.jdisc.Metric)1 Grouping (com.yahoo.searchlib.aggregation.Grouping)1 BufferSerializer (com.yahoo.vespa.objects.BufferSerializer)1 ArrayList (java.util.ArrayList)1