Search in sources :

Example 11 with JSONString

use of com.yahoo.prelude.hitfield.JSONString in project vespa by vespa-engine.

the class JSONDebugSearcher method search.

public Result search(com.yahoo.search.Query query, Execution execution) {
    Result r = execution.search(query);
    String propertyName = query.properties().getString(PROPERTYNAME);
    if (propertyName != null) {
        execution.fill(r);
        for (Iterator<Hit> i = r.hits().deepIterator(); i.hasNext(); ) {
            Hit h = i.next();
            if (h instanceof FastHit) {
                FastHit hit = (FastHit) h;
                Object o = hit.getField(propertyName);
                if (o instanceof JSONString) {
                    JSONString j = (JSONString) o;
                    r.getQuery().trace(JSON_FIELD + j.getContent(), false, 5);
                }
                if (o instanceof StructuredData) {
                    StructuredData d = (StructuredData) o;
                    r.getQuery().trace(STRUCT_FIELD + d.toJson(), false, 5);
                }
                if (o instanceof FeatureData) {
                    FeatureData d = (FeatureData) o;
                    r.getQuery().trace(FEATURE_FIELD + d.toJson(), false, 5);
                }
            }
        }
    }
    return r;
}
Also used : Hit(com.yahoo.search.result.Hit) FastHit(com.yahoo.prelude.fastsearch.FastHit) FastHit(com.yahoo.prelude.fastsearch.FastHit) StructuredData(com.yahoo.search.result.StructuredData) FeatureData(com.yahoo.search.result.FeatureData) JSONString(com.yahoo.prelude.hitfield.JSONString) JSONString(com.yahoo.prelude.hitfield.JSONString) Result(com.yahoo.search.Result)

Example 12 with JSONString

use of com.yahoo.prelude.hitfield.JSONString in project vespa by vespa-engine.

the class JSONStringTestCase method testArrayOfStruct.

@Test
public void testArrayOfStruct() {
    String json = "[{\"as1\":[\"per\",\"paal\"]," + "\"l1\":1122334455667788994,\"d1\":74.790001," + "\"i1\":14,\"al1\":[11223344556677881,11223344556677883],\"s1\":\"string\\n" + "espa\u00F1a\\n" + "asf1[0].s1\"},{\"as1\":[\"per\",\"paal\"],\"l1\":1122334455667788995,\"d1\":75.790001,\"i1\":15,\"al1\":[11223344556677881,11223344556677883],\"s1\":\"string\\n" + "espa\u00F1a asf1[1].s1\"}]";
    JSONString js = new JSONString(json);
    String[] o1Fields = { "\n      <item>\n", "        <struct-field name=\"l1\">1122334455667788994</struct-field>\n", "        <struct-field name=\"al1\">\n" + "          <item>11223344556677881</item>\n" + "          <item>11223344556677883</item>\n" + "        </struct-field>\n", "        <struct-field name=\"i1\">14</struct-field>\n", "        <struct-field name=\"d1\">74.790001</struct-field>\n", "        <struct-field name=\"as1\">\n" + "          <item>per</item>\n" + "          <item>paal</item>\n" + "        </struct-field>\n", "        <struct-field name=\"s1\">string\n" + "españa\n" + "asf1[0].s1</struct-field>\n" };
    String separator = "      </item>\n" + "      <item>\n";
    String[] o2Fields = { "        <struct-field name=\"l1\">1122334455667788995</struct-field>\n", "        <struct-field name=\"al1\">\n" + "          <item>11223344556677881</item>\n" + "          <item>11223344556677883</item>\n" + "        </struct-field>\n", "        <struct-field name=\"i1\">15</struct-field>\n", "        <struct-field name=\"d1\">75.790001</struct-field>\n", "        <struct-field name=\"as1\">\n" + "          <item>per</item>\n" + "          <item>paal</item>\n" + "        </struct-field>\n", "        <struct-field name=\"s1\">string\n" + "españa asf1[1].s1</struct-field>\n" };
    String rendered = js.toString();
    int o2Offset = rendered.indexOf(separator);
    assertTrue(-1 < o2Offset);
    checkSubstrings(o1Fields, rendered);
    checkSubstrings(o2Fields, rendered, o2Offset);
    Inspector top = new Value.ArrayValue().add(new Value.ObjectValue().put("d1", 74.790001).put("s1", "string\n" + "espa\u00F1a\n" + "asf1[0].s1").put("al1", new Value.ArrayValue().add(11223344556677881L).add(11223344556677883L)).put("l1", 1122334455667788994L).put("as1", new Value.ArrayValue().add("per").add("paal")).put("i1", 14)).add(new Value.ObjectValue().put("d1", 75.790001).put("s1", "string\n" + "espa\u00F1a asf1[1].s1").put("al1", new Value.ArrayValue().add(11223344556677881L).add(11223344556677883L)).put("l1", 1122334455667788995L).put("as1", new Value.ArrayValue().add(new Value.StringValue("per")).add(new Value.StringValue("paal"))).put("i1", 15));
    js = new JSONString(top);
    rendered = js.renderFromInspector();
    o2Offset = rendered.indexOf(separator);
    assertTrue(-1 < o2Offset);
    checkSubstrings(o1Fields, rendered.substring(0, o2Offset));
    checkSubstrings(o2Fields, rendered, o2Offset);
}
Also used : Value(com.yahoo.data.access.simple.Value) Inspector(com.yahoo.data.access.Inspector) JSONString(com.yahoo.prelude.hitfield.JSONString) JSONString(com.yahoo.prelude.hitfield.JSONString) Test(org.junit.Test)

