Search in sources :

Example 11 with GroupingListHit

use of com.yahoo.prelude.fastsearch.GroupingListHit in project vespa by vespa-engine.

the class VdsStreamingSearcher method doSearch2.

@Override
public Result doSearch2(Query query, QueryPacket queryPacket, CacheKey cacheKey, Execution execution) {
    // TODO refactor this method into smaller methods, it's hard to see the actual code
    lazyTrace(query, 7, "Routing to storage cluster ", getStorageClusterRouteSpec());
    if (route == null) {
        route = Route.parse(getStorageClusterRouteSpec());
    }
    lazyTrace(query, 8, "Route is ", route);
    lazyTrace(query, 7, "doSearch2(): query docsum class=", query.getPresentation().getSummary(), ", default docsum class=", getDefaultDocsumClass());
    if (query.getPresentation().getSummary() == null) {
        lazyTrace(query, 6, "doSearch2(): No summary class specified in query, using default: ", getDefaultDocsumClass());
        query.getPresentation().setSummary(getDefaultDocsumClass());
    } else {
        lazyTrace(query, 6, "doSearch2(): Summary class has been specified in query: ", query.getPresentation().getSummary());
    }
    lazyTrace(query, 8, "doSearch2(): rank properties=", query.getRanking());
    lazyTrace(query, 8, "doSearch2(): sort specification=", query.getRanking().getSorting() == null ? null : query.getRanking().getSorting().fieldOrders());
    int documentSelectionQueryParameterCount = 0;
    if (query.properties().getString(streamingUserid) != null)
        documentSelectionQueryParameterCount++;
    if (query.properties().getString(streamingGroupname) != null)
        documentSelectionQueryParameterCount++;
    if (query.properties().getString(streamingSelection) != null)
        documentSelectionQueryParameterCount++;
    if (documentSelectionQueryParameterCount != 1) {
        return new Result(query, ErrorMessage.createBackendCommunicationError("Streaming search needs one and " + "only one of these query parameters to be set: streaming.userid, streaming.groupname, " + "streaming.selection"));
    }
    query.trace("Routing to search cluster " + getSearchClusterConfigId(), 4);
    Visitor visitor = visitorFactory.createVisitor(query, getSearchClusterConfigId(), route);
    try {
        visitor.doSearch();
    } catch (ParseException e) {
        return new Result(query, ErrorMessage.createBackendCommunicationError("Failed to parse document selection string: " + e.getMessage() + "'."));
    } catch (TokenMgrError e) {
        return new Result(query, ErrorMessage.createBackendCommunicationError("Failed to tokenize document selection string: " + e.getMessage() + "'."));
    } catch (TimeoutException e) {
        return new Result(query, ErrorMessage.createTimeout(e.getMessage()));
    } catch (InterruptedException | IllegalArgumentException e) {
        return new Result(query, ErrorMessage.createBackendCommunicationError(e.getMessage()));
    }
    lazyTrace(query, 8, "offset=", query.getOffset(), ", hits=", query.getHits());
    Result result = new Result(query);
    // Sorted on rank
    List<SearchResult.Hit> hits = visitor.getHits();
    Map<String, DocumentSummary.Summary> summaryMap = visitor.getSummaryMap();
    lazyTrace(query, 7, "total hit count = ", visitor.getTotalHitCount(), ", returned hit count = ", hits.size(), ", summary count = ", summaryMap.size());
    result.setTotalHitCount(visitor.getTotalHitCount());
    query.trace(visitor.getStatistics().toString(), false, 2);
    query.getContext(true).setProperty(STREAMING_STATISTICS, visitor.getStatistics());
    Packet[] summaryPackets = new Packet[hits.size()];
    int index = 0;
    boolean skippedEarlierResult = false;
    for (SearchResult.Hit hit : hits) {
        if (!verifyDocId(hit.getDocId(), query, skippedEarlierResult)) {
            skippedEarlierResult = true;
            continue;
        }
        FastHit fastHit = buildSummaryHit(query, hit);
        result.hits().add(fastHit);
        DocumentSummary.Summary summary = summaryMap.get(hit.getDocId());
        if (summary != null) {
            DocsumPacket dp = new DocsumPacket(summary.getSummary());
            // log.log(LogLevel.SPAM, "DocsumPacket: " + dp);
            summaryPackets[index] = dp;
        } else {
            return new Result(query, ErrorMessage.createBackendCommunicationError("Did not find summary for hit with document id " + hit.getDocId()));
        }
        index++;
    }
    if (result.isFilled(query.getPresentation().getSummary())) {
        lazyTrace(query, 8, "Result is filled for summary class ", query.getPresentation().getSummary());
    } else {
        lazyTrace(query, 8, "Result is not filled for summary class ", query.getPresentation().getSummary());
    }
    List<Grouping> groupingList = visitor.getGroupings();
    lazyTrace(query, 8, "Grouping list=", groupingList);
    if (!groupingList.isEmpty()) {
        GroupingListHit groupHit = new GroupingListHit(groupingList, getDocsumDefinitionSet(query));
        result.hits().add(groupHit);
    }
    int skippedHits;
    try {
        FillHitsResult fillHitsResult = fillHits(result, summaryPackets, query.getPresentation().getSummary());
        skippedHits = fillHitsResult.skippedHits;
        if (fillHitsResult.error != null) {
            result.hits().addError(ErrorMessage.createTimeout(fillHitsResult.error));
            return result;
        }
    } catch (TimeoutException e) {
        result.hits().addError(ErrorMessage.createTimeout(e.getMessage()));
        return result;
    } catch (IOException e) {
        return new Result(query, ErrorMessage.createBackendCommunicationError("Error filling hits with summary fields"));
    }
    if (skippedHits == 0) {
        // TODO: cache results or result.analyzeHits(); ?
        query.trace("All hits have been filled", 4);
    } else {
        lazyTrace(query, 8, "Skipping some hits for query: ", result.getQuery());
    }
    lazyTrace(query, 8, "Returning result ", result);
    if (skippedHits > 0) {
        getLogger().info("skipping " + skippedHits + " hits for query: " + result.getQuery());
        result.hits().addError(com.yahoo.search.result.ErrorMessage.createTimeout("Missing hit summary data for " + skippedHits + " hits"));
    }
    return result;
}
Also used : IdString(com.yahoo.document.idstring.IdString) Result(com.yahoo.search.Result) SearchResult(com.yahoo.vdslib.SearchResult) TimeoutException(com.yahoo.prelude.fastsearch.TimeoutException) DocsumPacket(com.yahoo.fs4.DocsumPacket) QueryPacket(com.yahoo.fs4.QueryPacket) Packet(com.yahoo.fs4.Packet) DocsumPacket(com.yahoo.fs4.DocsumPacket) TokenMgrError(com.yahoo.document.select.parser.TokenMgrError) SearchResult(com.yahoo.vdslib.SearchResult) Grouping(com.yahoo.searchlib.aggregation.Grouping) IOException(java.io.IOException) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) FastHit(com.yahoo.prelude.fastsearch.FastHit) FastHit(com.yahoo.prelude.fastsearch.FastHit) DocumentSummary(com.yahoo.vdslib.DocumentSummary) ParseException(com.yahoo.document.select.parser.ParseException) DocumentSummary(com.yahoo.vdslib.DocumentSummary)

