use of com.yahoo.prelude.hitfield.JSONString in project vespa by vespa-engine.
the class JSONStringTestCase method testWeightedSet.
@Test
public void testWeightedSet() {
String json = "[[{\"as1\":[\"per\",\"paal\"],\"l1\":1122334455667788997,\"d1\":87.790001,\"i1\":7,\"al1\":[11223344556677881,11223344556677883],\"s1\":\"string\\n" + "espa\u00F1a\\n" + "wssf1.s1[0]\"},10]," + "[{\"as1\":[\"per\",\"paal\"],\"l1\":1122334455667788998,\"d1\":88.790001,\"i1\":8,\"al1\":[11223344556677881,11223344556677883],\"s1\":\"string\\n" + "espa\u00F1a wssf1.s1[1]\"},20]]";
JSONString js = new JSONString(json);
String o1 = " <item weight=\"10\">\n";
String[] o1Fields = { " <struct-field name=\"l1\">1122334455667788997</struct-field>\n", " <struct-field name=\"al1\">\n" + " <item>11223344556677881</item>\n" + " <item>11223344556677883</item>\n" + " </struct-field>\n", " <struct-field name=\"i1\">7</struct-field>\n", " <struct-field name=\"d1\">87.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" + "wssf1.s1[0]</struct-field>\n" };
String o2 = " <item weight=\"20\">\n";
String[] o2Fields = { " <struct-field name=\"l1\">1122334455667788998</struct-field>\n", " <struct-field name=\"al1\">\n" + " <item>11223344556677881</item>\n" + " <item>11223344556677883</item>\n" + " </struct-field>\n", " <struct-field name=\"i1\">8</struct-field>\n", " <struct-field name=\"d1\">88.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 wssf1.s1[1]</struct-field>\n" };
String rendered = js.toString();
int o1Offset = rendered.indexOf(o1);
assertTrue(-1 < o1Offset);
int o2Offset = rendered.indexOf(o2);
assertTrue(-1 < o2Offset);
checkSubstrings(o1Fields, rendered.substring(o1Offset, o2Offset));
checkSubstrings(o2Fields, rendered, o2Offset);
}
use of com.yahoo.prelude.hitfield.JSONString in project vespa by vespa-engine.
the class JSONStringTestCase method testArrayOfArray.
@Test
public void testArrayOfArray() {
String json = "[[\"c1\", 0], [\"c2\", 2, 3], [\"c3\", 3, 4, 5], [\"c4\", 4,5,6,7]]";
JSONString js = new JSONString(json);
Inspector outer = js.inspect();
assertEquals(4, outer.entryCount());
assertEquals(2, outer.entry(0).entryCount());
assertEquals("c1", outer.entry(0).entry(0).asString());
assertEquals(0, outer.entry(0).entry(1).asLong());
assertEquals(3, outer.entry(1).entryCount());
assertEquals("c2", outer.entry(1).entry(0).asString());
assertEquals(2, outer.entry(1).entry(1).asLong());
assertEquals(3, outer.entry(1).entry(2).asLong());
assertEquals(4, outer.entry(2).entryCount());
assertEquals("c3", outer.entry(2).entry(0).asString());
assertEquals(3, outer.entry(2).entry(1).asLong());
assertEquals(4, outer.entry(2).entry(2).asLong());
assertEquals(5, outer.entry(2).entry(3).asLong());
assertEquals(5, outer.entry(3).entryCount());
assertEquals("c4", outer.entry(3).entry(0).asString());
assertEquals(4, outer.entry(3).entry(1).asLong());
assertEquals(5, outer.entry(3).entry(2).asLong());
assertEquals(6, outer.entry(3).entry(3).asLong());
assertEquals(7, outer.entry(3).entry(4).asLong());
}
use of com.yahoo.prelude.hitfield.JSONString in project vespa by vespa-engine.
the class JSONDebugSearcherTestCase method addResult.
private void addResult(Query q, String content, DocumentSourceSearcher docsource) {
Result r = new Result(q);
FastHit hit = new FastHit();
hit.setId("http://abc.html");
hit.setRelevance(new Relevance(1));
hit.setField("jsonfield", new JSONString(content));
r.hits().add(hit);
docsource.addResult(q, r);
}
use of com.yahoo.prelude.hitfield.JSONString in project vespa by vespa-engine.
the class NGramSearcherTestCase method testNGramRecombining.
public void testNGramRecombining() {
Query q = new Query("?query=ignored");
Result r = new Execution(new Chain<>(searcher, new MockBackend1()), createContextStub(indexFacts)).search(q);
Hit h1 = r.hits().get("hit1");
assertEquals("Should be untouched,\u001feven if containing \u001f", h1.getField("test").toString());
assertTrue(h1.getField("test") instanceof String);
assertEquals("Blue red Ed A", h1.getField("gram2").toString());
assertTrue(h1.getField("gram2") instanceof XMLString);
assertEquals("Separators on borders work", "Blue red ed a\u001f", h1.getField("gram3").toString());
assertTrue(h1.getField("gram3") instanceof String);
Hit h2 = r.hits().get("hit2");
assertEquals("katt i...morgen", h2.getField("gram3").toString());
assertTrue(h2.getField("gram3") instanceof JSONString);
Hit h3 = r.hits().get("hit3");
assertEquals("\u001ffin\u001f \u001fen\u001f \u001fa\u001f", h3.getField("gram2").toString());
assertEquals("#Logging in #Java is like that \"Judean P\u001fopul\u001far Front\" scene from \"Life of Brian\".", h3.getField("gram3").toString());
}
Aggregations