Search in sources :

Example 1 with AccessResultCallback

use of org.codelibs.fess.crawler.util.AccessResultCallback in project fess-crawler by codelibs.

the class EsDataService method iterate.

@Override
public void iterate(final String sessionId, final AccessResultCallback<EsAccessResult> callback) {
    SearchResponse response = null;
    while (true) {
        if (response == null) {
            response = getClient().get(c -> c.prepareSearch(index).setTypes(type).setScroll(new TimeValue(scrollTimeout)).setQuery(QueryBuilders.boolQuery().filter(QueryBuilders.termQuery(SESSION_ID, sessionId))).setSize(scrollSize).execute());
        } else {
            final String scrollId = response.getScrollId();
            response = getClient().get(c -> c.prepareSearchScroll(scrollId).setScroll(new TimeValue(scrollTimeout)).execute());
        }
        final SearchHits searchHits = response.getHits();
        if (searchHits.getHits().length == 0) {
            break;
        }
        for (final SearchHit searchHit : searchHits) {
            final Map<String, Object> source = searchHit.getSourceAsMap();
            final EsAccessResult accessResult = BeanUtil.copyMapToNewBean(source, EsAccessResult.class, option -> {
                option.converter(new EsTimestampConverter(), timestampFields).excludeWhitespace();
                option.exclude(EsAccessResult.ACCESS_RESULT_DATA);
            });
            @SuppressWarnings("unchecked") final Map<String, Object> data = (Map<String, Object>) source.get(EsAccessResult.ACCESS_RESULT_DATA);
            if (data != null) {
                accessResult.setAccessResultData(new EsAccessResultData(data));
            }
            callback.iterate(accessResult);
        }
    }
}
Also used : BeanUtil(org.codelibs.core.beans.util.BeanUtil) SearchHit(org.elasticsearch.search.SearchHit) AccessResultCallback(org.codelibs.fess.crawler.util.AccessResultCallback) EsAccessException(org.codelibs.fess.crawler.exception.EsAccessException) SearchHits(org.elasticsearch.search.SearchHits) DataService(org.codelibs.fess.crawler.service.DataService) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) Consumer(java.util.function.Consumer) OpType(org.elasticsearch.action.DocWriteRequest.OpType) List(java.util.List) EsAccessResultData(org.codelibs.fess.crawler.entity.EsAccessResultData) EsAccessResult(org.codelibs.fess.crawler.entity.EsAccessResult) Map(java.util.Map) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) TimeValue(org.elasticsearch.common.unit.TimeValue) PostConstruct(javax.annotation.PostConstruct) SearchResponse(org.elasticsearch.action.search.SearchResponse) EsResultList(org.codelibs.fess.crawler.util.EsResultList) EsAccessResultData(org.codelibs.fess.crawler.entity.EsAccessResultData) SearchHit(org.elasticsearch.search.SearchHit) SearchResponse(org.elasticsearch.action.search.SearchResponse) EsAccessResult(org.codelibs.fess.crawler.entity.EsAccessResult) SearchHits(org.elasticsearch.search.SearchHits) Map(java.util.Map) TimeValue(org.elasticsearch.common.unit.TimeValue)

Aggregations

List (java.util.List)1 Map (java.util.Map)1 Consumer (java.util.function.Consumer)1 PostConstruct (javax.annotation.PostConstruct)1 BeanUtil (org.codelibs.core.beans.util.BeanUtil)1 EsAccessResult (org.codelibs.fess.crawler.entity.EsAccessResult)1 EsAccessResultData (org.codelibs.fess.crawler.entity.EsAccessResultData)1 EsAccessException (org.codelibs.fess.crawler.exception.EsAccessException)1 DataService (org.codelibs.fess.crawler.service.DataService)1 AccessResultCallback (org.codelibs.fess.crawler.util.AccessResultCallback)1 EsResultList (org.codelibs.fess.crawler.util.EsResultList)1 OpType (org.elasticsearch.action.DocWriteRequest.OpType)1 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 TimeValue (org.elasticsearch.common.unit.TimeValue)1 QueryBuilders (org.elasticsearch.index.query.QueryBuilders)1 SearchHit (org.elasticsearch.search.SearchHit)1 SearchHits (org.elasticsearch.search.SearchHits)1