...
|
...
|
@@ -27,7 +27,6 @@ public class SearchCommonService { |
|
|
private IndexService indexService;
|
|
|
@Autowired
|
|
|
private CacheService cacheService;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 通用的查询接口
|
...
|
...
|
@@ -38,10 +37,10 @@ public class SearchCommonService { |
|
|
*/
|
|
|
public SearchResult doSearch(final String indexName, final SearchParam searchParam) {
|
|
|
// 1、先从缓存中取结果
|
|
|
SearchResult resultFromCache = cacheService.getSearchResultFromCache(indexName, searchParam);
|
|
|
if (resultFromCache != null) {
|
|
|
return resultFromCache;
|
|
|
}
|
|
|
// SearchResult resultFromCache = cacheService.getSearchResultFromCache(indexName, searchParam);
|
|
|
// if (resultFromCache != null) {
|
|
|
// return resultFromCache;
|
|
|
// }
|
|
|
// 2、取不到再从ES获取结果
|
|
|
SearchResult searchResult = null;
|
|
|
Index firstIndex = indexService.getIndex(indexName);
|
...
|
...
|
@@ -53,10 +52,10 @@ public class SearchCommonService { |
|
|
}
|
|
|
}, firstIndex);
|
|
|
}
|
|
|
// 3、将ES中的缓存结果放进缓存中
|
|
|
if (searchResult != null) {
|
|
|
cacheService.addSearchResultToCache(indexName, searchParam, searchResult);
|
|
|
}
|
|
|
// // 3、将ES中的缓存结果放进缓存中
|
|
|
// if (searchResult != null) {
|
|
|
// cacheService.addSearchResultToCache(indexName, searchParam, searchResult);
|
|
|
// }
|
|
|
return searchResult;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -111,11 +110,11 @@ public class SearchCommonService { |
|
|
if (idList == null || idList.size() == 0) {
|
|
|
return result;
|
|
|
}
|
|
|
// 1、先从缓存中取结果
|
|
|
List<Map<String, Object>> resultFromCache = cacheService.getMultiGetResultFromCache(indexName, idList, fields);
|
|
|
if (resultFromCache != null) {
|
|
|
return resultFromCache;
|
|
|
}
|
|
|
// // 1、先从缓存中取结果
|
|
|
// List<Map<String, Object>> resultFromCache = cacheService.getMultiGetResultFromCache(indexName, idList, fields);
|
|
|
// if (resultFromCache != null) {
|
|
|
// return resultFromCache;
|
|
|
// }
|
|
|
// 2、先ES中批量获取结果
|
|
|
Index firstIndex = indexService.getIndex(indexName);
|
|
|
if (firstIndex != null) {
|
...
|
...
|
@@ -126,10 +125,10 @@ public class SearchCommonService { |
|
|
}
|
|
|
}, firstIndex);
|
|
|
}
|
|
|
// 3、将搜索结果加入到缓存中
|
|
|
if (result != null) {
|
|
|
cacheService.addMultiGetResultResultToCache(indexName, idList,fields, result);
|
|
|
}
|
|
|
// // 3、将搜索结果加入到缓存中
|
|
|
// if (result != null) {
|
|
|
// cacheService.addMultiGetResultResultToCache(indexName, idList,fields, result);
|
|
|
// }
|
|
|
return result;
|
|
|
}
|
|
|
|
...
|
...
|
|