Example 13 with JSONString

use of com.yahoo.prelude.hitfield.JSONString in project vespa by vespa-engine.

the class JSONStringTestCase method testWeightedSetFromInspector.

@Test
public void testWeightedSetFromInspector() {
    Value.ArrayValue top = new Value.ArrayValue();
    top.add(new Value.ArrayValue().add(new Value.ObjectValue().put("d1", new Value.DoubleValue(87.790001)).put("s1", new Value.StringValue("string\n" + "espa\u00F1a\n" + "wssf1.s1[0]")).put("al1", new Value.ArrayValue().add(new Value.LongValue(11223344556677881L)).add(new Value.LongValue(11223344556677883L))).put("l1", new Value.LongValue(1122334455667788997L)).put("as1", new Value.ArrayValue().add(new Value.StringValue("per")).add(new Value.StringValue("paal"))).put("i1", new Value.LongValue(7))).add(new Value.LongValue(10))).add(new Value.ArrayValue().add(new Value.ObjectValue().put("d1", new Value.DoubleValue(88.790001)).put("s1", new Value.StringValue("string\n" + "espa\u00F1a wssf1.s1[1]")).put("al1", new Value.ArrayValue().add(new Value.LongValue(11223344556677881L)).add(new Value.LongValue(11223344556677883L))).put("l1", new Value.LongValue(1122334455667788998L)).put("as1", new Value.ArrayValue().add(new Value.StringValue("per")).add(new Value.StringValue("paal"))).put("i1", new Value.LongValue(8))).add(new Value.LongValue(20)));
    JSONString js = new JSONString(top);
    String correct = "\n" + "      <item weight=\"10\">\n" + "        <struct-field name=\"d1\">87.790001</struct-field>\n" + "        <struct-field name=\"s1\">string\n" + "espa\u00F1a\n" + "wssf1.s1[0]</struct-field>\n" + "        <struct-field name=\"al1\">\n" + "          <item>11223344556677881</item>\n" + "          <item>11223344556677883</item>\n" + "        </struct-field>\n" + "        <struct-field name=\"l1\">1122334455667788997</struct-field>\n" + "        <struct-field name=\"as1\">\n" + "          <item>per</item>\n" + "          <item>paal</item>\n" + "        </struct-field>\n" + "        <struct-field name=\"i1\">7</struct-field>\n" + "      </item>\n" + "      <item weight=\"20\">\n" + "        <struct-field name=\"d1\">88.790001</struct-field>\n" + "        <struct-field name=\"s1\">string\n" + "espa\u00F1a wssf1.s1[1]</struct-field>\n" + "        <struct-field name=\"al1\">\n" + "          <item>11223344556677881</item>\n" + "          <item>11223344556677883</item>\n" + "        </struct-field>\n" + "        <struct-field name=\"l1\">1122334455667788998</struct-field>\n" + "        <struct-field name=\"as1\">\n" + "          <item>per</item>\n" + "          <item>paal</item>\n" + "        </struct-field>\n" + "        <struct-field name=\"i1\">8</struct-field>\n" + "      </item>\n" + "    ";
    assertEquals(correct, js.renderFromInspector());
    top = new Value.ArrayValue();
    top.add(new Value.ArrayValue().add(new Value.StringValue("s1")).add(new Value.LongValue(10))).add(new Value.ArrayValue().add(new Value.StringValue("s2")).add(new Value.LongValue(20)));
    js = new JSONString(top);
    correct = "\n" + "      <item weight=\"10\">s1</item>\n" + "      <item weight=\"20\">s2</item>\n" + "    ";
    assertEquals(correct, js.renderFromInspector());
}
Also used : JSONString(com.yahoo.prelude.hitfield.JSONString) Value(com.yahoo.data.access.simple.Value) JSONString(com.yahoo.prelude.hitfield.JSONString) Test(org.junit.Test)

