use of com.yahoo.search.Result in project vespa by vespa-engine.
the class BlendingSearcherTestCase method testOnlyFirstBackend.
@Test
public void testOnlyFirstBackend() {
BlendingSearcherWrapper searcher = setupFirstAndSecond();
Query query = new Query("/search?query=banana&search=first");
Result result = new Execution(searcher, Execution.Context.createContextStub()).search(query);
assertEquals(1, result.getHitCount());
assertEquals(200.0, result.hits().get(0).getRelevance().getScore(), delta);
}
use of com.yahoo.search.Result in project vespa by vespa-engine.
the class BlendingSearcherTestCase method testExistingAndNonExistingBackendCausesBothErrorAndResult.
@Test
public void testExistingAndNonExistingBackendCausesBothErrorAndResult() {
BlendingSearcherWrapper searcher = setupFirstAndSecond();
Query query = new Query("/search?query=banana&search=first,nonesuch,second");
Result result = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())).search(query);
assertEquals(3, result.getConcreteHitCount());
assertEquals(300.0, result.hits().get(1).getRelevance().getScore(), delta);
assertEquals(200.0, result.hits().get(2).getRelevance().getScore(), delta);
assertEquals(100.0, result.hits().get(3).getRelevance().getScore(), delta);
assertNotNull(result.hits().getError());
ErrorMessage e = result.hits().getError();
// TODO: Do not depend on sources order
assertEquals("Could not resolve source ref 'nonesuch'. Valid source refs are first, second.", e.getDetailedMessage());
}
use of com.yahoo.search.Result in project vespa by vespa-engine.
the class BlendingSearcherTestCase method testOnlySecondBackend.
@Test
public void testOnlySecondBackend() {
BlendingSearcherWrapper searcher = setupFirstAndSecond();
Query query = new Query("/search?query=banana&search=second");
Result result = new Execution(searcher, Execution.Context.createContextStub()).search(query);
assertEquals(2, result.getHitCount());
assertEquals(300.0, result.hits().get(0).getRelevance().getScore(), delta);
assertEquals(100.0, result.hits().get(1).getRelevance().getScore(), delta);
}
use of com.yahoo.search.Result in project vespa by vespa-engine.
the class BlendingSearcherTestCase method testNonexistingBackendCausesError.
@Test
public void testNonexistingBackendCausesError() {
BlendingSearcherWrapper searcher = setupFirstAndSecond();
Query query = new Query("/search?query=banana&search=nonesuch");
Result result = new Execution(searcher, Execution.Context.createContextStub(new IndexFacts())).search(query);
assertEquals(0, result.getConcreteHitCount());
assertNotNull(result.hits().getError());
ErrorMessage e = result.hits().getError();
assertEquals("Invalid query parameter", e.getMessage());
// assertEquals("No source named 'nonesuch' to search. Valid sources are [first, second]",
// e.getDetailedMessage());
}
use of com.yahoo.search.Result in project vespa by vespa-engine.
the class BlendingSearcherTestCase method setupFirstAndSecond.
private BlendingSearcherWrapper setupFirstAndSecond() {
DocumentSourceSearcher first = new DocumentSourceSearcher();
DocumentSourceSearcher second = new DocumentSourceSearcher();
Query query = new Query("?query=banana");
Result r1 = new Result(query);
r1.setTotalHitCount(1);
Hit r1h1 = new Hit("http://first/relevancy100", 200);
r1.hits().add(r1h1);
first.addResultSet(query, r1);
Result r2 = new Result(query);
r2.setTotalHitCount(2);
Hit r2h1 = new Hit("http://second/relevancy300", 300);
Hit r2h2 = new Hit("http://second/relevancy100", 100);
r2.hits().add(r2h1);
r2.hits().add(r2h2);
second.addResultSet(query, r2);
BlendingSearcherWrapper blender = new BlendingSearcherWrapper();
blender.addChained(new FillSearcher(first), "first");
blender.addChained(new FillSearcher(second), "second");
blender.initialize();
return blender;
}
Aggregations