Search in sources :

Example 6 with DocumentSourceSearcher

use of com.yahoo.prelude.searcher.DocumentSourceSearcher in project vespa by vespa-engine.

the class BlendingSearcherTestCase method testBlendingWithSortSpecAnd2Phase.

/**
 * Disabled because the document source searcher does not handle being asked for
 * document sumaries for hits it did not create (it will insert the wrong values).
 * But are we sure fsearch handles this case correctly?
 */
@Test
public void testBlendingWithSortSpecAnd2Phase() {
    DocumentSourceSearcher chain1 = new DocumentSourceSearcher();
    DocumentSourceSearcher chain2 = new DocumentSourceSearcher();
    Query q = new Query("/search?query=banana+&sorting=%2Battributefoobar");
    Result r1 = new Result(q);
    Result r2 = new Result(q);
    r1.setTotalHitCount(3);
    Hit r1h1 = new Hit("http://host1.com/relevancy101", 101);
    r1h1.setField("attributefoobar", "3");
    Hit r1h2 = new Hit("http://host2.com/relevancy102", 102);
    r1h2.setField("attributefoobar", "6");
    Hit r1h3 = new Hit("http://host3.com/relevancy103", 103);
    r1h3.setField("attributefoobar", "2");
    r1.hits().add(r1h1);
    r1.hits().add(r1h2);
    r1.hits().add(r1h3);
    chain1.addResultSet(q, r1);
    r2.setTotalHitCount(3);
    Hit r2h1 = new Hit("http://host1.com/relevancy201", 201);
    r2h1.setField("attributefoobar", "5");
    Hit r2h2 = new Hit("http://host2.com/relevancy202", 202);
    r2h2.setField("attributefoobar", "1");
    Hit r2h3 = new Hit("http://host3.com/relevancy203", 203);
    r2h3.setField("attributefoobar", "4");
    r2.hits().add(r2h1);
    r2.hits().add(r2h2);
    r2.hits().add(r2h3);
    chain2.addResultSet(q, r2);
    BlendingSearcherWrapper blender = new BlendingSearcherWrapper();
    blender.addChained(chain1, "chainedone");
    blender.addChained(chain2, "chainedtwo");
    blender.initialize();
    q.setWindow(0, 10);
    Result br = new Execution(blender, Execution.Context.createContextStub()).search(q);
    assertEquals(202, ((int) br.hits().get(0).getRelevance().getScore()));
    assertEquals(103, ((int) br.hits().get(1).getRelevance().getScore()));
    assertEquals(101, ((int) br.hits().get(2).getRelevance().getScore()));
    assertEquals(203, ((int) br.hits().get(3).getRelevance().getScore()));
    assertEquals(201, ((int) br.hits().get(4).getRelevance().getScore()));
    assertEquals(102, ((int) br.hits().get(5).getRelevance().getScore()));
}
Also used : FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) DocumentSourceSearcher(com.yahoo.prelude.searcher.DocumentSourceSearcher) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 7 with DocumentSourceSearcher

use of com.yahoo.prelude.searcher.DocumentSourceSearcher 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 8 with DocumentSourceSearcher

use of com.yahoo.prelude.searcher.DocumentSourceSearcher in project vespa by vespa-engine.

the class BlendingSearcherTestCase method testitTwoPhase.

