Search in sources :

Example 1 with DocMeta

use of org.codelibs.fess.es.user.allcommon.EsAbstractEntity.DocMeta in project fess by codelibs.

the class EsAbstractBehavior method delegateSelectCursor.

@Override
protected <RESULT extends ENTITY> void delegateSelectCursor(final ConditionBean cb, final EntityRowHandler<RESULT> handler, final Class<? extends RESULT> entityType) {
    delegateBulkRequest(cb, searchHits -> {
        searchHits.forEach(hit -> {
            if (handler.isBreakCursor()) {
                return;
            }
            final Map<String, Object> source = hit.getSourceAsMap();
            final RESULT entity = createEntity(source, entityType);
            final DocMeta docMeta = ((EsAbstractEntity) entity).asDocMeta();
            docMeta.id(hit.getId());
            docMeta.version(hit.getVersion());
            docMeta.seqNo(hit.getSeqNo());
            docMeta.primaryTerm(hit.getPrimaryTerm());
            handler.handle(entity);
        });
        return !handler.isBreakCursor();
    });
}
Also used : DocMeta(org.codelibs.fess.es.user.allcommon.EsAbstractEntity.DocMeta)

Example 2 with DocMeta

use of org.codelibs.fess.es.user.allcommon.EsAbstractEntity.DocMeta in project fess by codelibs.

the class EsAbstractBehavior method delegateSelectBulk.

protected <RESULT extends ENTITY> void delegateSelectBulk(final ConditionBean cb, final EntityRowHandler<List<RESULT>> handler, final Class<? extends RESULT> entityType) {
    assertCBStateValid(cb);
    assertObjectNotNull("entityRowHandler", handler);
    assertSpecifyDerivedReferrerEntityProperty(cb, entityType);
    assertObjectNotNull("entityRowHandler", handler);
    delegateBulkRequest(cb, searchHits -> {
        List<RESULT> list = new ArrayList<>();
        searchHits.forEach(hit -> {
            final Map<String, Object> source = hit.getSourceAsMap();
            final RESULT entity = createEntity(source, entityType);
            final DocMeta docMeta = ((EsAbstractEntity) entity).asDocMeta();
            docMeta.id(hit.getId());
            docMeta.version(hit.getVersion());
            docMeta.seqNo(hit.getSeqNo());
            docMeta.primaryTerm(hit.getPrimaryTerm());
            list.add(entity);
        });
        handler.handle(list);
        return !handler.isBreakCursor();
    });
}
Also used : DocMeta(org.codelibs.fess.es.user.allcommon.EsAbstractEntity.DocMeta) ArrayList(java.util.ArrayList)

Example 3 with DocMeta

use of org.codelibs.fess.es.user.allcommon.EsAbstractEntity.DocMeta in project fess by codelibs.

the class EsAbstractBehavior method delegateSelectList.

@Override
protected <RESULT extends ENTITY> List<RESULT> delegateSelectList(final ConditionBean cb, final Class<? extends RESULT> entityType) {
    // #pending check response
    final SearchRequestBuilder builder = client.prepareSearch(asEsIndex());
    final int from;
    final int size;
    if (cb.isFetchScopeEffective()) {
        from = cb.getPageStartIndex();
        size = cb.getFetchSize();
    } else {
        from = 0;
        size = 10;
    }
    builder.setFrom(from);
    builder.setSize(size);
    final EsAbstractConditionBean esCb = (EsAbstractConditionBean) cb;
    if (esCb.getPreference() != null) {
        builder.setPreference(esCb.getPreference());
    }
    esCb.request().build(builder);
    final SearchResponse response = esCb.build(builder).execute().actionGet(searchTimeout);
    final EsPagingResultBean<RESULT> list = new EsPagingResultBean<>(builder);
    final SearchHits searchHits = getSearchHits(response);
    searchHits.forEach(hit -> {
        final Map<String, Object> source = hit.getSourceAsMap();
        final RESULT entity = createEntity(source, entityType);
        final DocMeta docMeta = ((EsAbstractEntity) entity).asDocMeta();
        docMeta.id(hit.getId());
        docMeta.version(hit.getVersion());
        docMeta.seqNo(hit.getSeqNo());
        docMeta.primaryTerm(hit.getPrimaryTerm());
        list.add(entity);
    });
    list.setPageSize(size);
    list.setAllRecordCount((int) searchHits.getTotalHits().value);
    list.setCurrentPageNumber(cb.getFetchPageNumber());
    list.setTook(response.getTook().getMillis());
    list.setTotalShards(response.getTotalShards());
    list.setSuccessfulShards(response.getSuccessfulShards());
    list.setFailedShards(response.getFailedShards());
    list.setTotalHits(searchHits.getTotalHits());
    list.setAggregation(response.getAggregations());
    return list;
}
Also used : SearchRequestBuilder(org.opensearch.action.search.SearchRequestBuilder) SearchResponse(org.opensearch.action.search.SearchResponse) DocMeta(org.codelibs.fess.es.user.allcommon.EsAbstractEntity.DocMeta) SearchHits(org.opensearch.search.SearchHits)

Aggregations

DocMeta (org.codelibs.fess.es.user.allcommon.EsAbstractEntity.DocMeta)3 ArrayList (java.util.ArrayList)1 SearchRequestBuilder (org.opensearch.action.search.SearchRequestBuilder)1 SearchResponse (org.opensearch.action.search.SearchResponse)1 SearchHits (org.opensearch.search.SearchHits)1