Search in sources :

Example 41 with FastHit

use of com.yahoo.prelude.fastsearch.FastHit in project vespa by vespa-engine.

the class XMLRendererTestCase method testImplicitDefaultRender.

@Test
public final void testImplicitDefaultRender() throws Exception {
    Query q = new Query("/?query=a&tracelevel=5&reportCoverage=true");
    q.getPresentation().setTiming(true);
    Result r = new Result(q);
    r.setCoverage(new Coverage(500, 1, true));
    TimeTracker t = new TimeTracker(new Chain<Searcher>(new UselessSearcher("first"), new UselessSearcher("second"), new UselessSearcher("third")));
    ElapsedTimeTestCase.doInjectTimeSource(t, new CreativeTimeSource(new long[] { 1L, 2L, 3L, 4L, 5L, 6L, 7L }));
    t.sampleSearch(0, true);
    t.sampleSearch(1, true);
    t.sampleSearch(2, true);
    t.sampleSearch(3, true);
    t.sampleSearchReturn(2, true, null);
    t.sampleSearchReturn(1, true, null);
    t.sampleSearchReturn(0, true, null);
    r.getElapsedTime().add(t);
    r.getTemplating().setRenderer(d);
    FastHit h = new FastHit("http://localhost/", .95);
    h.setField("$a", "Hello, world.");
    h.setField("b", "foo");
    r.hits().add(h);
    HitGroup g = new HitGroup("usual");
    h = new FastHit("http://localhost/1", .90);
    h.setField("c", "d");
    g.add(h);
    r.hits().add(g);
    HitGroup gg = new HitGroup("type grouphit");
    gg.types().add("grouphit");
    gg.setField("e", "f");
    r.hits().add(gg);
    r.hits().addError(ErrorMessage.createInternalServerError("boom"));
    ByteArrayOutputStream bs = new ByteArrayOutputStream();
    ListenableFuture<Boolean> f = d.render(bs, r, null, null);
    assertTrue(f.get());
    String summary = Utf8.toString(bs.toByteArray());
    assertEquals("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" + "<result total-hit-count=\"0\"", summary.substring(0, 67));
    assertTrue(summary.contains("<meta type=\"context\">"));
    assertTrue(summary.contains("<error code=\"18\">Internal server error.</error>"));
    assertTrue(summary.contains("<hit type=\"grouphit\" relevancy=\"1.0\">"));
    assertTrue(summary.contains("<hit type=\"summary\" relevancy=\"0.95\">"));
    assertEquals(2, occurrences("<error ", summary));
    assertTrue(summary.length() > 1000);
}
Also used : Query(com.yahoo.search.Query) CreativeTimeSource(com.yahoo.search.statistics.ElapsedTimeTestCase.CreativeTimeSource) Searcher(com.yahoo.search.Searcher) UselessSearcher(com.yahoo.search.statistics.ElapsedTimeTestCase.UselessSearcher) Coverage(com.yahoo.search.result.Coverage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Result(com.yahoo.search.Result) UselessSearcher(com.yahoo.search.statistics.ElapsedTimeTestCase.UselessSearcher) FastHit(com.yahoo.prelude.fastsearch.FastHit) TimeTracker(com.yahoo.search.statistics.TimeTracker) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 42 with FastHit

use of com.yahoo.prelude.fastsearch.FastHit in project vespa by vespa-engine.

the class BlendingSearcherTestCase method testMultipleBackendsWithDuplicateRemoval.

@Test
public void testMultipleBackendsWithDuplicateRemoval() {
    DocumentSourceSearcher chain1 = new DocumentSourceSearcher();
    DocumentSourceSearcher chain2 = new DocumentSourceSearcher();
    Query q = new Query("/search?query=hannibal&search=a,b");
    Result r1 = new Result(q);
    Result r2 = new Result(q);
    r1.setTotalHitCount(1);
    r1.hits().add(new FastHit("http://host1.com/", 101));
    chain1.addResultSet(q, r1);
    r2.hits().add(new FastHit("http://host1.com/", 102));
    r2.setTotalHitCount(1);
    chain2.addResultSet(q, r2);
    BlendingSearcherWrapper blender = new BlendingSearcherWrapper("uri");
    blender.addChained(new FillSearcher(chain1), "a");
    blender.addChained(new FillSearcher(chain2), "b");
    blender.initialize();
    q.setWindow(0, 10);
    Result cr = new Execution(blender, Execution.Context.createContextStub()).search(q);
    assertEquals(1, cr.getHitCount());
    assertEquals(101, ((int) cr.hits().get(0).getRelevance().getScore()));
}
Also used : FastHit(com.yahoo.prelude.fastsearch.FastHit) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) FillSearcher(com.yahoo.prelude.searcher.FillSearcher) DocumentSourceSearcher(com.yahoo.prelude.searcher.DocumentSourceSearcher) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 43 with FastHit

use of com.yahoo.prelude.fastsearch.FastHit in project vespa by vespa-engine.

the class BlendingSearcherTestCase method testMultipleBackendsWithErrorMerging.

