Search in sources :

Example 1 with HitGroup

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);
}
Also used : Hit(com.yahoo.search.result.Hit) HitGroup(com.yahoo.search.result.HitGroup) Result(com.yahoo.search.Result)

Example 2 with HitGroup

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);
        }
    }
}
Also used : Hit(com.yahoo.search.result.Hit) HitGroup(com.yahoo.search.result.HitGroup)

Example 3 with HitGroup

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);
}
Also used : XMLString(com.yahoo.prelude.hitfield.XMLString) HitGroup(com.yahoo.search.result.HitGroup)

Example 4 with 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");
}
Also used : Choice(com.yahoo.search.pagetemplates.model.Choice) Query(com.yahoo.search.Query) Organizer(com.yahoo.search.pagetemplates.engine.Organizer) Result(com.yahoo.search.Result) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 5 with HitGroup

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());
}
Also used : Choice(com.yahoo.search.pagetemplates.model.Choice) Query(com.yahoo.search.Query) Organizer(com.yahoo.search.pagetemplates.engine.Organizer) DeterministicResolver(com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver) Result(com.yahoo.search.Result) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Aggregations

HitGroup (com.yahoo.search.result.HitGroup)48 Test (org.junit.Test)28 Result (com.yahoo.search.Result)27 Query (com.yahoo.search.Query)24 Hit (com.yahoo.search.result.Hit)21 Execution (com.yahoo.search.searchchain.Execution)11 Searcher (com.yahoo.search.Searcher)8 Organizer (com.yahoo.search.pagetemplates.engine.Organizer)8 Choice (com.yahoo.search.pagetemplates.model.Choice)8 DeterministicResolver (com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver)7 DefaultErrorHit (com.yahoo.search.result.DefaultErrorHit)6 Chain (com.yahoo.component.chain.Chain)5 ErrorHit (com.yahoo.search.result.ErrorHit)4 ComponentId (com.yahoo.component.ComponentId)3 FastHit (com.yahoo.prelude.fastsearch.FastHit)3 FederationSearcher (com.yahoo.search.federation.FederationSearcher)3 Resolution (com.yahoo.search.pagetemplates.engine.Resolution)3 Resolver (com.yahoo.search.pagetemplates.engine.Resolver)3 Coverage (com.yahoo.search.result.Coverage)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3