Search in sources :

Example 21 with BoolQueryBuilder

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

the class SearchHelper method getDocumentListByDocIds.

public List<Map<String, Object>> getDocumentListByDocIds(final String[] docIds, final String[] fields, final OptionalThing<FessUserBean> userBean, final SearchRequestType searchRequestType) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    return ComponentUtil.getSearchEngineClient().getDocumentList(fessConfig.getIndexDocumentSearchIndex(), builder -> {
        final BoolQueryBuilder boolQuery = QueryBuilders.boolQuery().must(QueryBuilders.termsQuery(fessConfig.getIndexFieldDocId(), docIds));
        final QueryHelper queryHelper = ComponentUtil.getQueryHelper();
        if (searchRequestType != SearchRequestType.ADMIN_SEARCH) {
            final Set<String> roleSet = ComponentUtil.getRoleQueryHelper().build(searchRequestType);
            if (!roleSet.isEmpty()) {
                queryHelper.buildRoleQuery(roleSet, boolQuery);
            }
        }
        builder.setQuery(boolQuery);
        builder.setSize(fessConfig.getPagingSearchPageMaxSizeAsInteger());
        builder.setFetchSource(fields, null);
        queryHelper.processSearchPreference(builder, userBean, String.join(StringUtil.EMPTY, docIds));
        return true;
    });
}
Also used : BoolQueryBuilder(org.opensearch.index.query.BoolQueryBuilder) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig)

Example 22 with BoolQueryBuilder

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

the class SuggestHelper method purgeSearchlogSuggest.

public void purgeSearchlogSuggest(final LocalDateTime time) {
    final BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
    boolQueryBuilder.must(QueryBuilders.rangeQuery(FieldNames.TIMESTAMP).lt(time.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()));
    boolQueryBuilder.mustNot(QueryBuilders.termQuery(FieldNames.KINDS, SuggestItem.Kind.DOCUMENT.toString()));
    boolQueryBuilder.must(QueryBuilders.termQuery(FieldNames.KINDS, SuggestItem.Kind.QUERY.toString()));
    boolQueryBuilder.mustNot(QueryBuilders.termQuery(FieldNames.KINDS, SuggestItem.Kind.USER.toString()));
    SuggestUtil.deleteByQuery(ComponentUtil.getSearchEngineClient(), suggester.settings(), suggester.getIndex(), boolQueryBuilder);
}
Also used : BoolQueryBuilder(org.opensearch.index.query.BoolQueryBuilder)

Example 23 with BoolQueryBuilder

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

the class SuggestHelper method purgeDocumentSuggest.

public void purgeDocumentSuggest(final LocalDateTime time) {
    final BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
    boolQueryBuilder.must(QueryBuilders.rangeQuery(FieldNames.TIMESTAMP).lt(time.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()));
    boolQueryBuilder.must(QueryBuilders.termQuery(FieldNames.KINDS, SuggestItem.Kind.DOCUMENT.toString()));
    boolQueryBuilder.mustNot(QueryBuilders.termQuery(FieldNames.KINDS, SuggestItem.Kind.QUERY.toString()));
    boolQueryBuilder.mustNot(QueryBuilders.termQuery(FieldNames.KINDS, SuggestItem.Kind.USER.toString()));
    SuggestUtil.deleteByQuery(ComponentUtil.getSearchEngineClient(), suggester.settings(), suggester.getIndex(), boolQueryBuilder);
}
Also used : BoolQueryBuilder(org.opensearch.index.query.BoolQueryBuilder)

Example 24 with BoolQueryBuilder

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

the class KeyMatchHelper method load.

