use of org.codelibs.fess.es.log.allcommon.EsPagingResultBean in project fess by codelibs.
the class SearchLogService method getSearchLogList.
public List<?> getSearchLogList(final SearchLogPager pager) {
final EsPagingResultBean<?> list;
if (SearchLogPager.LOG_TYPE_USERINFO.equalsIgnoreCase(pager.logType)) {
list = (EsPagingResultBean<?>) userInfoBhv.selectPage(cb -> {
cb.paging(pager.getPageSize(), pager.getCurrentPageNumber());
cb.query().addOrderBy_UpdatedAt_Desc();
createUserInfoCondition(pager, cb);
});
} else if (SearchLogPager.LOG_TYPE_CLICK.equalsIgnoreCase(pager.logType)) {
list = (EsPagingResultBean<?>) clickLogBhv.selectPage(cb -> {
cb.paging(pager.getPageSize(), pager.getCurrentPageNumber());
cb.query().addOrderBy_RequestedAt_Desc();
createClickLogCondition(pager, cb);
});
} else if (SearchLogPager.LOG_TYPE_CLICK_COUNT.equalsIgnoreCase(pager.logType)) {
list = (EsPagingResultBean<?>) clickLogBhv.selectPage(cb -> {
cb.fetchFirst(0);
createClickLogCondition(pager, cb);
cb.aggregation().setUrl_Terms(SearchLogPager.LOG_TYPE_CLICK_COUNT, op -> {
op.size(pager.getPageSize());
if (fessConfig.getSearchlogAggShardSizeAsInteger() >= 0) {
op.shardSize(fessConfig.getSearchlogAggShardSizeAsInteger());
}
}, null);
});
final Terms agg = list.getAggregations().get(SearchLogPager.LOG_TYPE_CLICK_COUNT);
final List<? extends Terms.Bucket> buckets = agg.getBuckets();
updatePagerByAgg(pager, buckets.size());
return buckets.stream().map(e -> {
final Map<String, Object> map = new HashMap<>();
map.put(ID, Base64.getUrlEncoder().encodeToString(e.getKeyAsString().getBytes(StandardCharsets.UTF_8)));
map.put(KEY, e.getKeyAsString());
map.put(COUNT, e.getDocCount());
return map;
}).collect(Collectors.toList());
} else if (SearchLogPager.LOG_TYPE_FAVORITE.equalsIgnoreCase(pager.logType)) {
list = (EsPagingResultBean<?>) favoriteLogBhv.selectPage(cb -> {
cb.paging(pager.getPageSize(), pager.getCurrentPageNumber());
cb.query().addOrderBy_CreatedAt_Desc();
createFavoriteLogCondition(pager, cb);
});
} else if (SearchLogPager.LOG_TYPE_FAVORITE_COUNT.equalsIgnoreCase(pager.logType)) {
list = (EsPagingResultBean<?>) favoriteLogBhv.selectPage(cb -> {
cb.fetchFirst(0);
createFavoriteLogCondition(pager, cb);
cb.aggregation().setUrl_Terms(SearchLogPager.LOG_TYPE_FAVORITE_COUNT, op -> {
op.size(pager.getPageSize());
if (fessConfig.getSearchlogAggShardSizeAsInteger() >= 0) {
op.shardSize(fessConfig.getSearchlogAggShardSizeAsInteger());
}
}, null);
});
final Terms agg = list.getAggregations().get(SearchLogPager.LOG_TYPE_FAVORITE_COUNT);
final List<? extends Terms.Bucket> buckets = agg.getBuckets();
updatePagerByAgg(pager, buckets.size());
return buckets.stream().map(e -> {
final Map<String, Object> map = new HashMap<>();
map.put(ID, Base64.getUrlEncoder().encodeToString(e.getKeyAsString().getBytes(StandardCharsets.UTF_8)));
map.put(KEY, e.getKeyAsString());
map.put(COUNT, e.getDocCount());
return map;
}).collect(Collectors.toList());
} else if (SearchLogPager.LOG_TYPE_SEARCH_COUNT_HOUR.equalsIgnoreCase(pager.logType)) {
list = (EsPagingResultBean<?>) searchLogBhv.selectPage(cb -> {
cb.fetchFirst(0);
createSearchLogCondition(pager, cb);
cb.aggregation().setRequestedAt_DateHistogram(SearchLogPager.LOG_TYPE_SEARCH_COUNT_HOUR, op -> {
op.calendarInterval(DateHistogramInterval.HOUR);
op.minDocCount(0);
op.order(BucketOrder.key(true));
}, null);
});
final Histogram agg = list.getAggregations().get(SearchLogPager.LOG_TYPE_SEARCH_COUNT_HOUR);
final List<? extends Histogram.Bucket> buckets = agg.getBuckets();
updatePagerByAgg(pager, buckets.size());
return buckets.stream().map(e -> {
final Map<String, Object> map = new HashMap<>();
map.put(ID, Base64.getUrlEncoder().encodeToString(e.getKeyAsString().getBytes(StandardCharsets.UTF_8)));
map.put(KEY, e.getKeyAsString());
map.put(COUNT, e.getDocCount());
return map;
}).collect(Collectors.toList());
} else if (SearchLogPager.LOG_TYPE_SEARCH_COUNT_DAY.equalsIgnoreCase(pager.logType)) {
list = (EsPagingResultBean<?>) searchLogBhv.selectPage(cb -> {
cb.fetchFirst(0);
createSearchLogCondition(pager, cb);
cb.aggregation().setRequestedAt_DateHistogram(SearchLogPager.LOG_TYPE_SEARCH_COUNT_DAY, op -> {
op.calendarInterval(DateHistogramInterval.DAY);
op.minDocCount(0);
op.order(BucketOrder.key(true));
}, null);
});
final Histogram agg = list.getAggregations().get(SearchLogPager.LOG_TYPE_SEARCH_COUNT_DAY);
final List<? extends Histogram.Bucket> buckets = agg.getBuckets();
updatePagerByAgg(pager, buckets.size());
return buckets.stream().map(e -> {
final Map<String, Object> map = new HashMap<>();
map.put(ID, Base64.getUrlEncoder().encodeToString(e.getKeyAsString().getBytes(StandardCharsets.UTF_8)));
map.put(KEY, e.getKeyAsString());
map.put(COUNT, e.getDocCount());
return map;
}).collect(Collectors.toList());
} else if (SearchLogPager.LOG_TYPE_SEARCH_USER_HOUR.equalsIgnoreCase(pager.logType)) {
list = (EsPagingResultBean<?>) searchLogBhv.selectPage(cb -> {
cb.fetchFirst(0);
createSearchLogCondition(pager, cb);
cb.aggregation().setRequestedAt_DateHistogram(SearchLogPager.LOG_TYPE_SEARCH_USER_HOUR, op -> {
op.calendarInterval(DateHistogramInterval.HOUR);
op.subAggregation(AggregationBuilders.cardinality(USER_INFO_ID).field(USER_INFO_ID));
op.minDocCount(0);
op.order(BucketOrder.key(true));
}, null);
});
final Histogram agg = list.getAggregations().get(SearchLogPager.LOG_TYPE_SEARCH_USER_HOUR);
final List<? extends Histogram.Bucket> buckets = agg.getBuckets();
updatePagerByAgg(pager, buckets.size());
return buckets.stream().map(e -> {
final Map<String, Object> map = new HashMap<>();
map.put(ID, Base64.getUrlEncoder().encodeToString(e.getKeyAsString().getBytes(StandardCharsets.UTF_8)));
map.put(KEY, e.getKeyAsString());
final Cardinality value = e.getAggregations().get(USER_INFO_ID);
map.put(COUNT, value.getValue());
return map;
}).collect(Collectors.toList());
} else if (SearchLogPager.LOG_TYPE_SEARCH_USER_DAY.equalsIgnoreCase(pager.logType)) {
list = (EsPagingResultBean<?>) searchLogBhv.selectPage(cb -> {
cb.fetchFirst(0);
createSearchLogCondition(pager, cb);
cb.aggregation().setRequestedAt_DateHistogram(SearchLogPager.LOG_TYPE_SEARCH_USER_DAY, op -> {
op.calendarInterval(DateHistogramInterval.DAY);
op.subAggregation(AggregationBuilders.cardinality(USER_INFO_ID).field(USER_INFO_ID));
op.minDocCount(0);
op.order(BucketOrder.key(true));
}, null);
});
final Histogram agg = list.getAggregations().get(SearchLogPager.LOG_TYPE_SEARCH_USER_DAY);
final List<? extends Histogram.Bucket> buckets = agg.getBuckets();
updatePagerByAgg(pager, buckets.size());
return buckets.stream().map(e -> {
final Map<String, Object> map = new HashMap<>();
map.put(ID, Base64.getUrlEncoder().encodeToString(e.getKeyAsString().getBytes(StandardCharsets.UTF_8)));
map.put(KEY, e.getKeyAsString());
final Cardinality value = e.getAggregations().get(USER_INFO_ID);
map.put(COUNT, value.getValue());
return map;
}).collect(Collectors.toList());
} else if (SearchLogPager.LOG_TYPE_SEARCH_REQTIMEAVG_HOUR.equalsIgnoreCase(pager.logType)) {
list = (EsPagingResultBean<?>) searchLogBhv.selectPage(cb -> {
cb.fetchFirst(0);
createSearchLogCondition(pager, cb);
cb.aggregation().setRequestedAt_DateHistogram(SearchLogPager.LOG_TYPE_SEARCH_REQTIMEAVG_HOUR, op -> {
op.calendarInterval(DateHistogramInterval.HOUR);
op.subAggregation(AggregationBuilders.avg(QUERY_TIME).field(QUERY_TIME));
op.minDocCount(0);
op.order(BucketOrder.key(true));
}, null);
});
final Histogram agg = list.getAggregations().get(SearchLogPager.LOG_TYPE_SEARCH_REQTIMEAVG_HOUR);
final List<? extends Histogram.Bucket> buckets = agg.getBuckets();
updatePagerByAgg(pager, buckets.size());
return buckets.stream().map(e -> {
final Map<String, Object> map = new HashMap<>();
map.put(ID, Base64.getUrlEncoder().encodeToString(e.getKeyAsString().getBytes(StandardCharsets.UTF_8)));
map.put(KEY, e.getKeyAsString());
final Avg value = e.getAggregations().get(QUERY_TIME);
map.put(COUNT, value.getValueAsString());
return map;
}).collect(Collectors.toList());
} else if (SearchLogPager.LOG_TYPE_SEARCH_REQTIMEAVG_DAY.equalsIgnoreCase(pager.logType)) {
list = (EsPagingResultBean<?>) searchLogBhv.selectPage(cb -> {
cb.fetchFirst(0);
createSearchLogCondition(pager, cb);
cb.aggregation().setRequestedAt_DateHistogram(SearchLogPager.LOG_TYPE_SEARCH_REQTIMEAVG_DAY, op -> {
op.calendarInterval(DateHistogramInterval.DAY);
op.subAggregation(AggregationBuilders.avg(QUERY_TIME).field(QUERY_TIME));
op.minDocCount(0);
op.order(BucketOrder.key(true));
}, null);
});
final Histogram agg = list.getAggregations().get(SearchLogPager.LOG_TYPE_SEARCH_REQTIMEAVG_DAY);
final List<? extends Histogram.Bucket> buckets = agg.getBuckets();
updatePagerByAgg(pager, buckets.size());
return buckets.stream().map(e -> {
final Map<String, Object> map = new HashMap<>();
map.put(ID, Base64.getUrlEncoder().encodeToString(e.getKeyAsString().getBytes(StandardCharsets.UTF_8)));
map.put(KEY, e.getKeyAsString());
final Avg value = e.getAggregations().get(QUERY_TIME);
map.put(COUNT, value.getValueAsString());
return map;
}).collect(Collectors.toList());
} else if (SearchLogPager.LOG_TYPE_SEARCH_KEYWORD.equalsIgnoreCase(pager.logType)) {
list = (EsPagingResultBean<?>) searchLogBhv.selectPage(cb -> {
cb.fetchFirst(0);
createSearchLogCondition(pager, cb);
cb.aggregation().setSearchWord_Terms(SearchLogPager.LOG_TYPE_SEARCH_KEYWORD, op -> {
op.size(pager.getPageSize());
if (fessConfig.getSearchlogAggShardSizeAsInteger() >= 0) {
op.shardSize(fessConfig.getSearchlogAggShardSizeAsInteger());
}
}, null);
});
final Terms agg = list.getAggregations().get(SearchLogPager.LOG_TYPE_SEARCH_KEYWORD);
final List<? extends Terms.Bucket> buckets = agg.getBuckets();
updatePagerByAgg(pager, buckets.size());
return buckets.stream().map(e -> {
final Map<String, Object> map = new HashMap<>();
map.put(ID, Base64.getUrlEncoder().encodeToString(e.getKeyAsString().getBytes(StandardCharsets.UTF_8)));
map.put(KEY, e.getKeyAsString());
map.put(COUNT, e.getDocCount());
return map;
}).collect(Collectors.toList());
} else if (SearchLogPager.LOG_TYPE_SEARCH_ZEROHIT.equalsIgnoreCase(pager.logType)) {
list = (EsPagingResultBean<?>) searchLogBhv.selectPage(cb -> {
cb.fetchFirst(0);
createSearchLogCondition(pager, cb);
cb.query().setHitCount_Equal(0L);
cb.aggregation().setSearchWord_Terms(SearchLogPager.LOG_TYPE_SEARCH_ZEROHIT, op -> {
op.size(pager.getPageSize());
if (fessConfig.getSearchlogAggShardSizeAsInteger() >= 0) {
op.shardSize(fessConfig.getSearchlogAggShardSizeAsInteger());
}
}, null);
});
final Terms agg = list.getAggregations().get(SearchLogPager.LOG_TYPE_SEARCH_ZEROHIT);
final List<? extends Terms.Bucket> buckets = agg.getBuckets();
updatePagerByAgg(pager, buckets.size());
return buckets.stream().map(e -> {
final Map<String, Object> map = new HashMap<>();
map.put(ID, Base64.getUrlEncoder().encodeToString(e.getKeyAsString().getBytes(StandardCharsets.UTF_8)));
map.put(KEY, e.getKeyAsString());
map.put(COUNT, e.getDocCount());
return map;
}).collect(Collectors.toList());
// } else if (SearchLogPager.LOG_TYPE_SEARCH_ZEROCLICK.equalsIgnoreCase(pager.logType)) {
// list = (EsPagingResultBean<?>) searchLogBhv.selectPage(cb -> {
// cb.fetchFirst(0);
// createSearchLogCondition(pager, cb);
// // TODO 0 clicked
// });
} else {
list = (EsPagingResultBean<?>) searchLogBhv.selectPage(cb -> {
cb.paging(pager.getPageSize(), pager.getCurrentPageNumber());
cb.query().addOrderBy_RequestedAt_Desc();
createSearchLogCondition(pager, cb);
});
}
// update pager
BeanUtil.copyBeanToBean(list, pager, option -> option.include(Constants.PAGER_CONVERSION_RULE));
pager.setPageNumberList(list.pageRange(op -> {
op.rangeSize(fessConfig.getPagingPageRangeSizeAsInteger());
}).createPageNumberList());
return list;
}
Aggregations