Search in sources :

Example 86 with Searcher

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

the class GetSearcherTestCase method testBadPriorityValue.

@Test
public void testBadPriorityValue() 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=userdoc:kittens:1:2&priority=onkel_jubalon"));
    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: No enum const" + (Util.isJava7Compatible() ? "ant " : " class ") + "com.yahoo.documentapi.messagebus.protocol.DocumentProtocol" + (Util.isJava7Compatible() ? "." : "$") + "Priority.onkel_jubalon\"/>\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 87 with Searcher

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

the class GetSearcherTestCase method testJsonRendererSetting.

@Test
public void testJsonRendererSetting() 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);
    Query query = newQuery("?id=userdoc:kittens:1:2&format=json");
    Result result = new Execution(searchChain, Execution.Context.createContextStub()).search(query);
    assertFalse(result.getTemplating().getTemplates() instanceof DocumentXMLTemplate);
}
Also used : Chain(com.yahoo.component.chain.Chain) ClusterList(com.yahoo.vespaclient.ClusterList) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) Result(com.yahoo.search.Result) Execution(com.yahoo.search.searchchain.Execution) FeedContext(com.yahoo.feedapi.FeedContext) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor) NullFeedMetric(com.yahoo.feedhandler.NullFeedMetric) Test(org.junit.Test)

Example 88 with Searcher

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

the class GetSearcherTestCase method testVespaXMLTemplate.

@Test
public void testVespaXMLTemplate() throws Exception {
    Document doc1 = new Document(docType, new DocumentId("userdoc:kittens:3:4"));
    doc1.setFieldValue("name", "mittens");
    doc1.setFieldValue("description", "it's a cat");
    doc1.setFieldValue("fluffiness", 8);
    Document doc2 = new Document(docType, new DocumentId("userdoc:kittens:1:2"));
    doc2.setFieldValue("name", "garfield");
    doc2.setFieldValue("description", "preliminary research indicates <em>hatred</em> of mondays. caution advised");
    doc2.setFieldValue("fluffiness", 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 lost in a <ni!>\"shrubbery\"</ni!>"));
    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 result = new Execution(searchChain, Execution.Context.createContextStub()).search(// TODO!
    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 lost in a &lt;ni!&gt;&quot;shrubbery&quot;&lt;/ni!&gt;\"/>\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", 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 89 with Searcher

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

the class GetSearcherTestCase method testDocumentFieldEscapeXML.

@Test
public void testDocumentFieldEscapeXML() throws Exception {
    Document doc1 = new Document(docType, new DocumentId("userdoc:kittens:5:1"));
    doc1.setFieldValue("name", "asfd");
    doc1.setFieldValue("description", "<script type=\"evil/madness\">horror & screams</script>");
    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>&lt;script type=\"evil/madness\"&gt;horror &amp; screams&lt;/script&gt;</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 90 with Searcher

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

the class FederationSearcherTestCase method testNoCloning.

@Test
public void testNoCloning() {
    String sourceName = "cloningcheck";
    Query query = new Query(QueryTestCase.httpEncode("?query=test&sources=" + sourceName));
    addChained(new QueryCheckSearcher(query), sourceName);
    addChained(new MockSearcher(), "mySource1");
    Chain<Searcher> mainChain = new Chain<>("default", createStrictFederationSearcher());
    Result result = new Execution(mainChain, Execution.Context.createContextStub(chainRegistry, null)).search(query);
    HitGroup h = (HitGroup) result.hits().get(0);
    assertNull(h.getErrorHit());
    assertSame(QueryCheckSearcher.OK, h.get(0).getField(QueryCheckSearcher.STATUS));
    mainChain = new Chain<>("default", createFederationSearcher());
    result = new Execution(mainChain, Execution.Context.createContextStub(chainRegistry, null)).search(query);
    h = (HitGroup) result.hits().get(0);
    assertSame(QueryCheckSearcher.FEDERATION_SEARCHER_HAS_CLONED_THE_QUERY, h.getError().getDetailedMessage());
    query = new Query(QueryTestCase.httpEncode("?query=test&sources=" + sourceName + ",mySource1"));
    addChained(new QueryCheckSearcher(query), sourceName);
    result = new Execution(mainChain, Execution.Context.createContextStub(chainRegistry, null)).search(query);
    h = (HitGroup) result.hits().get(0);
    assertEquals("source:" + sourceName, h.getId().stringValue());
    assertSame(QueryCheckSearcher.FEDERATION_SEARCHER_HAS_CLONED_THE_QUERY, h.getError().getDetailedMessage());
    assertEquals("source:mySource1", result.hits().get(1).getId().stringValue());
}
Also used : Chain(com.yahoo.component.chain.Chain) SearchChain(com.yahoo.search.searchchain.SearchChain) 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) HitGroup(com.yahoo.search.result.HitGroup) 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