use of org.codelibs.fess.helper.QueryHelper in project fess by codelibs.
the class FessEsClient method search.
public <T> T search(final String index, final String type, final SearchCondition<SearchRequestBuilder> condition, final SearchResult<T, SearchRequestBuilder, SearchResponse> searchResult) {
final long startTime = System.currentTimeMillis();
SearchResponse searchResponse = null;
final SearchRequestBuilder searchRequestBuilder = client.prepareSearch(index).setTypes(type);
if (condition.build(searchRequestBuilder)) {
if (ComponentUtil.hasQueryHelper()) {
final QueryHelper queryHelper = ComponentUtil.getQueryHelper();
if (queryHelper.getTimeAllowed() >= 0) {
searchRequestBuilder.setTimeout(TimeValue.timeValueMillis(queryHelper.getTimeAllowed()));
}
}
try {
if (logger.isDebugEnabled()) {
logger.debug("Query DSL:\n" + searchRequestBuilder.toString());
}
searchResponse = searchRequestBuilder.execute().actionGet(ComponentUtil.getFessConfig().getIndexSearchTimeout());
} catch (final SearchPhaseExecutionException e) {
throw new InvalidQueryException(messages -> messages.addErrorsInvalidQueryParseError(UserMessages.GLOBAL_PROPERTY_KEY), "Invalid query: " + searchRequestBuilder, e);
}
}
final long execTime = System.currentTimeMillis() - startTime;
return searchResult.build(searchRequestBuilder, execTime, OptionalEntity.ofNullable(searchResponse, () -> {
}));
}
use of org.codelibs.fess.helper.QueryHelper in project fess by codelibs.
the class QueryResponseList method init.
public void init(final OptionalEntity<SearchResponse> searchResponseOpt, final int start, final int pageSize) {
searchResponseOpt.ifPresent(searchResponse -> {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final SearchHits searchHits = searchResponse.getHits();
allRecordCount = searchHits.getTotalHits();
queryTime = searchResponse.getTookInMillis();
if (searchResponse.getTotalShards() != searchResponse.getSuccessfulShards()) {
partialResults = true;
}
final QueryHelper queryHelper = ComponentUtil.getQueryHelper();
final String hlPrefix = queryHelper.getHighlightPrefix();
for (final SearchHit searchHit : searchHits.getHits()) {
final Map<String, Object> docMap = parseSearchHit(fessConfig, hlPrefix, searchHit);
if (fessConfig.isResultCollapsed()) {
final Map<String, SearchHits> innerHits = searchHit.getInnerHits();
if (innerHits != null) {
final SearchHits innerSearchHits = innerHits.get(fessConfig.getQueryCollapseInnerHitsName());
if (innerSearchHits != null) {
final long totalHits = innerSearchHits.getTotalHits();
if (totalHits > 1) {
docMap.put(fessConfig.getQueryCollapseInnerHitsName() + "_count", totalHits);
final SearchHitField bitsField = searchHit.getFields().get(fessConfig.getIndexFieldContentMinhashBits());
if (bitsField != null && !bitsField.getValues().isEmpty()) {
docMap.put(fessConfig.getQueryCollapseInnerHitsName() + "_hash", bitsField.getValues().get(0));
}
docMap.put(fessConfig.getQueryCollapseInnerHitsName(), StreamUtil.stream(innerSearchHits.getHits()).get(stream -> stream.map(v -> parseSearchHit(fessConfig, hlPrefix, v)).toArray(n -> new Map[n])));
}
}
}
}
parent.add(docMap);
}
final Aggregations aggregations = searchResponse.getAggregations();
if (aggregations != null) {
facetResponse = new FacetResponse(aggregations);
}
});
calculatePageInfo(start, pageSize);
}
Aggregations