|
@ -13,6 +13,8 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
@Service
|
|
@ -21,6 +23,8 @@ public class ProfileSearchService extends BaseJpaService<HotWord, HotWordDao> {
|
|
|
|
|
|
private static final String PrefixRedis = "HOTWORDS_";
|
|
|
|
|
|
private static final Pattern p = Pattern.compile("\"(.*?)\"");//正则提取引号的内容
|
|
|
|
|
|
@Autowired
|
|
|
private RedisTemplate redisTemplate;
|
|
|
@Autowired
|
|
@ -68,12 +72,18 @@ public class ProfileSearchService extends BaseJpaService<HotWord, HotWordDao> {
|
|
|
private List<String> getSearchKeyWords(String keys){
|
|
|
List<String> list = new ArrayList<>();
|
|
|
if(StringUtils.isNotBlank(keys)){
|
|
|
Matcher m = p.matcher(keys);
|
|
|
while(m.find()){
|
|
|
String group = m.group();
|
|
|
list.add(group.replace("\"",""));
|
|
|
}
|
|
|
for(String key:list){
|
|
|
keys = keys.replace("\""+key+"\"","");
|
|
|
}
|
|
|
String[] keyArray = keys.split(" ");
|
|
|
for(String key:keyArray){
|
|
|
if(StringUtils.isNotBlank(key) && !"or".equalsIgnoreCase(key) && !"and".equalsIgnoreCase(key)){
|
|
|
if(key.startsWith("\"") && key.endsWith("\"")){
|
|
|
key = key.substring(1,key.length()-1);
|
|
|
}else if(key.startsWith("+") || key.startsWith("-")){
|
|
|
if(key.startsWith("+") || key.startsWith("-")){
|
|
|
key = key.substring(1);
|
|
|
}
|
|
|
list.add(key);
|