Search in sources :

Example 41 with Hit

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

the class FutureDataTestCase method testAsyncFederation.

@Test
public void testAsyncFederation() throws InterruptedException, ExecutionException, TimeoutException {
    // Setup environment
    AsyncProviderSearcher asyncProviderSearcher = new AsyncProviderSearcher();
    Searcher syncProviderSearcher = new SyncProviderSearcher();
    Chain<Searcher> asyncSource = new Chain<Searcher>(new ComponentId("async"), asyncProviderSearcher);
    Chain<Searcher> syncSource = new Chain<>(new ComponentId("sync"), syncProviderSearcher);
    SearchChainResolver searchChainResolver = new SearchChainResolver.Builder().addSearchChain(new ComponentId("sync"), new FederationOptions().setUseByDefault(true)).addSearchChain(new ComponentId("async"), new FederationOptions().setUseByDefault(true)).build();
    Chain<Searcher> main = new Chain<Searcher>(new FederationSearcher(new ComponentId("federator"), searchChainResolver));
    SearchChainRegistry searchChainRegistry = new SearchChainRegistry();
    searchChainRegistry.register(main);
    searchChainRegistry.register(syncSource);
    searchChainRegistry.register(asyncSource);
    Result result = new Execution(main, Execution.Context.createContextStub(searchChainRegistry, null)).search(new Query());
    assertNotNull(result);
    HitGroup syncGroup = (HitGroup) result.hits().get("source:sync");
    assertNotNull(syncGroup);
    HitGroup asyncGroup = (HitGroup) result.hits().get("source:async");
    assertNotNull(asyncGroup);
    assertEquals("Got all sync data", 3, syncGroup.size());
    assertEquals("sync:0", syncGroup.get(0).getId().toString());
    assertEquals("sync:1", syncGroup.get(1).getId().toString());
    assertEquals("sync:2", syncGroup.get(2).getId().toString());
    assertTrue(asyncGroup.incoming() == asyncProviderSearcher.incomingData);
    assertEquals("Got no async data yet", 0, asyncGroup.size());
    asyncProviderSearcher.simulateOneHitIOComplete(new Hit("async:0"));
    assertEquals("Got no async data yet, as we haven't completed the incoming buffer and there is no data listener", 0, asyncGroup.size());
    asyncProviderSearcher.simulateOneHitIOComplete(new Hit("async:1"));
    asyncProviderSearcher.simulateAllHitsIOComplete();
    assertEquals("Got no async data yet, as we haven't pulled it", 0, asyncGroup.size());
    asyncGroup.complete().get();
    assertEquals("Completed, so we have the data", 2, asyncGroup.size());
    assertEquals("async:0", asyncGroup.get(0).getId().toString());
    assertEquals("async:1", asyncGroup.get(1).getId().toString());
}
Also used : Chain(com.yahoo.component.chain.Chain) FederationSearcher(com.yahoo.search.federation.FederationSearcher) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) FederationSearcher(com.yahoo.search.federation.FederationSearcher) SearchChainResolver(com.yahoo.search.federation.sourceref.SearchChainResolver) Result(com.yahoo.search.Result) FederationOptions(com.yahoo.search.searchchain.model.federation.FederationOptions) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) SearchChainRegistry(com.yahoo.search.searchchain.SearchChainRegistry) ComponentId(com.yahoo.component.ComponentId) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 42 with Hit

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

the class JsonRendererTestCase method testJsonObjects.

