Search in sources :

Example 76 with BoolQueryBuilder

use of org.elasticsearch.index.query.BoolQueryBuilder in project fess by codelibs.

the class QueryHelper method buildDefaultQueryBuilder.

private QueryBuilder buildDefaultQueryBuilder(final DefaultQueryBuilderFunction builder) {
    final BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
    final QueryBuilder titleQuery = builder.apply(fessConfig.getIndexFieldTitle(), fessConfig.getQueryBoostTitleAsDecimal().floatValue());
    boolQuery.should(titleQuery);
    final QueryBuilder contentQuery = builder.apply(fessConfig.getIndexFieldContent(), fessConfig.getQueryBoostContentAsDecimal().floatValue());
    boolQuery.should(contentQuery);
    getQueryLanguages().ifPresent(langs -> {
        stream(langs).of(stream -> stream.forEach(lang -> {
            final QueryBuilder titleLangQuery = builder.apply(fessConfig.getIndexFieldTitle() + "_" + lang, fessConfig.getQueryBoostTitleLangAsDecimal().floatValue());
            boolQuery.should(titleLangQuery);
            final QueryBuilder contentLangQuery = builder.apply(fessConfig.getIndexFieldContent() + "_" + lang, fessConfig.getQueryBoostContentLangAsDecimal().floatValue());
            boolQuery.should(contentLangQuery);
        }));
    });
    return boolQuery;
}
Also used : Query(org.apache.lucene.search.Query) Constants(org.codelibs.fess.Constants) SortBuilders(org.elasticsearch.search.sort.SortBuilders) OptionalThing(org.dbflute.optional.OptionalThing) Term(org.apache.lucene.index.Term) PhraseQuery(org.apache.lucene.search.PhraseQuery) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) ScoreFunctionBuilders(org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders) GeoInfo(org.codelibs.fess.entity.GeoInfo) QueryContext(org.codelibs.fess.entity.QueryContext) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Fuzziness(org.elasticsearch.common.unit.Fuzziness) Locale(java.util.Locale) Map(java.util.Map) BytesRef(org.apache.lucene.util.BytesRef) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder) Resource(javax.annotation.Resource) Set(java.util.Set) PrefixQuery(org.apache.lucene.search.PrefixQuery) UUID(java.util.UUID) FuzzyQuery(org.apache.lucene.search.FuzzyQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) WildcardQuery(org.apache.lucene.search.WildcardQuery) List(java.util.List) Stream(java.util.stream.Stream) ComponentUtil(org.codelibs.fess.util.ComponentUtil) PostConstruct(javax.annotation.PostConstruct) SortOrder(org.elasticsearch.search.sort.SortOrder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) ParseException(org.apache.lucene.queryparser.classic.ParseException) HashMap(java.util.HashMap) LaRequestUtil(org.lastaflute.web.util.LaRequestUtil) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SearchRequestType(org.codelibs.fess.entity.SearchRequestParams.SearchRequestType) FacetInfo(org.codelibs.fess.entity.FacetInfo) SortBuilder(org.elasticsearch.search.sort.SortBuilder) UserMessages(org.lastaflute.core.message.UserMessages) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) StringUtil(org.codelibs.core.lang.StringUtil) BooleanClause(org.apache.lucene.search.BooleanClause) Consumer(java.util.function.Consumer) TermQuery(org.apache.lucene.search.TermQuery) FilterFunctionBuilder(org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder) BooleanQuery(org.apache.lucene.search.BooleanQuery) QueryParser(org.apache.lucene.queryparser.classic.QueryParser) BoostQuery(org.apache.lucene.search.BoostQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder)

Example 77 with BoolQueryBuilder

use of org.elasticsearch.index.query.BoolQueryBuilder in project fess by codelibs.

the class KeyMatchHelper method reload.

protected void reload(final long interval) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final KeyMatchService keyMatchService = ComponentUtil.getComponent(KeyMatchService.class);
    final Map<String, Pair<QueryBuilder, ScoreFunctionBuilder>> keyMatchQueryMap = new HashMap<>();
    keyMatchService.getAvailableKeyMatchList().stream().forEach(keyMatch -> {
        final BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
        getDocumentList(keyMatch).stream().map(doc -> {
            return DocumentUtil.getValue(doc, fessConfig.getIndexFieldDocId(), String.class);
        }).forEach(docId -> {
            boolQuery.should(QueryBuilders.termQuery(fessConfig.getIndexFieldDocId(), docId));
        });
        if (boolQuery.hasClauses()) {
            keyMatchQueryMap.put(toLowerCase(keyMatch.getTerm()), new Pair<>(boolQuery, ScoreFunctionBuilders.weightFactorFunction(keyMatch.getBoost())));
        }
        if (reloadInterval > 0) {
            try {
                Thread.sleep(reloadInterval);
            } catch (final InterruptedException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Interrupted.", e);
                }
            }
        }
    });
    this.keyMatchQueryMap = keyMatchQueryMap;
}
Also used : QueryBuilder(org.elasticsearch.index.query.QueryBuilder) Constants(org.codelibs.fess.Constants) DocumentUtil(org.codelibs.fess.util.DocumentUtil) Logger(org.slf4j.Logger) FessEsClient(org.codelibs.fess.es.client.FessEsClient) LoggerFactory(org.slf4j.LoggerFactory) Pair(org.codelibs.core.misc.Pair) HashMap(java.util.HashMap) SearchConditionBuilder(org.codelibs.fess.es.client.FessEsClient.SearchConditionBuilder) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) ScoreFunctionBuilders(org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders) KeyMatchService(org.codelibs.fess.app.service.KeyMatchService) List(java.util.List) SearchRequestType(org.codelibs.fess.entity.SearchRequestParams.SearchRequestType) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) FilterFunctionBuilder(org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder) ComponentUtil(org.codelibs.fess.util.ComponentUtil) Locale(java.util.Locale) Map(java.util.Map) KeyMatch(org.codelibs.fess.es.config.exentity.KeyMatch) PostConstruct(javax.annotation.PostConstruct) ScoreFunctionBuilder(org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Collections(java.util.Collections) HashMap(java.util.HashMap) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) KeyMatchService(org.codelibs.fess.app.service.KeyMatchService) Pair(org.codelibs.core.misc.Pair)

