Search in sources :

Example 96 with Searcher

use of com.yahoo.search.Searcher in project vespa by vespa-engine.

the class FieldCollapsingSearcherTestCase method testCollapsingDispersedCollection.

/**
 * Tests collapsing of "messy" data
 */
@Test
public void testCollapsingDispersedCollection() {
    // Set up
    Map<Searcher, Searcher> chained = new HashMap<>();
    FieldCollapsingSearcher collapse = new FieldCollapsingSearcher(1, 2.0, "amid");
    DocumentSourceSearcher docsource = new DocumentSourceSearcher();
    chained.put(collapse, docsource);
    Query q = new Query("?query=test_collapse&collapse=true&collapsefield=amid");
    // The searcher turns off collapsing further on in the chain
    q.properties().set("collapse", "0");
    Result r = new Result(q);
    r.hits().add(createHit("http://acme.org/a.html", 10, 1));
    r.hits().add(createHit("http://acme.org/b.html", 10, 1));
    r.hits().add(createHit("http://acme.org/c.html", 10, 0));
    r.hits().add(createHit("http://acme.org/d.html", 10, 0));
    r.hits().add(createHit("http://acme.org/e.html", 10, 0));
    r.hits().add(createHit("http://acme.org/f.html", 10, 0));
    r.hits().add(createHit("http://acme.org/g.html", 10, 0));
    r.hits().add(createHit("http://acme.org/h.html", 10, 0));
    r.hits().add(createHit("http://acme.org/i.html", 10, 0));
    r.hits().add(createHit("http://acme.org/j.html", 10, 1));
    r.setTotalHitCount(10);
    docsource.addResult(q, r);
    // Test collapsing
    q = new Query("?query=test_collapse&collapse=true&collapsefield=amid");
    r = doSearch(collapse, q, 0, 3, chained);
    assertEquals(2, r.getHitCount());
    assertHit("http://acme.org/a.html", 10, 1, r.hits().get(0));
    assertHit("http://acme.org/c.html", 10, 0, r.hits().get(1));
}
Also used : Query(com.yahoo.search.Query) HashMap(java.util.HashMap) Searcher(com.yahoo.search.Searcher) DocumentSourceSearcher(com.yahoo.search.searchchain.testutil.DocumentSourceSearcher) FieldCollapsingSearcher(com.yahoo.prelude.searcher.FieldCollapsingSearcher) DocumentSourceSearcher(com.yahoo.search.searchchain.testutil.DocumentSourceSearcher) FieldCollapsingSearcher(com.yahoo.prelude.searcher.FieldCollapsingSearcher) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 97 with Searcher

use of com.yahoo.search.Searcher in project vespa by vespa-engine.

the class FieldCollapsingSearcherTestCase method testFieldCollapsingWithoutHits.

@Test
public void testFieldCollapsingWithoutHits() {
    // Set up
    Map<Searcher, Searcher> chained = new HashMap<>();
    FieldCollapsingSearcher collapse = new FieldCollapsingSearcher("other");
    ZeroHitsControl checker = new ZeroHitsControl();
    chained.put(collapse, checker);
    Query q = new Query("?query=test_collapse&collapsefield=amid");
    Result r = doSearch(collapse, q, 0, 0, chained);
    assertEquals(0, r.getHitCount());
    assertNull(r.hits().getError());
    assertEquals(1, checker.queryCount);
}
Also used : Query(com.yahoo.search.Query) HashMap(java.util.HashMap) Searcher(com.yahoo.search.Searcher) DocumentSourceSearcher(com.yahoo.search.searchchain.testutil.DocumentSourceSearcher) FieldCollapsingSearcher(com.yahoo.prelude.searcher.FieldCollapsingSearcher) FieldCollapsingSearcher(com.yahoo.prelude.searcher.FieldCollapsingSearcher) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 98 with Searcher

use of com.yahoo.search.Searcher in project vespa by vespa-engine.

the class FieldCollapsingSearcherTestCase method testCollapsingLargeCollection.

/**
 * Tests that collapsing many hits from one site works, and without
 * an excessive number of backend requests
 */
@Test
public void testCollapsingLargeCollection() {
    // Set up
    Map<Searcher, Searcher> chained = new HashMap<>();
    FieldCollapsingSearcher collapse = new FieldCollapsingSearcher(4, 2.0, "amid");
    DocumentSourceSearcher docsource = new DocumentSourceSearcher();
    chained.put(collapse, docsource);
    Query q = new Query("?query=test_collapse&collapsesize=1&collapsefield=amid");
    // The searcher turns off collapsing further on in the chain
    q.properties().set("collapse", "0");
    Result r = new Result(q);
    r.hits().add(createHit("http://acme.org/a.html", 10, 0));
    r.hits().add(createHit("http://acme.org/b.html", 9, 0));
    r.hits().add(createHit("http://acme.org/c.html", 9, 0));
    r.hits().add(createHit("http://acme.org/d.html", 8, 0));
    r.hits().add(createHit("http://acme.org/e.html", 8, 0));
    r.hits().add(createHit("http://acme.org/f.html", 7, 0));
    r.hits().add(createHit("http://acme.org/g.html", 7, 0));
    r.hits().add(createHit("http://acme.org/h.html", 6, 0));
    r.hits().add(createHit("http://acme.org/i.html", 5, 1));
    r.hits().add(createHit("http://acme.org/j.html", 4, 2));
    r.setTotalHitCount(10);
    docsource.addResult(q, r);
    // Test collapsing
    q = new Query("?query=test_collapse&collapsesize=1&collapsefield=amid");
    r = doSearch(collapse, q, 0, 2, chained);
    assertEquals(2, r.getHitCount());
    assertEquals(2, docsource.getQueryCount());
    assertHit("http://acme.org/a.html", 10, 0, r.hits().get(0));
    assertHit("http://acme.org/i.html", 5, 1, r.hits().get(1));
    // Next results
    docsource.resetQueryCount();
    r = doSearch(collapse, q, 2, 2, chained);
    assertEquals(1, r.getHitCount());
    assertEquals(2, docsource.getQueryCount());
    assertHit("http://acme.org/j.html", 4, 2, r.hits().get(0));
}
Also used : Query(com.yahoo.search.Query) HashMap(java.util.HashMap) Searcher(com.yahoo.search.Searcher) DocumentSourceSearcher(com.yahoo.search.searchchain.testutil.DocumentSourceSearcher) FieldCollapsingSearcher(com.yahoo.prelude.searcher.FieldCollapsingSearcher) DocumentSourceSearcher(com.yahoo.search.searchchain.testutil.DocumentSourceSearcher) FieldCollapsingSearcher(com.yahoo.prelude.searcher.FieldCollapsingSearcher) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 99 with Searcher

