• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Suggestion类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.elasticsearch.search.suggest.Suggest.Suggestion的典型用法代码示例。如果您正苦于以下问题:Java Suggestion类的具体用法?Java Suggestion怎么用?Java Suggestion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Suggestion类属于org.elasticsearch.search.suggest.Suggest包,在下文中一共展示了Suggestion类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: fromXContent

import org.elasticsearch.search.suggest.Suggest.Suggestion; //导入依赖的package包/类
public static Option fromXContent(XContentParser parser) {
    Map<String, Object> values = PARSER.apply(parser, null);

    Text text = new Text((String) values.get(Suggestion.Entry.Option.TEXT.getPreferredName()));
    Float score = (Float) values.get(Suggestion.Entry.Option.SCORE.getPreferredName());
    @SuppressWarnings("unchecked")
    Map<String, Set<CharSequence>> contexts = (Map<String, Set<CharSequence>>) values
            .get(CompletionSuggestion.Entry.Option.CONTEXTS.getPreferredName());
    if (contexts == null) {
        contexts = Collections.emptyMap();
    }

    SearchHit hit = null;
    // the option either prints SCORE or inlines the search hit
    if (score == null) {
        hit = SearchHit.createFromMap(values);
        score = hit.getScore();
    }
    CompletionSuggestion.Entry.Option option = new CompletionSuggestion.Entry.Option(-1, text, score, contexts);
    option.setHit(hit);
    return option;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:CompletionSuggestion.java


示例2: compare

import org.elasticsearch.search.suggest.Suggest.Suggestion; //导入依赖的package包/类
@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());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:TermSuggestion.java


示例3: testFromXContent

import org.elasticsearch.search.suggest.Suggest.Suggestion; //导入依赖的package包/类
public void testFromXContent() throws IOException {
    ToXContent.Params params = new ToXContent.MapParams(Collections.singletonMap(RestSearchAction.TYPED_KEYS_PARAM, "true"));
    Suggest suggest = createTestItem();
    XContentType xContentType = randomFrom(XContentType.values());
    boolean humanReadable = randomBoolean();
    BytesReference originalBytes = toXContent(suggest, xContentType, params, humanReadable);
    Suggest parsed;
    try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
        ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
        ensureFieldName(parser, parser.nextToken(), Suggest.NAME);
        ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
        parsed = Suggest.fromXContent(parser);
        assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken());
        assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken());
        assertNull(parser.nextToken());
    }
    assertEquals(suggest.size(), parsed.size());
    for (Suggestion suggestion : suggest) {
        Suggestion<? extends Entry<? extends Option>> parsedSuggestion = parsed.getSuggestion(suggestion.getName());
        assertNotNull(parsedSuggestion);
        assertEquals(suggestion.getClass(), parsedSuggestion.getClass());
    }
    assertToXContentEquivalent(originalBytes, toXContent(parsed, xContentType, params, humanReadable), xContentType);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:SuggestTests.java


示例4: testToXContent

