use of org.opensearch.common.document.DocumentField 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().value;
allRecordCountRelation = searchHits.getTotalHits().relation.toString();
queryTime = searchResponse.getTook().millis();
if (searchResponse.getTotalShards() != searchResponse.getSuccessfulShards()) {
partialResults = true;
}
// build highlighting fields
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().value;
if (totalHits > 1) {
docMap.put(fessConfig.getQueryCollapseInnerHitsName() + "_count", totalHits);
final DocumentField 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);
}
// facet
final Aggregations aggregations = searchResponse.getAggregations();
if (aggregations != null) {
facetResponse = new FacetResponse(aggregations);
}
});
if (pageSize > 0) {
calculatePageInfo(start, pageSize);
}
}
use of org.opensearch.common.document.DocumentField in project fess by codelibs.
the class SearchHelper method scrollSearch.
public long scrollSearch(final SearchRequestParams params, final BooleanFunction<Map<String, Object>> cursor, final OptionalThing<FessUserBean> userBean) {
LaRequestUtil.getOptionalRequest().ifPresent(request -> {
request.setAttribute(Constants.REQUEST_LANGUAGES, params.getLanguages());
request.setAttribute(Constants.REQUEST_QUERIES, params.getQuery());
});
final int pageSize = params.getPageSize();
final String query = ComponentUtil.getQueryStringBuilder().params(params).sortField(params.getSort()).build();
final FessConfig fessConfig = ComponentUtil.getFessConfig();
return ComponentUtil.getSearchEngineClient().<Map<String, Object>>scrollSearch(fessConfig.getIndexDocumentSearchIndex(), searchRequestBuilder -> {
final QueryHelper queryHelper = ComponentUtil.getQueryHelper();
queryHelper.processSearchPreference(searchRequestBuilder, userBean, query);
return SearchConditionBuilder.builder(searchRequestBuilder).scroll().query(query).size(pageSize).responseFields(queryHelper.getScrollResponseFields()).searchRequestType(params.getType()).build();
}, (searchResponse, hit) -> {
final Map<String, Object> docMap = new HashMap<>();
final Map<String, Object> source = hit.getSourceAsMap();
if (source != null) {
docMap.putAll(source);
}
final Map<String, DocumentField> fields = hit.getFields();
if (fields != null) {
docMap.putAll(fields.entrySet().stream().collect(Collectors.toMap(Entry::getKey, e -> (Object) e.getValue().getValues())));
}
final ViewHelper viewHelper = ComponentUtil.getViewHelper();
if (viewHelper != null && !docMap.isEmpty()) {
docMap.put(fessConfig.getResponseFieldContentTitle(), viewHelper.getContentTitle(docMap));
docMap.put(fessConfig.getResponseFieldContentDescription(), viewHelper.getContentDescription(docMap));
docMap.put(fessConfig.getResponseFieldUrlLink(), viewHelper.getUrlLink(docMap));
docMap.put(fessConfig.getResponseFieldSitePath(), viewHelper.getSitePath(docMap));
}
if (!docMap.containsKey(Constants.SCORE)) {
docMap.put(Constants.SCORE, hit.getScore());
}
docMap.put(fessConfig.getIndexFieldId(), hit.getId());
docMap.put(fessConfig.getIndexFieldVersion(), hit.getVersion());
docMap.put(fessConfig.getIndexFieldSeqNo(), hit.getSeqNo());
docMap.put(fessConfig.getIndexFieldPrimaryTerm(), hit.getPrimaryTerm());
return docMap;
}, cursor);
}
Aggregations