use of com.yahoo.prelude.hitfield.XMLString in project vespa by vespa-engine.
the class SimpleSearcher method search.
public Result search(Query query, Execution execution) {
try {
BooleanParser.parseBoolean("true");
XMLString xmlString = new XMLString("<sampleXmlString/>");
Hit hit = new Hit("Hello world!");
hit.setField("json", new JSONObject().put("price", 42).toString());
Result result = execution.search(query);
result.hits().add(hit);
return result;
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
use of com.yahoo.prelude.hitfield.XMLString in project vespa by vespa-engine.
the class Hit method buildHitField.
public HitField buildHitField(String key, boolean forceNoPreTokenize, boolean forceStringHandling) {
Object o = getField(key);
if (o == null) {
return null;
}
if (o instanceof HitField) {
return (HitField) o;
}
HitField h;
if (forceNoPreTokenize) {
if (o instanceof XMLString && !forceStringHandling) {
h = new HitField(key, (XMLString) o, false);
} else {
h = new HitField(key, o.toString(), false);
}
} else {
if (o instanceof XMLString && !forceStringHandling) {
h = new HitField(key, (XMLString) o);
} else {
h = new HitField(key, o.toString());
}
}
h.setOriginal(o);
getFieldMap().put(key, h);
return h;
}
use of com.yahoo.prelude.hitfield.XMLString in project vespa by vespa-engine.
the class ResultBuilder method endElementInHitField.
private void endElementInHitField(String qName) {
if (FIELD.equals(qName) && --fieldLevel == 0) {
Object content;
if (hasLiteralTags) {
content = new XMLString(fieldContent.toString());
} else {
content = fieldContent.toString();
}
hitFields.put(fieldName, content);
if ("collapseId".equals(fieldName)) {
hitFields.put(fieldName, Integer.valueOf(content.toString()));
}
fieldName = null;
fieldContent = null;
tagStack = null;
} else {
Tag prevTag = tagStack.get(tagStack.size() - 1);
if (qName.equals(prevTag.name) && offset == (prevTag.offset + 1)) {
fieldContent.append(" />");
} else {
fieldContent.append("</").append(qName).append('>');
}
if (prevTag.name.equals(qName)) {
tagStack.remove(tagStack.size() - 1);
}
}
}
use of com.yahoo.prelude.hitfield.XMLString in project vespa by vespa-engine.
the class ArrayOutputTestCase method testArrayOutput.
public void testArrayOutput() throws IOException {
Result r = new Result(new Query("?query=ignored"));
Hit hit = new Hit("test");
hit.setField("phone", new XMLString("\n <item>408-555-1234</item>" + "\n <item>408-555-5678</item>\n "));
r.hits().add(hit);
String rendered = TilingTestCase.getRendered(r);
String[] lines = rendered.split("\n");
assertEquals(" <field name=\"phone\">", lines[4]);
assertEquals(" <item>408-555-1234</item>", lines[5]);
assertEquals(" <item>408-555-5678</item>", lines[6]);
assertEquals(" </field>", lines[7]);
}
use of com.yahoo.prelude.hitfield.XMLString 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