本文整理汇总了Java中org.elasticsearch.index.query.MultiMatchQueryBuilder.Type方法的典型用法代码示例。如果您正苦于以下问题:Java MultiMatchQueryBuilder.Type方法的具体用法?Java MultiMatchQueryBuilder.Type怎么用?Java MultiMatchQueryBuilder.Type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.index.query.MultiMatchQueryBuilder
的用法示例。
在下文中一共展示了MultiMatchQueryBuilder.Type方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: raiseIllegalOptions
import org.elasticsearch.index.query.MultiMatchQueryBuilder; //导入方法依赖的package包/类
private static void raiseIllegalOptions(MultiMatchQueryBuilder.Type matchType, Map options) {
List<String> unknownOptions = new ArrayList<>();
List<String> invalidOptions = new ArrayList<>();
for (Object o : options.keySet()) {
assert o instanceof String;
if (!SUPPORTED_OPTIONS.contains(o)) {
unknownOptions.add((String) o);
} else {
invalidOptions.add((String) o);
}
}
if (!unknownOptions.isEmpty()) {
throw new IllegalArgumentException(String.format(Locale.ENGLISH,
"match predicate doesn't support any of the given options: %s",
Joiner.on(", ").join(unknownOptions)));
} else {
throw new IllegalArgumentException(String.format(Locale.ENGLISH,
"match predicate option(s) \"%s\" cannot be used with matchType \"%s\"",
Joiner.on(", ").join(invalidOptions),
matchType.name().toLowerCase(Locale.ENGLISH)
));
}
}
示例2: parse
import org.elasticsearch.index.query.MultiMatchQueryBuilder; //导入方法依赖的package包/类
public Query parse(MultiMatchQueryBuilder.Type type, Map<String, Float> fieldNames, Object value, String minimumShouldMatch) throws IOException {
if (fieldNames.size() == 1) {
Map.Entry<String, Float> fieldBoost = fieldNames.entrySet().iterator().next();
Float boostValue = fieldBoost.getValue();
return parseAndApply(type.matchQueryType(), fieldBoost.getKey(), value, minimumShouldMatch, boostValue);
}
final float tieBreaker = groupTieBreaker == null ? type.tieBreaker() : groupTieBreaker;
switch (type) {
case PHRASE:
case PHRASE_PREFIX:
case BEST_FIELDS:
case MOST_FIELDS:
queryBuilder = new QueryBuilder(tieBreaker);
break;
case CROSS_FIELDS:
queryBuilder = new CrossFieldsQueryBuilder(tieBreaker);
break;
default:
throw new IllegalStateException("No such type: " + type);
}
final List<? extends Query> queries = queryBuilder.buildGroupedQueries(type, fieldNames, value, minimumShouldMatch);
return queryBuilder.combineGrouped(queries);
}
示例3: parse
import org.elasticsearch.index.query.MultiMatchQueryBuilder; //导入方法依赖的package包/类
public Query parse(MultiMatchQueryBuilder.Type type, Map<String, Float> fieldNames, Object value, String minimumShouldMatch) throws IOException {
Query result;
if (fieldNames.size() == 1) {
Map.Entry<String, Float> fieldBoost = fieldNames.entrySet().iterator().next();
Float boostValue = fieldBoost.getValue();
result = parseAndApply(type.matchQueryType(), fieldBoost.getKey(), value, minimumShouldMatch, boostValue);
} else {
final float tieBreaker = groupTieBreaker == null ? type.tieBreaker() : groupTieBreaker;
switch (type) {
case PHRASE:
case PHRASE_PREFIX:
case BEST_FIELDS:
case MOST_FIELDS:
queryBuilder = new QueryBuilder(tieBreaker);
break;
case CROSS_FIELDS:
queryBuilder = new CrossFieldsQueryBuilder(tieBreaker);
break;
default:
throw new IllegalStateException("No such type: " + type);
}
final List<? extends Query> queries = queryBuilder.buildGroupedQueries(type, fieldNames, value, minimumShouldMatch);
result = queryBuilder.combineGrouped(queries);
}
assert result != null;
return result;
}
示例4: buildGroupedQueries
import org.elasticsearch.index.query.MultiMatchQueryBuilder; //导入方法依赖的package包/类
public List<Query> buildGroupedQueries(MultiMatchQueryBuilder.Type type, Map<String, Float> fieldNames, Object value, String minimumShouldMatch) throws IOException{
List<Query> queries = new ArrayList<>();
for (String fieldName : fieldNames.keySet()) {
Float boostValue = fieldNames.get(fieldName);
Query query = parseGroup(type.matchQueryType(), fieldName, boostValue, value, minimumShouldMatch);
if (query != null) {
queries.add(query);
}
}
return queries;
}
示例5: parse
import org.elasticsearch.index.query.MultiMatchQueryBuilder; //导入方法依赖的package包/类
public static ParsedOptions parse(MultiMatchQueryBuilder.Type matchType,
@Nullable Map options) throws IllegalArgumentException {
if (options == null) {
options = Collections.emptyMap();
} else {
// need a copy. Otherwise manipulations on a shared option will lead to strange race conditions.
options = new HashMap(options);
}
ParsedOptions parsedOptions = new ParsedOptions(
floatValue(options, OPTIONS.BOOST, null),
analyzer(options.remove(OPTIONS.ANALYZER)),
zeroTermsQuery(options.remove(OPTIONS.ZERO_TERMS_QUERY)),
intValue(options, OPTIONS.MAX_EXPANSIONS, FuzzyQuery.defaultMaxExpansions),
fuzziness(options.remove(OPTIONS.FUZZINESS)),
intValue(options, OPTIONS.PREFIX_LENGTH, FuzzyQuery.defaultPrefixLength),
transpositions(options.remove(OPTIONS.FUZZY_TRANSPOSITIONS))
);
switch (matchType.matchQueryType()) {
case BOOLEAN:
parsedOptions.commonTermsCutoff(floatValue(options, OPTIONS.CUTOFF_FREQUENCY, null));
parsedOptions.operator(operator(options.remove(OPTIONS.OPERATOR)));
parsedOptions.minimumShouldMatch(minimumShouldMatch(options.remove(OPTIONS.MINIMUM_SHOULD_MATCH)));
break;
case PHRASE:
parsedOptions.phraseSlop(intValue(options, OPTIONS.SLOP, 0));
parsedOptions.tieBreaker(floatValue(options, OPTIONS.TIE_BREAKER, null));
break;
case PHRASE_PREFIX:
parsedOptions.phraseSlop(intValue(options, OPTIONS.SLOP, 0));
parsedOptions.tieBreaker(floatValue(options, OPTIONS.TIE_BREAKER, null));
parsedOptions.rewrite(rewrite(options.remove(OPTIONS.REWRITE)));
break;
}
if (!options.isEmpty()) {
raiseIllegalOptions(matchType, options);
}
return parsedOptions;
}
示例6: buildMultiMatchQuery
import org.elasticsearch.index.query.MultiMatchQueryBuilder; //导入方法依赖的package包/类
/**
* Private method to build a multi match query.
*
* @param searchTerm the term on which to search
* @param queryType the query type for this multi match query
* @param queryBoost the query boost for this multi match query
* @param fieldType the field type for this multi match query
* @param match the set of match fields that are to be searched upon in the index search
*
* @return the multi match query
*/
private MultiMatchQueryBuilder buildMultiMatchQuery(final String searchTerm, final MultiMatchQueryBuilder.Type queryType, final float queryBoost,
final String fieldType, Set<String> match)
{
MultiMatchQueryBuilder multiMatchQueryBuilder = QueryBuilders.multiMatchQuery(searchTerm).type(queryType);
multiMatchQueryBuilder.boost(queryBoost);
if (fieldType.equals(FIELD_TYPE_STEMMED))
{
// Get the configured value for 'stemmed' fields and their respective boosts if any
String stemmedFieldsValue = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_SEARCHABLE_FIELDS_STEMMED);
// build the query
buildMultiMatchQueryWithBoosts(multiMatchQueryBuilder, stemmedFieldsValue, match);
}
if (fieldType.equals(FIELD_TYPE_NGRAMS))
{
// Get the configured value for 'ngrams' fields and their respective boosts if any
String ngramsFieldsValue = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_SEARCHABLE_FIELDS_NGRAMS);
// build the query
buildMultiMatchQueryWithBoosts(multiMatchQueryBuilder, ngramsFieldsValue, match);
}
if (fieldType.equals(FIELD_TYPE_SHINGLES))
{
// Get the configured value for 'shingles' fields and their respective boosts if any
String shinglesFieldsValue = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_SEARCHABLE_FIELDS_SHINGLES);
// build the query
buildMultiMatchQueryWithBoosts(multiMatchQueryBuilder, shinglesFieldsValue, match);
}
return multiMatchQueryBuilder;
}
示例7: randomizeType
import org.elasticsearch.index.query.MultiMatchQueryBuilder; //导入方法依赖的package包/类
private static MultiMatchQueryBuilder randomizeType(MultiMatchQueryBuilder builder) {
try {
MultiMatchQueryBuilder.Type type = builder.getType();
if (type == null && randomBoolean()) {
return builder;
}
if (type == null) {
type = MultiMatchQueryBuilder.Type.BEST_FIELDS;
}
if (randomBoolean()) {
builder.type(type);
} else {
Object oType = type;
switch (type) {
case BEST_FIELDS:
if (randomBoolean()) {
oType = MatchQuery.Type.BOOLEAN;
}
break;
case MOST_FIELDS:
if (randomBoolean()) {
oType = MatchQuery.Type.BOOLEAN;
}
break;
case CROSS_FIELDS:
break;
case PHRASE:
if (randomBoolean()) {
oType = MatchQuery.Type.PHRASE;
}
break;
case PHRASE_PREFIX:
if (randomBoolean()) {
oType = MatchQuery.Type.PHRASE_PREFIX;
}
break;
}
builder.type(oType);
}
return builder;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
示例8: testMultiMatchQueryHighlight
import org.elasticsearch.index.query.MultiMatchQueryBuilder; //导入方法依赖的package包/类
public void testMultiMatchQueryHighlight() throws IOException {
String[] highlighterTypes = new String[] {"fvh", "plain", "postings", "unified"};
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("properties")
.startObject("field1")
.field("type", "text")
.field("index_options", "offsets")
.field("term_vector", "with_positions_offsets")
.endObject()
.startObject("field2")
.field("type", "text")
.field("index_options", "offsets")
.field("term_vector", "with_positions_offsets")
.endObject()
.endObject()
.endObject().endObject();
assertAcked(prepareCreate("test").addMapping("type1", mapping));
ensureGreen();
client().prepareIndex("test", "type1")
.setSource("field1", "The quick brown fox jumps over",
"field2", "The quick brown fox jumps over").get();
refresh();
final int iters = scaledRandomIntBetween(20, 30);
for (int i = 0; i < iters; i++) {
String highlighterType = rarely() ? null : RandomPicks.randomFrom(random(), highlighterTypes);
MultiMatchQueryBuilder.Type[] supportedQueryTypes;
if ("postings".equals(highlighterType)) {
/*
* phrase_prefix is not supported by postings highlighter, as it rewrites against an empty reader, the prefix will never
* match any term
*/
supportedQueryTypes = new MultiMatchQueryBuilder.Type[]{
MultiMatchQueryBuilder.Type.BEST_FIELDS,
MultiMatchQueryBuilder.Type.CROSS_FIELDS,
MultiMatchQueryBuilder.Type.MOST_FIELDS,
MultiMatchQueryBuilder.Type.PHRASE};
} else {
supportedQueryTypes = MultiMatchQueryBuilder.Type.values();
}
MultiMatchQueryBuilder.Type matchQueryType = RandomPicks.randomFrom(random(), supportedQueryTypes);
MultiMatchQueryBuilder multiMatchQueryBuilder = multiMatchQuery("the quick brown fox", "field1", "field2").type(matchQueryType);
SearchSourceBuilder source = searchSource()
.query(multiMatchQueryBuilder)
.highlighter(highlight().highlightQuery(randomBoolean() ? multiMatchQueryBuilder : null)
.highlighterType(highlighterType)
.field(new Field("field1").requireFieldMatch(true).preTags("<field1>").postTags("</field1>")));
logger.info("Running multi-match type: [{}] highlight with type: [{}]", matchQueryType, highlighterType);
SearchResponse searchResponse = client().search(searchRequest("test").source(source)).actionGet();
assertHitCount(searchResponse, 1L);
assertHighlight(searchResponse, 0, "field1", 0, anyOf(equalTo("<field1>The quick brown fox</field1> jumps over"),
equalTo("<field1>The</field1> <field1>quick</field1> <field1>brown</field1> <field1>fox</field1> jumps over")));
}
}