use of org.codelibs.fess.es.config.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.getSource();
final RESULT entity = createEntity(source, entityType);
final DocMeta docMeta = ((EsAbstractEntity) entity).asDocMeta();
docMeta.id(hit.getId());
docMeta.version(hit.getVersion());
handler.handle(entity);
});
return !handler.isBreakCursor();
});
}
use of org.codelibs.fess.es.config.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.getSource();
final RESULT entity = createEntity(source, entityType);
final DocMeta docMeta = ((EsAbstractEntity) entity).asDocMeta();
docMeta.id(hit.getId());
docMeta.version(hit.getVersion());
list.add(entity);
});
handler.handle(list);
return !handler.isBreakCursor();
});
}
use of org.codelibs.fess.es.config.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()).setTypes(asEsSearchType());
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 = response.getHits();
searchHits.forEach(hit -> {
final Map<String, Object> source = hit.getSource();
final RESULT entity = createEntity(source, entityType);
final DocMeta docMeta = ((EsAbstractEntity) entity).asDocMeta();
docMeta.id(hit.getId());
docMeta.version(hit.getVersion());
list.add(entity);
});
list.setPageSize(size);
list.setAllRecordCount((int) searchHits.getTotalHits());
list.setCurrentPageNumber(cb.getFetchPageNumber());
list.setTook(response.getTookInMillis());
list.setTotalShards(response.getTotalShards());
list.setSuccessfulShards(response.getSuccessfulShards());
list.setFailedShards(response.getFailedShards());
list.setAggregation(response.getAggregations());
return list;
}
Aggregations