@Test
public void testitTwoPhase() {
    DocumentSourceSearcher chain1 = new DocumentSourceSearcher();
    DocumentSourceSearcher chain2 = new DocumentSourceSearcher();
    DocumentSourceSearcher chain3 = new DocumentSourceSearcher();
    Query q = new Query("/search?query=hannibal");
    Result r1 = new Result(q);
    Result r2 = new Result(q);
    Result r3 = new Result(q);
    r1.setTotalHitCount(13);
    r1.hits().add(new Hit("http://host1.com", 101) {

        {
            setSource("one");
        }
    });
    r1.hits().add(new Hit("http://host2.com", 102) {

        {
            setSource("one");
        }
    });
    r1.hits().add(new Hit("http://host3.com", 103) {

        {
            setSource("one");
        }
    });
    chain1.addResultSet(q, r1);
    r2.setTotalHitCount(17);
    r2.hits().add(new Hit("http://host1.com", 101) {

        {
            setSource("two");
        }
    });
    r2.hits().add(new Hit("http://host2.com", 102) {

        {
            setSource("two");
        }
    });
    r2.hits().add(new Hit("http://host4.com", 104) {

        {
            setSource("two");
        }
    });
    chain2.addResultSet(q, r2);
    r3.setTotalHitCount(37);
    r3.hits().add(new Hit("http://host5.com", 100) {

        {
            setSource("three");
        }
    });
    r3.hits().add(new Hit("http://host6.com", 106) {

        {
            setSource("three");
        }
    });
    r3.hits().add(new Hit("http://host7.com", 105) {

        {
            setSource("three");
        }
    });
    chain3.addResultSet(q, r3);
    BlendingSearcherWrapper blender1 = new BlendingSearcherWrapper();
    blender1.addChained(chain1, "one");
    blender1.initialize();
    q.setWindow(0, 10);
    Result br1 = new Execution(blender1, Execution.Context.createContextStub()).search(q);
    assertEquals(3, br1.getHitCount());
    assertEquals(13, br1.getTotalHitCount());
    assertEquals("http://host3.com/", br1.hits().get(0).getId().toString());
    BlendingSearcherWrapper blender2 = new BlendingSearcherWrapper();
    blender2.addChained(chain1, "two");
    blender2.addChained(chain2, "three");
    blender2.initialize();
    q.setWindow(0, 10);
    Result br2 = new Execution(blender2, Execution.Context.createContextStub()).search(q);
    assertEquals(6, br2.getHitCount());
    assertEquals(30, br2.getTotalHitCount());
    assertEquals("http://host4.com/", br2.hits().get(0).getId().toString());
    BlendingSearcherWrapper blender3 = new BlendingSearcherWrapper();
    blender3.addChained(chain1, "four");
    blender3.addChained(chain2, "five");
    blender3.addChained(chain3, "six");
    blender3.initialize();
    q.setWindow(0, 10);
    Result br3 = new Execution(blender3, Execution.Context.createContextStub()).search(q);
    assertEquals(9, br3.getHitCount());
    assertEquals(67, br3.getTotalHitCount());
    assertEquals("http://host6.com/", br3.hits().get(0).getId().toString());
    q.setWindow(0, 10);
    Result br4 = new Execution(blender3, Execution.Context.createContextStub()).search(q);
    assertEquals(9, br4.getHitCount());
    assertEquals("http://host6.com/", br4.hits().get(0).getId().toString());
    q.setWindow(3, 10);
    Result br5 = new Execution(blender3, Execution.Context.createContextStub()).search(q);
    assertEquals(6, br5.getHitCount());
    assertEquals("http://host3.com/", br5.hits().get(0).getId().toString());
    q.setWindow(3, 10);
    br5 = new Execution(blender3, Execution.Context.createContextStub()).search(q);
    assertEquals(6, br5.getHitCount());
    assertEquals("http://host3.com/", br5.hits().get(0).getId().toString());
    q.setWindow(3, 10);
    br5 = new Execution(blender3, Execution.Context.createContextStub()).search(q);
    assertEquals(6, br5.getHitCount());
    assertEquals("http://host3.com/", br5.hits().get(0).getId().toString());
}
Also used : FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) DocumentSourceSearcher(com.yahoo.prelude.searcher.DocumentSourceSearcher) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 9 with DocumentSourceSearcher

use of com.yahoo.prelude.searcher.DocumentSourceSearcher in project vespa by vespa-engine.

the class QuotingSearcherTestCase method testFieldQuotingWithNoisyStrings.

