Search in sources :

Example 36 with Searcher

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

the class GetSearcherTestCase method testQueryPassThroughAndGetUnknownBackendHit.

@Test
public void testQueryPassThroughAndGetUnknownBackendHit() throws Exception {
    DocumentSessionFactory factory = new DocumentSessionFactory(docType);
    GetSearcher searcher = new GetSearcher(new FeedContext(new MessagePropertyProcessor(defFeedCfg, defLoadTypeCfg), factory, docMan, new ClusterList(), new NullFeedMetric()));
    HitGroup hits = new HitGroup("mock");
    hits.add(new Hit("blernsball"));
    Chain<Searcher> searchChain = new Chain<>(searcher, new MockBackend(hits));
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?flarn=blern&id=userdoc:kittens:9:aaa"));
    assertEquals(0, factory.messages.size());
    assertNotNull(result.hits().getErrorHit());
    assertRendered("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<result>\n" + "<errors>\n" + "<error type=\"searcher\" code=\"18\" message=\"Internal server error.: " + "A backend searcher to com.yahoo.storage.searcher.GetSearcher returned a " + "hit that was not an instance of com.yahoo.storage.searcher.DocumentHit. " + "Only DocumentHit instances are supported in the backend hit result set " + "when doing queries that contain document identifier sets recognised by the " + "Get Searcher.\"/>\n" + "</errors>\n" + "</result>\n", result);
}
Also used : Chain(com.yahoo.component.chain.Chain) ClusterList(com.yahoo.vespaclient.ClusterList) Searcher(com.yahoo.search.Searcher) Result(com.yahoo.search.Result) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) FeedContext(com.yahoo.feedapi.FeedContext) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor) NullFeedMetric(com.yahoo.feedhandler.NullFeedMetric) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 37 with Searcher

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

the class GetSearcherTestCase method testMultiIdBadArrayIndex.

@Test
public void testMultiIdBadArrayIndex() throws Exception {
    DocumentSessionFactory factory = new DocumentSessionFactory(docType);
    GetSearcher searcher = new GetSearcher(new FeedContext(new MessagePropertyProcessor(defFeedCfg, defLoadTypeCfg), factory, docMan, new ClusterList(), new NullFeedMetric()));
    Chain<Searcher> searchChain = new Chain<>(searcher);
    {
        Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id[1]=userdoc:kittens:1:2"));
        assertNotNull(result.hits().getErrorHit());
        assertRendered("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<result>\n" + "<errors>\n" + "<error type=\"searcher\" code=\"3\" message=\"Illegal query: " + "java.lang.IllegalArgumentException: query contains document ID " + "array that is not zero-based and/or linearly increasing\"/>\n" + "</errors>\n" + "</result>\n", result);
    }
    {
        Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id[0]=userdoc:kittens:1:2&id[2]=userdoc:kittens:2:3"));
        assertNotNull(result.hits().getErrorHit());
        assertRendered("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<result>\n" + "<errors>\n" + "<error type=\"searcher\" code=\"3\" message=\"Illegal query: " + "java.lang.IllegalArgumentException: query contains document ID " + "array that is not zero-based and/or linearly increasing\"/>\n" + "</errors>\n" + "</result>\n", result);
    }
    {
        Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id[1]=userdoc:kittens:2:3"));
        assertNotNull(result.hits().getErrorHit());
        assertRendered("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<result>\n" + "<errors>\n" + "<error type=\"searcher\" code=\"3\" message=\"Illegal query: " + "java.lang.IllegalArgumentException: query contains document ID " + "array that is not zero-based and/or linearly increasing\"/>\n" + "</errors>\n" + "</result>\n", result);
    }
    {
        Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id[0=userdoc:kittens:1:2"));
        assertNotNull(result.hits().getErrorHit());
        assertRendered("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<result>\n" + "<errors>\n" + "<error type=\"searcher\" code=\"3\" message=\"Illegal query: " + "java.lang.IllegalArgumentException: Malformed document ID array parameter\"/>\n" + "</errors>\n" + "</result>\n", result);
    }
}
Also used : Chain(com.yahoo.component.chain.Chain) ClusterList(com.yahoo.vespaclient.ClusterList) Execution(com.yahoo.search.searchchain.Execution) FeedContext(com.yahoo.feedapi.FeedContext) Searcher(com.yahoo.search.Searcher) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor) NullFeedMetric(com.yahoo.feedhandler.NullFeedMetric) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 38 with Searcher

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

the class GetSearcherTestCase method testDocumentFieldRawContent.