Example 12 with GroupingListHit

use of com.yahoo.prelude.fastsearch.GroupingListHit in project vespa by vespa-engine.

the class HitConverter method convertFs4Hit.

private Hit convertFs4Hit(String summaryClass, FS4Hit groupHit) {
    FastHit hit = new FastHit();
    hit.setRelevance(groupHit.getRank());
    hit.setGlobalId(groupHit.getGlobalId());
    hit.setPartId(groupHit.getPath(), 0);
    hit.setDistributionKey(groupHit.getDistributionKey());
    hit.setFillable();
    hit.setSearcherSpecificMetaData(searcher, summaryClass);
    Hit ctxHit = (Hit) groupHit.getContext();
    if (ctxHit == null) {
        throw new NullPointerException("Hit has no context.");
    }
    hit.setSource(ctxHit.getSource());
    hit.setSourceNumber(ctxHit.getSourceNumber());
    hit.setQuery(ctxHit.getQuery());
    if (ctxHit instanceof GroupingListHit) {
        // in a live system the ctxHit can only by GroupingListHit, but because the code used Hit prior to version
        // 5.10 we need to check to avoid breaking existing unit tests -- both internally and with customers
        QueryPacketData queryPacketData = ((GroupingListHit) ctxHit).getQueryPacketData();
        if (queryPacketData != null) {
            hit.setQueryPacketData(queryPacketData);
        }
    }
    return hit;
}
Also used : FS4Hit(com.yahoo.searchlib.aggregation.FS4Hit) Hit(com.yahoo.search.result.Hit) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) VdsHit(com.yahoo.searchlib.aggregation.VdsHit) FastHit(com.yahoo.prelude.fastsearch.FastHit) FastHit(com.yahoo.prelude.fastsearch.FastHit) QueryPacketData(com.yahoo.fs4.QueryPacketData) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit)