Example 78 with BoolQueryBuilder

use of org.elasticsearch.index.query.BoolQueryBuilder in project fess by codelibs.

the class BsDataConfigToRoleCQ method bool.

public void bool(BoolCall<DataConfigToRoleCQ> boolLambda, ConditionOptionCall<BoolQueryBuilder> opLambda) {
    DataConfigToRoleCQ mustQuery = new DataConfigToRoleCQ();
    DataConfigToRoleCQ shouldQuery = new DataConfigToRoleCQ();
    DataConfigToRoleCQ mustNotQuery = new DataConfigToRoleCQ();
    DataConfigToRoleCQ filterQuery = new DataConfigToRoleCQ();
    boolLambda.callback(mustQuery, shouldQuery, mustNotQuery, filterQuery);
    if (mustQuery.hasQueries() || shouldQuery.hasQueries() || mustNotQuery.hasQueries() || filterQuery.hasQueries()) {
        BoolQueryBuilder builder = regBoolCQ(mustQuery.getQueryBuilderList(), shouldQuery.getQueryBuilderList(), mustNotQuery.getQueryBuilderList(), filterQuery.getQueryBuilderList());
        if (opLambda != null) {
            opLambda.callback(builder);
        }
    }
}
Also used : BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) DataConfigToRoleCQ(org.codelibs.fess.es.config.cbean.cq.DataConfigToRoleCQ)

Example 79 with BoolQueryBuilder

use of org.elasticsearch.index.query.BoolQueryBuilder in project fess by codelibs.

the class BsElevateWordCQ method bool.

public void bool(BoolCall<ElevateWordCQ> boolLambda, ConditionOptionCall<BoolQueryBuilder> opLambda) {
    ElevateWordCQ mustQuery = new ElevateWordCQ();
    ElevateWordCQ shouldQuery = new ElevateWordCQ();
    ElevateWordCQ mustNotQuery = new ElevateWordCQ();
    ElevateWordCQ filterQuery = new ElevateWordCQ();
    boolLambda.callback(mustQuery, shouldQuery, mustNotQuery, filterQuery);
    if (mustQuery.hasQueries() || shouldQuery.hasQueries() || mustNotQuery.hasQueries() || filterQuery.hasQueries()) {
        BoolQueryBuilder builder = regBoolCQ(mustQuery.getQueryBuilderList(), shouldQuery.getQueryBuilderList(), mustNotQuery.getQueryBuilderList(), filterQuery.getQueryBuilderList());
        if (opLambda != null) {
            opLambda.callback(builder);
        }
    }
}
Also used : BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) ElevateWordCQ(org.codelibs.fess.es.config.cbean.cq.ElevateWordCQ)

Example 80 with BoolQueryBuilder

use of org.elasticsearch.index.query.BoolQueryBuilder in project fess by codelibs.

the class BsRequestHeaderCQ method bool.

public void bool(BoolCall<RequestHeaderCQ> boolLambda, ConditionOptionCall<BoolQueryBuilder> opLambda) {
    RequestHeaderCQ mustQuery = new RequestHeaderCQ();
    RequestHeaderCQ shouldQuery = new RequestHeaderCQ();
    RequestHeaderCQ mustNotQuery = new RequestHeaderCQ();
    RequestHeaderCQ filterQuery = new RequestHeaderCQ();
    boolLambda.callback(mustQuery, shouldQuery, mustNotQuery, filterQuery);
    if (mustQuery.hasQueries() || shouldQuery.hasQueries() || mustNotQuery.hasQueries() || filterQuery.hasQueries()) {
        BoolQueryBuilder builder = regBoolCQ(mustQuery.getQueryBuilderList(), shouldQuery.getQueryBuilderList(), mustNotQuery.getQueryBuilderList(), filterQuery.getQueryBuilderList());
        if (opLambda != null) {
            opLambda.callback(builder);
        }
    }
}
Also used : RequestHeaderCQ(org.codelibs.fess.es.config.cbean.cq.RequestHeaderCQ) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder)

Aggregations

BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)98 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)25 SearchResponse (org.elasticsearch.action.search.SearchResponse)15 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)9 MatchQueryBuilder (org.elasticsearch.index.query.MatchQueryBuilder)9 HasParentQueryBuilder (org.elasticsearch.index.query.HasParentQueryBuilder)8 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)7 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 List (java.util.List)5 MatchAllQueryBuilder (org.elasticsearch.index.query.MatchAllQueryBuilder)5 RangeQueryBuilder (org.elasticsearch.index.query.RangeQueryBuilder)5 Map (java.util.Map)4 AbstractAggregationBuilder (org.elasticsearch.search.aggregations.AbstractAggregationBuilder)4 FilterAggregationBuilder (org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder)4 FieldSortBuilder (org.elasticsearch.search.sort.FieldSortBuilder)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 StickyFacetBuilder (org.sonar.server.es.StickyFacetBuilder)4 HasChildQueryBuilder (org.elasticsearch.index.query.HasChildQueryBuilder)3 InnerHitBuilder (org.elasticsearch.index.query.InnerHitBuilder)3