Search in sources :

Example 1 with XMLString

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);
    }
}
Also used : Hit(com.yahoo.search.result.Hit) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) XMLString(com.yahoo.prelude.hitfield.XMLString) Result(com.yahoo.search.Result)

Example 2 with XMLString

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;
}
Also used : HitField(com.yahoo.prelude.hitfield.HitField) XMLString(com.yahoo.prelude.hitfield.XMLString)

Example 3 with XMLString

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);
        }
    }
}
Also used : XMLString(com.yahoo.prelude.hitfield.XMLString)

Example 4 with XMLString

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]);
}
Also used : Hit(com.yahoo.search.result.Hit) Query(com.yahoo.search.Query) XMLString(com.yahoo.prelude.hitfield.XMLString) XMLString(com.yahoo.prelude.hitfield.XMLString) Result(com.yahoo.search.Result)

Example 5 with XMLString

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());
}
Also used : Chain(com.yahoo.component.chain.Chain) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) Query(com.yahoo.search.Query) XMLString(com.yahoo.prelude.hitfield.XMLString) JSONString(com.yahoo.prelude.hitfield.JSONString) XMLString(com.yahoo.prelude.hitfield.XMLString) JSONString(com.yahoo.prelude.hitfield.JSONString) Result(com.yahoo.search.Result)

Aggregations

XMLString (com.yahoo.prelude.hitfield.XMLString)5 Result (com.yahoo.search.Result)3 Hit (com.yahoo.search.result.Hit)3 Query (com.yahoo.search.Query)2 Chain (com.yahoo.component.chain.Chain)1 HitField (com.yahoo.prelude.hitfield.HitField)1 JSONString (com.yahoo.prelude.hitfield.JSONString)1 Execution (com.yahoo.search.searchchain.Execution)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1