Search in sources :

Example 51 with Execution

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

the class GetSearcherTestCase method testDefaultDocumentHitRendering.

@Test
public void testDefaultDocumentHitRendering() throws Exception {
    Document doc1 = new Document(docType, new DocumentId("userdoc:kittens:3:4"));
    doc1.setFieldValue("name", new StringFieldValue("mittens"));
    doc1.setFieldValue("description", new StringFieldValue("it's a cat"));
    doc1.setFieldValue("fluffiness", new IntegerFieldValue(8));
    Document doc2 = new Document(docType, new DocumentId("userdoc:kittens:1:2"));
    doc2.setFieldValue("name", new StringFieldValue("garfield"));
    doc2.setFieldValue("description", new StringFieldValue("preliminary research indicates <em>hatred</em> of mondays. caution advised"));
    doc2.setFieldValue("fluffiness", new IntegerFieldValue(2));
    Document doc3 = new Document(docType, new DocumentId("userdoc:kittens:77:88"));
    GetDocumentReply errorReply = new GetDocumentReply(doc3);
    errorReply.addError(new com.yahoo.messagebus.Error(123, "userdoc:kittens:77:88 had fleas."));
    GetDocumentReply[] replies = new GetDocumentReply[] { new GetDocumentReply(doc1), new GetDocumentReply(doc2), errorReply };
    // Use a predefined reply list to ensure messages are answered out of order
    Chain<Searcher> searchChain = createSearcherChain(replies);
    Result xmlResult = new Execution(searchChain, Execution.Context.createContextStub()).search(newQuery("?id[0]=userdoc:kittens:77:88&id[1]=userdoc:kittens:1:2&id[2]=userdoc:kittens:3:4"));
    assertRendered("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<result>\n" + "<errors>\n" + "<error type=\"messagebus\" code=\"123\" message=\"userdoc:kittens:77:88 had fleas.\"/>\n" + "</errors>\n" + "<document documenttype=\"kittens\" documentid=\"userdoc:kittens:1:2\">\n" + "  <name>garfield</name>\n" + "  <description>preliminary research indicates &lt;em&gt;hatred&lt;/em&gt; of mondays. caution advised</description>\n" + "  <fluffiness>2</fluffiness>\n" + "</document>\n" + "<document documenttype=\"kittens\" documentid=\"userdoc:kittens:3:4\">\n" + "  <name>mittens</name>\n" + "  <description>it's a cat</description>\n" + "  <fluffiness>8</fluffiness>\n" + "</document>\n" + "</result>\n", xmlResult);
}
Also used : Searcher(com.yahoo.search.Searcher) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Result(com.yahoo.search.Result) Execution(com.yahoo.search.searchchain.Execution) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) Test(org.junit.Test)

Example 52 with Execution

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

the class GetSearcherTestCase method testGetMultipleDocumentsQuery.

@Test
public void testGetMultipleDocumentsQuery() 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);
    Query query = newQuery("?id[0]=userdoc:kittens:1:2&id[1]=userdoc:kittens:3:4");
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(query);
    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());
    }
    {
        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(2, result.hits().size());
    assertNull(result.hits().getErrorHit());
    assertHits(result.hits(), "userdoc:kittens:1:2", "userdoc:kittens:3:4");
    assertEquals(2, query.getHits());
}
Also used : Chain(com.yahoo.component.chain.Chain) ClusterList(com.yahoo.vespaclient.ClusterList) Query(com.yahoo.search.Query) 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 53 with Execution

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

the class GetSearcherTestCase method testDocumentFieldNoContentType.

@Test
public void testDocumentFieldNoContentType() throws Exception {
    Document doc1 = new Document(docType, new DocumentId("userdoc:kittens:5:1"));
    doc1.setFieldValue("name", "derrick");
    doc1.setFieldValue("description", "kommisar katze");
    doc1.setFieldValue("fluffiness", 0);
    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:5:1&field=description"));
    assertNull(result.hits().getErrorHit());
    assertEquals("text/xml", result.getTemplating().getTemplates().getMimeType());
    assertEquals("UTF-8", result.getTemplating().getTemplates().getEncoding());
    assertRendered("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<result>kommisar katze</result>\n", result);
}
Also used : Execution(com.yahoo.search.searchchain.Execution) Searcher(com.yahoo.search.Searcher) GetDocumentReply(com.yahoo.documentapi.messagebus.protocol.GetDocumentReply) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 54 with Execution

use of com.yahoo.search.searchchain.Execution 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 55 with Execution

use of com.yahoo.search.searchchain.Execution 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)

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