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);
}
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());
}
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);
}
Aggregations