Search in sources :

Example 6 with Execution

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

the class FastSearcherTestCase method testThatPropertiesAreReencoded.

@Test
public void testThatPropertiesAreReencoded() throws Exception {
    FastSearcher fastSearcher = createFastSearcher();
    // Default cache =100MB
    assertEquals(100, fastSearcher.getCacheControl().capacity());
    Query query = new Query("?query=ignored");
    query.getRanking().setQueryCache(true);
    Result result = doSearch(fastSearcher, query, 0, 10);
    Execution execution = new Execution(chainedAsSearchChain(fastSearcher), Execution.Context.createContextStub());
    assertEquals(2, result.getHitCount());
    execution.fill(result);
    BasicPacket receivedPacket = mockBackend.getChannel().getLastReceived();
    ByteBuffer buf = ByteBuffer.allocate(1000);
    receivedPacket.encode(buf);
    buf.flip();
    byte[] actual = new byte[buf.remaining()];
    buf.get(actual);
    SessionId sessionId = query.getSessionId(false);
    byte IGNORE = 69;
    ByteBuffer answer = ByteBuffer.allocate(1024);
    answer.put(new byte[] { 0, 0, 0, (byte) (145 + sessionId.asUtf8String().getByteLength()), 0, 0, 0, -37, 0, 0, 48, 17, 0, 0, 0, 0, // query timeout
    IGNORE, IGNORE, IGNORE, IGNORE, // "default" - rank profile
    7, 'd', 'e', 'f', 'a', 'u', 'l', 't', 0, 0, 0, 0x03, // 3 property entries (rank, match, caches)
    0, 0, 0, 3, // rank: sessionId => qrserver.0.XXXXXXXXXXXXX.0
    0, 0, 0, 4, 'r', 'a', 'n', 'k', 0, 0, 0, 1, 0, 0, 0, 9, 's', 'e', 's', 's', 'i', 'o', 'n', 'I', 'd' });
    answer.putInt(sessionId.asUtf8String().getBytes().length);
    answer.put(sessionId.asUtf8String().getBytes());
    answer.put(new byte[] { // match: documentdb.searchdoctype => test
    0, 0, 0, 5, 'm', 'a', 't', 'c', 'h', 0, 0, 0, 1, 0, 0, 0, 24, 'd', 'o', 'c', 'u', 'm', 'e', 'n', 't', 'd', 'b', '.', 's', 'e', 'a', 'r', 'c', 'h', 'd', 'o', 'c', 't', 'y', 'p', 'e', 0, 0, 0, 4, 't', 'e', 's', 't', // sessionId => qrserver.0.XXXXXXXXXXXXX.0
    0, 0, 0, 6, 'c', 'a', 'c', 'h', 'e', 's', 0, 0, 0, 1, 0, 0, 0, 5, 'q', 'u', 'e', 'r', 'y', 0, 0, 0, 4, 't', 'r', 'u', 'e', // flags
    0, 0, 0, 2 });
    byte[] expected = new byte[answer.position()];
    answer.flip();
    answer.get(expected);
    assertEquals(expected.length, actual.length);
    for (int i = 0; i < expected.length; ++i) {
        if (expected[i] == IGNORE) {
            actual[i] = IGNORE;
        }
    }
    assertArrayEquals(expected, actual);
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) ByteBuffer(java.nio.ByteBuffer) SessionId(com.yahoo.search.query.SessionId) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 7 with Execution

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

the class FastSearcherTestCase method testSinglePassGroupingIsNotForcedWithSingleNodeGroups.

@Test
public void testSinglePassGroupingIsNotForcedWithSingleNodeGroups() {
    MockDispatcher dispatcher = new MockDispatcher(ImmutableList.of(new SearchCluster.Node("host0", 123, 0), new SearchCluster.Node("host1", 123, 0)));
    FastSearcher fastSearcher = new FastSearcher(new MockBackend(), new FS4ResourcePool(1), dispatcher, new SummaryParameters(null), new ClusterParams("testhittype"), new CacheParams(100, 1e64), documentdbInfoConfig);
    Query q = new Query("?query=foo");
    GroupingRequest request1 = GroupingRequest.newInstance(q);
    request1.setRootOperation(new AllOperation());
    GroupingRequest request2 = GroupingRequest.newInstance(q);
    AllOperation all = new AllOperation();
    all.addChild(new EachOperation());
    all.addChild(new EachOperation());
    request2.setRootOperation(all);
    assertForceSinglePassIs(false, q);
    fastSearcher.search(q, new Execution(Execution.Context.createContextStub()));
    assertForceSinglePassIs(false, q);
}
Also used : Query(com.yahoo.search.Query) TraceNode(com.yahoo.yolean.trace.TraceNode) EachOperation(com.yahoo.search.grouping.request.EachOperation) Execution(com.yahoo.search.searchchain.Execution) MockBackend(com.yahoo.prelude.fastsearch.test.fs4mock.MockBackend) GroupingRequest(com.yahoo.search.grouping.GroupingRequest) AllOperation(com.yahoo.search.grouping.request.AllOperation) Test(org.junit.Test)

Example 8 with Execution

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

the class PageTemplateSearcherTestCase method testSearcher.

