Search in sources :

Example 71 with Result

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);
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 72 with Result

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());
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) IndexFacts(com.yahoo.prelude.IndexFacts) ErrorMessage(com.yahoo.search.result.ErrorMessage) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 73 with Result

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);
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 74 with Result

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());
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) IndexFacts(com.yahoo.prelude.IndexFacts) ErrorMessage(com.yahoo.search.result.ErrorMessage) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 75 with Result

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;
}
Also used : FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) Query(com.yahoo.search.Query) FillSearcher(com.yahoo.prelude.searcher.FillSearcher) DocumentSourceSearcher(com.yahoo.prelude.searcher.DocumentSourceSearcher) Result(com.yahoo.search.Result)

Aggregations

Result (com.yahoo.search.Result)398 Test (org.junit.Test)231 Query (com.yahoo.search.Query)229 Execution (com.yahoo.search.searchchain.Execution)127 Searcher (com.yahoo.search.Searcher)94 Hit (com.yahoo.search.result.Hit)72 Chain (com.yahoo.component.chain.Chain)48 FastHit (com.yahoo.prelude.fastsearch.FastHit)36 HitGroup (com.yahoo.search.result.HitGroup)29 JSONString (com.yahoo.prelude.hitfield.JSONString)26 HashMap (java.util.HashMap)21 FeedContext (com.yahoo.feedapi.FeedContext)19 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)19 NullFeedMetric (com.yahoo.feedhandler.NullFeedMetric)19 ClusterList (com.yahoo.vespaclient.ClusterList)19 ErrorMessage (com.yahoo.search.result.ErrorMessage)17 Choice (com.yahoo.search.pagetemplates.model.Choice)16 Organizer (com.yahoo.search.pagetemplates.engine.Organizer)15 DocumentSourceSearcher (com.yahoo.search.searchchain.testutil.DocumentSourceSearcher)15 DeterministicResolver (com.yahoo.search.pagetemplates.engine.resolvers.DeterministicResolver)14