|
@@ -1,10 +1,12 @@
|
|
|
package com.bowintek.smartsearch.services.impl;
|
|
|
|
|
|
+import ch.qos.logback.core.joran.node.ComponentNode;
|
|
|
import com.bowintek.smartsearch.mapper.EsQueryLogMapper;
|
|
|
import com.bowintek.smartsearch.mapper.EsRelationLogMapper;
|
|
|
import com.bowintek.smartsearch.mapper.cquery.EsQueryLogCQuery;
|
|
|
import com.bowintek.smartsearch.model.*;
|
|
|
import com.bowintek.smartsearch.services.service.QueryLogService;
|
|
|
+import com.bowintek.smartsearch.util.DictionaryUtils;
|
|
|
import com.bowintek.smartsearch.vo.EsQueryLogVo;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
@@ -12,9 +14,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.function.Predicate;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
@Component
|
|
|
public class QueryLogServiceImpl implements QueryLogService {
|
|
@@ -45,12 +50,11 @@ public class QueryLogServiceImpl implements QueryLogService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Cacheable(value = "esQueryLogList")
|
|
|
public List<EsQueryLogVo> getQueryList(String queryText) {
|
|
|
- /*synchronized (lockObject) {
|
|
|
+ synchronized (lockObject) {
|
|
|
//用户输入查询时,从本地缓存加载数据
|
|
|
long timeSpan = (new Date()).getTime() - cacheTime;
|
|
|
- if (timeSpan > 30 * 1000 || queryTextCache == null) {
|
|
|
+ if (timeSpan > 5 * 60 * 1000 || queryTextCache == null) {
|
|
|
queryTextCache = getQueryGroupList(0, 10000, null).getList();
|
|
|
cacheTime = (new Date()).getTime();
|
|
|
}
|
|
@@ -58,9 +62,37 @@ public class QueryLogServiceImpl implements QueryLogService {
|
|
|
|
|
|
List<EsQueryLogVo> rtnList = queryTextCache.stream()
|
|
|
.filter(log -> log.getQueryText().contains(queryText)).toList();
|
|
|
- return rtnList;*/
|
|
|
- List<EsQueryLogVo> rtnList = getQueryGroupList(0, 10000, null).getList();
|
|
|
- return rtnList.stream().filter(log -> log.getQueryText().contains(queryText)).toList();
|
|
|
+ return rtnList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<EsQueryLogVo> getCurrentUserListByKeyString(String queryText, String userId) {
|
|
|
+ List<EsQueryLogVo> resList = new ArrayList<>();
|
|
|
+ List<EsQueryLogVo> firstList = esQueryLogCQuery.getCurrentUserQueryGroupList(queryText, userId);
|
|
|
+ resList.addAll(firstList);
|
|
|
+
|
|
|
+ if(firstList.size() < 30){
|
|
|
+ //不足30条,则从搜索次数最多的前10000条数据中补充
|
|
|
+ List<EsQueryLogVo> lastList = getQueryList(queryText).stream().filter(log -> log.getQueryText().contains(queryText)).toList();
|
|
|
+ int poorNum = 30 - firstList.size();
|
|
|
+ int poorNumSize = lastList.size() >= poorNum ? poorNum : lastList.size();
|
|
|
+ if(poorNumSize>0){
|
|
|
+ //合并
|
|
|
+ resList.addAll(lastList.subList(0, poorNumSize));
|
|
|
+ //去重
|
|
|
+ resList = resList.stream()
|
|
|
+ .filter(distinctByKey(d->d.getQueryText()))
|
|
|
+ .sorted(Comparator.comparing(EsQueryLogVo::getIsSelf))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return resList;
|
|
|
+ }
|
|
|
+
|
|
|
+ static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
|
|
|
+ Map<Object, Boolean> seen = new ConcurrentHashMap<>();
|
|
|
+ return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
|
|
|
}
|
|
|
|
|
|
@Override
|