本文整理汇总了Java中org.elasticsearch.search.suggest.term.TermSuggestionBuilder类的典型用法代码示例。如果您正苦于以下问题:Java TermSuggestionBuilder类的具体用法?Java TermSuggestionBuilder怎么用?Java TermSuggestionBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TermSuggestionBuilder类属于org.elasticsearch.search.suggest.term包,在下文中一共展示了TermSuggestionBuilder类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testSizeOneShard
import org.elasticsearch.search.suggest.term.TermSuggestionBuilder; //导入依赖的package包/类
public void testSizeOneShard() throws Exception {
prepareCreate("test").setSettings(
SETTING_NUMBER_OF_SHARDS, 1,
SETTING_NUMBER_OF_REPLICAS, 0).get();
ensureGreen();
for (int i = 0; i < 15; i++) {
index("test", "type1", Integer.toString(i), "text", "abc" + i);
}
refresh();
SearchResponse search = client().prepareSearch().setQuery(matchQuery("text", "spellchecker")).get();
assertThat("didn't ask for suggestions but got some", search.getSuggest(), nullValue());
TermSuggestionBuilder termSuggestion = termSuggestion("text")
.suggestMode(SuggestMode.ALWAYS) // Always, otherwise the results can vary between requests.
.text("abcd")
.size(10);
Suggest suggest = searchSuggest("test", termSuggestion);
assertSuggestion(suggest, 0, "test", 10, "abc0");
termSuggestion.text("abcd").shardSize(5);
suggest = searchSuggest("test", termSuggestion);
assertSuggestion(suggest, 0, "test", 5, "abc0");
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:SuggestSearchIT.java
示例2: testSimple
import org.elasticsearch.search.suggest.term.TermSuggestionBuilder; //导入依赖的package包/类
public void testSimple() throws Exception {
createIndex("test");
ensureGreen();
index("test", "type1", "1", "text", "abcd");
index("test", "type1", "2", "text", "aacd");
index("test", "type1", "3", "text", "abbd");
index("test", "type1", "4", "text", "abcc");
refresh();
SearchResponse search = client().prepareSearch().setQuery(matchQuery("text", "spellcecker")).get();
assertThat("didn't ask for suggestions but got some", search.getSuggest(), nullValue());
TermSuggestionBuilder termSuggest = termSuggestion("text")
.suggestMode(SuggestMode.ALWAYS) // Always, otherwise the results can vary between requests.
.text("abcd");
Suggest suggest = searchSuggest("test", termSuggest);
assertSuggestion(suggest, 0, "test", "aacd", "abbd", "abcc");
assertThat(suggest.getSuggestion("test").getEntries().get(0).getText().string(), equalTo("abcd"));
suggest = searchSuggest("test", termSuggest);
assertSuggestion(suggest, 0, "test", "aacd","abbd", "abcc");
assertThat(suggest.getSuggestion("test").getEntries().get(0).getText().string(), equalTo("abcd"));
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:SuggestSearchIT.java
示例3: testEmpty
import org.elasticsearch.search.suggest.term.TermSuggestionBuilder; //导入依赖的package包/类
public void testEmpty() throws Exception {
createIndex("test");
ensureGreen();
index("test", "type1", "1", "text", "bar");
refresh();
TermSuggestionBuilder termSuggest = termSuggestion("text")
.suggestMode(SuggestMode.ALWAYS) // Always, otherwise the results can vary between requests.
.text("abcd");
Suggest suggest = searchSuggest("test", termSuggest);
assertSuggestionSize(suggest, 0, 0, "test");
assertThat(suggest.getSuggestion("test").getEntries().get(0).getText().string(), equalTo("abcd"));
suggest = searchSuggest("test", termSuggest);
assertSuggestionSize(suggest, 0, 0, "test");
assertThat(suggest.getSuggestion("test").getEntries().get(0).getText().string(), equalTo("abcd"));
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:SuggestSearchIT.java
示例4: should_suggest
import org.elasticsearch.search.suggest.term.TermSuggestionBuilder; //导入依赖的package包/类
@Test
@Ignore("suggestion are not serialized correctly as of 1.4.4, missing the start_object")
public void should_suggest() throws Exception {
createIndex("music");
createDocFromClasspathFile("music", "song", "1", "com/github/obourgain/elasticsearch/http/handler/search/suggest/doc1.json");
createDocFromClasspathFile("music", "song", "2", "com/github/obourgain/elasticsearch/http/handler/search/suggest/doc2.json");
createDocFromClasspathFile("music", "song", "3", "com/github/obourgain/elasticsearch/http/handler/search/suggest/doc3.json");
TermSuggestionBuilder termSuggestionBuilder = termSuggestion("terms-suggest").text("everythign").field("name");
SuggestRequest suggest = new SuggestRequest("music")
.suggest(termSuggestionBuilder);
SuggestResponse response = httpClient.suggest(suggest).get();
Assertions.assertThat(response.getSuggestions()).isNotNull();
Assertions.assertThat(response.getSuggestions().names()).hasSize(1);
Completion completion = response.getSuggestions().getCompletion("song-suggest");
Assertions.assertThat(completion.getOptions()).hasSize(3);
// Term term = response.getSuggestions().getTerm("term-suggest");
// Assertions.assertThat(term.getOptions()).hasSize(1);
}
开发者ID:obourgain,项目名称:elasticsearch-http,代码行数:24,代码来源:SuggestActionHandlerTest.java
示例5: registerSuggesters
import org.elasticsearch.search.suggest.term.TermSuggestionBuilder; //导入依赖的package包/类
private void registerSuggesters(List<SearchPlugin> plugins) {
registerSmoothingModels(namedWriteables);
registerSuggester(new SuggesterSpec<>("term", TermSuggestionBuilder::new, TermSuggestionBuilder::fromXContent));
registerSuggester(new SuggesterSpec<>("phrase", PhraseSuggestionBuilder::new, PhraseSuggestionBuilder::fromXContent));
registerSuggester(new SuggesterSpec<>("completion", CompletionSuggestionBuilder::new, CompletionSuggestionBuilder::fromXContent));
registerFromPlugin(plugins, SearchPlugin::getSuggesters, this::registerSuggester);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:SearchModule.java
示例6: addSuggestions
import org.elasticsearch.search.suggest.term.TermSuggestionBuilder; //导入依赖的package包/类
private SearchRequestBuilder addSuggestions(SearchRequestBuilder request, int i) {
final SuggestBuilder suggestBuilder = new SuggestBuilder();
for (int s = 0; s < randomIntBetween(2, 10); s++) {
if (randomBoolean()) {
suggestBuilder.addSuggestion("s" + s, new PhraseSuggestionBuilder("f").text("test" + i + " test" + (i - 1)));
} else {
suggestBuilder.addSuggestion("s" + s, new TermSuggestionBuilder("f").text("test" + i));
}
}
return request.suggest(suggestBuilder);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:SuggestStatsIT.java
示例7: suggest
import org.elasticsearch.search.suggest.term.TermSuggestionBuilder; //导入依赖的package包/类
private static void suggest(){
Client client = createTransportClient();
// CompletionSuggestionBuilder completionSuggestion = new CompletionSuggestionBuilder("suggestions");
// completionSuggestion.field("text");
// completionSuggestion.text("园");
// completionSuggestion.size(10);
//
// SuggestRequestBuilder suggestRequestBuilder = client.prepareSuggest("article");
// suggestRequestBuilder.addSuggestion(completionSuggestion);
// SuggestResponse suggestResponse = suggestRequestBuilder.execute().actionGet();
//
// Suggestion<? extends Entry<? extends Option>> suggestion = suggestResponse.getSuggest().getSuggestion("suggestions");
// for(Entry<? extends Option> entry:suggestion){
// for (Option option : entry) {
// System.out.println(option.getText().string());
// }
// }
TermSuggestionBuilder termSuggestionBuilder = new TermSuggestionBuilder("suggest");
termSuggestionBuilder.text("编程");
termSuggestionBuilder.field("desc");
TermSuggestion termSuggestion = client.prepareSuggest("book")
.addSuggestion(termSuggestionBuilder)
.execute()
.actionGet()
.getSuggest()
.getSuggestion("suggest");
Suggestion<? extends Entry<? extends Option>> suggestion = termSuggestion;
for(Entry<? extends Option> entry:suggestion){
for (Option option : entry) {
System.out.println(option.getText().string());
}
}
}
开发者ID:ameizi,项目名称:elasticsearch-jest-example,代码行数:37,代码来源:TransportClient.java
示例8: addTermSuggest
import org.elasticsearch.search.suggest.term.TermSuggestionBuilder; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T extends SearchCriteria> T addTermSuggest(String field, String term) {
Assert.notNull(field, "parameter field is NULL.");
Assert.notNull(term, "parameter term is NULL.");
TermSuggestionBuilder builder = SuggestBuilder.termSuggestion(field);
builder.field(field).text(term);
suggests.add(builder);
return (T) this;
}
开发者ID:yamingd,项目名称:argo,代码行数:11,代码来源:SearchCriteriaImpl.java
示例9: getAutoSuggestions
import org.elasticsearch.search.suggest.term.TermSuggestionBuilder; //导入依赖的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
示例10: getAutoSuggestions
import org.elasticsearch.search.suggest.term.TermSuggestionBuilder; //导入依赖的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
示例11: getAutoSuggestions
import org.elasticsearch.search.suggest.term.TermSuggestionBuilder; //导入依赖的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
示例12: termSuggestion
import org.elasticsearch.search.suggest.term.TermSuggestionBuilder; //导入依赖的package包/类
/**
* Creates a term suggestion lookup query with the provided <code>name</code>
*
* @param name The suggestion name
* @return a {@link org.elasticsearch.search.suggest.term.TermSuggestionBuilder}
* instance
*/
public static TermSuggestionBuilder termSuggestion(String name) {
return new TermSuggestionBuilder(name);
}
开发者ID:baidu,项目名称:Elasticsearch,代码行数:11,代码来源:SuggestBuilders.java
示例13: termSuggestion
import org.elasticsearch.search.suggest.term.TermSuggestionBuilder; //导入依赖的package包/类
/**
* Creates a term suggestion lookup query with the provided <code>field</code>
*
* @return a {@link org.elasticsearch.search.suggest.term.TermSuggestionBuilder}
* instance
*/
public static TermSuggestionBuilder termSuggestion(String fieldname) {
return new TermSuggestionBuilder(fieldname);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:SuggestBuilders.java
注:本文中的org.elasticsearch.search.suggest.term.TermSuggestionBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论