Example 14 with JSONString

use of com.yahoo.prelude.hitfield.JSONString in project vespa by vespa-engine.

the class JSONStringTestCase method testArrayOfStructWithMap.

/**
 * here is some json for you
 *
 *     [{"asf":"here is 1st simple string field",
 *     "map":[{"key":"one key string","value":["one value string","embedded array"]},
 *     {"key":"two key string","value":["two value string","embedded array"]}],
 *     "sf2":"here is 2nd simple string field"},
 *     {"asf":"here is 3rd simple string field",
 *     "map":[{"key":"three key string","value":["three value string","embedded array"]},
 *     {"key":"four key string","value":["four value string","embedded array"]}],
 *     "sf2":"here is 4th simple string field"},
 *     ]
 *
 **
 */
/**
 * and here is some corresponding XML
 *
 *     <item>
 *     <struct-field name="asf">here is 1st simple string field</struct-field>
 *     <struct-field name="map">
 *     <item><key>one key string</key><value>
 *     <item>one value string</item>
 *     <item>embedded array</item>
 *     </value></item>
 *     <item><key>two key string</key><value>
 *     <item>two value string</item>
 *     <item>embedded array</item>
 *     </value></item>
 *     </struct-field>
 *     <struct-field name="sf2">here is 2nd simple string field</struct-field>
 *     </item>
 *     <item>
 *     <struct-field name="asf">here is 3rd simple string field</struct-field>
 *     <struct-field name="map">
 *     <item><key>three key string</key><value>
 *     <item>three value string</item>
 *     <item>embedded array</item>
 *     </value></item>
 *     <item><key>four key string</key><value>
 *     <item>four value string</item>
 *     <item>embedded array</item>
 *     </value></item>
 *     </struct-field>
 *     <struct-field name="sf2">here is 4th simple string field</struct-field>
 *     </item>
 *
 **
 */
@Test
public void testArrayOfStructWithMap() {
    String json = "[{\"asf\":\"here is 1st simple string field\",\"map\":[{\"key\":\"one key string\",\"value\":[\"one value string\",\"embedded array\"]},{\"key\":\"two key string\",\"value\":[\"two value string\",\"embedded array\"]}],\"sf2\":\"here is 2nd simple string field\"},{\"asf\":\"here is 3rd simple string field\",\"map\":[{\"key\":\"three key string\",\"value\":[\"three value string\",\"embedded array\"]},{\"key\":\"four key string\",\"value\":[\"four value string\",\"embedded array\"]}],\"sf2\":\"here is 4th simple string field\"}]";
    JSONString js = new JSONString(json);
    String correct = "\n" + "      <item>\n" + "        <struct-field name=\"asf\">here is 1st simple string field</struct-field>\n" + "        <struct-field name=\"map\">\n" + "          <item><key>one key string</key><value>\n" + "            <item>one value string</item>\n" + "            <item>embedded array</item>\n" + "          </value></item>\n" + "          <item><key>two key string</key><value>\n" + "            <item>two value string</item>\n" + "            <item>embedded array</item>\n" + "          </value></item>\n" + "        </struct-field>\n" + "        <struct-field name=\"sf2\">here is 2nd simple string field</struct-field>\n" + "      </item>\n" + "      <item>\n" + "        <struct-field name=\"asf\">here is 3rd simple string field</struct-field>\n" + "        <struct-field name=\"map\">\n" + "          <item><key>three key string</key><value>\n" + "            <item>three value string</item>\n" + "            <item>embedded array</item>\n" + "          </value></item>\n" + "          <item><key>four key string</key><value>\n" + "            <item>four value string</item>\n" + "            <item>embedded array</item>\n" + "          </value></item>\n" + "        </struct-field>\n" + "        <struct-field name=\"sf2\">here is 4th simple string field</struct-field>\n" + "      </item>\n" + "    ";
    assertEquals(correct, js.toString());
    Inspector top = new Value.ArrayValue().add(new Value.ObjectValue().put("asf", "here is 1st simple string field").put("map", new Value.ArrayValue().add(new Value.ObjectValue().put("key", "one key string").put("value", new Value.ArrayValue().add("one value string").add("embedded array"))).add(new Value.ObjectValue().put("key", "two key string").put("value", new Value.ArrayValue().add("two value string").add("embedded array")))).put("sf2", "here is 2nd simple string field")).add(new Value.ObjectValue().put("asf", "here is 3rd simple string field").put("map", new Value.ArrayValue().add(new Value.ObjectValue().put("key", "three key string").put("value", new Value.ArrayValue().add("three value string").add("embedded array"))).add(new Value.ObjectValue().put("key", "four key string").put("value", new Value.ArrayValue().add("four value string").add("embedded array")))).put("sf2", "here is 4th simple string field"));
    js = new JSONString(top);
    assertEquals(correct, js.renderFromInspector());
}
Also used : Value(com.yahoo.data.access.simple.Value) Inspector(com.yahoo.data.access.Inspector) JSONString(com.yahoo.prelude.hitfield.JSONString) JSONString(com.yahoo.prelude.hitfield.JSONString) Test(org.junit.Test)