import org.elasticsearch.search.suggest.Suggest.Suggestion; //导入依赖的package包/类
public void testToXContent() throws IOException {
    Option option = new Option(new Text("someText"), new Text("somethingHighlighted"), 1.3f, true);
    Entry<Option> entry = new Entry<>(new Text("entryText"), 42, 313);
    entry.addOption(option);
    Suggestion<Entry<Option>> suggestion = new Suggestion<>("suggestionName", 5);
    suggestion.addTerm(entry);
    Suggest suggest = new Suggest(Collections.singletonList(suggestion));
    BytesReference xContent = toXContent(suggest, XContentType.JSON, randomBoolean());
    assertEquals(
            "{\"suggest\":"
                    + "{\"suggestionName\":"
                        + "[{\"text\":\"entryText\","
                        + "\"offset\":42,"
                        + "\"length\":313,"
                        + "\"options\":[{\"text\":\"someText\","
                                    + "\"highlighted\":\"somethingHighlighted\","
                                    + "\"score\":1.3,"
                                    + "\"collate_match\":true}]"
                        + "}]"
                    + "}"
            +"}",
            xContent.utf8ToString());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:SuggestTests.java


示例5: testFilter

import org.elasticsearch.search.suggest.Suggest.Suggestion; //导入依赖的package包/类
public void testFilter() throws Exception {
    List<Suggest.Suggestion<? extends Suggest.Suggestion.Entry<? extends Suggest.Suggestion.Entry.Option>>> suggestions;
    CompletionSuggestion completionSuggestion = new CompletionSuggestion(randomAsciiOfLength(10), 2);
    PhraseSuggestion phraseSuggestion = new PhraseSuggestion(randomAsciiOfLength(10), 2);
    TermSuggestion termSuggestion = new TermSuggestion(randomAsciiOfLength(10), 2, SortBy.SCORE);
    suggestions = Arrays.asList(completionSuggestion, phraseSuggestion, termSuggestion);
    Suggest suggest = new Suggest(suggestions);
    List<PhraseSuggestion> phraseSuggestions = suggest.filter(PhraseSuggestion.class);
    assertThat(phraseSuggestions.size(), equalTo(1));
    assertThat(phraseSuggestions.get(0), equalTo(phraseSuggestion));
    List<TermSuggestion> termSuggestions = suggest.filter(TermSuggestion.class);
    assertThat(termSuggestions.size(), equalTo(1));
    assertThat(termSuggestions.get(0), equalTo(termSuggestion));
    List<CompletionSuggestion> completionSuggestions = suggest.filter(CompletionSuggestion.class);
    assertThat(completionSuggestions.size(), equalTo(1));
    assertThat(completionSuggestions.get(0), equalTo(completionSuggestion));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:SuggestTests.java


示例6: testSuggestionOrdering

import org.elasticsearch.search.suggest.Suggest.Suggestion; //导入依赖的package包/类
public void testSuggestionOrdering() throws Exception {
    List<Suggest.Suggestion<? extends Suggest.Suggestion.Entry<? extends Suggest.Suggestion.Entry.Option>>> suggestions;
    suggestions = new ArrayList<>();
    int n = randomIntBetween(2, 5);
    for (int i = 0; i < n; i++) {
        suggestions.add(new CompletionSuggestion(randomAsciiOfLength(10), randomIntBetween(3, 5)));
    }
    Collections.shuffle(suggestions, random());
    Suggest suggest = new Suggest(suggestions);
    List<Suggest.Suggestion<? extends Suggest.Suggestion.Entry<? extends Suggest.Suggestion.Entry.Option>>> sortedSuggestions;
    sortedSuggestions = new ArrayList<>(suggestions);
    sortedSuggestions.sort((o1, o2) -> o1.getName().compareTo(o2.getName()));
    List<CompletionSuggestion> completionSuggestions = suggest.filter(CompletionSuggestion.class);
    assertThat(completionSuggestions.size(), equalTo(n));
    for (int i = 0; i < n; i++) {
        assertThat(completionSuggestions.get(i).getName(), equalTo(sortedSuggestions.get(i).getName()));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:SuggestTests.java


示例7: testFromXContent

import org.elasticsearch.search.suggest.Suggest.Suggestion; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes" })
public void testFromXContent() throws IOException {
    ToXContent.Params params = new ToXContent.MapParams(Collections.singletonMap(RestSearchAction.TYPED_KEYS_PARAM, "true"));
    for (Class<Suggestion<? extends Entry<? extends Option>>> type : SUGGESTION_TYPES) {
        Suggestion suggestion = createTestItem(type);
        XContentType xContentType = randomFrom(XContentType.values());
        boolean humanReadable = randomBoolean();
        BytesReference originalBytes = toXContent(suggestion, xContentType, params, humanReadable);
        Suggestion parsed;
        try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
            ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
            ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.nextToken(), parser::getTokenLocation);
            parsed = Suggestion.fromXContent(parser);
            assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken());
            assertNull(parser.nextToken());
        }
        assertEquals(suggestion.getName(), parsed.getName());
        assertEquals(suggestion.getEntries().size(), parsed.getEntries().size());
        // We don't parse size via xContent, instead we set it to -1 on the client side
        assertEquals(-1, parsed.getSize());
        assertToXContentEquivalent(originalBytes, toXContent(parsed, xContentType, params, humanReadable), xContentType);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:SuggestionTests.java


示例8: testUnknownSuggestionTypeThrows

import org.elasticsearch.search.suggest.Suggest.Suggestion; //导入依赖的package包/类
public void testUnknownSuggestionTypeThrows() throws IOException {
    XContent xContent = JsonXContent.jsonXContent;
    String suggestionString =
             "{\"unknownType#suggestionName\":"
                + "[{\"text\":\"entryText\","
                + "\"offset\":42,"
                + "\"length\":313,"
                + "\"options\":[{\"text\":\"someText\","
                            + "\"highlighted\":\"somethingHighlighted\","
                            + "\"score\":1.3,"
                            + "\"collate_match\":true}]"
                        + "}]"
            + "}";
    try (XContentParser parser = xContent.createParser(xContentRegistry(), suggestionString)) {
        ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
        ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.nextToken(), parser::getTokenLocation);
        ParsingException e = expectThrows(ParsingException.class, () -> Suggestion.fromXContent(parser));
        assertEquals("Unknown Suggestion [unknownType]", e.getMessage());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:SuggestionTests.java


示例9: testThis

import org.elasticsearch.search.suggest.Suggest.Suggestion; //导入依赖的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


示例10: reduceTo

import org.elasticsearch.search.suggest.Suggest.Suggestion; //导入依赖的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


示例11: merge

import org.elasticsearch.search.suggest.Suggest.Suggestion; //导入依赖的package包/类
@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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:PhraseSuggestion.java


示例12: getSuggestersRegistry

import org.elasticsearch.search.suggest.Suggest.Suggestion; //导入依赖的package包/类
static NamedXContentRegistry getSuggestersRegistry() {
    List<NamedXContentRegistry.Entry> namedXContents = new ArrayList<>();
    namedXContents.add(new NamedXContentRegistry.Entry(Suggest.Suggestion.class, new ParseField("term"),
            (parser, context) -> TermSuggestion.fromXContent(parser, (String)context)));
    namedXContents.add(new NamedXContentRegistry.Entry(Suggest.Suggestion.class, new ParseField("phrase"),
            (parser, context) -> PhraseSuggestion.fromXContent(parser, (String)context)));
    namedXContents.add(new NamedXContentRegistry.Entry(Suggest.Suggestion.class, new ParseField("completion"),
            (parser, context) -> CompletionSuggestion.fromXContent(parser, (String)context)));
    return new NamedXContentRegistry(namedXContents);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:SuggestTests.java


示例13: createTestItem

import org.elasticsearch.search.suggest.Suggest.Suggestion; //导入依赖的package包/类
public static Suggest createTestItem() {
    int numEntries = randomIntBetween(0, 5);
    List<Suggestion<? extends Entry<? extends Option>>> suggestions = new ArrayList<>();
    for (int i = 0; i < numEntries; i++) {
        suggestions.add(SuggestionTests.createTestItem());
    }
    return new Suggest(suggestions);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:SuggestTests.java


示例14: testFromXContentFailsWithoutTypeParam

import org.elasticsearch.search.suggest.Suggest.Suggestion; //导入依赖的package包/类
/**
 * test that we throw error if RestSearchAction.TYPED_KEYS_PARAM isn't set while rendering xContent
 */
public void testFromXContentFailsWithoutTypeParam() throws IOException {
    XContentType xContentType = randomFrom(XContentType.values());
    BytesReference originalBytes = toXContent(createTestItem(), xContentType, ToXContent.EMPTY_PARAMS, randomBoolean());
    try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
        ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
        ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.nextToken(), parser::getTokenLocation);
        ParsingException e = expectThrows(ParsingException.class, () -> Suggestion.fromXContent(parser));
        assertEquals(
                "Cannot parse suggestion response without type information. "
                + "Set [typed_keys] parameter on the request to ensure the type information "
                + "is added to the response output", e.getMessage());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:SuggestionTests.java


示例15: getOptions

import org.elasticsearch.search.suggest.Suggest.Suggestion; //导入依赖的package包/类
@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;
	});
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:16,代码来源:SimpleSuggestionBuilder.java


示例16: suggest

import org.elasticsearch.search.suggest.Suggest.Suggestion; //导入依赖的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


示例17: OptionPriorityQueue

import org.elasticsearch.search.suggest.Suggest.Suggestion; //导入依赖的package包/类
OptionPriorityQueue(int maxSize, Comparator<Suggest.Suggestion.Entry.Option> comparator) {
    super(maxSize);
    this.comparator = comparator;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:CompletionSuggestion.java


示例18: reduce

import org.elasticsearch.search.suggest.Suggest.Suggestion; //导入依赖的package包/类
@Override
public Suggest.Suggestion<Entry> reduce(List<Suggest.Suggestion<Entry>> toReduce) {
    return reduceTo(toReduce);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:CompletionSuggestion.java


示例19: mergeInto

import org.elasticsearch.search.suggest.Suggest.Suggestion; //导入依赖的package包/类
@Override
protected void mergeInto(Suggest.Suggestion.Entry.Option otherOption) {
    // Completion suggestions are reduced by
    // org.elasticsearch.search.suggest.completion.CompletionSuggestion.reduce()
    throw new UnsupportedOperationException();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:7,代码来源:CompletionSuggestion.java


示例20: mergeInto

import org.elasticsearch.search.suggest.Suggest.Suggestion; //导入依赖的package包/类
@Override
protected void mergeInto(Suggestion.Entry.Option otherOption) {
    super.mergeInto(otherOption);
    freq += ((Option) otherOption).freq;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:6,代码来源:TermSuggestion.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TabSet类代码示例发布时间:2022-05-23
下一篇:
Java Action类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap