org.elasticsearch.search.suggest.completion.CompletionSuggestionFuzzyBuilder Java Examples

The following examples show how to use org.elasticsearch.search.suggest.completion.CompletionSuggestionFuzzyBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EsSearch.java    From es-service-parent with Apache License 2.0 5 votes vote down vote up
/**
 * 无奈es的版本太低了,无法在建议器中做过滤操作(笔者es版本1.1),在更高版本的es中可以通过Context Suggester做过滤
 * 
 * @param indices
 * @param suggestQuery
 * @return
 */
@SuppressWarnings({ "unchecked" })
private static List<Map<String, Object>> getCompletionSuggest(String indices,
        SuggestQuery suggestQuery) {
    // 查询体
    CompletionSuggestionFuzzyBuilder suggestionsBuilder = new CompletionSuggestionFuzzyBuilder(
            suggestQuery.suggestName);
    suggestionsBuilder.setFuzziness(Fuzziness.build(suggestQuery.getFuzziness()));
    suggestionsBuilder.text(suggestQuery.getText());
    suggestionsBuilder.field(suggestQuery.getField());
    suggestionsBuilder.size(suggestQuery.getSize());

    SuggestRequestBuilder suggestRequestBuilder = ESClient.getClient()
            .prepareSuggest(indices.split(",")).addSuggestion(suggestionsBuilder);
    SuggestResponse resp = suggestRequestBuilder.execute().actionGet();
    // 查询结果
    List<? extends Entry<? extends Option>> entries = (List<? extends Entry<? extends Option>>) resp
            .getSuggest().getSuggestion(suggestQuery.suggestName).getEntries();
    if (entries == null) {
        return Lists.newArrayList();
    }
    List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
    for (Entry<? extends Option> e : entries) {
        for (Option option : e) {
            Map<String, Object> map_payload = option.getPayloadAsMap();
            map_payload.put("NAME", option.getText().toString());
            result.add(map_payload);
        }
    }

    // 调试模式
    if (Constants.isDebug) {
        logger.info(suggestRequestBuilder.toString());
        logger.info(suggestionsBuilder.toString());
        logger.info(JsonUtil.toJson(result));
    }
    return result;
}
 
Example #2
Source File: SimpleSuggestionBuilder.java    From onetwo with Apache License 2.0 4 votes vote down vote up
public SimpleSuggestionBuilder completionFuzzy(Consumer<CompletionSuggestionFuzzyBuilder> consumer){
	CompletionSuggestionFuzzyBuilder completion = new CompletionSuggestionFuzzyBuilder(name).field(field).text(text);
	build(completion, consumer);
	return this;
}
 
Example #3
Source File: SuggestBuilders.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a fuzzy completion suggestion lookup query with the provided <code>name</code>
 *
 * @param name The suggestion name
 * @return a {@link org.elasticsearch.search.suggest.completion.CompletionSuggestionFuzzyBuilder}
 * instance
 */
public static CompletionSuggestionFuzzyBuilder fuzzyCompletionSuggestion(String name) {
    return new CompletionSuggestionFuzzyBuilder(name);
}