use of com.yahoo.search.result.HitGroup in project vespa by vespa-engine.
the class TwoSectionsFourSourcesTestCase method testExecutionMissingAllSources.
@Test
public void testExecutionMissingAllSources() {
// Create the page template
Choice page = Choice.createSingleton(importPage("TwoSectionsFourSources.xml"));
// Create a federated result
Query query = new Query();
Result result = new Result(query);
new Organizer().organize(page, new DeterministicResolver().resolve(page, query, result), result);
// Check execution:
// Two subsections with two sources each, the first grouped the second blended
assertEquals(2, result.hits().size());
HitGroup section1 = (HitGroup) result.hits().get(0);
HitGroup section2 = (HitGroup) result.hits().get(1);
assertEquals(0, section1.size());
assertEquals(0, section2.size());
}
use of com.yahoo.search.result.HitGroup in project vespa by vespa-engine.
the class TwoSectionsFourSourcesTestCase method testExecutionMissingOneSource.
@Test
public void testExecutionMissingOneSource() {
// Create the page template
Choice page = Choice.createSingleton(importPage("TwoSectionsFourSources.xml"));
// Create a federated result
Query query = new Query();
Result result = new Result(query);
result.hits().add(createHits("source1", 3));
result.hits().add(createHits("source3", 12));
result.hits().add(createHits("source4", 13));
new Organizer().organize(page, new DeterministicResolver().resolve(page, query, result), result);
// Check execution:
// Two subsections with two sources each, the first grouped the second blended
assertEquals(2, result.hits().size());
HitGroup section1 = (HitGroup) result.hits().get(0);
HitGroup section2 = (HitGroup) result.hits().get(1);
assertGroupedSource3Source1(section1.asList());
assertEqualHitGroups(createHits("source4", 10), section2);
}
use of com.yahoo.search.result.HitGroup in project vespa by vespa-engine.
the class TwoSectionsFourSourcesTestCase method testExecution.
@Test
public void testExecution() {
// Create the page template
Choice page = Choice.createSingleton(importPage("TwoSectionsFourSources.xml"));
// Create a federated result
Query query = new Query();
Result result = new Result(query);
result.hits().add(createHits("source1", 3));
result.hits().add(createHits("source2", 4));
result.hits().add(createHits("source3", 12));
result.hits().add(createHits("source4", 13));
new Organizer().organize(page, new DeterministicResolver().resolve(page, query, result), result);
// Check execution:
// Two subsections with two sources each, the first grouped the second blended
assertEquals(2, result.hits().size());
HitGroup section1 = (HitGroup) result.hits().get(0);
HitGroup section2 = (HitGroup) result.hits().get(1);
assertGroupedSource3Source1(section1.asList());
assertBlendedSource4Source2(section2.asList());
// Check rendering
assertRendered(result, "TwoSectionsFourSourcesResult.xml");
}
use of com.yahoo.search.result.HitGroup in project vespa by vespa-engine.
the class GroupedResultTestCase method testGroupedResult.
public void testGroupedResult() {
Result result = new Result(new Query("?query=foo"));
HitGroup hitGroup1 = new HitGroup("group1", 300);
hitGroup1.add(new Hit("group1.1", 200));
HitGroup hitGroup2 = new HitGroup("group2", 600);
Hit topLevelHit1 = new Hit("toplevel.1", 500);
Hit topLevelHit2 = new Hit("toplevel.2", 700);
result.hits().add(hitGroup1);
result.hits().add(topLevelHit1);
result.hits().add(hitGroup2);
result.hits().add(topLevelHit2);
hitGroup1.add(new Hit("group1.2", 800));
hitGroup2.add(new Hit("group2.1", 800));
hitGroup2.add(new Hit("group2.2", 300));
hitGroup2.add(new Hit("group2.3", 500));
// Should have 7 concrete hits, ordered as
// toplevel.2
// group2
// group2.1
// group2.3
// group2.2
// toplevel.1
// group1
// group1.2
// group1.1
// Assert this:
assertEquals(7, result.getConcreteHitCount());
assertEquals(4, result.getHitCount());
Hit topLevel2 = result.hits().get(0);
assertEquals("toplevel.2", topLevel2.getId().stringValue());
HitGroup returnedGroup2 = (HitGroup) result.hits().get(1);
assertEquals(3, returnedGroup2.getConcreteSize());
assertEquals(3, returnedGroup2.size());
assertEquals("group2.1", returnedGroup2.get(0).getId().stringValue());
assertEquals("group2.3", returnedGroup2.get(1).getId().stringValue());
assertEquals("group2.2", returnedGroup2.get(2).getId().stringValue());
Hit topLevel1 = result.hits().get(2);
assertEquals("toplevel.1", topLevel1.getId().stringValue());
HitGroup returnedGroup1 = (HitGroup) result.hits().get(3);
assertEquals(2, returnedGroup1.getConcreteSize());
assertEquals(2, returnedGroup1.size());
assertEquals("group1.2", returnedGroup1.get(0).getId().stringValue());
assertEquals("group1.1", returnedGroup1.get(1).getId().stringValue());
}
use of com.yahoo.search.result.HitGroup in project vespa by vespa-engine.
the class FieldCollapsingSearcherTestCase method testFieldCollapsingWithGrouping.
@Test
public void testFieldCollapsingWithGrouping() {
// Set up
FieldCollapsingSearcher collapse = new FieldCollapsingSearcher("other");
DocumentSourceSearcher docsource = new DocumentSourceSearcher();
Chain<Searcher> chain = new Chain<>(collapse, new AddAggregationStyleGroupingResultSearcher(), docsource);
// Caveat: Collapse is set to false, because that's what the
// collapser asks for
Query q = new Query("?query=test_collapse&collapsefield=amid");
// The searcher turns off collapsing further on in the chain
q.properties().set("collapse", "0");
Result r = new Result(q);
r.hits().add(createHit("http://acme.org/a.html", 10, 0));
r.hits().add(createHit("http://acme.org/b.html", 9, 0));
r.hits().add(createHit("http://acme.org/c.html", 9, 1));
r.hits().add(createHit("http://acme.org/d.html", 8, 1));
r.hits().add(createHit("http://acme.org/e.html", 8, 2));
r.hits().add(createHit("http://acme.org/f.html", 7, 2));
r.hits().add(createHit("http://acme.org/g.html", 7, 3));
r.hits().add(createHit("http://acme.org/h.html", 6, 3));
r.setTotalHitCount(8);
docsource.addResult(q, r);
// Test basic collapsing on mid
Query query = new Query("?query=test_collapse&collapsefield=amid");
Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
// Assert that the regular hits are collapsed
assertEquals(4 + 1, result.getHitCount());
assertEquals(1, docsource.getQueryCount());
assertHit("http://acme.org/a.html", 10, 0, result.hits().get(0));
assertHit("http://acme.org/c.html", 9, 1, result.hits().get(1));
assertHit("http://acme.org/e.html", 8, 2, result.hits().get(2));
assertHit("http://acme.org/g.html", 7, 3, result.hits().get(3));
// Assert that the aggregation group hierarchy is left intact
HitGroup root = getFirstGroupIn(result.hits());
assertNotNull(root);
// The id ends by a global counter currently
assertEquals("group:root:", root.getId().stringValue().substring(0, 11));
assertEquals(1, root.size());
HitGroup groupList = (GroupList) root.get("grouplist:g1");
assertNotNull(groupList);
assertEquals(1, groupList.size());
HitGroup group = (HitGroup) groupList.get("group:long:37");
assertNotNull(group);
}
Aggregations