@Test
public void testJsonObjects() throws InterruptedException, ExecutionException, IOException, JSONException {
    String expected = "{\n" + "    \"root\": {\n" + "        \"children\": [\n" + "            {\n" + "                \"fields\": {\n" + "                    \"inspectable\": {\n" + "                        \"a\": \"b\"\n" + "                    },\n" + "                    \"jackson\": {\n" + "                        \"Nineteen-eighty-four\": 1984\n" + "                    },\n" + "                    \"json producer\": {\n" + "                        \"long in structured\": 7809531904\n" + "                    },\n" + "                    \"org.json array\": [\n" + "                        true,\n" + "                        true,\n" + "                        false\n" + "                    ],\n" + "                    \"org.json object\": {\n" + "                        \"forty-two\": 42\n" + "                    }\n" + "                },\n" + "                \"id\": \"json objects\",\n" + "                \"relevance\": 1.0\n" + "            }\n" + "        ],\n" + "        \"fields\": {\n" + "            \"totalCount\": 0\n" + "        },\n" + "        \"id\": \"toplevel\",\n" + "        \"relevance\": 1.0\n" + "    }\n" + "}\n";
    Result r = newEmptyResult();
    Hit h = new Hit("json objects");
    JSONObject o = new JSONObject();
    JSONArray a = new JSONArray();
    ObjectMapper mapper = new ObjectMapper();
    JsonNode j = mapper.createObjectNode();
    JSONString s = new JSONString("{\"a\": \"b\"}");
    Slime slime = new Slime();
    Cursor c = slime.setObject();
    c.setLong("long in structured", 7809531904L);
    SlimeAdapter slimeInit = new SlimeAdapter(slime.get());
    StructuredData struct = new StructuredData(slimeInit);
    ((ObjectNode) j).put("Nineteen-eighty-four", 1984);
    o.put("forty-two", 42);
    a.put(true);
    a.put(true);
    a.put(false);
    h.setField("inspectable", s);
    h.setField("jackson", j);
    h.setField("json producer", struct);
    h.setField("org.json array", a);
    h.setField("org.json object", o);
    r.hits().add(h);
    String summary = render(r);
    assertEqualJson(expected, summary);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) StructuredData(com.yahoo.search.result.StructuredData) JSONArray(org.json.JSONArray) JsonNode(com.fasterxml.jackson.databind.JsonNode) JSONString(com.yahoo.prelude.hitfield.JSONString) Slime(com.yahoo.slime.Slime) Cursor(com.yahoo.slime.Cursor) Result(com.yahoo.search.Result) FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) JSONObject(org.json.JSONObject) SlimeAdapter(com.yahoo.data.access.slime.SlimeAdapter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JSONString(com.yahoo.prelude.hitfield.JSONString) Test(org.junit.Test)

Example 43 with Hit

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

the class JsonRendererTestCase method testDocumentId.

@Test
public void testDocumentId() throws IOException, InterruptedException, ExecutionException, JSONException {
    String expected = "{\n" + "    \"root\": {\n" + "        \"children\": [\n" + "            {\n" + "                \"fields\": {\n" + "                    \"documentid\": \"id:unittest:smoke::whee\"\n" + "                },\n" + "                \"id\": \"id:unittest:smoke::whee\",\n" + "                \"relevance\": 1.0\n" + "            }\n" + "        ],\n" + "        \"fields\": {\n" + "            \"totalCount\": 1\n" + "        },\n" + "        \"id\": \"toplevel\",\n" + "        \"relevance\": 1.0\n" + "    }\n" + "}\n";
    Result r = newEmptyResult();
    Hit h = new Hit("docIdTest");
    h.setField("documentid", new DocumentId("id:unittest:smoke::whee"));
    r.hits().add(h);
    r.setTotalHitCount(1L);
    String summary = render(r);
    assertEqualJson(expected, summary);
}
Also used : FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) DocumentId(com.yahoo.document.DocumentId) JSONString(com.yahoo.prelude.hitfield.JSONString) Result(com.yahoo.search.Result) Test(org.junit.Test)

Example 44 with Hit

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

the class JsonRendererTestCase method createHitWithOnlyHiddenFields.

private Hit createHitWithOnlyHiddenFields() {
    Hit h = new Hit("hiddenFields");
    h.setField("NaN", NanNumber.NaN);
    h.setField("emptyString", "");
    h.setField("emptyStringFieldValue", new StringFieldValue(""));
    h.setField("$vespaImplementationDetail", "Hello, World!");
    return h;
}
Also used : FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue)

