Search in sources :

Example 31 with HitGroup

use of com.yahoo.search.result.HitGroup in project vespa by vespa-engine.

the class FederationSearcherTestCase method testNoCloning.

@Test
public void testNoCloning() {
    String sourceName = "cloningcheck";
    Query query = new Query(QueryTestCase.httpEncode("?query=test&sources=" + sourceName));
    addChained(new QueryCheckSearcher(query), sourceName);
    addChained(new MockSearcher(), "mySource1");
    Chain<Searcher> mainChain = new Chain<>("default", createStrictFederationSearcher());
    Result result = new Execution(mainChain, Execution.Context.createContextStub(chainRegistry, null)).search(query);
    HitGroup h = (HitGroup) result.hits().get(0);
    assertNull(h.getErrorHit());
    assertSame(QueryCheckSearcher.OK, h.get(0).getField(QueryCheckSearcher.STATUS));
    mainChain = new Chain<>("default", createFederationSearcher());
    result = new Execution(mainChain, Execution.Context.createContextStub(chainRegistry, null)).search(query);
    h = (HitGroup) result.hits().get(0);
    assertSame(QueryCheckSearcher.FEDERATION_SEARCHER_HAS_CLONED_THE_QUERY, h.getError().getDetailedMessage());
    query = new Query(QueryTestCase.httpEncode("?query=test&sources=" + sourceName + ",mySource1"));
    addChained(new QueryCheckSearcher(query), sourceName);
    result = new Execution(mainChain, Execution.Context.createContextStub(chainRegistry, null)).search(query);
    h = (HitGroup) result.hits().get(0);
    assertEquals("source:" + sourceName, h.getId().stringValue());
    assertSame(QueryCheckSearcher.FEDERATION_SEARCHER_HAS_CLONED_THE_QUERY, h.getError().getDetailedMessage());
    assertEquals("source:mySource1", result.hits().get(1).getId().stringValue());
}
Also used : Chain(com.yahoo.component.chain.Chain) SearchChain(com.yahoo.search.searchchain.SearchChain) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) FederationSearcher(com.yahoo.search.federation.FederationSearcher) Result(com.yahoo.search.Result) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 32 with HitGroup

use of com.yahoo.search.result.HitGroup in project vespa by vespa-engine.

the class FederationSearcherTest method custom_federation_target.

@Test
public void custom_federation_target() {
    ComponentId targetSelectorId = ComponentId.fromString("TargetSelector");
    ComponentRegistry<TargetSelector> targetSelectors = new ComponentRegistry<>();
    targetSelectors.register(targetSelectorId, new TestTargetSelector());
    FederationSearcher searcher = new FederationSearcher(new FederationConfig(new FederationConfig.Builder().targetSelector(targetSelectorId.toString())), new StrictContractsConfig(new StrictContractsConfig.Builder()), targetSelectors);
    Result result = new Execution(searcher, Context.createContextStub()).search(new Query());
    HitGroup myChainGroup = (HitGroup) result.hits().get(0);
    assertThat(myChainGroup.getId(), is(new URI("source:myChain")));
    assertThat(myChainGroup.get(0).getId(), is(new URI("myHit")));
}
Also used : FederationSearcher(com.yahoo.search.federation.FederationSearcher) Query(com.yahoo.search.Query) URI(com.yahoo.net.URI) Result(com.yahoo.search.Result) StrictContractsConfig(com.yahoo.search.federation.StrictContractsConfig) Execution(com.yahoo.search.searchchain.Execution) ComponentRegistry(com.yahoo.component.provider.ComponentRegistry) TargetSelector(com.yahoo.search.federation.selection.TargetSelector) ComponentId(com.yahoo.component.ComponentId) FederationConfig(com.yahoo.search.federation.FederationConfig) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 33 with HitGroup

use of com.yahoo.search.result.HitGroup in project vespa by vespa-engine.

the class HitGroupTestCase method testRecursiveGet.

