Search in sources :

Example 11 with Chain

use of com.yahoo.component.chain.Chain in project vespa by vespa-engine.

the class FederationSearcherTestCase method twoTracingSources.

private Chain<Searcher> twoTracingSources(boolean strictContracts) {
    addChained(new Searcher() {

        @Override
        public Result search(Query query, Execution execution) {
            query.trace(SOURCE1, 1);
            return execution.search(query);
        }
    }, SOURCE1);
    addChained(new Searcher() {

        @Override
        public Result search(Query query, Execution execution) {
            query.trace(SOURCE2, 1);
            return execution.search(query);
        }
    }, SOURCE2);
    Chain<Searcher> mainChain = new Chain<>("default", new FederationSearcher(new FederationConfig(builder), new StrictContractsConfig(new StrictContractsConfig.Builder().searchchains(strictContracts)), new ComponentRegistry<>()));
    return mainChain;
}
Also used : StrictContractsConfig(com.yahoo.search.federation.StrictContractsConfig) Chain(com.yahoo.component.chain.Chain) SearchChain(com.yahoo.search.searchchain.SearchChain) Execution(com.yahoo.search.searchchain.Execution) FederationSearcher(com.yahoo.search.federation.FederationSearcher) Query(com.yahoo.search.Query) ComponentRegistry(com.yahoo.component.provider.ComponentRegistry) Searcher(com.yahoo.search.Searcher) FederationSearcher(com.yahoo.search.federation.FederationSearcher) FederationConfig(com.yahoo.search.federation.FederationConfig) Result(com.yahoo.search.Result)

Example 12 with Chain

use of com.yahoo.component.chain.Chain in project vespa by vespa-engine.

the class TilingTestCase method testTiling2.

/**
 * This result contains center section and meta blocks.
 * <p>
 * Incidentally, this also tests using an old searcher in new search chains.
 */
public void testTiling2() throws IOException {
    Chain<Searcher> chain = new Chain<>("tiling", new TiledResultProducer2());
    // Query it
    Query query = new Query("/tiled?query=foo");
    Result result = callSearchAndSetRenderer(chain, query);
    assertRendered(IOUtils.readFile(new File("src/test/java/com/yahoo/prelude/templates/test/tilingexample2.xml")), result);
}
Also used : Chain(com.yahoo.component.chain.Chain) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) HTTPProviderSearcher(com.yahoo.search.federation.http.HTTPProviderSearcher) File(java.io.File) Result(com.yahoo.search.Result)

Example 13 with Chain

use of com.yahoo.component.chain.Chain in project vespa by vespa-engine.

the class FieldCollapsingSearcherTestCase method testFieldCollapsingWithGrouping.

@Test
public void testFieldCollapsingWithGrouping() {
    // Set up
    FieldCollapsingSearcher collapse = new FieldCollapsingSearcher("other");
    DocumentSourceSearcher docsource = new DocumentSourceSearcher();
    Chain<Searcher> chain = new Chain<>(collapse, new AddAggregationStyleGroupingResultSearcher(), docsource);
    // Caveat: Collapse is set to false, because that's what the
    // collapser asks for
    Query q = new Query("?query=test_collapse&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, 1));
    r.hits().add(createHit("http://acme.org/d.html", 8, 1));
    r.hits().add(createHit("http://acme.org/e.html", 8, 2));
    r.hits().add(createHit("http://acme.org/f.html", 7, 2));
    r.hits().add(createHit("http://acme.org/g.html", 7, 3));
    r.hits().add(createHit("http://acme.org/h.html", 6, 3));
    r.setTotalHitCount(8);
    docsource.addResult(q, r);
    // Test basic collapsing on mid
    Query query = new Query("?query=test_collapse&collapsefield=amid");
    Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
    // Assert that the regular hits are collapsed
    assertEquals(4 + 1, result.getHitCount());
    assertEquals(1, docsource.getQueryCount());
    assertHit("http://acme.org/a.html", 10, 0, result.hits().get(0));
    assertHit("http://acme.org/c.html", 9, 1, result.hits().get(1));
    assertHit("http://acme.org/e.html", 8, 2, result.hits().get(2));
    assertHit("http://acme.org/g.html", 7, 3, result.hits().get(3));
    // Assert that the aggregation group hierarchy is left intact
    HitGroup root = getFirstGroupIn(result.hits());
    assertNotNull(root);
    // The id ends by a global counter currently
    assertEquals("group:root:", root.getId().stringValue().substring(0, 11));
    assertEquals(1, root.size());
    HitGroup groupList = (GroupList) root.get("grouplist:g1");
    assertNotNull(groupList);
    assertEquals(1, groupList.size());
    HitGroup group = (HitGroup) groupList.get("group:long:37");
    assertNotNull(group);
}
Also used : Chain(com.yahoo.component.chain.Chain) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) GroupList(com.yahoo.search.grouping.result.GroupList) 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) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 14 with Chain