Example 13 with GroupingListHit

use of com.yahoo.prelude.fastsearch.GroupingListHit in project vespa by vespa-engine.

the class GroupingExecutorTestCase method requireThatUnfilledHitsRenderError.

@Test
public void requireThatUnfilledHitsRenderError() throws IOException {
    Query query = newQuery();
    GroupingRequest req = GroupingRequest.newInstance(query);
    req.setRootOperation(GroupingOperation.fromString("all(group(foo) each(each(output(summary(bar)))))"));
    Grouping grp0 = new Grouping(0);
    grp0.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("foo")).addAggregationResult(new HitsAggregationResult(1, "bar"))));
    Grouping grp1 = new Grouping(0);
    grp1.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("foo")).addAggregationResult(new HitsAggregationResult(1, "bar").addHit(new com.yahoo.searchlib.aggregation.FS4Hit()))));
    Execution exec = newExecution(new GroupingExecutor(), new ResultProvider(Arrays.asList(new GroupingListHit(Arrays.asList(grp0), null), new GroupingListHit(Arrays.asList(grp1), null))), new FillErrorProvider());
    Result res = exec.search(query);
    exec.fill(res);
    assertNotNull(res.hits().getError());
}
Also used : Group(com.yahoo.search.grouping.result.Group) Query(com.yahoo.search.Query) Grouping(com.yahoo.searchlib.aggregation.Grouping) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) Result(com.yahoo.search.Result) HitsAggregationResult(com.yahoo.searchlib.aggregation.HitsAggregationResult) CountAggregationResult(com.yahoo.searchlib.aggregation.CountAggregationResult) MinAggregationResult(com.yahoo.searchlib.aggregation.MinAggregationResult) MaxAggregationResult(com.yahoo.searchlib.aggregation.MaxAggregationResult) HitsAggregationResult(com.yahoo.searchlib.aggregation.HitsAggregationResult) Execution(com.yahoo.search.searchchain.Execution) GroupingRequest(com.yahoo.search.grouping.GroupingRequest) StringResultNode(com.yahoo.searchlib.expression.StringResultNode) Test(org.junit.Test)

Example 14 with GroupingListHit

use of com.yahoo.prelude.fastsearch.GroupingListHit in project vespa by vespa-engine.

the class GroupingExecutorTestCase method requireThatPassResultsAreMerged.

