本文整理汇总了Java中org.elasticsearch.action.suggest.SuggestResponse类的典型用法代码示例。如果您正苦于以下问题:Java SuggestResponse类的具体用法?Java SuggestResponse怎么用?Java SuggestResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SuggestResponse类属于org.elasticsearch.action.suggest包,在下文中一共展示了SuggestResponse类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getSuggestions
import org.elasticsearch.action.suggest.SuggestResponse; //导入依赖的package包/类
@Override
public List<String> getSuggestions(String partial) {
List<String> returnList = new ArrayList<>();
String suggestionName = "suggestion";
CompletionSuggestionBuilder completionSuggestionBuilder = new CompletionSuggestionBuilder(suggestionName);
SuggestResponse suggestResponse = client.prepareSuggest("wow").setSuggestText(partial).addSuggestion(completionSuggestionBuilder.field("name.suggest")).execute().actionGet();
Suggest suggest = suggestResponse.getSuggest();
Suggest.Suggestion suggestion = suggest.getSuggestion(suggestionName);
List<Suggest.Suggestion.Entry> list = suggestion.getEntries();
for(Suggest.Suggestion.Entry entry : list) {
List<Suggest.Suggestion.Entry.Option> options = entry.getOptions();
for(Suggest.Suggestion.Entry.Option option : options) {
returnList.add(option.getText().toString());
}
}
return returnList;
}
开发者ID:wendelfleming,项目名称:USC-LunchNLearn-ElasticSearch,代码行数:22,代码来源:SearchSuggestImpl.java
示例2: getSuggestions
import org.elasticsearch.action.suggest.SuggestResponse; //导入依赖的package包/类
public List<String> getSuggestions(String field, String text, boolean checkRecordGroup) {
CompletionSuggestionBuilder builder = new CompletionSuggestionBuilder("suggestions")
.field(field)
.text(text)
.size(size);
if (checkRecordGroup)
builder.addCategory("recordGroupId", getAccessibleRecordGroups());
SuggestResponse response = suggestRequestBuilder.addSuggestion(builder).execute().actionGet();
List<String> suggestions = new ArrayList<String>();
if (response != null && response.getSuggest() != null && response.getSuggest().getSuggestion("suggestions") != null
&& response.getSuggest().getSuggestion("suggestions").getEntries() != null && response.getSuggest().getSuggestion("suggestions").getEntries().size() > 0) {
Iterator<? extends Suggest.Suggestion.Entry.Option> iterator = response.getSuggest().getSuggestion("suggestions").getEntries().get(0).getOptions().iterator();
while (iterator.hasNext()) {
suggestions.add(iterator.next().getText().toString());
}
}
return suggestions;
}
开发者ID:dainst,项目名称:gazetteer,代码行数:27,代码来源:ElasticSearchSuggestionQuery.java
示例3: getCompletionSuggest
import org.elasticsearch.action.suggest.SuggestResponse; //导入依赖的package包/类
/**
* 无奈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;
}
开发者ID:hailin0,项目名称:es-service-parent,代码行数:45,代码来源:EsSearch.java
示例4: get
import org.elasticsearch.action.suggest.SuggestResponse; //导入依赖的package包/类
public <R> R get(ElasticsearchTemplate elasticsearchTemplate, Function<SuggestResponse, R> mapper){
Assert.notNull(this.suggestion);
Assert.notEmpty(indices);
SuggestResponse response = elasticsearchTemplate.suggest(suggestion, this.indices.toArray(new String[0]));
return mapper.apply(response);
}
开发者ID:wayshall,项目名称:onetwo,代码行数:8,代码来源:SimpleSuggestionBuilder.java
示例5: toXContent
import org.elasticsearch.action.suggest.SuggestResponse; //导入依赖的package包/类
@Override
protected XContentBuilder toXContent(SuggestRequest request, SuggestResponse response, XContentBuilder builder) throws IOException {
builder.startObject();
buildBroadcastShardsHeader(builder, response);
Suggest suggest = response.getSuggest();
if (suggest != null) {
suggest.toXContent(builder, ToXContent.EMPTY_PARAMS);
}
builder.endObject();
return builder;
}
开发者ID:javanna,项目名称:elasticshell,代码行数:12,代码来源:SuggestRequestBuilder.java
示例6: suggest
import org.elasticsearch.action.suggest.SuggestResponse; //导入依赖的package包/类
@Override
public ActionFuture<SuggestResponse> suggest(final SuggestRequest request) {
return execute(SuggestAction.INSTANCE, request);
}
开发者ID:baidu,项目名称:Elasticsearch,代码行数:5,代码来源:AbstractClient.java
示例7: querySuggest
import org.elasticsearch.action.suggest.SuggestResponse; //导入依赖的package包/类
public SuggestResponse querySuggest(ElasticsearchTemplate elasticsearchTemplate, SuggestionBuilder<?> suggestion){
SuggestResponse reponse = elasticsearchTemplate.suggest(suggestion, this.indices.toArray(new String[0]));
return reponse;
}
开发者ID:wayshall,项目名称:onetwo,代码行数:5,代码来源:SimpleSearchQueryBuilder.java
示例8: getAutoSuggestions
import org.elasticsearch.action.suggest.SuggestResponse; //导入依赖的package包/类
@Override
public List<AutoSuggestionEntry> getAutoSuggestions(ElasticSearchIndexConfig config, String queryString)
{
TermSuggestionBuilder suggesBuilder = SuggestBuilder.termSuggestion(SearchFacetName.AUTO_SUGGESTION.getCode())
.field(SearchDocumentFieldName.KEYWORDS.getFieldName())
.analyzer(config.getAutoSuggestionAnalyzerName())
.size(20)
.text(queryString)
// .suggestMode("always")
// .stringDistance("ngram")
;
// CompletionSuggestionBuilder suggesBuilder = new CompletionSuggestionBuilder(SearchFacetName.AUTO_SUGGESTION.getCode())
// .field(SearchDocumentFieldName.KEYWORDS.getFieldName())
// .analyzer(config.getAutoSuggestionAnalyzerName())
// .size(20)
// .text(queryString)
//// .stringDistance("ngram")
// ;
// PhraseSuggestionBuilder suggesBuilder = SuggestBuilder.phraseSuggestion(SearchFacetName.AUTO_SUGGESTION.getCode())
// .field(SearchDocumentFieldName.TITLE.getFieldName())
// .analyzer(config.getAutoSuggestionAnalyzerName())
// .size(10)
// .text(queryString)
// ;
SuggestRequestBuilder addSuggestion = searchClientService.getClient().prepareSuggest(config.getIndexAliasName())
.addSuggestion(suggesBuilder);
try
{
logger.debug("Auto Suggestion request is {}", suggesBuilder.toXContent(jsonBuilder().startObject(), null).prettyPrint().string());
} catch (IOException e)
{
//Do nothing
logger.error("Error in to string", e);
}
SuggestResponse suggestResponse = addSuggestion.get();
logger.debug("Auto Suggestion response is {}", suggestResponse);
List<AutoSuggestionEntry> suggestions = new ArrayList<AutoSuggestionEntry>();
if(suggestResponse !=null && suggestResponse.getSuggest() !=null && suggestResponse.getSuggest().getSuggestion(SearchFacetName.AUTO_SUGGESTION.getCode()) !=null)
{
for (org.elasticsearch.search.suggest.Suggest.Suggestion.Entry<? extends Option> suggestEntry : suggestResponse.getSuggest().getSuggestion(SearchFacetName.AUTO_SUGGESTION.getCode()).getEntries())
{
for (Option option : suggestEntry.getOptions())
{
int count = ((TermSuggestion.Entry.Option) option).getFreq();
AutoSuggestionEntry autoSuggestionEntry = new AutoSuggestionEntry(option.getText().string(), count);
suggestions.add(autoSuggestionEntry);
}
}
}
return suggestions;
}
开发者ID:jaibeermalik,项目名称:elasticsearch-tutorial,代码行数:61,代码来源:ProductQueryServiceImpl.java
示例9: getAutoSuggestions
import org.elasticsearch.action.suggest.SuggestResponse; //导入依赖的package包/类
@Override
public List<AutoSuggestionEntry> getAutoSuggestions(final ElasticSearchIndexConfig config, final String queryString)
{
final TermSuggestionBuilder suggesBuilder = SuggestBuilder.termSuggestion(SearchFacetName.AUTO_SUGGESTION.getCode())
.field(SearchDocumentFieldName.KEYWORDS.getFieldName()).analyzer(config.getAutoSuggestionAnalyzerName()).size(20)
.text(queryString)
// .suggestMode("always")
// .stringDistance("ngram")
;
// CompletionSuggestionBuilder suggesBuilder = new CompletionSuggestionBuilder(SearchFacetName.AUTO_SUGGESTION.getCode())
// .field(SearchDocumentFieldName.KEYWORDS.getFieldName())
// .analyzer(config.getAutoSuggestionAnalyzerName())
// .size(20)
// .text(queryString)
// // .stringDistance("ngram")
// ;
// PhraseSuggestionBuilder suggesBuilder = SuggestBuilder.phraseSuggestion(SearchFacetName.AUTO_SUGGESTION.getCode())
// .field(SearchDocumentFieldName.TITLE.getFieldName())
// .analyzer(config.getAutoSuggestionAnalyzerName())
// .size(10)
// .text(queryString)
// ;
final SuggestRequestBuilder addSuggestion = searchClientService.getClient().prepareSuggest(config.getIndexAliasName())
.addSuggestion(suggesBuilder);
try
{
logger.debug("Auto Suggestion request is {}", suggesBuilder.toXContent(jsonBuilder().startObject(), null).prettyPrint()
.string());
}
catch (final IOException e)
{
// Do nothing
logger.error("Error in to string", e);
}
final SuggestResponse suggestResponse = addSuggestion.get();
logger.debug("Auto Suggestion response is {}", suggestResponse);
final List<AutoSuggestionEntry> suggestions = new ArrayList<AutoSuggestionEntry>();
if (suggestResponse != null && suggestResponse.getSuggest() != null
&& suggestResponse.getSuggest().getSuggestion(SearchFacetName.AUTO_SUGGESTION.getCode()) != null)
{
for (final org.elasticsearch.search.suggest.Suggest.Suggestion.Entry<? extends Option> suggestEntry : suggestResponse
.getSuggest().getSuggestion(SearchFacetName.AUTO_SUGGESTION.getCode()).getEntries())
{
for (final Option option : suggestEntry.getOptions())
{
final int count = ((TermSuggestion.Entry.Option) option).getFreq();
final AutoSuggestionEntry autoSuggestionEntry = new AutoSuggestionEntry(option.getText().string(), count);
suggestions.add(autoSuggestionEntry);
}
}
}
return suggestions;
}
开发者ID:jaibeermalik,项目名称:elasticsearch-akka,代码行数:54,代码来源:ProductQueryServiceImpl.java
示例10: getAutoSuggestions
import org.elasticsearch.action.suggest.SuggestResponse; //导入依赖的package包/类
@Override
public List<AutoSuggestionEntry> getAutoSuggestions(
final ElasticSearchIndexConfig config, final String queryString) {
final TermSuggestionBuilder suggesBuilder = SuggestBuilder
.termSuggestion(SearchFacetName.AUTO_SUGGESTION.getCode())
.field(SearchDocumentFieldName.KEYWORDS.getFieldName())
.analyzer(config.getAutoSuggestionAnalyzerName()).size(20)
.text(queryString)
// .suggestMode("always")
// .stringDistance("ngram")
;
// CompletionSuggestionBuilder suggesBuilder = new
// CompletionSuggestionBuilder(SearchFacetName.AUTO_SUGGESTION.getCode())
// .field(SearchDocumentFieldName.KEYWORDS.getFieldName())
// .analyzer(config.getAutoSuggestionAnalyzerName())
// .size(20)
// .text(queryString)
// // .stringDistance("ngram")
// ;
// PhraseSuggestionBuilder suggesBuilder =
// SuggestBuilder.phraseSuggestion(SearchFacetName.AUTO_SUGGESTION.getCode())
// .field(SearchDocumentFieldName.TITLE.getFieldName())
// .analyzer(config.getAutoSuggestionAnalyzerName())
// .size(10)
// .text(queryString)
// ;
final SuggestRequestBuilder addSuggestion = searchClientService
.getClient().prepareSuggest(config.getIndexAliasName())
.addSuggestion(suggesBuilder);
try {
logger.debug("Auto Suggestion request is {}", suggesBuilder
.toXContent(jsonBuilder().startObject(), null)
.prettyPrint().string());
} catch (final IOException e) {
// Do nothing
logger.error("Error in to string", e);
}
final SuggestResponse suggestResponse = addSuggestion.get();
logger.debug("Auto Suggestion response is {}", suggestResponse);
final List<AutoSuggestionEntry> suggestions = new ArrayList<AutoSuggestionEntry>();
if (suggestResponse != null
&& suggestResponse.getSuggest() != null
&& suggestResponse.getSuggest().getSuggestion(
SearchFacetName.AUTO_SUGGESTION.getCode()) != null) {
for (final org.elasticsearch.search.suggest.Suggest.Suggestion.Entry<? extends Option> suggestEntry : suggestResponse
.getSuggest()
.getSuggestion(SearchFacetName.AUTO_SUGGESTION.getCode())
.getEntries()) {
for (final Option option : suggestEntry.getOptions()) {
final int count = ((TermSuggestion.Entry.Option) option)
.getFreq();
final AutoSuggestionEntry autoSuggestionEntry = new AutoSuggestionEntry(
option.getText().string(), count);
suggestions.add(autoSuggestionEntry);
}
}
}
return suggestions;
}
开发者ID:jaibeermalik,项目名称:searchanalytics-bigdata,代码行数:60,代码来源:ProductQueryServiceImpl.java
示例11: doExecute
import org.elasticsearch.action.suggest.SuggestResponse; //导入依赖的package包/类
@Override
protected ActionFuture<SuggestResponse> doExecute(SuggestRequest request) {
return client.suggest(request);
}
开发者ID:javanna,项目名称:elasticshell,代码行数:5,代码来源:SuggestRequestBuilder.java
示例12: suggest
import org.elasticsearch.action.suggest.SuggestResponse; //导入依赖的package包/类
/**
* Suggestion matching a specific phrase.
*
* @param request The suggest request
* @return The result future
* @see Requests#suggestRequest(String...)
*/
ActionFuture<SuggestResponse> suggest(SuggestRequest request);
开发者ID:baidu,项目名称:Elasticsearch,代码行数:9,代码来源:Client.java
注:本文中的org.elasticsearch.action.suggest.SuggestResponse类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论