use of com.yahoo.component.chain.Chain in project vespa by vespa-engine.

the class JuniperSearcherTestCase method createSearchChain.

/**
 * Creates a search chain which always returns a result with one hit containing information given in this
 *
 * @param sdName the search definition type of the returned hit
 * @param content the content of the "dynteaser" field of the returned hit
 */
private Chain<Searcher> createSearchChain(String sdName, String content) {
    JuniperSearcher searcher = new JuniperSearcher(new ComponentId("test"), new QrSearchersConfig(new QrSearchersConfig.Builder()));
    DocumentSourceSearcher docsource = new DocumentSourceSearcher();
    addResult(new Query("?query=12"), sdName, content, docsource);
    addResult(new Query("?query=12&bolding=false"), sdName, content, docsource);
    return new Chain<Searcher>(searcher, docsource);
}
Also used : Chain(com.yahoo.component.chain.Chain) Query(com.yahoo.search.Query) QrSearchersConfig(com.yahoo.container.QrSearchersConfig) JuniperSearcher(com.yahoo.prelude.searcher.JuniperSearcher) DocumentSourceSearcher(com.yahoo.search.searchchain.testutil.DocumentSourceSearcher) ComponentId(com.yahoo.component.ComponentId)

Example 15 with Chain

use of com.yahoo.component.chain.Chain in project vespa by vespa-engine.

the class JSONDebugSearcherTestCase method makeSearchChain.

private Chain<Searcher> makeSearchChain(String content, Searcher dumper) {
    DocumentSourceSearcher docsource = new DocumentSourceSearcher();
    addResult(new Query(DUMPJSON), content, docsource);
    addResult(new Query(NODUMPJSON), content, docsource);
    return new Chain<>(dumper, docsource);
}
Also used : Chain(com.yahoo.component.chain.Chain) Query(com.yahoo.search.Query) DocumentSourceSearcher(com.yahoo.search.searchchain.testutil.DocumentSourceSearcher)

Aggregations

Chain (com.yahoo.component.chain.Chain)92 Execution (com.yahoo.search.searchchain.Execution)59 Searcher (com.yahoo.search.Searcher)57 Test (org.junit.Test)56 Result (com.yahoo.search.Result)48 Query (com.yahoo.search.Query)47 FeedContext (com.yahoo.feedapi.FeedContext)21 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)21 NullFeedMetric (com.yahoo.feedhandler.NullFeedMetric)21 ClusterList (com.yahoo.vespaclient.ClusterList)21 Processor (com.yahoo.processing.Processor)17 Request (com.yahoo.processing.Request)10 Response (com.yahoo.processing.Response)10 ComponentId (com.yahoo.component.ComponentId)8 FederationSearcher (com.yahoo.search.federation.FederationSearcher)8 ArrayList (java.util.ArrayList)8 GetDocumentMessage (com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage)7 Message (com.yahoo.messagebus.Message)7 Hit (com.yahoo.search.result.Hit)7 AsyncExecution (com.yahoo.search.searchchain.AsyncExecution)6