use of com.yahoo.search.Searcher in project vespa by vespa-engine.

the class JuniperSearcherTestCase method testExplicitTwoPhase.

@Test
public void testExplicitTwoPhase() {
    Chain<Searcher> searchChain = createSearchChain("one", "\u001e\uFFFAbe\uFFFB within the set of \u001f\uFFF9documents\uFFFAdocument\uFFFB\u001f. \uFFF9phrases\uFFFA\u001E\uFFFA\uFFFB to as a remedy). Each of the \u001fdocument\u001f \uFFF9fields\uFFFAfield\uFFFB in a catalog can be \uFFF9\u001e");
    Query q = new Query("?query=12");
    Result check = createExecution(searchChain).search(q);
    assertEquals(1, check.getHitCount());
    assertNull(check.hits().get(0).getField("dynteaser"));
    createExecution(searchChain).fill(check);
    assertEquals(1, check.getHitCount());
    assertEquals("<sep /> within the set of <hi>documents</hi>. phrases<sep /> to as a remedy). Each of the <hi>document</hi> fields in a catalog can be <sep />", check.hits().get(0).getField("dynteaser").toString());
}
Also used : Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) DocumentSourceSearcher(com.yahoo.search.searchchain.testutil.DocumentSourceSearcher) JuniperSearcher(com.yahoo.prelude.searcher.JuniperSearcher) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 100 with Searcher

use of com.yahoo.search.Searcher in project vespa by vespa-engine.

the class ClusterSearcherTestCase method testSimple.

public void testSimple() {
    Hit blockingHit = new Hit("blocking");
    Hit nonblockingHit = new Hit("nonblocking");
    BlockingBackendSearcher blockingSearcher = new BlockingBackendSearcher(blockingHit);
    List<Searcher> searchers = new ArrayList<>();
    searchers.add(blockingSearcher);
    searchers.add(new TestingBackendSearcher(nonblockingHit));
    ClusterSearcher<?> provider = new SearcherClusterSearcher(new ComponentId("simple"), searchers, new SimpleHasher<>());
    Result blockingResult = new Execution(provider, Execution.Context.createContextStub()).search(new SimpleQuery(0));
    assertEquals(blockingHit, blockingResult.hits().get(0));
    Result nonblockingResult = new Execution(provider, Execution.Context.createContextStub()).search(new SimpleQuery(1));
    assertEquals(nonblockingHit, nonblockingResult.hits().get(0));
    blockingSearcher.setBlocking(true);
    blockingResult = new Execution(provider, Execution.Context.createContextStub()).search(new SimpleQuery(0));
    assertEquals(blockingResult.hits().get(0), nonblockingHit);
    nonblockingResult = new Execution(provider, Execution.Context.createContextStub()).search(new SimpleQuery(1));
    assertEquals(nonblockingResult.hits().get(0), nonblockingHit);
}
Also used : PingableSearcher(com.yahoo.search.cluster.PingableSearcher) Searcher(com.yahoo.search.Searcher) ClusterSearcher(com.yahoo.search.cluster.ClusterSearcher) ArrayList(java.util.ArrayList) Result(com.yahoo.search.Result) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) ComponentId(com.yahoo.component.ComponentId)

Aggregations

Searcher (com.yahoo.search.Searcher)130 Result (com.yahoo.search.Result)94 Execution (com.yahoo.search.searchchain.Execution)88 Query (com.yahoo.search.Query)82 Test (org.junit.Test)74 Chain (com.yahoo.component.chain.Chain)57 FeedContext (com.yahoo.feedapi.FeedContext)20 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)20 NullFeedMetric (com.yahoo.feedhandler.NullFeedMetric)20 ClusterList (com.yahoo.vespaclient.ClusterList)20 Hit (com.yahoo.search.result.Hit)17 DocumentSourceSearcher (com.yahoo.search.searchchain.testutil.DocumentSourceSearcher)14 HashMap (java.util.HashMap)14 GetDocumentReply (com.yahoo.documentapi.messagebus.protocol.GetDocumentReply)13 FederationSearcher (com.yahoo.search.federation.FederationSearcher)11 FieldCollapsingSearcher (com.yahoo.prelude.searcher.FieldCollapsingSearcher)10 ArrayList (java.util.ArrayList)10 AsyncExecution (com.yahoo.search.searchchain.AsyncExecution)9 ComponentId (com.yahoo.component.ComponentId)8 FastHit (com.yahoo.prelude.fastsearch.FastHit)8