public void testSearcher() {
    PageTemplateSearcher s = new PageTemplateSearcher(createPageTemplateRegistry(), new FirstChoiceResolver());
    Chain<Searcher> chain = new Chain<>(s, new MockFederator());
    {
        // No template specified, should use default
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(new Query("?query=foo&page.resolver=native.deterministic"));
        assertSources("source1 source2", result);
    }
    {
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(new Query("?query=foo&page.id=oneSource&page.resolver=native.deterministic"));
        assertSources("source1", result);
    }
    {
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(new Query("?query=foo&page.id=twoSources&model.sources=source1&page.resolver=native.deterministic"));
        assertSources("source1", result);
    }
    {
        Query query = new Query("?query=foo&page.resolver=native.deterministic");
        addIntentModelSpecifyingSource3(query);
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertSources("source1 source2", result);
    }
    {
        Query query = new Query("?query=foo&page.id=twoSourcesAndAny&page.resolver=native.deterministic");
        addIntentModelSpecifyingSource3(query);
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertSources("source1 source2 source3", result);
    }
    {
        Query query = new Query("?query=foo&page.id=anySource&page.resolver=native.deterministic");
        addIntentModelSpecifyingSource3(query);
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertSources("source3", result);
    }
    {
        Query query = new Query("?query=foo&page.id=anySource&page.resolver=native.deterministic");
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertTrue(query.getModel().getSources().isEmpty());
        assertNotNull(result.hits().get("source1"));
        assertNotNull(result.hits().get("source2"));
        assertNotNull(result.hits().get("source3"));
    }
    {
        Query query = new Query("?query=foo&page.id=choiceOfSources&page.resolver=native.deterministic");
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertSources("source1 source2", "source2", result);
    }
    {
        Query query = new Query("?query=foo&page.id=choiceOfSources&page.resolver=test.firstChoice");
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertSources("source1 source2", "source1", result);
    }
    {
        // Specifying two templates, should pick the last
        Query query = new Query("?query=foo&page.id=threeSources+oneSource&page.resolver=native.deterministic");
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertSources("source1 source2 source3", "source1", result);
    }
    {
        // Specifying two templates as a list, should override the page.id setting
        Query query = new Query("?query=foo&page.id=anySource&page.resolver=native.deterministic");
        query.properties().set("page.idList", Arrays.asList("oneSource", "threeSources"));
        Result result = new Execution(chain, Execution.Context.createContextStub()).search(query);
        assertSources("source1 source2 source3", "source1 source2 source3", result);
    }
    {
        try {
            Query query = new Query("?query=foo&page.id=oneSource+choiceOfSources&page.resolver=noneSuch");
            new Execution(chain, Execution.Context.createContextStub()).search(query);
            fail("Expected exception");
        } catch (IllegalArgumentException e) {
            assertEquals("No page template resolver 'noneSuch'", e.getMessage());
        }
    }
}
Also used : Chain(com.yahoo.component.chain.Chain) Execution(com.yahoo.search.searchchain.Execution) PageTemplateSearcher(com.yahoo.search.pagetemplates.PageTemplateSearcher) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) PageTemplateSearcher(com.yahoo.search.pagetemplates.PageTemplateSearcher) Result(com.yahoo.search.Result)

Example 9 with Execution

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

the class QueryMarshallerTestCase method testQueryString.

private void testQueryString(QueryMarshaller marshaller, String uq, String mq, String lang, Linguistics linguistics) {
    Query query = new Query("/?query=" + QueryTestCase.httpEncode(uq) + ((lang != null) ? "&language=" + lang : ""));
    query.getModel().setExecution(new Execution(new Execution.Context(null, new IndexFacts(), null, null, linguistics)));
    assertEquals(mq, marshaller.marshal(query.getModel().getQueryTree().getRoot()));
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) IndexFacts(com.yahoo.prelude.IndexFacts)

Example 10 with Execution

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

the class VespaSearcherTestCase method testVespaSearcher.

public void testVespaSearcher() {
    VespaSearcher v = new VespaSearcherValidatingSubclass();
    new Execution(v, Execution.Context.createContextStub()).search(new Query(com.yahoo.search.test.QueryTestCase.httpEncode("?query=test&filter=myfilter")));
}
Also used : VespaSearcher(com.yahoo.search.federation.vespa.VespaSearcher) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query)

Aggregations

Execution (com.yahoo.search.searchchain.Execution)232 Query (com.yahoo.search.Query)184 Result (com.yahoo.search.Result)127 Test (org.junit.Test)123 Searcher (com.yahoo.search.Searcher)88 Chain (com.yahoo.component.chain.Chain)59 IndexFacts (com.yahoo.prelude.IndexFacts)34 Hit (com.yahoo.search.result.Hit)25 FeedContext (com.yahoo.feedapi.FeedContext)20 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)20 NullFeedMetric (com.yahoo.feedhandler.NullFeedMetric)20 ClusterList (com.yahoo.vespaclient.ClusterList)20 AndItem (com.yahoo.prelude.query.AndItem)18 WordItem (com.yahoo.prelude.query.WordItem)17 ComponentId (com.yahoo.component.ComponentId)13 GetDocumentReply (com.yahoo.documentapi.messagebus.protocol.GetDocumentReply)13 FastHit (com.yahoo.prelude.fastsearch.FastHit)13 FederationSearcher (com.yahoo.search.federation.FederationSearcher)13 ArrayList (java.util.ArrayList)12 CompositeItem (com.yahoo.prelude.query.CompositeItem)11