public void testFieldQuotingWithNoisyStrings() {
    Map<Searcher, Searcher> chained = new HashMap<>();
    Searcher s = createQuotingSearcher("file:src/test/java/com/yahoo/prelude/" + "searcher/test/testquoting.cfg");
    DocumentSourceSearcher docsource = new DocumentSourceSearcher();
    chained.put(s, docsource);
    Query q = new Query("?query=a");
    Result r = new Result(q);
    Hit hit = new FastHit();
    hit.setId("http://abc.html");
    hit.setRelevance(new Relevance(1));
    hit.setField("title", new HitField("title", "&smith &jo& nes"));
    r.hits().add(hit);
    docsource.addResultSet(q, r);
    Result check = doSearch(s, q, 0, 10, chained);
    assertEquals("&amp;smith &amp;jo&amp; nes", check.hits().get(0).getField("title").toString());
    assertTrue(check.hits().get(0).fields().containsKey("title"));
}
Also used : Relevance(com.yahoo.search.result.Relevance) FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) FastHit(com.yahoo.prelude.fastsearch.FastHit) Query(com.yahoo.search.Query) HashMap(java.util.HashMap) Searcher(com.yahoo.search.Searcher) QuotingSearcher(com.yahoo.prelude.searcher.QuotingSearcher) DocumentSourceSearcher(com.yahoo.prelude.searcher.DocumentSourceSearcher) HitField(com.yahoo.prelude.hitfield.HitField) DocumentSourceSearcher(com.yahoo.prelude.searcher.DocumentSourceSearcher) Result(com.yahoo.search.Result)

Example 10 with DocumentSourceSearcher

use of com.yahoo.prelude.searcher.DocumentSourceSearcher in project vespa by vespa-engine.

the class QuotingSearcherTestCase method testNoQuotingWithOtherTypes.

public void testNoQuotingWithOtherTypes() {
    Map<Searcher, Searcher> chained = new HashMap<>();
    Searcher s = createQuotingSearcher("file:src/test/java/com/yahoo/prelude/" + "searcher/test/testquoting.cfg");
    DocumentSourceSearcher docsource = new DocumentSourceSearcher();
    chained.put(s, docsource);
    Query q = new Query("?query=a");
    Result r = new Result(q);
    Hit hit = new FastHit();
    hit.setId("http://abc.html");
    hit.setRelevance(new Relevance(1));
    hit.setField("title", new Integer(42));
    r.hits().add(hit);
    docsource.addResultSet(q, r);
    Result check = doSearch(s, q, 0, 10, chained);
    // should not quote non-string properties
    assertEquals(new Integer(42), check.hits().get(0).getField("title"));
}
Also used : Relevance(com.yahoo.search.result.Relevance) FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) FastHit(com.yahoo.prelude.fastsearch.FastHit) Query(com.yahoo.search.Query) HashMap(java.util.HashMap) Searcher(com.yahoo.search.Searcher) QuotingSearcher(com.yahoo.prelude.searcher.QuotingSearcher) DocumentSourceSearcher(com.yahoo.prelude.searcher.DocumentSourceSearcher) DocumentSourceSearcher(com.yahoo.prelude.searcher.DocumentSourceSearcher) Result(com.yahoo.search.Result)

Aggregations

DocumentSourceSearcher (com.yahoo.prelude.searcher.DocumentSourceSearcher)11 FastHit (com.yahoo.prelude.fastsearch.FastHit)10 Query (com.yahoo.search.Query)10 Result (com.yahoo.search.Result)10 Hit (com.yahoo.search.result.Hit)8 Execution (com.yahoo.search.searchchain.Execution)5 Test (org.junit.Test)5 FillSearcher (com.yahoo.prelude.searcher.FillSearcher)4 QuotingSearcher (com.yahoo.prelude.searcher.QuotingSearcher)4 Searcher (com.yahoo.search.Searcher)4 Relevance (com.yahoo.search.result.Relevance)4 HashMap (java.util.HashMap)4 QrSearchersConfig (com.yahoo.container.QrSearchersConfig)1 HitField (com.yahoo.prelude.hitfield.HitField)1 CachingSearcher (com.yahoo.prelude.searcher.CachingSearcher)1 Iterator (java.util.Iterator)1 Before (org.junit.Before)1