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


Java MultiMatchQueryBuilder类代码示例

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


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

示例1: testForClient

import org.elasticsearch.index.query.MultiMatchQueryBuilder; //导入依赖的package包/类
@Test
public void testForClient() throws Exception {

    /**
     * @see <a href='https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-multi-match-query.html'></a>
     * MultiMatchQuery依赖于match query ,也就是其核心是基于MatchQuery构建的
     *
     */

    MultiMatchQueryBuilder multiMatchQueryBuilder = QueryBuilders.multiMatchQuery("elasticsearch match query","title", "descrption");

    multiMatchQueryBuilder.analyzer("standard");
    multiMatchQueryBuilder.cutoffFrequency(0.001f);
    multiMatchQueryBuilder.field("title",20);
    multiMatchQueryBuilder.fuzziness(Fuzziness.TWO);
    multiMatchQueryBuilder.maxExpansions(100);
    multiMatchQueryBuilder.prefixLength(10);
    multiMatchQueryBuilder.tieBreaker(20);
    multiMatchQueryBuilder.type(MultiMatchQueryBuilder.Type.BEST_FIELDS);
    multiMatchQueryBuilder.boost(20);



   SearchResponse searchResponse =  client.prepareSearch()
            .setIndices("blogs")
            .setTypes("blog")
            .setQuery(multiMatchQueryBuilder)
            .execute()
            .actionGet();

}
 
开发者ID:felayman,项目名称:elasticsearch-full,代码行数:32,代码来源:MultiMatchQueryDemo.java

示例2: goodSearch

import org.elasticsearch.index.query.MultiMatchQueryBuilder; //导入依赖的package包/类
/**
 * http://blog.csdn.net/xiaohulunb/article/details/37877435
 */
public static <Goods> Pagination<Goods> goodSearch(GoodsSearchCondition condition, String sortField, boolean desc, int from, int size) {
    String value = condition.getGoodsName();
    if (Pinyin4jUtil.isContainChinese(condition.getGoodsName())) {
        MultiMatchQueryBuilder multiMatchQueryBuilder = QueryBuilders.multiMatchQuery(value,
                "categoryName1", "categoryName2", "categoryName3", "goodsName", "goodsSkuAttr");
        multiMatchQueryBuilder.field("categoryName1", 0.8f);
        multiMatchQueryBuilder.field("categoryName2", 1f);
        multiMatchQueryBuilder.field("categoryName3", 1.5f);
        multiMatchQueryBuilder.field("goodsName", 2f);
        multiMatchQueryBuilder.field("goodsSkuAttr", 0.8f);
        Pagination<Goods> goodsPagination =
                search(multiMatchQueryBuilder, IndexType.GOODS, sortField, desc, from, size);
        if (!CollectionUtils.isEmpty(goodsPagination.getDataList())) {
            return goodsPagination;
        }
    }
    return boolSearch(sortField, desc, from, size, StringUtils.lowerCase(value));

}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:23,代码来源:IndexManager.java

示例3: testCrossFieldMultiMatchQuery

