@Override public void doWriteTo(StreamOutput out) throws IOException { suggestMode.writeTo(out); out.writeFloat(accuracy); sort.writeTo(out); stringDistance.writeTo(out); out.writeVInt(maxEdits); out.writeVInt(maxInspections); out.writeFloat(maxTermFreq); out.writeVInt(prefixLength); out.writeVInt(minWordLength); out.writeFloat(minDocFreq); }
/** Read from a stream. */ TermSuggestionBuilder(StreamInput in) throws IOException { super(in); suggestMode = SuggestMode.readFromStream(in); accuracy = in.readFloat(); sort = SortBy.readFromStream(in); stringDistance = StringDistanceImpl.readFromStream(in); maxEdits = in.readVInt(); maxInspections = in.readVInt(); maxTermFreq = in.readFloat(); prefixLength = in.readVInt(); minWordLength = in.readVInt(); minDocFreq = in.readFloat(); }
static TermSuggestionBuilder innerFromXContent(QueryParseContext parseContext) throws IOException { XContentParser parser = parseContext.parser(); TermSuggestionBuilder tmpSuggestion = new TermSuggestionBuilder("_na_"); ParseFieldMatcher parseFieldMatcher = parseContext.getParseFieldMatcher(); XContentParser.Token token; String currentFieldName = null; String fieldname = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { if (parseFieldMatcher.match(currentFieldName, SuggestionBuilder.ANALYZER_FIELD)) { tmpSuggestion.analyzer(parser.text()); } else if (parseFieldMatcher.match(currentFieldName, SuggestionBuilder.FIELDNAME_FIELD)) { fieldname = parser.text(); } else if (parseFieldMatcher.match(currentFieldName, SuggestionBuilder.SIZE_FIELD)) { tmpSuggestion.size(parser.intValue()); } else if (parseFieldMatcher.match(currentFieldName, SuggestionBuilder.SHARDSIZE_FIELD)) { tmpSuggestion.shardSize(parser.intValue()); } else if (parseFieldMatcher.match(currentFieldName, SUGGESTMODE_FIELD)) { tmpSuggestion.suggestMode(SuggestMode.resolve(parser.text())); } else if (parseFieldMatcher.match(currentFieldName, ACCURACY_FIELD)) { tmpSuggestion.accuracy(parser.floatValue()); } else if (parseFieldMatcher.match(currentFieldName, SORT_FIELD)) { tmpSuggestion.sort(SortBy.resolve(parser.text())); } else if (parseFieldMatcher.match(currentFieldName, STRING_DISTANCE_FIELD)) { tmpSuggestion.stringDistance(StringDistanceImpl.resolve(parser.text())); } else if (parseFieldMatcher.match(currentFieldName, MAX_EDITS_FIELD)) { tmpSuggestion.maxEdits(parser.intValue()); } else if (parseFieldMatcher.match(currentFieldName, MAX_INSPECTIONS_FIELD)) { tmpSuggestion.maxInspections(parser.intValue()); } else if (parseFieldMatcher.match(currentFieldName, MAX_TERM_FREQ_FIELD)) { tmpSuggestion.maxTermFreq(parser.floatValue()); } else if (parseFieldMatcher.match(currentFieldName, PREFIX_LENGTH_FIELD)) { tmpSuggestion.prefixLength(parser.intValue()); } else if (parseFieldMatcher.match(currentFieldName, MIN_WORD_LENGTH_FIELD)) { tmpSuggestion.minWordLength(parser.intValue()); } else if (parseFieldMatcher.match(currentFieldName, MIN_DOC_FREQ_FIELD)) { tmpSuggestion.minDocFreq(parser.floatValue()); } else if (parseFieldMatcher.match(currentFieldName, EXACT_MATCH_FIELD)) { tmpSuggestion.exactMatch(parser.booleanValue()); } else { throw new ParsingException( parser.getTokenLocation(), "suggester[term] doesn't support field [" + currentFieldName + "]"); } } else { throw new ParsingException( parser.getTokenLocation(), "suggester[term] parsing failed on [" + currentFieldName + "]"); } } // now we should have field name, check and copy fields over to the suggestion builder we return if (fieldname == null) { throw new ElasticsearchParseException( "the required field option [" + FIELDNAME_FIELD.getPreferredName() + "] is missing"); } return new TermSuggestionBuilder(fieldname, tmpSuggestion); }