added FuzzyOptionsBuilder javadocs and cleanups

This commit is contained in:
Areek Zillur 2015-11-02 20:14:33 -05:00
parent dd1c687ace
commit 96c9849f5a
4 changed files with 24 additions and 5 deletions

View File

@ -54,7 +54,7 @@ public class CompletionSuggester extends Suggester<CompletionSuggestionContext>
final CompletionSuggestionContext suggestionContext, final IndexSearcher searcher, CharsRefBuilder spare) throws IOException {
final CompletionFieldMapper.CompletionFieldType fieldType = suggestionContext.getFieldType();
if (fieldType == null) {
throw new ElasticsearchException("field [" + suggestionContext.getField() + "] is not a completion field");
throw new IllegalArgumentException("field [" + suggestionContext.getField() + "] is not a completion field");
}
CompletionSuggestion completionSuggestion = new CompletionSuggestion(name, suggestionContext.getSize());
spare.copyUTF8Bytes(suggestionContext.getText());
@ -71,13 +71,12 @@ public class CompletionSuggester extends Suggester<CompletionSuggestionContext>
contexts = fieldType.getContextMappings().getNamedContexts(suggestDoc.getContexts());
}
// collect payloads
Map<String, List<Object>> payload = Collections.emptyMap();
final Map<String, List<Object>> payload = new HashMap<>(0);
Set<String> payloadFields = suggestionContext.getPayloadFields();
if (!payloadFields.isEmpty()) {
int readerIndex = ReaderUtil.subIndex(suggestDoc.doc, searcher.getIndexReader().leaves());
LeafReaderContext subReaderContext = searcher.getIndexReader().leaves().get(readerIndex);
int subDocId = suggestDoc.doc - subReaderContext.docBase;
payload = new LinkedHashMap<>(payloadFields.size());
for (String field : payloadFields) {
MappedFieldType payloadFieldType = suggestionContext.getMapperService().smartNameFieldType(field);
if (payloadFieldType != null) {

View File

@ -127,26 +127,48 @@ public class CompletionSuggestionBuilder extends SuggestBuilder.SuggestionBuilde
return this;
}
/**
* Returns the maximum number of edits
*/
int getEditDistance() {
return editDistance;
}
/**
* Returns if transpositions option is set
*
* if transpositions is set, then swapping one character for another counts as one edit instead of two.
*/
boolean isTranspositions() {
return transpositions;
}
/**
* Returns the length of input prefix after which edits are applied
*/
int getFuzzyMinLength() {
return fuzzyMinLength;
}
/**
* Returns the minimum length of the input prefix required to apply any edits
*/
int getFuzzyPrefixLength() {
return fuzzyPrefixLength;
}
/**
* Returns if all measurements (like edit distance, transpositions and lengths) are in unicode code
* points (actual letters) instead of bytes.
*/
boolean isUnicodeAware() {
return unicodeAware;
}
/**
* Returns the maximum automaton states allowed for fuzzy expansion
*/
int getMaxDeterminizedStates() {
return maxDeterminizedStates;
}

View File

@ -26,7 +26,6 @@ import org.elasticsearch.index.mapper.core.CompletionFieldMapper;
import org.elasticsearch.search.suggest.Suggester;
import org.elasticsearch.search.suggest.SuggestionSearchContext;
import org.elasticsearch.search.suggest.completion.context.CategoryQueryContext;
import org.elasticsearch.search.suggest.completion.context.ContextMapping;
import org.elasticsearch.search.suggest.completion.context.ContextMappings;
import java.util.List;

View File

@ -64,7 +64,6 @@ public abstract class ContextMapping implements ToXContent {
* @param name name of context mapping
*/
protected ContextMapping(Type type, String name) {
super();
this.type = type;
this.name = name;
}