@Test
public void testDocumentFieldRawContent() throws Exception {
    byte[] contentBytes = new byte[] { 0, -128, 127 };
    Document doc1 = new Document(docType, new DocumentId("userdoc:kittens:123:456"));
    doc1.setFieldValue("foo", new Raw(ByteBuffer.wrap(contentBytes)));
    GetDocumentReply[] replies = new GetDocumentReply[] { new GetDocumentReply(doc1) };
    Chain<Searcher> searchChain = createSearcherChain(replies);
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id=userdoc:kittens:123:456&field=foo"));
    assertNull(result.hits().getErrorHit());
    assertEquals("application/octet-stream", result.getTemplating().getTemplates().getMimeType());
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    SearchRendererAdaptor.callRender(stream, result);
    stream.flush();
    byte[] resultBytes = stream.toByteArray();
    assertEquals(contentBytes.length, resultBytes.length);
    for (int i = 0; i < resultBytes.length; ++i) {
        assertEquals(contentBytes[i], resultBytes[i]);
    }
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Searcher(com.yahoo.search.Searcher) Raw(com.yahoo.document.datatypes.Raw) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 39 with Searcher

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

the class GetSearcherTestCase method testQueryOverridesConfig.

@Test
public void testQueryOverridesConfig() throws Exception {
    String config = "raw:timeout 458\nroute \"route66\"";
    DocumentSessionFactory factory = new DocumentSessionFactory(docType);
    GetSearcher searcher = new GetSearcher(new FeedContext(new MessagePropertyProcessor(defFeedCfg, defLoadTypeCfg), factory, docMan, new ClusterList(), new NullFeedMetric()));
    Chain<Searcher> searchChain = new Chain<>(searcher);
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id[0]=userdoc:kittens:1:2&id[1]=userdoc:kittens:3:4&priority=LOW_2&route=highwaytohell&timeout=123"));
    long lastTimeout = 123000;
    assertEquals(2, factory.messages.size());
    {
        Message m = factory.messages.get(0);
        assertEquals(DocumentProtocol.MESSAGE_GETDOCUMENT, m.getType());
        GetDocumentMessage gdm = (GetDocumentMessage) m;
        DocumentId d = gdm.getDocumentId();
        assertEquals("userdoc:kittens:1:2", d.toString());
        assertEquals("[all]", gdm.getFieldSet());
        assertEquals(DocumentProtocol.Priority.LOW_2, gdm.getPriority());
        assertEquals(Route.parse("highwaytohell"), gdm.getRoute());
        assertTrue(lastTimeout >= gdm.getTimeRemaining());
        lastTimeout = gdm.getTimeRemaining();
    }
    {
        Message m = factory.messages.get(1);
        assertEquals(DocumentProtocol.MESSAGE_GETDOCUMENT, m.getType());
        GetDocumentMessage gdm = (GetDocumentMessage) m;
        DocumentId d = gdm.getDocumentId();
        assertEquals("userdoc:kittens:3:4", d.toString());
        assertEquals("[all]", gdm.getFieldSet());
        assertEquals(DocumentProtocol.Priority.LOW_2, gdm.getPriority());
        assertEquals(Route.parse("highwaytohell"), gdm.getRoute());
        assertTrue(lastTimeout >= gdm.getTimeRemaining());
    }
}
Also used : Chain(com.yahoo.component.chain.Chain) ClusterList(com.yahoo.vespaclient.ClusterList) Message(com.yahoo.messagebus.Message) GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage) Searcher(com.yahoo.search.Searcher) Result(com.yahoo.search.Result) Execution(com.yahoo.search.searchchain.Execution) FeedContext(com.yahoo.feedapi.FeedContext) GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor) NullFeedMetric(com.yahoo.feedhandler.NullFeedMetric) Test(org.junit.Test)

Example 40 with Searcher

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

the class GetSearcherTestCase method testLegacyHeadersOnly.

@Test
public void testLegacyHeadersOnly() throws Exception {
    // Needs auto-reply
    DocumentSessionFactory factory = new DocumentSessionFactory(docType);
    GetSearcher searcher = new GetSearcher(new FeedContext(new MessagePropertyProcessor(defFeedCfg, defLoadTypeCfg), factory, docMan, new ClusterList(), new NullFeedMetric()));
    Chain<Searcher> searchChain = new Chain<>(searcher);
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id=userdoc:kittens:1:2&headersonly=true"));
    assertEquals(1, factory.messages.size());
    {
        Message m = factory.messages.get(0);
        assertEquals(DocumentProtocol.MESSAGE_GETDOCUMENT, m.getType());
        GetDocumentMessage gdm = (GetDocumentMessage) m;
        DocumentId d = gdm.getDocumentId();
        assertEquals("userdoc:kittens:1:2", d.toString());
        assertEquals("[header]", gdm.getFieldSet());
    }
    assertEquals(1, result.hits().size());
    assertHits(result.hits(), "userdoc:kittens:1:2");
}
Also used : Chain(com.yahoo.component.chain.Chain) ClusterList(com.yahoo.vespaclient.ClusterList) Message(com.yahoo.messagebus.Message) GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage) Searcher(com.yahoo.search.Searcher) Result(com.yahoo.search.Result) Execution(com.yahoo.search.searchchain.Execution) FeedContext(com.yahoo.feedapi.FeedContext) GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor) NullFeedMetric(com.yahoo.feedhandler.NullFeedMetric) Test(org.junit.Test)

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