import org.elasticsearch.index.query.MultiMatchQueryBuilder; //导入依赖的package包/类
public void testCrossFieldMultiMatchQuery() throws IOException {
    QueryShardContext queryShardContext = indexService.newQueryShardContext(
            randomInt(20), null, () -> { throw new UnsupportedOperationException(); });
    queryShardContext.setAllowUnmappedFields(true);
    Query parsedQuery = multiMatchQuery("banon").field("name.first", 2).field("name.last", 3).field("foobar").type(MultiMatchQueryBuilder.Type.CROSS_FIELDS).toQuery(queryShardContext);
    try (Engine.Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
        Query rewrittenQuery = searcher.searcher().rewrite(parsedQuery);

        BooleanQuery.Builder expected = new BooleanQuery.Builder();
        expected.add(new TermQuery(new Term("foobar", "banon")), BooleanClause.Occur.SHOULD);
        Query tq1 = new BoostQuery(new TermQuery(new Term("name.first", "banon")), 2);
        Query tq2 = new BoostQuery(new TermQuery(new Term("name.last", "banon")), 3);
        expected.add(new DisjunctionMaxQuery(Arrays.<Query>asList(tq1, tq2), 0f), BooleanClause.Occur.SHOULD);
        assertEquals(expected.build(), rewrittenQuery);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:MultiMatchQueryTests.java

示例4: getMatchType

import org.elasticsearch.index.query.MultiMatchQueryBuilder; //导入依赖的package包/类
public static String getMatchType(@Nullable  String matchType, DataType columnType) {
    if (matchType == null) {
        return defaultMatchType(columnType);
    }
    if (columnType.equals(DataTypes.STRING)) {
        try {
            MultiMatchQueryBuilder.Type.parse(matchType, ParseFieldMatcher.STRICT);
            return matchType;
        } catch (ElasticsearchParseException e) {
            throw new IllegalArgumentException(String.format(Locale.ENGLISH,
                    "invalid MATCH type '%s' for type '%s'", matchType, columnType), e);
        }
    } else if (columnType.equals(DataTypes.GEO_SHAPE)) {
        if (!SUPPORTED_GEO_MATCH_TYPES.contains(matchType)) {
            throw new IllegalArgumentException(String.format(Locale.ENGLISH,
                    "invalid MATCH type '%s' for type '%s', valid types are: [%s]",
                    matchType, columnType, Joiner.on(",").join(SUPPORTED_GEO_MATCH_TYPES)));
        }
        return matchType;
    }
    throw new IllegalArgumentException("No match type for dataType: " + columnType);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:MatchPredicate.java

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

示例6: MatchQueryBuilder

import org.elasticsearch.index.query.MultiMatchQueryBuilder; //导入依赖的package包/类
public MatchQueryBuilder(MapperService mapperService,
                         IndexCache indexCache,
                         @Nullable BytesRef matchType,
                         @Nullable Map options) throws IOException {
    this.mapperService = mapperService;
    this.indexCache = indexCache;
    if (matchType == null) {
        this.matchType = MultiMatchQueryBuilder.Type.BEST_FIELDS;
    } else {
        this.matchType = SUPPORTED_TYPES.get(matchType);
        if (this.matchType == null) {
            throw illegalMatchType(BytesRefs.toString(matchType));
        }
    }
    this.options = OptionParser.parse(this.matchType, options);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:17,代码来源:MatchQueryBuilder.java

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

示例8: buildQueryBuilder

import org.elasticsearch.index.query.MultiMatchQueryBuilder; //导入依赖的package包/类
private QueryBuilder buildQueryBuilder(ElasticsearchSearchOption option) {
    ElasticsearchSearchOption.Operator op = option.getOperator();
    MultiMatchQueryBuilder query = multiMatchQuery(
            option.getKeyword(),
            option.getSearchFields().stream().toArray(String[]::new));
    if (op != null && ElasticsearchSearchOption.Operator.AND == op) {
        query = query.operator(MatchQueryBuilder.Operator.AND);
    }
    if (option.getOptionalSearchConditions().isEmpty()) {
        return query;
    } else {
        BoolQueryBuilder q = boolQuery().must(query);
        option.getOptionalSearchConditions().forEach((k, v) -> {
            q.must(matchQuery(k, v));
        });
        return q;
    }
}
 
开发者ID:otsecbsol,项目名称:linkbinder,代码行数:19,代码来源:ElasticsearchClient.java

示例9: simpleQueryBuilder

import org.elasticsearch.index.query.MultiMatchQueryBuilder; //导入依赖的package包/类
public static QueryBuilder simpleQueryBuilder(String q) {
    if (q.equals("yacyall")) return new MatchAllQueryBuilder();
    final MultiMatchQueryBuilder qb = QueryBuilders
            .multiMatchQuery(q)
            .operator(Operator.AND)
            .zeroTermsQuery(ZeroTermsQuery.ALL);
    QUERY_DEFAULT_FIELDS.forEach((mapping, boost) -> qb.field(mapping.getSolrFieldName(), boost));
    return qb;
}
 
开发者ID:yacy,项目名称:yacy_grid_mcp,代码行数:10,代码来源:YaCyQuery.java

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

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

示例12: testMultiMatchPrefixWithAllField

import org.elasticsearch.index.query.MultiMatchQueryBuilder; //导入依赖的package包/类
public void testMultiMatchPrefixWithAllField() throws IOException {
    QueryShardContext queryShardContext = indexService.newQueryShardContext(
            randomInt(20), null, () -> { throw new UnsupportedOperationException(); });
    queryShardContext.setAllowUnmappedFields(true);
    Query parsedQuery =
        multiMatchQuery("foo").field("_all").type(MultiMatchQueryBuilder.Type.PHRASE_PREFIX).toQuery(queryShardContext);
    assertThat(parsedQuery, instanceOf(MultiPhrasePrefixQuery.class));
    assertThat(parsedQuery.toString(), equalTo("_all:\"foo*\""));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:MultiMatchQueryTests.java

示例13: testMultiMatchCrossFieldsWithSynonyms

import org.elasticsearch.index.query.MultiMatchQueryBuilder; //导入依赖的package包/类
public void testMultiMatchCrossFieldsWithSynonyms() throws IOException {
    QueryShardContext queryShardContext = indexService.newQueryShardContext(
        randomInt(20), null, () -> { throw new UnsupportedOperationException(); });

    // check that synonym query is used for a single field
    Query parsedQuery =
        multiMatchQuery("quick").field("name.first")
            .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS).toQuery(queryShardContext);
    Term[] terms = new Term[2];
    terms[0] = new Term("name.first", "quick");
    terms[1] = new Term("name.first", "fast");
    Query expectedQuery = new SynonymQuery(terms);
    assertThat(parsedQuery, equalTo(expectedQuery));

    // check that blended term query is used for multiple fields
    parsedQuery =
        multiMatchQuery("quick").field("name.first").field("name.last")
            .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS).toQuery(queryShardContext);
    terms = new Term[4];
    terms[0] = new Term("name.first", "quick");
    terms[1] = new Term("name.first", "fast");
    terms[2] = new Term("name.last", "quick");
    terms[3] = new Term("name.last", "fast");
    float[] boosts = new float[4];
    Arrays.fill(boosts, 1.0f);
    expectedQuery = BlendedTermQuery.dismaxBlendedQuery(terms, boosts, 1.0f);
    assertThat(parsedQuery, equalTo(expectedQuery));

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:MultiMatchQueryTests.java

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

示例15: createSemQuery

import org.elasticsearch.index.query.MultiMatchQueryBuilder; //导入依赖的package包/类
/**
 * Method of creating semantic query based on Threshold
 *
 * @param input          regular query
 * @param T              threshold raning from 0 to 1
 * @param query_operator query mode
 * @return a multiMatch query builder
 */
public BoolQueryBuilder createSemQuery(String input, double T, String query_operator) {
  Map<String, Double> selected_Map = getRelatedTermsByT(input, T);
  selected_Map.put(input, (double) 1);

  String fieldsList[] = { "Dataset-Metadata", "Dataset-ShortName", "Dataset-LongName", 
      "DatasetParameter-Topic", "DatasetParameter-VariableDetail", "DatasetParameter-Category",
      "DatasetParameter-Variable", "DatasetParameter-Term",       
      "DatasetSource-Source-LongName", "DatasetSource-Source-LongName-Full",
      "DatasetSource-Source-ShortName", "DatasetSource-Source-ShortName-Full", 
      "DatasetSource-Sensor-LongName", "DatasetSource-Sensor-LongName-Full", "DatasetSource-Sensor-ShortName",
      "DatasetSource-Sensor-ShortName-Full" };
  BoolQueryBuilder qb = new BoolQueryBuilder();
  for (Entry<String, Double> entry : selected_Map.entrySet()) {
    if (query_operator.toLowerCase().trim().equals("phrase")) {
      qb.should(QueryBuilders.multiMatchQuery(entry.getKey(), fieldsList).boost(entry.getValue().floatValue()).type(MultiMatchQueryBuilder.Type.PHRASE).tieBreaker((float) 0.5)); // when
      // set
      // to
      // 1.0,
      // it
      // would
      // be
      // equal
      // to
      // "most
      // fields"
      // query
    } else if (query_operator.toLowerCase().trim().equals("and")) {
      qb.should(QueryBuilders.multiMatchQuery(entry.getKey(), fieldsList).boost(entry.getValue().floatValue()).operator(MatchQueryBuilder.DEFAULT_OPERATOR.AND).tieBreaker((float) 0.5));
    } else {
      qb.should(QueryBuilders.multiMatchQuery(entry.getKey(), fieldsList).boost(entry.getValue().floatValue()).operator(MatchQueryBuilder.DEFAULT_OPERATOR.OR).tieBreaker((float) 0.5));
    }
  }

  // LOG.info(qb.toString());
  return qb;
}
 
开发者ID:apache,项目名称:incubator-sdap-mudrod,代码行数:45,代码来源:Dispatcher.java


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