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