@Test
public void testMultipleBackendsWithErrorMerging() {
    DocumentSourceSearcher chain1 = new DocumentSourceSearcher();
    DocumentSourceSearcher chain2 = new DocumentSourceSearcher();
    Query q = new Query("/search?query=hannibal&search=a,b");
    Result r1 = new Result(q, ErrorMessage.createNoBackendsInService(null));
    Result r2 = new Result(q, ErrorMessage.createRequestTooLarge(null));
    r1.setTotalHitCount(0);
    chain1.addResultSet(q, r1);
    r2.hits().add(new FastHit("http://host1.com/", 102));
    r2.setTotalHitCount(1);
    chain2.addResultSet(q, r2);
    BlendingSearcherWrapper blender = new BlendingSearcherWrapper();
    blender.addChained(new FillSearcher(chain1), "a");
    blender.addChained(new FillSearcher(chain2), "b");
    blender.initialize();
    q.setWindow(0, 10);
    Result cr = new Execution(blender, Execution.Context.createContextStub()).search(q);
    assertEquals(2, cr.getHitCount());
    assertEquals(1, cr.getConcreteHitCount());
    com.yahoo.search.result.ErrorHit errorHit = cr.hits().getErrorHit();
    Iterator errorIterator = errorHit.errorIterator();
    List<String> errorList = Arrays.asList("Source 'a': No backends in service. Try later", "Source 'b': 2: Request too large");
    String a = errorIterator.next().toString();
    assertTrue(a, errorList.contains(a));
    String b = errorIterator.next().toString();
    assertTrue(a, errorList.contains(b));
    assertFalse(errorIterator.hasNext());
    assertEquals(102, ((int) cr.hits().get(1).getRelevance().getScore()));
    assertEquals(com.yahoo.container.protect.Error.NO_BACKENDS_IN_SERVICE.code, cr.hits().getError().getCode());
}
Also used : Query(com.yahoo.search.Query) DocumentSourceSearcher(com.yahoo.prelude.searcher.DocumentSourceSearcher) Result(com.yahoo.search.Result) FastHit(com.yahoo.prelude.fastsearch.FastHit) Execution(com.yahoo.search.searchchain.Execution) FillSearcher(com.yahoo.prelude.searcher.FillSearcher) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 44 with FastHit

use of com.yahoo.prelude.fastsearch.FastHit in project vespa by vespa-engine.

the class JSONDebugSearcherTestCase method addResult.

private void addResult(Query q, String content, DocumentSourceSearcher docsource) {
    Result r = new Result(q);
    FastHit hit = new FastHit();
    hit.setId("http://abc.html");
    hit.setRelevance(new Relevance(1));
    hit.setField("jsonfield", new JSONString(content));
    r.hits().add(hit);
    docsource.addResult(q, r);
}
Also used : Relevance(com.yahoo.search.result.Relevance) FastHit(com.yahoo.prelude.fastsearch.FastHit) JSONString(com.yahoo.prelude.hitfield.JSONString) Result(com.yahoo.search.Result)

Example 45 with FastHit

use of com.yahoo.prelude.fastsearch.FastHit in project vespa by vespa-engine.

the class PartialFillTestCase method testMergeErrors.

@Test
public void testMergeErrors() {
    BadFS4 fs4 = new BadFS4();
    Query a = new Query("/?query=foo");
    Query b = new Query("/?query=bar");
    Result r = new Result(new Query("/?query=ignorethis"));
    {
        FastHit h = new FastHit();
        h.setQuery(a);
        h.setFillable();
        r.hits().add(h);
    }
    {
        FastHit h = new FastHit();
        h.setQuery(b);
        h.setFillable();
        r.hits().add(h);
    }
    doFill(fs4, r, "default");
    ErrorHit eh = r.hits().getErrorHit();
    assertNotNull(eh);
    ErrorMessage exp_sub = ErrorMessage.createUnspecifiedError("error");
    int n = 0;
    for (Iterator<? extends com.yahoo.search.result.ErrorMessage> i = eh.errorIterator(); i.hasNext(); ) {
        com.yahoo.search.result.ErrorMessage error = i.next();
        switch(n) {
            case 0:
                assertEquals(exp_sub, error);
                break;
            case 1:
                assertEquals(exp_sub, error);
                break;
            default:
                assertTrue(false);
        }
        n++;
    }
}
Also used : FastHit(com.yahoo.prelude.fastsearch.FastHit) Query(com.yahoo.search.Query) ErrorHit(com.yahoo.search.result.ErrorHit) ErrorMessage(com.yahoo.search.result.ErrorMessage) ErrorMessage(com.yahoo.search.result.ErrorMessage) Result(com.yahoo.search.Result) Test(org.junit.Test)

Aggregations

FastHit (com.yahoo.prelude.fastsearch.FastHit)51 Result (com.yahoo.search.Result)21 Query (com.yahoo.search.Query)20 Test (org.junit.Test)20 Hit (com.yahoo.search.result.Hit)19 GroupingListHit (com.yahoo.prelude.fastsearch.GroupingListHit)9 Relevance (com.yahoo.search.result.Relevance)8 Searcher (com.yahoo.search.Searcher)7 DocumentSourceSearcher (com.yahoo.prelude.searcher.DocumentSourceSearcher)6 Execution (com.yahoo.search.searchchain.Execution)5 FS4Hit (com.yahoo.searchlib.aggregation.FS4Hit)5 VdsHit (com.yahoo.searchlib.aggregation.VdsHit)5 JSONString (com.yahoo.prelude.hitfield.JSONString)4 QuotingSearcher (com.yahoo.prelude.searcher.QuotingSearcher)4 Utf8String (com.yahoo.text.Utf8String)4 HashMap (java.util.HashMap)4 ByteWriter (com.yahoo.io.ByteWriter)3 DocsumDefinitionSet (com.yahoo.prelude.fastsearch.DocsumDefinitionSet)3 Coverage (com.yahoo.search.result.Coverage)3 HitGroup (com.yahoo.search.result.HitGroup)3