@Test
public void requireThatPassResultsAreMerged() {
    Query query = newQuery();
    GroupingRequest req = GroupingRequest.newInstance(query);
    req.setRootOperation(GroupingOperation.fromString("all(group(foo) each(output(min(bar), max(bar))))"));
    Grouping grpA = new Grouping(0);
    grpA.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("uniqueA")).addAggregationResult(new MaxAggregationResult().setMax(new IntegerResultNode(6)).setTag(4))).addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("common")).addAggregationResult(new MaxAggregationResult().setMax(new IntegerResultNode(9)).setTag(4))));
    Grouping grpB = new Grouping(0);
    grpB.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("uniqueB")).addAggregationResult(new MaxAggregationResult().setMax(new IntegerResultNode(9)).setTag(4))).addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("common")).addAggregationResult(new MinAggregationResult().setMin(new IntegerResultNode(6)).setTag(3))));
    Execution exec = newExecution(new GroupingExecutor(), new ResultProvider(Arrays.asList(new GroupingListHit(Arrays.asList(grpA), null), new GroupingListHit(Arrays.asList(grpB), null))));
    Group grp = req.getResultGroup(exec.search(query));
    assertEquals(1, grp.size());
    Hit hit = grp.get(0);
    assertTrue(hit instanceof GroupList);
    GroupList lst = (GroupList) hit;
    assertEquals(3, lst.size());
    assertNotNull(hit = lst.get("group:string:uniqueA"));
    assertEquals(6L, hit.getField("max(bar)"));
    assertNotNull(hit = lst.get("group:string:uniqueB"));
    assertEquals(9L, hit.getField("max(bar)"));
    assertNotNull(hit = lst.get("group:string:common"));
    assertEquals(6L, hit.getField("min(bar)"));
    assertEquals(9L, hit.getField("max(bar)"));
}
Also used : Group(com.yahoo.search.grouping.result.Group) Query(com.yahoo.search.Query) MinAggregationResult(com.yahoo.searchlib.aggregation.MinAggregationResult) Grouping(com.yahoo.searchlib.aggregation.Grouping) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) MaxAggregationResult(com.yahoo.searchlib.aggregation.MaxAggregationResult) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) IntegerResultNode(com.yahoo.searchlib.expression.IntegerResultNode) GroupList(com.yahoo.search.grouping.result.GroupList) GroupingRequest(com.yahoo.search.grouping.GroupingRequest) StringResultNode(com.yahoo.searchlib.expression.StringResultNode) Test(org.junit.Test)

Example 15 with GroupingListHit

use of com.yahoo.prelude.fastsearch.GroupingListHit in project vespa by vespa-engine.

the class HitConverterTestCase method requireThatHitTagIsCopiedFromGroupingListContext.

@Test
public void requireThatHitTagIsCopiedFromGroupingListContext() {
    QueryPacketData ctxTag = new QueryPacketData();
    GroupingListHit ctxHit = new GroupingListHit(null, null);
    ctxHit.setQueryPacketData(ctxTag);
    HitConverter converter = new HitConverter(new MySearcher(), new Query());
    Hit hit = converter.toSearchHit("default", new FS4Hit(1, createGlobalId(2), 3).setContext(ctxHit));
    assertNotNull(hit);
    assertTrue(hit instanceof FastHit);
    assertSame(ctxTag, ((FastHit) hit).getQueryPacketData());
}
Also used : FS4Hit(com.yahoo.searchlib.aggregation.FS4Hit) FS4Hit(com.yahoo.searchlib.aggregation.FS4Hit) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) VdsHit(com.yahoo.searchlib.aggregation.VdsHit) FastHit(com.yahoo.prelude.fastsearch.FastHit) Query(com.yahoo.search.Query) QueryPacketData(com.yahoo.fs4.QueryPacketData) GroupingListHit(com.yahoo.prelude.fastsearch.GroupingListHit) Test(org.junit.Test)

Aggregations

GroupingListHit (com.yahoo.prelude.fastsearch.GroupingListHit)15 Query (com.yahoo.search.Query)11 Grouping (com.yahoo.searchlib.aggregation.Grouping)11 Test (org.junit.Test)11 FastHit (com.yahoo.prelude.fastsearch.FastHit)9 GroupingRequest (com.yahoo.search.grouping.GroupingRequest)9 Group (com.yahoo.search.grouping.result.Group)9 StringResultNode (com.yahoo.searchlib.expression.StringResultNode)9 Hit (com.yahoo.search.result.Hit)8 Execution (com.yahoo.search.searchchain.Execution)8 HitsAggregationResult (com.yahoo.searchlib.aggregation.HitsAggregationResult)7 MaxAggregationResult (com.yahoo.searchlib.aggregation.MaxAggregationResult)7 Result (com.yahoo.search.Result)6 MinAggregationResult (com.yahoo.searchlib.aggregation.MinAggregationResult)6 CountAggregationResult (com.yahoo.searchlib.aggregation.CountAggregationResult)5 GroupList (com.yahoo.search.grouping.result.GroupList)4 FS4Hit (com.yahoo.searchlib.aggregation.FS4Hit)3 VdsHit (com.yahoo.searchlib.aggregation.VdsHit)3 DocumentId (com.yahoo.document.DocumentId)2 GlobalId (com.yahoo.document.GlobalId)2