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());
}
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")));
}
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));
}
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());
}
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()));
}
Aggregations