本文整理汇总了Java中org.elasticsearch.search.suggest.Suggest.Suggestion.Entry类的典型用法代码示例。如果您正苦于以下问题:Java Entry类的具体用法?Java Entry怎么用?Java Entry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Entry类属于org.elasticsearch.search.suggest.Suggest.Suggestion包,在下文中一共展示了Entry类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: fromXContent
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static Suggestion<? extends Entry<? extends Option>> fromXContent(XContentParser parser) throws IOException {
ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.currentToken(), parser::getTokenLocation);
String typeAndName = parser.currentName();
// we need to extract the type prefix from the name and throw error if it is not present
int delimiterPos = typeAndName.indexOf(InternalAggregation.TYPED_KEYS_DELIMITER);
String type;
String name;
if (delimiterPos > 0) {
type = typeAndName.substring(0, delimiterPos);
name = typeAndName.substring(delimiterPos + 1);
} else {
throw new ParsingException(parser.getTokenLocation(),
"Cannot parse suggestion response without type information. Set [" + RestSearchAction.TYPED_KEYS_PARAM
+ "] parameter on the request to ensure the type information is added to the response output");
}
return parser.namedObject(Suggestion.class, type, name);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:Suggest.java
示例2: testFromXContent
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry; //导入依赖的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
示例3: testToXContent
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry; //导入依赖的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
示例4: testFilter
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry; //导入依赖的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
示例5: testSuggestionOrdering
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry; //导入依赖的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
示例6: createTestItem
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry; //导入依赖的package包/类
/**
* Create a randomized Suggestion.Entry
*/
@SuppressWarnings("unchecked")
public static <O extends Option> Entry<O> createTestItem(Class<? extends Entry> entryType) {
Text entryText = new Text(randomAsciiOfLengthBetween(5, 15));
int offset = randomInt();
int length = randomInt();
Entry entry;
Supplier<Option> supplier;
if (entryType == TermSuggestion.Entry.class) {
entry = new TermSuggestion.Entry(entryText, offset, length);
supplier = TermSuggestionOptionTests::createTestItem;
} else if (entryType == PhraseSuggestion.Entry.class) {
entry = new PhraseSuggestion.Entry(entryText, offset, length, randomDouble());
supplier = SuggestionOptionTests::createTestItem;
} else if (entryType == CompletionSuggestion.Entry.class) {
entry = new CompletionSuggestion.Entry(entryText, offset, length);
supplier = CompletionSuggestionOptionTests::createTestItem;
} else {
throw new UnsupportedOperationException("entryType not supported [" + entryType + "]");
}
int numOptions = randomIntBetween(0, 5);
for (int i = 0; i < numOptions; i++) {
entry.addOption(supplier.get());
}
return entry;
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:SuggestionEntryTests.java
示例7: testFromXContent
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void testFromXContent() throws IOException {
for (Class<? extends Entry> entryType : ENTRY_PARSERS.keySet()) {
Entry<Option> entry = createTestItem(entryType);
XContentType xContentType = randomFrom(XContentType.values());
boolean humanReadable = randomBoolean();
BytesReference originalBytes = toXContent(entry, xContentType, humanReadable);
Entry<Option> parsed;
try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
parsed = ENTRY_PARSERS.get(entry.getClass()).apply(parser);
assertEquals(XContentParser.Token.END_OBJECT, parser.currentToken());
assertNull(parser.nextToken());
}
assertEquals(entry.getClass(), parsed.getClass());
assertEquals(entry.getText(), parsed.getText());
assertEquals(entry.getLength(), parsed.getLength());
assertEquals(entry.getOffset(), parsed.getOffset());
assertEquals(entry.getOptions().size(), parsed.getOptions().size());
for (int i = 0; i < entry.getOptions().size(); i++) {
assertEquals(entry.getOptions().get(i).getClass(), parsed.getOptions().get(i).getClass());
}
assertToXContentEquivalent(originalBytes, toXContent(parsed, xContentType, humanReadable), xContentType);
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:SuggestionEntryTests.java
示例8: testFromXContent
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry; //导入依赖的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
示例9: testThis
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry; //导入依赖的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: Suggest
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry; //导入依赖的package包/类
public Suggest(List<Suggestion<? extends Entry<? extends Option>>> suggestions) {
// we sort suggestions by their names to ensure iteration over suggestions are consistent
// this is needed as we need to fill in suggestion docs in SearchPhaseController#sortDocs
// in the same order as we enrich the suggestions with fetch results in SearchPhaseController#merge
suggestions.sort((o1, o2) -> o1.getName().compareTo(o2.getName()));
this.suggestions = suggestions;
this.hasScoreDocs = filter(CompletionSuggestion.class).stream().anyMatch(CompletionSuggestion::hasScoreDocs);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:Suggest.java
示例11: getSuggestion
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry; //导入依赖的package包/类
public <T extends Suggestion<? extends Entry<? extends Option>>> T getSuggestion(String name) {
if (suggestions.isEmpty() || name == null) {
return null;
} else if (suggestions.size() == 1) {
return (T) (name.equals(suggestions.get(0).name) ? suggestions.get(0) : null);
} else if (this.suggestMap == null) {
suggestMap = new HashMap<>();
for (Suggest.Suggestion<? extends Entry<? extends Option>> item : suggestions) {
suggestMap.put(item.getName(), item);
}
}
return (T) suggestMap.get(name);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:Suggest.java
示例12: writeTo
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry; //导入依赖的package包/类
@Override
public void writeTo(StreamOutput out) throws IOException {
innerWriteTo(out);
out.writeVInt(entries.size());
for (Entry<?> entry : entries) {
entry.writeTo(out);
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:Suggest.java
示例13: toXContent
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry; //导入依赖的package包/类
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
if (params.paramAsBoolean(RestSearchAction.TYPED_KEYS_PARAM, false)) {
// Concatenates the type and the name of the suggestion (ex: completion#foo)
builder.startArray(String.join(InternalAggregation.TYPED_KEYS_DELIMITER, getType(), getName()));
} else {
builder.startArray(getName());
}
for (Entry<?> entry : entries) {
entry.toXContent(builder, params);
}
builder.endArray();
return builder;
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:Suggest.java
示例14: parseEntries
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry; //导入依赖的package包/类
protected static <E extends Suggestion.Entry<?>> void parseEntries(XContentParser parser, Suggestion<E> suggestion,
CheckedFunction<XContentParser, E, IOException> entryParser)
throws IOException {
ensureExpectedToken(XContentParser.Token.START_ARRAY, parser.nextToken(), parser::getTokenLocation);
while ((parser.nextToken()) != XContentParser.Token.END_ARRAY) {
suggestion.addTerm(entryParser.apply(parser));
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:Suggest.java
示例15: reduce
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry; //导入依赖的package包/类
protected <T extends Entry<O>> Entry<O> reduce(List<T> toReduce) {
if (toReduce.size() == 1) {
return toReduce.get(0);
}
final Map<O, O> entries = new HashMap<>();
Entry<O> leader = toReduce.get(0);
for (Entry<O> entry : toReduce) {
if (!leader.text.equals(entry.text)) {
throw new IllegalStateException("Can't merge suggest entries, this might be caused by suggest calls " +
"across multiple indices with different analysis chains. Suggest entries have different text actual [" +
entry.text + "] expected [" + leader.text +"]");
}
assert leader.offset == entry.offset;
assert leader.length == entry.length;
leader.merge(entry);
for (O option : entry) {
O merger = entries.get(option);
if (merger == null) {
entries.put(option, option);
} else {
merger.mergeInto(option);
}
}
}
leader.options.clear();
for (O option: entries.keySet()) {
leader.addOption(option);
}
return leader;
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:31,代码来源:Suggest.java
示例16: equals
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry; //导入依赖的package包/类
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Entry<?> entry = (Entry<?>) o;
if (length != entry.length) return false;
if (offset != entry.offset) return false;
if (!this.text.equals(entry.text)) return false;
return true;
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:Suggest.java
示例17: fillTopDocs
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry; //导入依赖的package包/类
static <T extends TopDocs> void fillTopDocs(T[] shardTopDocs,
List<? extends AtomicArray.Entry<? extends QuerySearchResultProvider>> results,
T empytTopDocs) {
if (results.size() != shardTopDocs.length) {
// TopDocs#merge can't deal with null shard TopDocs
Arrays.fill(shardTopDocs, empytTopDocs);
}
for (AtomicArray.Entry<? extends QuerySearchResultProvider> resultProvider : results) {
final T topDocs = (T) resultProvider.value.queryResult().topDocs();
assert topDocs != null : "top docs must not be null in a valid result";
// the 'index' field is the position in the resultsArr atomic array
shardTopDocs[resultProvider.index] = topDocs;
}
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:15,代码来源:SearchPhaseController.java
示例18: getSuggestersRegistry
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry; //导入依赖的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
示例19: createTestItem
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry; //导入依赖的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
示例20: group
import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry; //导入依赖的package包/类
public static Map<String, List<Suggest.Suggestion>> group(Map<String, List<Suggest.Suggestion>> groupedSuggestions, Suggest suggest) {
for (Suggestion<? extends Entry<? extends Option>> suggestion : suggest) {
List<Suggestion> list = groupedSuggestions.get(suggestion.getName());
if (list == null) {
list = new ArrayList<>();
groupedSuggestions.put(suggestion.getName(), list);
}
list.add(suggestion);
}
return groupedSuggestions;
}
开发者ID:baidu,项目名称:Elasticsearch,代码行数:12,代码来源:Suggest.java
注:本文中的org.elasticsearch.search.suggest.Suggest.Suggestion.Entry类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论