Search in sources :

Example 61 with Query

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

the class FederationSearcherTestCase method assertSelects.

private void assertSelects(String providerName, SearchChainRegistry registry) {
    QueryProfile profile = new QueryProfile("test");
    profile.set("source.news.provider", providerName, null);
    Query query = new Query(QueryTestCase.httpEncode("?query=test&model.sources=news"), profile.compile(null));
    Result result = new Execution(registry.getComponent("default"), Execution.Context.createContextStub(registry, null)).search(query);
    assertEquals(1, result.hits().size());
    assertNotNull(result.hits().get(providerName + ":1"));
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) Result(com.yahoo.search.Result)

Example 62 with Query

use of com.yahoo.search.Query 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 63 with Query

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

the class FederationSearcherTestCase method testTraceTwoSources.

@Test
public void testTraceTwoSources() {
    Chain<Searcher> mainChain = twoTracingSources(false);
    Query q = new Query(com.yahoo.search.test.QueryTestCase.httpEncode("?query=test&traceLevel=1"));
    Execution execution = new Execution(mainChain, Execution.Context.createContextStub(chainRegistry, null));
    Result result = execution.search(q);
    assertNull(result.hits().getError());
    TwoSourceChecker lookForTraces = new TwoSourceChecker();
    execution.trace().accept(lookForTraces);
    assertTrue(lookForTraces.traceFromSource1);
    assertTrue(lookForTraces.traceFromSource2);
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) FederationSearcher(com.yahoo.search.federation.FederationSearcher) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 64 with Query

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

the class HttpPostTestCase method testPostingSearcher.

@Test
public void testPostingSearcher() throws Exception {
    StupidSingleThreadedHttpServer server = new StupidSingleThreadedHttpServer();
    server.start();
    TestPostSearcher searcher = new TestPostSearcher(new ComponentId("foo:1"), Arrays.asList(new Connection("localhost", server.getServerPort())), "/");
    Query q = new Query("");
    q.setTimeout(10000000L);
    Execution e = new Execution(searcher, Execution.Context.createContextStub());
    searcher.search(q, e);
    assertThat(server.getRequest(), containsString("My POST body"));
    server.stop();
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) StupidSingleThreadedHttpServer(com.yahoo.search.StupidSingleThreadedHttpServer) Connection(com.yahoo.search.federation.http.Connection) ComponentId(com.yahoo.component.ComponentId) Test(org.junit.Test)

Example 65 with Query

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

the class SemanticSearcherTestCase method testNullQuery.

public void testNullQuery() {
    // Causes a query containing a NullItem
    Query query = new Query("");
    doSearch(searcher, query, 0, 10);
    // Still a NullItem
    assertEquals(NullItem.class, query.getModel().getQueryTree().getRoot().getClass());
}
Also used : Query(com.yahoo.search.Query)

Aggregations

Query (com.yahoo.search.Query)689 Test (org.junit.Test)415 Result (com.yahoo.search.Result)229 Execution (com.yahoo.search.searchchain.Execution)184 Searcher (com.yahoo.search.Searcher)82 QueryProfile (com.yahoo.search.query.profile.QueryProfile)63 Hit (com.yahoo.search.result.Hit)52 Chain (com.yahoo.component.chain.Chain)47 IndexFacts (com.yahoo.prelude.IndexFacts)44 CompiledQueryProfileRegistry (com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry)37 AndItem (com.yahoo.prelude.query.AndItem)33 WordItem (com.yahoo.prelude.query.WordItem)33 FastHit (com.yahoo.prelude.fastsearch.FastHit)31 CompiledQueryProfile (com.yahoo.search.query.profile.compiled.CompiledQueryProfile)27 HitGroup (com.yahoo.search.result.HitGroup)24 Item (com.yahoo.prelude.query.Item)21 HashMap (java.util.HashMap)20 CacheKey (com.yahoo.prelude.fastsearch.CacheKey)18 GroupingRequest (com.yahoo.search.grouping.GroupingRequest)18 ArrayList (java.util.ArrayList)18