|
|
@ -4,22 +4,22 @@ import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.bfd.mf.common.service.common.CrudService; |
|
|
|
import com.bfd.mf.common.service.es.*; |
|
|
|
import com.bfd.mf.common.util.ESServerUtils; |
|
|
|
import com.bfd.mf.common.util.cache.ResponseParseUtils; |
|
|
|
import com.bfd.mf.common.util.constants.ESConstant; |
|
|
|
import com.bfd.mf.common.web.entity.mysql.SentimentModify; |
|
|
|
import com.bfd.mf.common.web.entity.mysql.cache.Cluster; |
|
|
|
import com.bfd.mf.common.web.repository.mysql.SentimentRepository; |
|
|
|
import com.bfd.mf.common.web.repository.mysql.base.SiteRepository; |
|
|
|
import com.bfd.mf.common.web.vo.params.QueryRequest; |
|
|
|
import com.bfd.mf.common.web.vo.view.monitor.ESMonitorBaseEntity; |
|
|
|
import com.bfd.mf.common.web.vo.view.monitor.ESMonitorEntity; |
|
|
|
import com.bfd.mf.config.BFDApiConfig; |
|
|
|
import org.elasticsearch.action.search.SearchRequestBuilder; |
|
|
|
import org.elasticsearch.action.search.SearchResponse; |
|
|
|
import org.elasticsearch.common.text.Text; |
|
|
|
import org.elasticsearch.index.query.BoolQueryBuilder; |
|
|
|
import org.elasticsearch.index.query.QueryBuilder; |
|
|
|
import org.elasticsearch.index.query.QueryBuilders; |
|
|
|
import org.elasticsearch.search.SearchHit; |
|
|
|
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField; |
|
|
|
import org.elasticsearch.search.sort.SortOrder; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
@ -54,27 +54,27 @@ public class SearchDataService extends CrudService<SentimentModify, SentimentRep |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
private SearchResponse buildDataIdQueryCrawl(Integer from, Integer searchSize, List<String> dataIdList, |
|
|
|
String orderFlag, String sortFlag, |
|
|
|
List<String> currentIndexList, Cluster cluster) { |
|
|
|
if (sortFlag.equals(ESConstant.COMMENT)) { |
|
|
|
sortFlag = ESConstant.COMMENTS_COUNT; |
|
|
|
} |
|
|
|
if (sortFlag.equals("")) { |
|
|
|
sortFlag = ESConstant.PUBTIME; |
|
|
|
} |
|
|
|
QueryBuilder queryBuilder = esCommonService.buildStringQueryByField(ESConstant.DATA_ID, dataIdList); |
|
|
|
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery().filter(queryBuilder); |
|
|
|
SearchRequestBuilder resultBuilder = esServerUtils |
|
|
|
.buildSearchRequestBuilder(cluster.getId(), currentIndexList) |
|
|
|
.setFrom(from) |
|
|
|
.setSize(searchSize) |
|
|
|
.setQuery(boolQueryBuilder) |
|
|
|
// .setScroll(TimeValue.timeValueMinutes(8)) |
|
|
|
.addSort(sortFlag, orderFlag.equals(ESConstant.ASC) ? SortOrder.ASC : SortOrder.DESC) |
|
|
|
.setFetchSource(ESConstant.FIELD_LIST_MONITOR_NORMAL, null); |
|
|
|
return resultBuilder.get(); |
|
|
|
} |
|
|
|
// private SearchResponse buildDataIdQueryCrawl(Integer from, Integer searchSize, List<String> dataIdList, |
|
|
|
// String orderFlag, String sortFlag, |
|
|
|
// List<String> currentIndexList, Cluster cluster) { |
|
|
|
// if (sortFlag.equals(ESConstant.COMMENT)) { |
|
|
|
// sortFlag = ESConstant.COMMENTS_COUNT; |
|
|
|
// } |
|
|
|
// if (sortFlag.equals("")) { |
|
|
|
// sortFlag = ESConstant.PUBTIME; |
|
|
|
// } |
|
|
|
// QueryBuilder queryBuilder = esCommonService.buildStringQueryByField(ESConstant.DATA_ID, dataIdList); |
|
|
|
// BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery().filter(queryBuilder); |
|
|
|
// SearchRequestBuilder resultBuilder = esServerUtils |
|
|
|
// .buildSearchRequestBuilder(cluster.getId(), currentIndexList) |
|
|
|
// .setFrom(from) |
|
|
|
// .setSize(searchSize) |
|
|
|
// .setQuery(boolQueryBuilder) |
|
|
|
// // .setScroll(TimeValue.timeValueMinutes(8)) |
|
|
|
// .addSort(sortFlag, orderFlag.equals(ESConstant.ASC) ? SortOrder.ASC : SortOrder.DESC) |
|
|
|
// .setFetchSource(ESConstant.FIELD_LIST_MONITOR_NORMAL, null); |
|
|
|
// return resultBuilder.get(); |
|
|
|
// } |
|
|
|
|
|
|
|
/** |
|
|
|
* 遍历查询结果调用解析组装方法 1 |
|
|
@ -497,6 +497,25 @@ public class SearchDataService extends CrudService<SentimentModify, SentimentRep |
|
|
|
if (sourceAsMap.containsKey("pageType")) { |
|
|
|
pageType = sourceAsMap.get("pageType").toString(); |
|
|
|
} |
|
|
|
// 获取高亮结果 |
|
|
|
// if(sourceAsMap.containsKey(ESConstant.HIGHLIGHT)){ |
|
|
|
// Map<String, HighlightField> highlight = (Map<String, HighlightField>) sourceAsMap.get(ESConstant.HIGHLIGHT); |
|
|
|
// |
|
|
|
// if(highlight.containsKey(ESConstant.CONTENT)){ |
|
|
|
// content = ""; |
|
|
|
// Text [] contents = highlight.get(ESConstant.CONTENT).getFragments(); |
|
|
|
// for (Text con:contents) { |
|
|
|
// content = content + con; |
|
|
|
// } |
|
|
|
// } |
|
|
|
// if(highlight.containsKey(ESConstant.TITLE)){ |
|
|
|
// title = ""; |
|
|
|
// Text [] titles = highlight.get(ESConstant.TITLE).getFragments(); |
|
|
|
// for (Text con:titles) { |
|
|
|
// title = title + con; |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
try { |
|
|
|
esMonitorEntity.setForwardContent(sourceAsMap.get("forwardContent").toString()); |
|
|
|
esMonitorEntity.setReadCount(readCount); |
|
|
@ -523,8 +542,17 @@ public class SearchDataService extends CrudService<SentimentModify, SentimentRep |
|
|
|
esMonitorEntity.setHlKeyWords(hlKeywords); |
|
|
|
// 评论数、转发数、点赞数、收藏数 |
|
|
|
esMonitorEntity.setCommentsCount(Integer.valueOf(sourceAsMap.getOrDefault(ESConstant.COMMENTS_COUNT, 0).toString())); |
|
|
|
if(quoteCount.equals("-1")){ |
|
|
|
quoteCount = "-"; |
|
|
|
} |
|
|
|
esMonitorEntity.setQuoteCount(quoteCount); |
|
|
|
if(attitudeCount.equals("-1")){ |
|
|
|
attitudeCount = "-"; |
|
|
|
} |
|
|
|
esMonitorEntity.setAttitudesCount(attitudeCount); |
|
|
|
if(collentCount.equals("-1")){ |
|
|
|
collentCount = "-"; |
|
|
|
} |
|
|
|
esMonitorEntity.setCollectCount(collentCount); |
|
|
|
esMonitorEntity.setViewCnt(viewCnt); |
|
|
|
// 视频、音频 |
|
|
@ -532,8 +560,17 @@ public class SearchDataService extends CrudService<SentimentModify, SentimentRep |
|
|
|
esMonitorEntity.setAsrText(asrText); |
|
|
|
// 用户字段 |
|
|
|
esMonitorEntity.setUserUrl(userUrl); |
|
|
|
if(fansCount.equals("-1")){ |
|
|
|
fansCount = "-"; |
|
|
|
} |
|
|
|
esMonitorEntity.setFansCount(fansCount); |
|
|
|
if(friendsCount.equals("-1")){ |
|
|
|
friendsCount = "-"; |
|
|
|
} |
|
|
|
esMonitorEntity.setFriendsCount(friendsCount); |
|
|
|
if(postCount.equals("-1")){ |
|
|
|
postCount = "-"; |
|
|
|
} |
|
|
|
esMonitorEntity.setPostCount(postCount); |
|
|
|
esMonitorEntity.setLocation(location); |
|
|
|
|
|
|
@ -599,11 +636,11 @@ public class SearchDataService extends CrudService<SentimentModify, SentimentRep |
|
|
|
String indexType = "cl_index_" + docId.split("_")[1]; |
|
|
|
currentIndexList.add(indexType); |
|
|
|
} |
|
|
|
JSONObject result = getCommentListByDocId(queryRequest, cluster, currentIndexList); |
|
|
|
JSONObject result = getCommentListByDocId(queryRequest, currentIndexList); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
private JSONObject getCommentListByDocId(QueryRequest queryRequest, Cluster cluster, List<String> currentIndexList) { |
|
|
|
private JSONObject getCommentListByDocId(QueryRequest queryRequest, List<String> currentIndexList) { |
|
|
|
JSONObject json = new JSONObject(); |
|
|
|
try { |
|
|
|
String docId = queryRequest.getDocId(); |
|
|
@ -633,7 +670,7 @@ public class SearchDataService extends CrudService<SentimentModify, SentimentRep |
|
|
|
if (null != queryRequest.getDataId() && !queryRequest.getDataId().equals("")) { |
|
|
|
String dataId = queryRequest.getDataId(); |
|
|
|
// String docType = queryRequest.getDocType(); |
|
|
|
JSONObject TopComment = getCommentByDataId(cluster, currentIndexList, dataId, docType); |
|
|
|
JSONObject TopComment = getCommentByDataId(currentIndexList, dataId, docType); |
|
|
|
// System.out.println(TopComment); |
|
|
|
if (TopComment.size() > 0) { |
|
|
|
size = 1L; |
|
|
@ -643,9 +680,10 @@ public class SearchDataService extends CrudService<SentimentModify, SentimentRep |
|
|
|
} |
|
|
|
|
|
|
|
String siteId = queryRequest.getSiteId(); |
|
|
|
long clusterId = 4; |
|
|
|
/**获取信息*/ |
|
|
|
SearchRequestBuilder builder = esServerUtils |
|
|
|
.buildSearchRequestBuilder(cluster.getId(), currentIndexList) |
|
|
|
.buildSearchRequestBuilder(clusterId,currentIndexList) |
|
|
|
.setQuery(boolQueryBuilder) |
|
|
|
.setFrom(start) |
|
|
|
.setSize(limit) |
|
|
@ -672,8 +710,9 @@ public class SearchDataService extends CrudService<SentimentModify, SentimentRep |
|
|
|
return json; |
|
|
|
} |
|
|
|
|
|
|
|
private JSONObject getCommentByDataId(Cluster cluster, List<String> currentIndexList, String dataId, String docType) { |
|
|
|
private JSONObject getCommentByDataId( List<String> currentIndexList, String dataId, String docType) { |
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
long clusterId = 4L; |
|
|
|
try { |
|
|
|
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery().must(QueryBuilders.termQuery(ESConstant.DATA_ID, dataId)); |
|
|
|
// 由于电商的数据的primary =1 因此不加这个条件了, |
|
|
@ -682,7 +721,7 @@ public class SearchDataService extends CrudService<SentimentModify, SentimentRep |
|
|
|
// }else { |
|
|
|
boolQueryBuilder.must(QueryBuilders.termQuery(ESConstant.PRIMARY, 0)); |
|
|
|
// } |
|
|
|
SearchRequestBuilder builder = esServerUtils.buildSearchRequestBuilder(cluster.getId(), currentIndexList) |
|
|
|
SearchRequestBuilder builder = esServerUtils.buildSearchRequestBuilder(clusterId, currentIndexList) |
|
|
|
.setQuery(boolQueryBuilder) |
|
|
|
.setFetchSource(ESConstant.COMMENT_FIELD_DATA, null); |
|
|
|
|
|
|
@ -720,7 +759,7 @@ public class SearchDataService extends CrudService<SentimentModify, SentimentRep |
|
|
|
currentIndexList.add(subjectId); |
|
|
|
String docId = queryRequest.getDocId(); |
|
|
|
// 根据ID 获取一条详情数据 |
|
|
|
JSONObject jsonObject = getOneDataByDocId(docId, cluster, currentIndexList); |
|
|
|
JSONObject jsonObject = getOneDataByDocId(docId,currentIndexList); |
|
|
|
jsonObject = setLable(jsonObject); |
|
|
|
// 替换几个 pathSize 中的链接的前缀 |
|
|
|
if (jsonObject.containsKey(ESConstant.IMAGEPATHSIZE)) { |
|
|
@ -815,6 +854,28 @@ public class SearchDataService extends CrudService<SentimentModify, SentimentRep |
|
|
|
newJsonObject.put(ESConstant.URL, jsonObject.get(ESConstant.URL)); |
|
|
|
jsonObject.put(ESConstant.AUTHOR, newJsonObject); |
|
|
|
} |
|
|
|
// attitudesCount |
|
|
|
if(jsonObject.containsKey(ESConstant.ATTITUDES_COUNT)){ |
|
|
|
String attitudesCount = jsonObject.get(ESConstant.ATTITUDES_COUNT).toString(); |
|
|
|
if(attitudesCount.equals("-1")){ |
|
|
|
attitudesCount = "-"; |
|
|
|
jsonObject.put(ESConstant.ATTITUDES_COUNT,attitudesCount); |
|
|
|
} |
|
|
|
} |
|
|
|
if(jsonObject.containsKey(ESConstant.COMMENTS_COUNT)){ |
|
|
|
String commentsCount = jsonObject.get(ESConstant.COMMENTS_COUNT).toString(); |
|
|
|
if(commentsCount.equals("-1")){ |
|
|
|
commentsCount = "-"; |
|
|
|
jsonObject.put(ESConstant.COMMENTS_COUNT,commentsCount); |
|
|
|
} |
|
|
|
} |
|
|
|
if(jsonObject.containsKey(ESConstant.QUOTE_COUNT)){ |
|
|
|
String quoteCount = jsonObject.get(ESConstant.QUOTE_COUNT).toString(); |
|
|
|
if(quoteCount.equals("-1")){ |
|
|
|
quoteCount = "-"; |
|
|
|
jsonObject.put(ESConstant.QUOTE_COUNT,quoteCount); |
|
|
|
} |
|
|
|
} |
|
|
|
return jsonObject; |
|
|
|
} |
|
|
|
|
|
|
@ -852,16 +913,17 @@ public class SearchDataService extends CrudService<SentimentModify, SentimentRep |
|
|
|
return jsonObject; |
|
|
|
} |
|
|
|
|
|
|
|
private JSONObject getOneDataByDocId(String docId, Cluster cluster, List<String> currentIndexList) { |
|
|
|
private JSONObject getOneDataByDocId(String docId, List<String> currentIndexList) { |
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
/**依据文档Id查询对应的文档*/ |
|
|
|
QueryBuilder queryBuilder = esCommonService.buildKeyWordsQueryBuilder(docId, ESConstant.DOC_ID); |
|
|
|
QueryBuilder queryBuilder1 = QueryBuilders.termQuery(ESConstant.PRIMARY, 1); |
|
|
|
BoolQueryBuilder conditionQuery = QueryBuilders.boolQuery().must(queryBuilder).must(queryBuilder1); |
|
|
|
|
|
|
|
Long clusterId = 4L; |
|
|
|
/**获取信息*/ |
|
|
|
SearchRequestBuilder builder = esServerUtils |
|
|
|
.buildSearchRequestBuilder(cluster.getId(), currentIndexList) |
|
|
|
.buildSearchRequestBuilder(clusterId, currentIndexList) |
|
|
|
.setQuery(conditionQuery) |
|
|
|
.setFetchSource(ESConstant.FIELD_DATA, null); |
|
|
|
|
|
|
@ -899,109 +961,109 @@ public class SearchDataService extends CrudService<SentimentModify, SentimentRep |
|
|
|
} |
|
|
|
|
|
|
|
// 之前的 queryDataList |
|
|
|
public JSONObject queryDataList(QueryRequest queryRequest) throws Exception { |
|
|
|
|
|
|
|
// 先看一下有没有 subjectId ,如果没有的话标识查询的是 全部数据 |
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
Cluster cluster = null; |
|
|
|
List<String> currentIndexList = new ArrayList<>(); |
|
|
|
// 获取ES的参数及要查询的索引列表 |
|
|
|
String subjectId = queryRequest.getSubjectId(); |
|
|
|
// cluster = clusterService.findClusterByType(Cluster.CLUSTER_TYPE.special_cluster_type); // 111 special_cluster_type |
|
|
|
currentIndexList = subjectQueryDataService.getIndexBySubjectIds(subjectId); |
|
|
|
Long clusterId = cluster.getId(); |
|
|
|
logger.info("[SearchDataService] queryDataList clusterId : {}; currentIndexList : {}", clusterId, currentIndexList.toString()); |
|
|
|
|
|
|
|
String orderFlag = queryRequest.getOrder(); // 排序方式 asc/desc |
|
|
|
String sortFlag = queryRequest.getSidx(); // 排序字段 |
|
|
|
|
|
|
|
long sortTimeSeries = System.currentTimeMillis(); |
|
|
|
long foldDocAllNumber = 0L; |
|
|
|
List<ESMonitorEntity> esMonitorEntityLists = new ArrayList<>(); |
|
|
|
|
|
|
|
// 开始查询 |
|
|
|
List<String> dataIdList = new ArrayList<>(); |
|
|
|
List<SearchResponse> cacheList = subjectQueryDataService.fetchResponseDataFromCache( |
|
|
|
queryRequest, clusterId, |
|
|
|
orderFlag, sortFlag, |
|
|
|
currentIndexList, |
|
|
|
ESConstant.FIELD_ID_LIST); |
|
|
|
|
|
|
|
if (cacheList.size() == 0) { |
|
|
|
logger.info("没有查到相关数据哦!"); |
|
|
|
jsonObject.put(ESConstant.ALLDOCNUMBER, foldDocAllNumber);// 实际查询总量 |
|
|
|
jsonObject.put(ESConstant.MONITORLISTS, esMonitorEntityLists); |
|
|
|
return jsonObject; |
|
|
|
} |
|
|
|
|
|
|
|
Map<String, ESMonitorBaseEntity> timeSeriesMap = new HashMap<>(); |
|
|
|
// 获取查询结果List的总量及结果的map |
|
|
|
foldDocAllNumber = ResponseParseUtils.combineEsAndCatchResponse( |
|
|
|
cacheList, |
|
|
|
timeSeriesMap); |
|
|
|
|
|
|
|
Collection<ESMonitorBaseEntity> values = timeSeriesMap.values(); |
|
|
|
List<ESMonitorBaseEntity> timeSeries = new ArrayList<>(values); |
|
|
|
|
|
|
|
Integer limit = queryRequest.getLimit(); //每页的数量 |
|
|
|
Integer start = (queryRequest.getPage() - 1) * limit; //起始页(0,20,40....) |
|
|
|
|
|
|
|
// 将查询结果的 dataId 写入到 dataIdList中 |
|
|
|
Map<String, String> dedupmap = new HashMap<>(); |
|
|
|
if (timeSeries.size() > 0) { |
|
|
|
for (int i = start; i < timeSeries.size(); i++) { |
|
|
|
if (null != timeSeries.get(i).getDataId() && !("").equals(timeSeries.get(i).getDataId())) { |
|
|
|
dedupmap.put(timeSeries.get(i).getDataId(), timeSeries.get(i).getDataId()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
for (String key : dedupmap.keySet()) { |
|
|
|
dataIdList.add(dedupmap.get(key)); |
|
|
|
} |
|
|
|
SearchResponse response = buildDataIdQueryCrawl( |
|
|
|
start, |
|
|
|
limit, |
|
|
|
dataIdList, |
|
|
|
orderFlag, |
|
|
|
sortFlag, |
|
|
|
currentIndexList, |
|
|
|
cluster); |
|
|
|
|
|
|
|
logger.info("Response : ", response); |
|
|
|
parseQueryResult(response, esMonitorEntityLists); |
|
|
|
Long responseStart = System.currentTimeMillis(); |
|
|
|
logger.info("[SearchDataService] [responseStart] used :{}", System.currentTimeMillis() - responseStart); |
|
|
|
long pageTimeCount = System.currentTimeMillis(); |
|
|
|
logger.info("--------------------------third step,structure page search from es ;response of the HTTP status " + |
|
|
|
"code is {} ,the time used: {}" + |
|
|
|
"-------------------------------------" + (pageTimeCount - sortTimeSeries)); |
|
|
|
|
|
|
|
Collections.sort(esMonitorEntityLists); |
|
|
|
// 实际查询总量 |
|
|
|
jsonObject.put(ESConstant.ALLDOCNUMBER, foldDocAllNumber); |
|
|
|
jsonObject.put(ESConstant.MONITORLISTS, esMonitorEntityLists); |
|
|
|
return jsonObject; |
|
|
|
} |
|
|
|
// public JSONObject queryDataList(QueryRequest queryRequest) throws Exception { |
|
|
|
// |
|
|
|
// // 先看一下有没有 subjectId ,如果没有的话标识查询的是 全部数据 |
|
|
|
// JSONObject jsonObject = new JSONObject(); |
|
|
|
// Cluster cluster = null; |
|
|
|
// List<String> currentIndexList = new ArrayList<>(); |
|
|
|
// // 获取ES的参数及要查询的索引列表 |
|
|
|
// String subjectId = queryRequest.getSubjectId(); |
|
|
|
// // cluster = clusterService.findClusterByType(Cluster.CLUSTER_TYPE.special_cluster_type); // 111 special_cluster_type |
|
|
|
// currentIndexList = subjectQueryDataService.getIndexBySubjectIds(subjectId); |
|
|
|
// // Long clusterId = cluster.getId(); |
|
|
|
// Long clusterId = 4L; |
|
|
|
// logger.info("[SearchDataService] queryDataList clusterId : {}; currentIndexList : {}", clusterId, currentIndexList.toString()); |
|
|
|
// |
|
|
|
// String orderFlag = queryRequest.getOrder(); // 排序方式 asc/desc |
|
|
|
// String sortFlag = queryRequest.getSidx(); // 排序字段 |
|
|
|
// |
|
|
|
// long sortTimeSeries = System.currentTimeMillis(); |
|
|
|
// long foldDocAllNumber = 0L; |
|
|
|
// List<ESMonitorEntity> esMonitorEntityLists = new ArrayList<>(); |
|
|
|
// |
|
|
|
// // 开始查询 |
|
|
|
// List<String> dataIdList = new ArrayList<>(); |
|
|
|
// List<SearchResponse> cacheList = subjectQueryDataService.fetchResponseDataFromCache( |
|
|
|
// queryRequest, clusterId, |
|
|
|
// orderFlag, sortFlag, |
|
|
|
// currentIndexList, |
|
|
|
// ESConstant.FIELD_ID_LIST); |
|
|
|
// |
|
|
|
// if (cacheList.size() == 0) { |
|
|
|
// logger.info("没有查到相关数据哦!"); |
|
|
|
// jsonObject.put(ESConstant.ALLDOCNUMBER, foldDocAllNumber);// 实际查询总量 |
|
|
|
// jsonObject.put(ESConstant.MONITORLISTS, esMonitorEntityLists); |
|
|
|
// return jsonObject; |
|
|
|
// } |
|
|
|
// |
|
|
|
// Map<String, ESMonitorBaseEntity> timeSeriesMap = new HashMap<>(); |
|
|
|
// // 获取查询结果List的总量及结果的map |
|
|
|
// foldDocAllNumber = ResponseParseUtils.combineEsAndCatchResponse( |
|
|
|
// cacheList, |
|
|
|
// timeSeriesMap); |
|
|
|
// |
|
|
|
// Collection<ESMonitorBaseEntity> values = timeSeriesMap.values(); |
|
|
|
// List<ESMonitorBaseEntity> timeSeries = new ArrayList<>(values); |
|
|
|
// |
|
|
|
// Integer limit = queryRequest.getLimit(); //每页的数量 |
|
|
|
// Integer start = (queryRequest.getPage() - 1) * limit; //起始页(0,20,40....) |
|
|
|
// |
|
|
|
// // 将查询结果的 dataId 写入到 dataIdList中 |
|
|
|
// Map<String, String> dedupmap = new HashMap<>(); |
|
|
|
// if (timeSeries.size() > 0) { |
|
|
|
// for (int i = start; i < timeSeries.size(); i++) { |
|
|
|
// if (null != timeSeries.get(i).getDataId() && !("").equals(timeSeries.get(i).getDataId())) { |
|
|
|
// dedupmap.put(timeSeries.get(i).getDataId(), timeSeries.get(i).getDataId()); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
// for (String key : dedupmap.keySet()) { |
|
|
|
// dataIdList.add(dedupmap.get(key)); |
|
|
|
// } |
|
|
|
// SearchResponse response = buildDataIdQueryCrawl( |
|
|
|
// start, |
|
|
|
// limit, |
|
|
|
// dataIdList, |
|
|
|
// orderFlag, |
|
|
|
// sortFlag, |
|
|
|
// currentIndexList, |
|
|
|
// cluster); |
|
|
|
// |
|
|
|
// logger.info("Response : ", response); |
|
|
|
// parseQueryResult(response, esMonitorEntityLists); |
|
|
|
// Long responseStart = System.currentTimeMillis(); |
|
|
|
// logger.info("[SearchDataService] [responseStart] used :{}", System.currentTimeMillis() - responseStart); |
|
|
|
// long pageTimeCount = System.currentTimeMillis(); |
|
|
|
// logger.info("--------------------------third step,structure page search from es ;response of the HTTP status " + |
|
|
|
// "code is {} ,the time used: {}" + |
|
|
|
// "-------------------------------------" + (pageTimeCount - sortTimeSeries)); |
|
|
|
// |
|
|
|
// Collections.sort(esMonitorEntityLists); |
|
|
|
// // 实际查询总量 |
|
|
|
// jsonObject.put(ESConstant.ALLDOCNUMBER, foldDocAllNumber); |
|
|
|
// jsonObject.put(ESConstant.MONITORLISTS, esMonitorEntityLists); |
|
|
|
// return jsonObject; |
|
|
|
// } |
|
|
|
|
|
|
|
/** |
|
|
|
* 查询某个确认的专题下的数据列表 |
|
|
|
* 查询某个确认的 文件夹 下的数据列表 |
|
|
|
*/ |
|
|
|
public JSONObject queryDataInOneIndex(QueryRequest queryRequest) { |
|
|
|
public JSONObject queryDataFromFolder(QueryRequest queryRequest) { |
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
try { |
|
|
|
// Cluster cluster = clusterService.findClusterByType(Cluster.CLUSTER_TYPE.special_cluster_type); |
|
|
|
List<String> currentIndexList = subjectQueryDataService.getIndexBySubjectIds( queryRequest.getSubjectId()); |
|
|
|
//Long clusterId = cluster.getId(); |
|
|
|
logger.info("[SearchDataService] queryDataInOneIndex: currentIndexList : {}", currentIndexList.toString()); |
|
|
|
logger.info("[SearchDataService] queryDataFromFolder: currentIndexList : {}", currentIndexList.toString()); |
|
|
|
// String indexName = currentIndexList.get(0); |
|
|
|
String indexNames[] = currentIndexList.toArray(new String[currentIndexList.size()]); |
|
|
|
List<JSONObject> dataList = esQueryServiceForSQMini.queryDataFromOneSubject(indexNames, queryRequest); |
|
|
|
|
|
|
|
List<ESMonitorEntity> esMonitorEntityLists = new ArrayList<>(); |
|
|
|
Integer searchType = queryRequest.getSearchType(); |
|
|
|
parseQueryResult(dataList, esMonitorEntityLists, searchType); |
|
|
|
Long totalCount = esQueryServiceForSQMini.queryDataCountFromOneSubject(indexNames, queryRequest); |
|
|
|
logger.info("[SearchDataService] queryDataInOneIndex: {}", totalCount); |
|
|
|
logger.info("[SearchDataService] queryDataFromFolder: {}", totalCount); |
|
|
|
jsonObject.put(ESConstant.ALLDOCNUMBER, totalCount); |
|
|
|
jsonObject.put(ESConstant.MONITORLISTS, esMonitorEntityLists); |
|
|
|
|
|
|
@ -1017,7 +1079,7 @@ public class SearchDataService extends CrudService<SentimentModify, SentimentRep |
|
|
|
* @param queryRequest |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public JSONObject exportDataInSubjectIndex(QueryRequest queryRequest) { |
|
|
|
public JSONObject exportDataFromFolder(QueryRequest queryRequest) { |
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
try { |
|
|
|
// 获取 ES 的连接方式及要查询的索引列表 专题索引 special_cluster_type |
|
|
@ -1025,7 +1087,7 @@ public class SearchDataService extends CrudService<SentimentModify, SentimentRep |
|
|
|
List<String> currentIndexList = subjectQueryDataService.getIndexBySubjectIds( queryRequest.getSubjectId()); |
|
|
|
// Long clusterId = cluster.getId(); |
|
|
|
String[] indexName = currentIndexList.toArray(new String[currentIndexList.size()]); |
|
|
|
logger.info("[SearchDataService] exportDataInSubjectIndex : IndexName :{} ; currentIndexList :{}", indexName[0], currentIndexList.toString()); |
|
|
|
logger.info("[SearchDataService] exportDataFromFolder : IndexName :{} ; currentIndexList :{}", indexName[0], currentIndexList.toString()); |
|
|
|
// 开始查询 |
|
|
|
jsonObject = esQueryServiceForSQMini.exportDataFromOneSubject(indexName, queryRequest); |
|
|
|
List<JSONObject> dataList = (List<JSONObject>) jsonObject.get(ESConstant.MONITORLISTS); |
|
|
|