@Override
public int load() {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    final Map<String, Map<String, List<Tuple3<String, QueryBuilder, ScoreFunctionBuilder<?>>>>> keyMatchQueryMap = new HashMap<>();
    getAvailableKeyMatchList().stream().forEach(keyMatch -> {
        try {
            final BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
            if (logger.isDebugEnabled()) {
                logger.debug("Loading KeyMatch Query: {}, Size: {}", keyMatch.getQuery(), keyMatch.getMaxSize());
            }
            getDocumentList(keyMatch).stream().map(doc -> {
                if (logger.isDebugEnabled()) {
                    logger.debug("Loaded KeyMatch doc: {}", doc);
                }
                return DocumentUtil.getValue(doc, fessConfig.getIndexFieldDocId(), String.class);
            }).forEach(docId -> {
                boolQuery.should(QueryBuilders.termQuery(fessConfig.getIndexFieldDocId(), docId));
            });
            if (boolQuery.hasClauses()) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Loaded KeyMatch Boost Query: {}", boolQuery);
                }
                String virtualHost = keyMatch.getVirtualHost();
                if (StringUtil.isBlank(virtualHost)) {
                    virtualHost = StringUtil.EMPTY;
                }
                Map<String, List<Tuple3<String, QueryBuilder, ScoreFunctionBuilder<?>>>> queryMap = keyMatchQueryMap.get(virtualHost);
                if (queryMap == null) {
                    queryMap = new HashMap<>();
                    keyMatchQueryMap.put(virtualHost, queryMap);
                }
                final String termKey = toLowerCase(keyMatch.getTerm());
                List<Tuple3<String, QueryBuilder, ScoreFunctionBuilder<?>>> boostList = queryMap.get(termKey);
                if (boostList == null) {
                    boostList = new ArrayList<>();
                    queryMap.put(termKey, boostList);
                }
                boostList.add(new Tuple3<>(keyMatch.getId(), boolQuery, ScoreFunctionBuilders.weightFactorFunction(keyMatch.getBoost())));
            } else if (logger.isDebugEnabled()) {
                logger.debug("No KeyMatch boost docs");
            }
            waitForNext();
        } catch (final Exception e) {
            logger.warn("Cannot load {}", keyMatch, e);
        }
    });
    this.keyMatchQueryMap = keyMatchQueryMap;
    return keyMatchQueryMap.size();
}
Also used : Constants(org.codelibs.fess.Constants) DocumentUtil(org.codelibs.fess.util.DocumentUtil) ScoreFunctionBuilder(org.opensearch.index.query.functionscore.ScoreFunctionBuilder) HashMap(java.util.HashMap) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) SearchConditionBuilder(org.codelibs.fess.es.client.SearchEngineClient.SearchConditionBuilder) ArrayList(java.util.ArrayList) SearchRequestType(org.codelibs.fess.entity.SearchRequestParams.SearchRequestType) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) KeyMatchBhv(org.codelibs.fess.es.config.exbhv.KeyMatchBhv) Locale(java.util.Locale) Map(java.util.Map) KeyMatch(org.codelibs.fess.es.config.exentity.KeyMatch) QueryBuilders(org.opensearch.index.query.QueryBuilders) StringUtil(org.codelibs.core.lang.StringUtil) ScoreFunctionBuilders(org.opensearch.index.query.functionscore.ScoreFunctionBuilders) Tuple3(org.codelibs.core.misc.Tuple3) List(java.util.List) Logger(org.apache.logging.log4j.Logger) QueryBuilder(org.opensearch.index.query.QueryBuilder) ComponentUtil(org.codelibs.fess.util.ComponentUtil) PostConstruct(javax.annotation.PostConstruct) FilterFunctionBuilder(org.opensearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) BoolQueryBuilder(org.opensearch.index.query.BoolQueryBuilder) ScoreFunctionBuilder(org.opensearch.index.query.functionscore.ScoreFunctionBuilder) HashMap(java.util.HashMap) QueryBuilder(org.opensearch.index.query.QueryBuilder) BoolQueryBuilder(org.opensearch.index.query.BoolQueryBuilder) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) BoolQueryBuilder(org.opensearch.index.query.BoolQueryBuilder) Tuple3(org.codelibs.core.misc.Tuple3) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 25 with BoolQueryBuilder

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

the class BsWebAuthenticationCQ method bool.

public void bool(BoolCall<WebAuthenticationCQ> boolLambda, ConditionOptionCall<BoolQueryBuilder> opLambda) {
    WebAuthenticationCQ mustQuery = new WebAuthenticationCQ();
    WebAuthenticationCQ shouldQuery = new WebAuthenticationCQ();
    WebAuthenticationCQ mustNotQuery = new WebAuthenticationCQ();
    WebAuthenticationCQ filterQuery = new WebAuthenticationCQ();
    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 : WebAuthenticationCQ(org.codelibs.fess.es.config.cbean.cq.WebAuthenticationCQ) BoolQueryBuilder(org.opensearch.index.query.BoolQueryBuilder)

Aggregations

BoolQueryBuilder (org.opensearch.index.query.BoolQueryBuilder)43 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)3 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 PostConstruct (javax.annotation.PostConstruct)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 StringUtil (org.codelibs.core.lang.StringUtil)1 Tuple3 (org.codelibs.core.misc.Tuple3)1 Constants (org.codelibs.fess.Constants)1 SearchRequestType (org.codelibs.fess.entity.SearchRequestParams.SearchRequestType)1 SearchEngineClient (org.codelibs.fess.es.client.SearchEngineClient)1 SearchConditionBuilder (org.codelibs.fess.es.client.SearchEngineClient.SearchConditionBuilder)1 AccessTokenCQ (org.codelibs.fess.es.config.cbean.cq.AccessTokenCQ)1 BadWordCQ (org.codelibs.fess.es.config.cbean.cq.BadWordCQ)1 BoostDocumentRuleCQ (org.codelibs.fess.es.config.cbean.cq.BoostDocumentRuleCQ)1