Commit 6476b0d5 by 陈健智

修改getFirstArticle方法

parent 8cc8e277
...@@ -30,6 +30,7 @@ import com.zhiwei.brandkbs2.util.RedisUtil; ...@@ -30,6 +30,7 @@ import com.zhiwei.brandkbs2.util.RedisUtil;
import com.zhiwei.brandkbs2.util.TextUtil; import com.zhiwei.brandkbs2.util.TextUtil;
import com.zhiwei.brandkbs2.util.Tools; import com.zhiwei.brandkbs2.util.Tools;
import com.zhiwei.qbjc.bean.pojo.common.MessagePlatform; import com.zhiwei.qbjc.bean.pojo.common.MessagePlatform;
import io.lettuce.core.ScriptOutputType;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
...@@ -52,6 +53,7 @@ import org.elasticsearch.search.aggregations.bucket.histogram.ParsedDateHistogra ...@@ -52,6 +53,7 @@ import org.elasticsearch.search.aggregations.bucket.histogram.ParsedDateHistogra
import org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms; import org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms;
import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.FieldSortBuilder; import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.SortBuilders; import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.search.sort.SortOrder;
...@@ -814,23 +816,20 @@ public class MarkDataServiceImpl implements MarkDataService { ...@@ -814,23 +816,20 @@ public class MarkDataServiceImpl implements MarkDataService {
public JSONObject getFirstArticle(Long startTime, Long endTime, String aggTitle, String projectId, String linkedGroupId) throws IOException { public JSONObject getFirstArticle(Long startTime, Long endTime, String aggTitle, String projectId, String linkedGroupId) throws IOException {
// 索引 // 索引
String[] indexes = esClientDao.getIndexes(); String[] indexes = esClientDao.getIndexes();
// query // postFilter
BoolQueryBuilder query = projectLinkedGroupQuery(projectId, linkedGroupId); BoolQueryBuilder postFilter = projectLinkedGroupQuery(projectId, linkedGroupId);
query.must(QueryBuilders.rangeQuery("time").gte(startTime).lt(endTime)) postFilter.must(QueryBuilders.rangeQuery("time").gte(startTime).lt(endTime))
.must(QueryBuilders.termQuery("agg_title.keyword", aggTitle)); .must(QueryBuilders.termQuery("agg_title.keyword", aggTitle));
// response //sort
SearchResponse searchResponse = FieldSortBuilder sort = new FieldSortBuilder("time").order(SortOrder.ASC);
esClientDao.searchResponse(indexes, null, query, null, null, null, 0, 0, null);
//hits //hits
SearchHits hits = searchResponse.getHits(); SearchHits hits = esClientDao.searchHits(indexes, postFilter, null, null, sort, 0, 1, null);
SearchHit hit = hits.getAt(0);
JSONObject resultJSONObject = new JSONObject(); JSONObject resultJSONObject = new JSONObject();
hits.forEach(hit -> { resultJSONObject.put("content", hit.getSourceAsMap().get("content"));
Map<String, Object> source = hit.getSourceAsMap(); resultJSONObject.put("url", hit.getSourceAsMap().get("url"));
resultJSONObject.put("time", source.get("time")); resultJSONObject.put("realSource", hit.getSourceAsMap().get("real_source"));
resultJSONObject.put("content", source.get("content"));
resultJSONObject.put("url", source.get("url"));
resultJSONObject.put("realSource", source.get("real_source"));
});
return resultJSONObject; return resultJSONObject;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment