use of com.yahoo.search.result.HitGroup in project vespa by vespa-engine.
the class MockSearcher method search.
@Override
public Result search(Query query, Execution execution) {
HitGroup hits = new HitGroup();
hits.add(new Hit("foo", query));
return new Result(query, hits);
}
use of com.yahoo.search.result.HitGroup in project vespa by vespa-engine.
the class BlendingSearcher method blendResults.
/**
* Produce a single blended result list from a group of hitgroups.
*
* It is assumed that the results are ordered in hitgroups. If not, the blend will not be performed
*/
protected Result blendResults(Result result, Query q, int offset, int hits, Execution execution) {
// Assert that there are more than one hitgroup and that there are only hitgroups on the lowest level
boolean foundNonGroup = false;
Iterator<Hit> hitIterator = result.hits().iterator();
List<HitGroup> groups = new ArrayList<>();
while (hitIterator.hasNext()) {
Hit hit = hitIterator.next();
if (hit instanceof HitGroup) {
groups.add((HitGroup) hit);
hitIterator.remove();
} else if (!hit.isMeta()) {
foundNonGroup = true;
}
}
if (foundNonGroup) {
result.hits().addError(ErrorMessage.createUnspecifiedError("Blendingsearcher could not blend - there are toplevel hits" + " that are not hitgroups"));
return result;
}
if (groups.size() == 0) {
return result;
} else if (groups.size() == 1) {
result.hits().addAll(groups.get(0).asUnorderedHits());
result.hits().setOrderer(groups.get(0).getOrderer());
return result;
} else {
if (documentId != null) {
return blendResultsUniquely(result, q, offset, hits, groups, execution);
} else {
return blendResultsDirectly(result, q, offset, hits, groups, execution);
}
}
}
use of com.yahoo.search.result.HitGroup in project vespa by vespa-engine.
the class ResultBuilder method startHitGroup.
private void startHitGroup(Attributes attrs) {
HitGroup g = new HitGroup();
Set<String> types = g.types();
final String source;
if (attrs != null) {
String groupType = attrs.getValue("type");
if (groupType != null) {
for (String s : groupType.split(" ")) {
if (s.length() > 0) {
types.add(s);
}
}
}
source = attrs.getValue("source");
} else {
source = null;
}
g.setId((source != null) ? source : "dummy");
hitGroups.peekFirst().add(g);
hitGroups.addFirst(g);
location.addFirst(ResultPart.HITGROUP);
}
use of com.yahoo.search.result.HitGroup in project vespa by vespa-engine.
the class ChoiceOfSubsectionsTestCase method testExecution.
@Test
public void testExecution() {
// Create the page template
Choice page = Choice.createSingleton(importPage("ChoiceOfSubsections.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", 3));
result.hits().add(createHits("source3", 3));
result.hits().add(createHits("source4", 3));
new Organizer().organize(page, new DeterministicResolverAssertingMethod().resolve(page, query, result), result);
// Check execution:
// Two subsections with one source each
assertEquals(2, result.hits().size());
HitGroup section1 = (HitGroup) result.hits().get(0);
HitGroup section2 = (HitGroup) result.hits().get(1);
assertEqualHitGroups(createHits("source2", 3), section1);
assertEqualHitGroups(createHits("source4", 3), section2);
// Check rendering
assertRendered(result, "ChoiceOfSubsectionsResult.xml");
}
use of com.yahoo.search.result.HitGroup in project vespa by vespa-engine.
the class TwoSectionsFourSourcesTestCase method testExecutionMissingTwoSources.
@Test
public void testExecutionMissingTwoSources() {
// 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));
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());
assertEquals(0, section2.size());
}
Aggregations