当前位置: 首页>>代码示例>>Java>>正文


Java Suggest类代码示例

本文整理汇总了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;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:SearchPhaseController.java

示例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));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:SearchPhaseControllerTests.java

示例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());
}
 
开发者ID:tokenmill,项目名称:crawling-framework,代码行数:21,代码来源:EsNamedQueryOperations.java

示例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;
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:20,代码来源:InternalSearchResponse.java

示例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());



   }
 
开发者ID:dlcs,项目名称:the-mathmos-server,代码行数:23,代码来源:TextUtilsTest.java

示例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;
}
 
开发者ID:wendelfleming,项目名称:USC-LunchNLearn-ElasticSearch,代码行数:22,代码来源:SearchSuggestImpl.java

示例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;
	}
 
开发者ID:dainst,项目名称:gazetteer,代码行数:27,代码来源:ElasticSearchSuggestionQuery.java

示例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]));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:TransportNoopSearchAction.java

示例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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:ElasticsearchAssertions.java

示例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));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:ElasticsearchAssertions.java

示例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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:ElasticsearchAssertions.java

示例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;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:QuerySearchResult.java

示例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;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:33,代码来源:CompletionSuggester.java

示例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;
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:38,代码来源:CompletionSuggestion.java

示例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;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:InternalSearchResponse.java


注:本文中的org.elasticsearch.search.suggest.Suggest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。