@Test
public void testRecursiveGet() {
    // Level 1
    HitGroup g1 = new HitGroup();
    g1.add(new Hit("1"));
    // Level 2
    HitGroup g1_1 = new HitGroup();
    g1_1.add(new Hit("1.1"));
    g1.add(g1_1);
    HitGroup g1_2 = new HitGroup();
    g1_2.add(new Hit("1.2"));
    g1.add(g1_2);
    // Level 3
    HitGroup g1_1_1 = new HitGroup();
    g1_1_1.add(new Hit("1.1.1"));
    g1_1.add(g1_1_1);
    HitGroup g1_1_2 = new HitGroup();
    g1_1_2.add(new Hit("1.1.2"));
    g1_1.add(g1_1_2);
    HitGroup g1_2_1 = new HitGroup();
    g1_2_1.add(new Hit("1.2.1"));
    g1_2.add(g1_2_1);
    HitGroup g1_2_2 = new HitGroup();
    g1_2_2.add(new Hit("1.2.2"));
    g1_2.add(g1_2_2);
    // Level 4
    HitGroup g1_1_1_1 = new HitGroup();
    g1_1_1_1.add(new Hit("1.1.1.1"));
    g1_1_1.add(g1_1_1_1);
    assertNotNull(g1.get("1"));
    assertNotNull(g1.get("1.1"));
    assertNotNull(g1.get("1.2"));
    assertNotNull(g1.get("1.1.1"));
    assertNotNull(g1.get("1.1.2"));
    assertNotNull(g1.get("1.2.1"));
    assertNotNull(g1.get("1.2.2"));
    assertNotNull(g1.get("1.1.1.1"));
    assertNotNull(g1.get("1", -1));
    assertNotNull(g1.get("1.1", -1));
    assertNotNull(g1.get("1.2", -1));
    assertNotNull(g1.get("1.1.1", -1));
    assertNotNull(g1.get("1.1.2", -1));
    assertNotNull(g1.get("1.2.1", -1));
    assertNotNull(g1.get("1.2.2", -1));
    assertNotNull(g1.get("1.1.1.1", -1));
    assertNotNull(g1.get("1", 0));
    assertNull(g1.get("1.1", 0));
    assertNull(g1.get("1.2", 0));
    assertNull(g1.get("1.1.1", 0));
    assertNull(g1.get("1.1.2", 0));
    assertNull(g1.get("1.2.1", 0));
    assertNull(g1.get("1.2.2", 0));
    assertNull(g1.get("1.1.1.1", 0));
    assertNotNull(g1.get("1", 1));
    assertNotNull(g1.get("1.1", 1));
    assertNotNull(g1.get("1.2", 1));
    assertNull(g1.get("1.1.1", 1));
    assertNull(g1.get("1.1.2", 1));
    assertNull(g1.get("1.2.1", 1));
    assertNull(g1.get("1.2.2", 1));
    assertNull(g1.get("1.1.1.1", 1));
    assertNotNull(g1.get("1", 2));
    assertNotNull(g1.get("1.1", 2));
    assertNotNull(g1.get("1.2", 2));
    assertNotNull(g1.get("1.1.1", 2));
    assertNotNull(g1.get("1.1.2", 2));
    assertNotNull(g1.get("1.2.1", 2));
    assertNotNull(g1.get("1.2.2", 2));
    assertNull(g1.get("1.1.1.1", 2));
    assertNotNull(g1.get("1.1.1.1", 3));
    assertNull(g1.get("3", 2));
}
Also used : DefaultErrorHit(com.yahoo.search.result.DefaultErrorHit) Hit(com.yahoo.search.result.Hit) ErrorHit(com.yahoo.search.result.ErrorHit) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 34 with HitGroup

use of com.yahoo.search.result.HitGroup in project vespa by vespa-engine.

the class HitGroupTestCase method testErrorsConsistencyUsingErrorOperations.

@Test
public void testErrorsConsistencyUsingErrorOperations() {
    HitGroup hits = new HitGroup();
    Query query = new Query();
    query.errors().add(ErrorMessage.createIllegalQuery("test1"));
    query.errors().add(ErrorMessage.createTimeout("test2"));
    hits.setQuery(query);
    hits.addError(ErrorMessage.createForbidden("test3"));
    hits.addError(ErrorMessage.createUnspecifiedError("test4"));
    assertEquals(4, hits.getErrorHit().errors().size());
    assertEquals(0, query.errors().size());
    assertEquals(Optional.of(hits.getErrorHit()), errorHitIn(hits.asList()));
    DefaultErrorHit removedErrors = hits.removeErrorHit();
    assertNotNull(removedErrors);
    assertEquals(4, removedErrors.errors().size());
    assertNull(hits.get(removedErrors.getId().toString()));
    assertFalse(errorHitIn(hits.asList()).isPresent());
    assertNull(hits.removeErrorHit());
}
Also used : Query(com.yahoo.search.Query) DefaultErrorHit(com.yahoo.search.result.DefaultErrorHit) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 35 with HitGroup

use of com.yahoo.search.result.HitGroup in project vespa by vespa-engine.

the class HitGroupTestCase method testErrorsConsistencyUsingHitOperations.

@Test
public void testErrorsConsistencyUsingHitOperations() {
    HitGroup hits = new HitGroup();
    Query query = new Query();
    query.errors().add(ErrorMessage.createIllegalQuery("test1"));
    query.errors().add(ErrorMessage.createTimeout("test2"));
    hits.setQuery(query);
    DefaultErrorHit errors = new DefaultErrorHit("source", ErrorMessage.createForbidden("test3"));
    errors.addError(ErrorMessage.createUnspecifiedError("test4"));
    hits.add(errors);
    assertEquals(4, hits.getErrorHit().errors().size());
    assertEquals(0, query.errors().size());
    assertEquals(Optional.of(hits.getErrorHit()), errorHitIn(hits.asList()));
    DefaultErrorHit removedErrors = (DefaultErrorHit) hits.remove(errors.getId());
    assertNotNull(removedErrors);
    assertEquals(4, removedErrors.errors().size());
    assertNull(hits.get(removedErrors.getId().toString()));
    assertFalse(errorHitIn(hits.asList()).isPresent());
    assertNull(hits.remove(errors.getId()));
}
Also used : Query(com.yahoo.search.Query) DefaultErrorHit(com.yahoo.search.result.DefaultErrorHit) 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