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;
});
}
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);
}
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);
}
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();
}
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);
}
}
}
Aggregations