use of com.yahoo.searchlib.aggregation.Grouping 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()));
}
}
use of com.yahoo.searchlib.aggregation.Grouping in project vespa by vespa-engine.
the class VespaBackEndSearcher method traceQuery.
static void traceQuery(String sourceName, String type, Query query, int offset, int hits, int level, Optional<String> quotedSummaryClass) {
if ((query.getTraceLevel() < level) || query.properties().getBoolean(TRACE_DISABLE))
return;
StringBuilder s = new StringBuilder();
s.append(sourceName).append(" " + type + " to dispatch: ").append("query=[").append(query.getModel().getQueryTree().getRoot().toString()).append("]");
s.append(" timeout=").append(query.getTimeout()).append("ms");
s.append(" offset=").append(offset).append(" hits=").append(hits);
if (query.getRanking().hasRankProfile()) {
s.append(" rankprofile[").append(query.getRanking().getProfile()).append("]");
}
if (query.getRanking().getFreshness() != null) {
s.append(" freshness=").append(query.getRanking().getFreshness().getRefTime());
}
if (query.getRanking().getSorting() != null) {
s.append(" sortspec=").append(query.getRanking().getSorting().fieldOrders().toString());
}
if (query.getRanking().getLocation() != null) {
s.append(" location=").append(query.getRanking().getLocation().toString());
}
if (query.getGroupingSessionCache()) {
s.append(" groupingSessionCache=true");
}
if (query.getRanking().getQueryCache()) {
s.append(" ranking.queryCache=true");
}
if (query.getGroupingSessionCache() || query.getRanking().getQueryCache()) {
s.append(" sessionId=").append(query.getSessionId(true));
}
List<Grouping> grouping = GroupingExecutor.getGroupingList(query);
s.append(" grouping=").append(grouping.size()).append(" : ");
for (Grouping g : grouping) {
s.append(g.toString());
}
if (!query.getRanking().getProperties().isEmpty()) {
s.append(" rankproperties=").append(query.getRanking().getProperties().toString());
}
if (!query.getRanking().getFeatures().isEmpty()) {
s.append(" rankfeatures=").append(query.getRanking().getFeatures().toString());
}
if (query.getModel().getRestrict() != null) {
s.append(" restrict=").append(query.getModel().getRestrict().toString());
}
if (quotedSummaryClass.isPresent()) {
s.append(" summary=").append(quotedSummaryClass.get());
}
query.trace(s.toString(), false, level);
if (query.isTraceable(level + 1)) {
query.trace("Current state of query tree: " + new TextualQueryRepresentation(query.getModel().getQueryTree().getRoot()), false, level + 1);
}
if (query.isTraceable(level + 2)) {
query.trace("YQL+ representation: " + query.yqlRepresentation(), level + 2);
}
}
use of com.yahoo.searchlib.aggregation.Grouping in project vespa by vespa-engine.
the class GroupingExecutorTestCase method requireThatHitsAreFilledWithCorrectSummary.
@Test
public void requireThatHitsAreFilledWithCorrectSummary() {
Query query = newQuery();
GroupingRequest req = GroupingRequest.newInstance(query);
req.setRootOperation(GroupingOperation.fromString("all(group(foo) each(each(output(summary(bar))) as(bar) " + " each(output(summary(baz))) as(baz)))"));
Grouping pass0A = new Grouping(0);
pass0A.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("foo")).addAggregationResult(new HitsAggregationResult(1, "bar"))));
Grouping pass0B = new Grouping(1);
pass0B.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("foo")).addAggregationResult(new HitsAggregationResult(1, "baz"))));
GlobalId gid1 = new GlobalId((new DocumentId("doc:test:1")).getGlobalId());
GlobalId gid2 = new GlobalId((new DocumentId("doc:test:2")).getGlobalId());
Grouping pass1A = new Grouping(0);
pass1A.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(1, gid1, 3)))));
Grouping pass1B = new Grouping(1);
pass1B.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("foo")).addAggregationResult(new HitsAggregationResult(1, "baz").addHit(new com.yahoo.searchlib.aggregation.FS4Hit(4, gid2, 6)))));
SummaryMapper sm = new SummaryMapper();
Execution exec = newExecution(new GroupingExecutor(), new ResultProvider(Arrays.asList(new GroupingListHit(Arrays.asList(pass0A, pass0B), null), new GroupingListHit(Arrays.asList(pass1A, pass1B), null))), sm);
exec.fill(exec.search(query), "default");
assertEquals(2, sm.hitsBySummary.size());
List<Hit> lst = sm.hitsBySummary.get("bar");
assertNotNull(lst);
assertEquals(1, lst.size());
Hit hit = lst.get(0);
assertTrue(hit instanceof FastHit);
assertEquals(1, ((FastHit) hit).getPartId());
assertEquals(gid1, ((FastHit) hit).getGlobalId());
assertNotNull(lst = sm.hitsBySummary.get("baz"));
assertNotNull(lst);
assertEquals(1, lst.size());
hit = lst.get(0);
assertTrue(hit instanceof FastHit);
assertEquals(4, ((FastHit) hit).getPartId());
assertEquals(gid2, ((FastHit) hit).getGlobalId());
}
use of com.yahoo.searchlib.aggregation.Grouping in project vespa by vespa-engine.
the class GroupingExecutorTestCase method requireThatHitsAreAttachedToCorrectQuery.
@Test
public void requireThatHitsAreAttachedToCorrectQuery() {
Query queryA = newQuery();
GroupingRequest req = GroupingRequest.newInstance(queryA);
req.setRootOperation(GroupingOperation.fromString("all(group(foo) each(each(output(summary(bar)))))"));
Grouping grp = new Grouping(0);
grp.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("foo")).addAggregationResult(new HitsAggregationResult(1, "bar"))));
GroupingListHit pass0 = new GroupingListHit(Arrays.asList(grp), null);
GlobalId gid = new GlobalId((new DocumentId("doc:test:1")).getGlobalId());
grp = new Grouping(0);
grp.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(4, gid, 6)))));
GroupingListHit pass1 = new GroupingListHit(Arrays.asList(grp), null);
Query queryB = newQuery();
/**
* required by {@link GroupingListHit#getSearchQuery()}
*/
pass1.setQuery(queryB);
QueryMapper qm = new QueryMapper();
Execution exec = newExecution(new GroupingExecutor(), new ResultProvider(Arrays.asList(pass0, pass1)), qm);
exec.fill(exec.search(queryA));
assertEquals(1, qm.hitsByQuery.size());
assertTrue(qm.hitsByQuery.containsKey(queryB));
}
use of com.yahoo.searchlib.aggregation.Grouping in project vespa by vespa-engine.
the class GroupingExecutorTestCase method requireThatHitsAreFilled.
@Test
public void requireThatHitsAreFilled() {
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 FillRequestThrower());
Result res = exec.search(query);
// Fill with summary specified in grouping
try {
exec.fill(res);
fail();
} catch (FillRequestException e) {
assertEquals("bar", e.summaryClass);
}
// Fill again, with another summary
try {
exec.fill(res, "otherSummary");
fail();
} catch (FillRequestException e) {
assertEquals("otherSummary", e.summaryClass);
}
}
Aggregations