本文整理汇总了Java中org.elasticsearch.search.suggest.Suggest类的典型用法代码示例。如果您正苦于以下问题:Java Suggest类的具体用法?Java Suggest怎么用?Java Suggest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Suggest类属于org.elasticsearch.search.suggest包,在下文中一共展示了Suggest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ReducedQueryPhase
import org.elasticsearch.search.suggest.Suggest; //导入依赖的package包/类
ReducedQueryPhase(long totalHits, long fetchHits, float maxScore, boolean timedOut, Boolean terminatedEarly,
QuerySearchResult oneResult, Suggest suggest, InternalAggregations aggregations,
SearchProfileShardResults shardResults, int numReducePhases) {
if (numReducePhases <= 0) {
throw new IllegalArgumentException("at least one reduce phase must have been applied but was: " + numReducePhases);
}
this.totalHits = totalHits;
this.fetchHits = fetchHits;
if (Float.isInfinite(maxScore)) {
this.maxScore = Float.NaN;
} else {
this.maxScore = maxScore;
}
this.timedOut = timedOut;
this.terminatedEarly = terminatedEarly;
this.oneResult = oneResult;
this.suggest = suggest;
this.aggregations = aggregations;
this.shardResults = shardResults;
this.numReducePhases = numReducePhases;
}
示例2: testSort
import org.elasticsearch.search.suggest.Suggest; //导入依赖的package包/类
public void testSort() throws Exception {
List<CompletionSuggestion> suggestions = new ArrayList<>();
for (int i = 0; i < randomIntBetween(1, 5); i++) {
suggestions.add(new CompletionSuggestion(randomAsciiOfLength(randomIntBetween(1, 5)), randomIntBetween(1, 20)));
}
int nShards = randomIntBetween(1, 20);
int queryResultSize = randomBoolean() ? 0 : randomIntBetween(1, nShards * 2);
AtomicArray<QuerySearchResultProvider> results = generateQueryResults(nShards, suggestions, queryResultSize, false);
ScoreDoc[] sortedDocs = searchPhaseController.sortDocs(true, results);
int accumulatedLength = Math.min(queryResultSize, getTotalQueryHits(results));
for (Suggest.Suggestion<?> suggestion : reducedSuggest(results)) {
int suggestionSize = suggestion.getEntries().get(0).getOptions().size();
accumulatedLength += suggestionSize;
}
assertThat(sortedDocs.length, equalTo(accumulatedLength));
}
示例3: suggest
import org.elasticsearch.search.suggest.Suggest; //导入依赖的package包/类
public List<String> suggest(String prefix) {
CompletionSuggestionBuilder suggestionBuilder = new CompletionSuggestionBuilder("name_suggest")
.prefix(prefix);
SearchResponse response = getConnection().getClient().prepareSearch(getIndex())
.setTypes(getType())
.suggest(new SuggestBuilder().addSuggestion("suggestion", suggestionBuilder))
.setSize(100)
.setFetchSource(true)
.setExplain(false)
.execute()
.actionGet();
return response.getSuggest().filter(CompletionSuggestion.class).stream()
.flatMap(s -> s.getOptions().stream())
.sorted(Comparator.comparingDouble(Suggest.Suggestion.Entry.Option::getScore))
.map(Suggest.Suggestion.Entry.Option::getText)
.map(Text::toString)
.collect(Collectors.toList());
}
示例4: readFrom
import org.elasticsearch.search.suggest.Suggest; //导入依赖的package包/类
@Override
public void readFrom(StreamInput in) throws IOException {
hits = readSearchHits(in);
if (in.readBoolean()) {
aggregations = InternalAggregations.readAggregations(in);
}
if (in.readBoolean()) {
suggest = Suggest.readSuggest(Suggest.Fields.SUGGEST, in);
}
timedOut = in.readBoolean();
terminatedEarly = in.readOptionalBoolean();
if (in.getVersion().onOrAfter(Version.V_2_2_0) && in.readBoolean()) {
profileResults = new InternalProfileShardResults(in);
} else {
profileResults = null;
}
}
示例5: testThis
import org.elasticsearch.search.suggest.Suggest; //导入依赖的package包/类
@Test
public void testThis(){
Map<String, Set<CharSequence>> contextsMap = new HashMap<>();
Set<CharSequence> contexts = new HashSet<>(1);
contexts.add("test");
contextsMap.put("manifest", contexts);
CompletionSuggestion.Entry.Option option = new CompletionSuggestion.Entry.Option(0, new Text("someText"), 1.3f, contextsMap);
CompletionSuggestion.Entry entry = new CompletionSuggestion.Entry(new Text("bacon"), 0, 5);
entry.addOption(option);
CompletionSuggestion suggestion = new CompletionSuggestion("annotation_suggest", 5);
suggestion.addTerm(entry);
List<Suggestion<? extends Entry<? extends Option>>> suggestions = new ArrayList<>();
suggestions.add(suggestion);
Suggest suggest = new Suggest(suggestions);
LOG.info(suggest.toString());
}
示例6: getSuggestions
import org.elasticsearch.search.suggest.Suggest; //导入依赖的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;
}
示例7: getSuggestions
import org.elasticsearch.search.suggest.Suggest; //导入依赖的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;
}
示例8: doExecute
import org.elasticsearch.search.suggest.Suggest; //导入依赖的package包/类
@Override
protected void doExecute(SearchRequest request, ActionListener<SearchResponse> listener) {
listener.onResponse(new SearchResponse(new InternalSearchResponse(
new SearchHits(
new SearchHit[0], 0L, 0.0f),
new InternalAggregations(Collections.emptyList()),
new Suggest(Collections.emptyList()),
new SearchProfileShardResults(Collections.emptyMap()), false, false, 1), "", 1, 1, 0, new ShardSearchFailure[0]));
}
示例9: assertSuggestionSize
import org.elasticsearch.search.suggest.Suggest; //导入依赖的package包/类
public static void assertSuggestionSize(Suggest searchSuggest, int entry, int size, String key) {
assertThat(searchSuggest, notNullValue());
String msg = "Suggest result: " + searchSuggest.toString();
assertThat(msg, searchSuggest.size(), greaterThanOrEqualTo(1));
assertThat(msg, searchSuggest.getSuggestion(key).getName(), equalTo(key));
assertThat(msg, searchSuggest.getSuggestion(key).getEntries().size(), greaterThanOrEqualTo(entry));
assertThat(msg, searchSuggest.getSuggestion(key).getEntries().get(entry).getOptions().size(), equalTo(size));
assertVersionSerializable(searchSuggest);
}
示例10: assertSuggestionPhraseCollateMatchExists
import org.elasticsearch.search.suggest.Suggest; //导入依赖的package包/类
public static void assertSuggestionPhraseCollateMatchExists(Suggest searchSuggest, String key, int numberOfPhraseExists) {
int counter = 0;
assertThat(searchSuggest, notNullValue());
String msg = "Suggest result: " + searchSuggest.toString();
assertThat(msg, searchSuggest.size(), greaterThanOrEqualTo(1));
assertThat(msg, searchSuggest.getSuggestion(key).getName(), equalTo(key));
for (Suggest.Suggestion.Entry.Option option : searchSuggest.getSuggestion(key).getEntries().get(0).getOptions()) {
if (option.collateMatch()) {
counter++;
}
}
assertThat(counter, equalTo(numberOfPhraseExists));
}
示例11: assertSuggestion
import org.elasticsearch.search.suggest.Suggest; //导入依赖的package包/类
public static void assertSuggestion(Suggest searchSuggest, int entry, int ord, String key, String text) {
assertThat(searchSuggest, notNullValue());
String msg = "Suggest result: " + searchSuggest.toString();
assertThat(msg, searchSuggest.size(), greaterThanOrEqualTo(1));
assertThat(msg, searchSuggest.getSuggestion(key).getName(), equalTo(key));
assertThat(msg, searchSuggest.getSuggestion(key).getEntries().size(), greaterThanOrEqualTo(entry));
assertThat(msg, searchSuggest.getSuggestion(key).getEntries().get(entry).getOptions().size(), greaterThan(ord));
assertThat(msg, searchSuggest.getSuggestion(key).getEntries().get(entry).getOptions().get(ord).getText().string(), equalTo(text));
assertVersionSerializable(searchSuggest);
}
示例12: readFromWithId
import org.elasticsearch.search.suggest.Suggest; //导入依赖的package包/类
public void readFromWithId(long id, StreamInput in) throws IOException {
this.id = id;
from = in.readVInt();
size = in.readVInt();
int numSortFieldsPlus1 = in.readVInt();
if (numSortFieldsPlus1 == 0) {
sortValueFormats = null;
} else {
sortValueFormats = new DocValueFormat[numSortFieldsPlus1 - 1];
for (int i = 0; i < sortValueFormats.length; ++i) {
sortValueFormats[i] = in.readNamedWriteable(DocValueFormat.class);
}
}
topDocs = readTopDocs(in);
if (hasAggs = in.readBoolean()) {
aggregations = InternalAggregations.readAggregations(in);
}
pipelineAggregators = in.readNamedWriteableList(PipelineAggregator.class).stream().map(a -> (SiblingPipelineAggregator) a)
.collect(Collectors.toList());
if (in.readBoolean()) {
suggest = Suggest.readSuggest(in);
}
searchTimedOut = in.readBoolean();
terminatedEarly = in.readOptionalBoolean();
profileShardResults = in.readOptionalWriteable(ProfileShardResult::new);
hasProfileResults = profileShardResults != null;
}
示例13: innerExecute
import org.elasticsearch.search.suggest.Suggest; //导入依赖的package包/类
@Override
protected Suggest.Suggestion<? extends Suggest.Suggestion.Entry<? extends Suggest.Suggestion.Entry.Option>> innerExecute(String name,
final CompletionSuggestionContext suggestionContext, final IndexSearcher searcher, CharsRefBuilder spare) throws IOException {
if (suggestionContext.getFieldType() != null) {
final CompletionFieldMapper.CompletionFieldType fieldType = suggestionContext.getFieldType();
CompletionSuggestion completionSuggestion = new CompletionSuggestion(name, suggestionContext.getSize());
spare.copyUTF8Bytes(suggestionContext.getText());
CompletionSuggestion.Entry completionSuggestEntry = new CompletionSuggestion.Entry(
new Text(spare.toString()), 0, spare.length());
completionSuggestion.addTerm(completionSuggestEntry);
TopSuggestDocsCollector collector = new TopDocumentsCollector(suggestionContext.getSize());
suggest(searcher, suggestionContext.toQuery(), collector);
int numResult = 0;
for (TopSuggestDocs.SuggestScoreDoc suggestScoreDoc : collector.get().scoreLookupDocs()) {
TopDocumentsCollector.SuggestDoc suggestDoc = (TopDocumentsCollector.SuggestDoc) suggestScoreDoc;
// collect contexts
Map<String, Set<CharSequence>> contexts = Collections.emptyMap();
if (fieldType.hasContextMappings() && suggestDoc.getContexts().isEmpty() == false) {
contexts = fieldType.getContextMappings().getNamedContexts(suggestDoc.getContexts());
}
if (numResult++ < suggestionContext.getSize()) {
CompletionSuggestion.Entry.Option option = new CompletionSuggestion.Entry.Option(suggestDoc.doc,
new Text(suggestDoc.key.toString()), suggestDoc.score, contexts);
completionSuggestEntry.addOption(option);
} else {
break;
}
}
return completionSuggestion;
}
return null;
}
示例14: reduceTo
import org.elasticsearch.search.suggest.Suggest; //导入依赖的package包/类
/**
* Reduces suggestions to a single suggestion containing at most
* top {@link CompletionSuggestion#getSize()} options across <code>toReduce</code>
*/
public static CompletionSuggestion reduceTo(List<Suggest.Suggestion<Entry>> toReduce) {
if (toReduce.isEmpty()) {
return null;
} else {
final CompletionSuggestion leader = (CompletionSuggestion) toReduce.get(0);
final Entry leaderEntry = leader.getEntries().get(0);
final String name = leader.getName();
if (toReduce.size() == 1) {
return leader;
} else {
// combine suggestion entries from participating shards on the coordinating node
// the global top <code>size</code> entries are collected from the shard results
// using a priority queue
OptionPriorityQueue priorityQueue = new OptionPriorityQueue(leader.getSize(), COMPARATOR);
for (Suggest.Suggestion<Entry> suggestion : toReduce) {
assert suggestion.getName().equals(name) : "name should be identical across all suggestions";
for (Entry.Option option : ((CompletionSuggestion) suggestion).getOptions()) {
if (option == priorityQueue.insertWithOverflow(option)) {
// if the current option has overflown from pq,
// we can assume all of the successive options
// from this shard result will be overflown as well
break;
}
}
}
final CompletionSuggestion suggestion = new CompletionSuggestion(leader.getName(), leader.getSize());
final Entry entry = new Entry(leaderEntry.getText(), leaderEntry.getOffset(), leaderEntry.getLength());
Collections.addAll(entry.getOptions(), priorityQueue.get());
suggestion.addTerm(entry);
return suggestion;
}
}
}
示例15: InternalSearchResponse
import org.elasticsearch.search.suggest.Suggest; //导入依赖的package包/类
public InternalSearchResponse(SearchHits hits, InternalAggregations aggregations, Suggest suggest,
SearchProfileShardResults profileResults, boolean timedOut, Boolean terminatedEarly,
int numReducePhases) {
this.hits = hits;
this.aggregations = aggregations;
this.suggest = suggest;
this.profileResults = profileResults;
this.timedOut = timedOut;
this.terminatedEarly = terminatedEarly;
this.numReducePhases = numReducePhases;
}