use of com.yahoo.prelude.fastsearch.GroupingListHit in project vespa by vespa-engine.
the class GroupingExecutorTestCase method requireThatUnexpectedGroupingResultsAreIgnored.
@Test
public void requireThatUnexpectedGroupingResultsAreIgnored() {
Query query = newQuery();
GroupingRequest req = GroupingRequest.newInstance(query);
req.setRootOperation(GroupingOperation.fromString("all(group(foo) each(output(max(bar))))"));
Grouping grpExpected = new Grouping(0);
grpExpected.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("expected")).addAggregationResult(new MaxAggregationResult().setMax(new IntegerResultNode(69)).setTag(3))));
Grouping grpUnexpected = new Grouping(1);
grpUnexpected.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("unexpected")).addAggregationResult(new MaxAggregationResult().setMax(new IntegerResultNode(96)).setTag(3))));
Execution exec = newExecution(new GroupingExecutor(), new ResultProvider(Arrays.asList(new GroupingListHit(Arrays.asList(grpExpected), null), new GroupingListHit(Arrays.asList(grpUnexpected), 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(1, lst.size());
assertNotNull(hit = lst.get("group:string:expected"));
assertEquals(69L, hit.getField("max(bar)"));
assertNull(lst.get("group:string:unexpected"));
}
use of com.yahoo.prelude.fastsearch.GroupingListHit in project vespa by vespa-engine.
the class GroupingExecutorTestCase method requireThatGroupRelevanceCanBeSynthesized.
@Test
public void requireThatGroupRelevanceCanBeSynthesized() {
Query query = newQuery();
GroupingRequest req = GroupingRequest.newInstance(query);
req.setRootOperation(GroupingOperation.fromString("all(group(foo) order(count()) each(output(count())))"));
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 CountAggregationResult(1)).addOrderBy(new AggregationRefNode(0), true)).addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("bar")).addAggregationResult(new CountAggregationResult(2)).addOrderBy(new AggregationRefNode(0), true)));
Result res = newExecution(new GroupingExecutor(), new ResultProvider(Arrays.asList(new GroupingListHit(Arrays.asList(grp), null), new GroupingListHit(Arrays.asList(grp), null)))).search(query);
GroupList groupList = (GroupList) req.getResultGroup(res).get(0);
assertEquals(1.0, groupList.get(0).getRelevance().getScore(), 1E-6);
assertEquals(0.5, groupList.get(1).getRelevance().getScore(), 1E-6);
}
use of com.yahoo.prelude.fastsearch.GroupingListHit in project vespa by vespa-engine.
the class GroupingExecutorTestCase method requireThatDefaultSummaryNameFillsHitsWithNull.
@Test
public void requireThatDefaultSummaryNameFillsHitsWithNull() {
Query query = newQuery();
GroupingRequest req = GroupingRequest.newInstance(query);
req.setRootOperation(GroupingOperation.fromString("all(group(foo) each(each(output(summary()))) as(foo))"));
Grouping pass0 = new Grouping(0);
pass0.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("foo")).addAggregationResult(new HitsAggregationResult(1, ExpressionConverter.DEFAULT_SUMMARY_NAME))));
Grouping pass1 = new Grouping(0);
pass1.setRoot(new com.yahoo.searchlib.aggregation.Group().addChild(new com.yahoo.searchlib.aggregation.Group().setId(new StringResultNode("foo")).addAggregationResult(new HitsAggregationResult(1, ExpressionConverter.DEFAULT_SUMMARY_NAME).addHit(new com.yahoo.searchlib.aggregation.FS4Hit()))));
Execution exec = newExecution(new GroupingExecutor(), new ResultProvider(Arrays.asList(new GroupingListHit(Arrays.asList(pass0), null), new GroupingListHit(Arrays.asList(pass1), null))));
Result res = exec.search(query);
exec.fill(res);
Hit hit = ((HitList) ((Group) ((GroupList) req.getResultGroup(res).get(0)).get(0)).get(0)).get(0);
assertTrue(hit instanceof FastHit);
assertTrue(hit.isFilled(null));
}
use of com.yahoo.prelude.fastsearch.GroupingListHit in project vespa by vespa-engine.
the class GroupingExecutor method mergeGroupingResults.
/**
* Merges the grouping content of the given result object. The first grouping hit found by iterating over the result
* content is kept, and all consecutive matching hits are merged into this.
*
* @param result The result to traverse.
* @return A map of merged grouping objects.
*/
private Map<Integer, Grouping> mergeGroupingResults(Result result) {
Map<Integer, Grouping> ret = new HashMap<>();
for (Iterator<Hit> i = result.hits().unorderedIterator(); i.hasNext(); ) {
Hit hit = i.next();
if (hit instanceof GroupingListHit) {
ContextInjector injector = new ContextInjector(hit);
for (Grouping grp : ((GroupingListHit) hit).getGroupingList()) {
grp.select(injector, injector);
Grouping old = ret.get(grp.getId());
if (old != null) {
old.merge(grp);
} else {
ret.put(grp.getId(), grp);
}
}
i.remove();
}
}
for (Grouping grouping : ret.values()) {
grouping.postMerge();
}
return ret;
}
use of com.yahoo.prelude.fastsearch.GroupingListHit in project vespa by vespa-engine.
the class HitConverter method convertVdsHit.
private Hit convertVdsHit(String summaryClass, VdsHit grpHit) {
FastHit ret = new FastHit();
ret.setRelevance(grpHit.getRank());
if (grpHit.getSummary().getData().length > 0) {
GroupingListHit ctxHit = (GroupingListHit) grpHit.getContext();
if (ctxHit == null) {
throw new NullPointerException("Hit has no context.");
}
DocsumDefinitionSet defs = ctxHit.getDocsumDefinitionSet();
defs.lazyDecode(summaryClass, grpHit.getSummary().getData(), ret);
ret.setFilled(summaryClass);
ret.setFilled(query.getPresentation().getSummary());
}
return ret;
}
Aggregations