org.elasticsearch.search.suggest.Suggest.Suggestion Java Examples
The following examples show how to use
org.elasticsearch.search.suggest.Suggest.Suggestion.
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: TermSuggestion.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public int compare(Suggestion.Entry.Option first, Suggestion.Entry.Option second) { // first criteria: the popularity int cmp = ((TermSuggestion.Entry.Option) second).getFreq() - ((TermSuggestion.Entry.Option) first).getFreq(); if (cmp != 0) { return cmp; } // second criteria (if first criteria is equal): the distance cmp = Float.compare(second.getScore(), first.getScore()); if (cmp != 0) { return cmp; } // third criteria: term text return first.getText().compareTo(second.getText()); }
Example #2
Source File: TermSuggestion.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public int compare(Suggestion.Entry.Option first, Suggestion.Entry.Option second) { // first criteria: the distance int cmp = Float.compare(second.getScore(), first.getScore()); if (cmp != 0) { return cmp; } return FREQUENCY.compare(first, second); }
Example #3
Source File: PhraseSuggestion.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override protected void merge(Suggestion.Entry<Suggestion.Entry.Option> other) { super.merge(other); // If the cluster contains both pre 0.90.4 and post 0.90.4 nodes then we'll see Suggestion.Entry // objects being merged with PhraseSuggestion.Entry objects. We merge Suggestion.Entry objects // by assuming they had a low cutoff score rather than a high one as that is the more common scenario // and the simplest one for us to implement. if (!(other instanceof PhraseSuggestion.Entry)) { return; } PhraseSuggestion.Entry otherSuggestionEntry = (PhraseSuggestion.Entry) other; this.cutoffScore = Math.max(this.cutoffScore, otherSuggestionEntry.cutoffScore); }
Example #4
Source File: SimpleSuggestionBuilder.java From onetwo with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public List<? extends Option> getOptions(ElasticsearchTemplate elasticsearchTemplate){ if(StringUtils.isBlank(text)){ return Collections.emptyList(); } return get(elasticsearchTemplate, response->{ Suggestion<?> suggestion = response.getSuggest().getSuggestion(name); if(suggestion==null || suggestion.getEntries().isEmpty()){ return Collections.emptyList(); } Suggestion.Entry<? extends Option> entry = suggestion.getEntries().get(0); List<? extends Option> options = entry.getOptions(); return options; }); }
Example #5
Source File: TransportClient.java From elasticsearch-jest-example with MIT License | 5 votes |
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()); } } }
Example #6
Source File: TermSuggestion.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override protected void mergeInto(Suggestion.Entry.Option otherOption) { super.mergeInto(otherOption); freq += ((Option) otherOption).freq; }
Example #7
Source File: PhraseSuggestion.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public void addOption(Suggestion.Entry.Option option) { if (option.getScore() > this.cutoffScore) { this.options.add(option); } }