Search in sources :

Example 51 with Query

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

the class XmlReadingTestCase method testSourceProvider.

@Test
public void testSourceProvider() {
    CompiledQueryProfileRegistry registry = new QueryProfileXMLReader().read("src/test/java/com/yahoo/search/query/profile/config/test/sourceprovider").compile();
    String queryString = "tiled?query=india&queryProfile=myprofile&source.common.intl=tw&source.common.mode=adv";
    Query query = new Query(HttpRequest.createTestRequest(queryString, Method.GET), registry.getComponent("myprofile"));
    for (Map.Entry e : query.properties().listProperties().entrySet()) System.out.println(e);
    assertEquals("news", query.properties().listProperties().get("source.common.provider"));
    assertEquals("news", query.properties().get("source.common.provider"));
}
Also used : CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) Query(com.yahoo.search.Query) QueryProfileXMLReader(com.yahoo.search.query.profile.config.QueryProfileXMLReader) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 52 with Query

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

the class XmlReadingTestCase method testNewsFE1.

@Test
public void testNewsFE1() {
    CompiledQueryProfileRegistry registry = new QueryProfileXMLReader().read("src/test/java/com/yahoo/search/query/profile/config/test/newsfe").compile();
    String queryString = "tiled?vertical=news&query=barack&intl=us&resulttypes=article&testid=&clientintl=us&SpellState=&rss=0&tracelevel=5";
    Query query = new Query(HttpRequest.createTestRequest(queryString, Method.GET), registry.getComponent("default"));
    assertEquals("13", query.properties().listProperties().get("source.news.discovery.sources.count"));
    assertEquals("13", query.properties().get("source.news.discovery.sources.count"));
    assertEquals("sources", query.properties().listProperties().get("source.news.discovery"));
    assertEquals("sources", query.properties().get("source.news.discovery"));
}
Also used : CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) Query(com.yahoo.search.Query) QueryProfileXMLReader(com.yahoo.search.query.profile.config.QueryProfileXMLReader) Test(org.junit.Test)

Example 53 with Query

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

the class XmlReadingTestCase method testQueryProfileVariants2.

@Test
public void testQueryProfileVariants2() {
    CompiledQueryProfileRegistry registry = new QueryProfileXMLReader().read("src/test/java/com/yahoo/search/query/profile/config/test/queryprofilevariants2").compile();
    CompiledQueryProfile multi = registry.getComponent("multi");
    {
        Query query = new Query(HttpRequest.createTestRequest("?queryProfile=multi", Method.GET), multi);
        query.validate();
        assertEquals("best", query.properties().get("model.queryString"));
        assertEquals("best", query.getModel().getQueryString());
    }
    {
        Query query = new Query(HttpRequest.createTestRequest("?queryProfile=multi&myindex=default", Method.GET), multi);
        query.validate();
        assertEquals("best", query.properties().get("model.queryString"));
        assertEquals("best", query.getModel().getQueryString());
        assertEquals("default", query.getModel().getDefaultIndex());
    }
    {
        Query query = new Query(HttpRequest.createTestRequest("?queryProfile=multi&myindex=default&myquery=love", Method.GET), multi);
        query.validate();
        assertEquals("love", query.properties().get("model.queryString"));
        assertEquals("love", query.getModel().getQueryString());
        assertEquals("default", query.getModel().getDefaultIndex());
    }
    {
        Query query = new Query(HttpRequest.createTestRequest("?model=querybest", Method.GET), multi);
        query.validate();
        assertEquals("best", query.getModel().getQueryString());
        assertEquals("title", query.properties().get("model.defaultIndex"));
        assertEquals("title", query.getModel().getDefaultIndex());
    }
}
Also used : CompiledQueryProfileRegistry(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry) CompiledQueryProfile(com.yahoo.search.query.profile.compiled.CompiledQueryProfile) Query(com.yahoo.search.Query) QueryProfileXMLReader(com.yahoo.search.query.profile.config.QueryProfileXMLReader) Test(org.junit.Test)

Example 54 with Query

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

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

the class ResultBuilderTestCase method testSimpleResult.

public void testSimpleResult() {
    boolean gotErrorDetails = false;
    ResultBuilder r = new ResultBuilder();
    Result res = r.parse("file:src/test/java/com/yahoo/prelude/searcher/test/testhit.xml", new Query("?query=a"));
    assertEquals(3, res.getConcreteHitCount());
    assertEquals(4, res.getHitCount());
    ErrorHit e = (ErrorHit) res.hits().get(0);
    // is no way of nuking an existing error if the details exist.
    for (Iterator<?> i = e.errorIterator(); i.hasNext(); ) {
        ErrorMessage err = (ErrorMessage) i.next();
        assertEquals(5, err.getCode());
        String details = err.getDetailedMessage();
        if (details != null) {
            gotErrorDetails = true;
            assertEquals("An error as ordered", details.trim());
        }
    }
    assertTrue("Error details are missing", gotErrorDetails);
    assertEquals(new URI("http://def"), res.hits().get(1).getId());
    assertEquals("test/stuff\\tsome/other", res.hits().get(2).getField("category"));
    assertEquals("<field>habla</field>" + "<hi>blbl</hi><br />&lt;&gt;&amp;fdlkkgj&lt;/field&gt;;lk<a b=\"1\" c=\"2\" />" + "<x><y><z /></y></x>", res.hits().get(3).getField("annoying").toString());
}
Also used : ResultBuilder(com.yahoo.search.federation.vespa.ResultBuilder) Query(com.yahoo.search.Query) ErrorHit(com.yahoo.search.result.ErrorHit) ErrorMessage(com.yahoo.search.result.ErrorMessage) URI(com.yahoo.net.URI) Result(com.yahoo.search.Result)

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