Example 45 with Hit

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

the class JsonRendererTestCase method testDataTypes.

@Test
public void testDataTypes() throws IOException, InterruptedException, ExecutionException, JSONException {
    String expected = "{\n" + "    \"root\": {\n" + "        \"children\": [\n" + "            {\n" + "                \"fields\": {\n" + "                    \"double\": 0.00390625,\n" + "                    \"float\": 14.29,\n" + "                    \"integer\": 1,\n" + "                    \"long\": 4398046511104,\n" + "                    \"object\": \"thingie\",\n" + "                    \"string\": \"stuff\",\n" + "                    \"predicate\": \"a in [b]\",\n" + "                    \"tensor1\": { \"cells\": [ { \"address\": {\"x\": \"a\"}, \"value\":2.0 } ] },\n" + "                    \"tensor2\": { \"cells\": [] },\n" + "                    \"tensor3\": { \"cells\": [ { \"address\": {\"x\": \"a\", \"y\": \"0\"}, \"value\":2.0 }, { \"address\": {\"x\": \"a\", \"y\": \"1\"}, \"value\":-1.0 } ] }\n" + "                },\n" + "                \"id\": \"datatypestuff\",\n" + "                \"relevance\": 1.0\n" + "            }\n" + "        ],\n" + "        \"fields\": {\n" + "            \"totalCount\": 1\n" + "        },\n" + "        \"id\": \"toplevel\",\n" + "        \"relevance\": 1.0\n" + "    }\n" + "}\n";
    Result r = newEmptyResult();
    Hit h = new Hit("datatypestuff");
    // the floating point values are chosen to get a deterministic string representation
    h.setField("double", 0.00390625d);
    h.setField("float", 14.29f);
    h.setField("integer", 1);
    h.setField("long", 4398046511104L);
    h.setField("string", "stuff");
    h.setField("predicate", Predicate.fromString("a in [b]"));
    h.setField("tensor1", new TensorFieldValue(Tensor.from("{ {x:a}: 2.0}")));
    h.setField("tensor2", new TensorFieldValue(TensorType.empty));
    h.setField("tensor3", Tensor.from("{ {x:a, y:0}: 2.0, {x:a, y:1}: -1 }"));
    h.setField("object", new Thingie());
    r.hits().add(h);
    r.setTotalHitCount(1L);
    String summary = render(r);
    assertEqualJson(expected, summary);
}
Also used : TensorFieldValue(com.yahoo.document.datatypes.TensorFieldValue) FastHit(com.yahoo.prelude.fastsearch.FastHit) Hit(com.yahoo.search.result.Hit) JSONString(com.yahoo.prelude.hitfield.JSONString) Result(com.yahoo.search.Result) Test(org.junit.Test)

Aggregations

Hit (com.yahoo.search.result.Hit)127 Result (com.yahoo.search.Result)72 Query (com.yahoo.search.Query)52 FastHit (com.yahoo.prelude.fastsearch.FastHit)42 Test (org.junit.Test)41 Execution (com.yahoo.search.searchchain.Execution)25 HitGroup (com.yahoo.search.result.HitGroup)21 Searcher (com.yahoo.search.Searcher)17 JSONString (com.yahoo.prelude.hitfield.JSONString)13 GroupingListHit (com.yahoo.prelude.fastsearch.GroupingListHit)12 ErrorHit (com.yahoo.search.result.ErrorHit)10 Relevance (com.yahoo.search.result.Relevance)10 HashMap (java.util.HashMap)9 DocumentSourceSearcher (com.yahoo.prelude.searcher.DocumentSourceSearcher)8 Group (com.yahoo.search.grouping.result.Group)8 ComponentId (com.yahoo.component.ComponentId)7 Chain (com.yahoo.component.chain.Chain)7 FS4Hit (com.yahoo.searchlib.aggregation.FS4Hit)6 VdsHit (com.yahoo.searchlib.aggregation.VdsHit)6 GroupList (com.yahoo.search.grouping.result.GroupList)5