Search in sources :

Example 1 with Option

use of org.elasticsearch.search.suggest.term.TermSuggestion.Entry.Option in project elasticsearch by elastic.

the class TermSuggestionOptionTests method testFromXContent.

public void testFromXContent() throws IOException {
    Option option = createTestItem();
    XContentType xContentType = randomFrom(XContentType.values());
    boolean humanReadable = randomBoolean();
    BytesReference originalBytes = toXContent(option, xContentType, humanReadable);
    Option parsed;
    try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
        ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
        parsed = Option.fromXContent(parser);
        assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken());
        assertNull(parser.nextToken());
    }
    assertEquals(option.getText(), parsed.getText());
    assertEquals(option.getScore(), parsed.getScore(), Float.MIN_VALUE);
    assertEquals(option.getFreq(), parsed.getFreq());
    assertToXContentEquivalent(originalBytes, toXContent(parsed, xContentType, humanReadable), xContentType);
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) XContentType(org.elasticsearch.common.xcontent.XContentType) Option(org.elasticsearch.search.suggest.term.TermSuggestion.Entry.Option) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Example 2 with Option

use of org.elasticsearch.search.suggest.term.TermSuggestion.Entry.Option in project elasticsearch by elastic.

the class TermSuggestionOptionTests method testToXContent.

public void testToXContent() throws IOException {
    Option option = new Option(new Text("someText"), 100, 1.3f);
    BytesReference xContent = toXContent(option, XContentType.JSON, randomBoolean());
    assertEquals("{\"text\":\"someText\",\"score\":1.3,\"freq\":100}", xContent.utf8ToString());
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) Option(org.elasticsearch.search.suggest.term.TermSuggestion.Entry.Option) Text(org.elasticsearch.common.text.Text)

Example 3 with Option

use of org.elasticsearch.search.suggest.term.TermSuggestion.Entry.Option in project elasticsearch by elastic.

the class TermSuggestionOptionTests method createTestItem.

public static Option createTestItem() {
    Text text = new Text(randomAsciiOfLengthBetween(5, 15));
    float score = randomFloat();
    int freq = randomInt();
    return new Option(text, freq, score);
}
Also used : Text(org.elasticsearch.common.text.Text) Option(org.elasticsearch.search.suggest.term.TermSuggestion.Entry.Option)

Aggregations

Option (org.elasticsearch.search.suggest.term.TermSuggestion.Entry.Option)3 BytesReference (org.elasticsearch.common.bytes.BytesReference)2 Text (org.elasticsearch.common.text.Text)2 XContentParser (org.elasticsearch.common.xcontent.XContentParser)1 XContentType (org.elasticsearch.common.xcontent.XContentType)1