Example 15 with JSONString

use of com.yahoo.prelude.hitfield.JSONString in project vespa by vespa-engine.

the class JSONStringTestCase method testSimpleArrays.

@Test
public void testSimpleArrays() {
    String json = "[1, 2, 3]";
    JSONString js = new JSONString(json);
    String correct = "\n" + "      <item>1</item>\n" + "      <item>2</item>\n" + "      <item>3</item>\n    ";
    assertEquals(correct, js.toString());
    Inspector top = new Value.ArrayValue().add(1).add(2).add(3);
    js = new JSONString(top);
    assertEquals(correct, js.renderFromInspector());
    json = "[1.0, 2.0, 3.0]";
    js = new JSONString(json);
    correct = "\n" + "      <item>1.0</item>\n" + "      <item>2.0</item>\n" + "      <item>3.0</item>\n    ";
    assertEquals(correct, js.toString());
    top = new Value.ArrayValue().add(1.0).add(2.0).add(3.0);
    js = new JSONString(top);
    assertEquals(correct, js.renderFromInspector());
    json = "[\"a\", \"b\", \"c\"]";
    correct = "\n" + "      <item>a</item>\n" + "      <item>b</item>\n" + "      <item>c</item>\n    ";
    js = new JSONString(json);
    assertEquals(correct, js.toString());
    top = new Value.ArrayValue().add("a").add("b").add("c");
    js = new JSONString(top);
    assertEquals(correct, js.renderFromInspector());
}
Also used : Value(com.yahoo.data.access.simple.Value) Inspector(com.yahoo.data.access.Inspector) JSONString(com.yahoo.prelude.hitfield.JSONString) JSONString(com.yahoo.prelude.hitfield.JSONString) Test(org.junit.Test)

Aggregations

JSONString (com.yahoo.prelude.hitfield.JSONString)19 Test (org.junit.Test)15 Inspector (com.yahoo.data.access.Inspector)8 Value (com.yahoo.data.access.simple.Value)7 XMLString (com.yahoo.prelude.hitfield.XMLString)4 Result (com.yahoo.search.Result)4 FastHit (com.yahoo.prelude.fastsearch.FastHit)3 Hit (com.yahoo.search.result.Hit)3 StructuredData (com.yahoo.search.result.StructuredData)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Chain (com.yahoo.component.chain.Chain)1 SlimeAdapter (com.yahoo.data.access.slime.SlimeAdapter)1 SlowInflate (com.yahoo.io.SlowInflate)1 RawData (com.yahoo.prelude.hitfield.RawData)1 Query (com.yahoo.search.Query)1 FeatureData (com.yahoo.search.result.FeatureData)1 Relevance (com.yahoo.search.result.Relevance)1 Execution (com.yahoo.search.searchchain.Execution)1