|
@@ -109,7 +109,7 @@ func (kws *KeyWordsSearch) SaveKeyWordsToHistory(in *bxcore.SearchReq) {
|
|
|
if in.KeyWords != "" {
|
|
|
//历史记录
|
|
|
history := redis.GetStr("other", "s_"+in.UserId)
|
|
|
- keys := util.SearchHistory(history, in.KeyWords)
|
|
|
+ keys := util.SearchHistory(history, in.KeyWords, in.AdditionalWords)
|
|
|
if len(keys) > 0 {
|
|
|
if b := redis.Put("other", "s_"+in.UserId, strings.Join(keys, ","), -1); !b {
|
|
|
logx.Info("保存搜索记录异常,用户id:", in.UserId)
|
|
@@ -118,8 +118,62 @@ func (kws *KeyWordsSearch) SaveKeyWordsToHistory(in *bxcore.SearchReq) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// GetSearchKeyWordsQueryStr 关键词和附加词处理 获取关键词查询条件;是否进行分词查询
|
|
|
+func (kws *KeyWordsSearch) GetSearchKeyWordsQueryStr(in *bxcore.SearchReq) (words []string) {
|
|
|
+ // in.SearchMode 搜索模式:0:精准搜索;1:模糊搜索
|
|
|
+ // 精准搜索:不分词,完全匹配;(中间带空格的关键词组自动分词)
|
|
|
+ // 模糊搜索:对用户输入的单个关键词进行分词处理,但必须都存在;
|
|
|
+ if in.SearchMode == 1 {
|
|
|
+ var (
|
|
|
+ keyWords, addWords []string
|
|
|
+ )
|
|
|
+ //主关键词词组
|
|
|
+ if in.KeyWords != "" {
|
|
|
+ for _, mv := range strings.Split(in.KeyWords, IC.C.JYKeyMark) {
|
|
|
+ if strings.TrimSpace(mv) != "" {
|
|
|
+ if ikWords := util.HttpEs(mv, "ik_smart", IC.DB.Es.Addr); ikWords != "" {
|
|
|
+ keyWords = append(keyWords, strings.Split(ikWords, IC.C.JYKeyMark)...)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ in.KeyWords = strings.Join(keyWords, IC.C.JYKeyMark)
|
|
|
+ words = append(words, in.KeyWords)
|
|
|
+ }
|
|
|
+ //附加词组
|
|
|
+ //多组附加词,每组间,号隔开。每组内如果关键词中间有空格,自动分词
|
|
|
+ if in.AdditionalWords != "" {
|
|
|
+ for _, awv := range strings.Split(in.AdditionalWords, ",") {
|
|
|
+ var (
|
|
|
+ addWord []string
|
|
|
+ )
|
|
|
+ for _, av := range strings.Split(awv, IC.C.JYKeyMark) {
|
|
|
+ if strings.TrimSpace(av) != "" {
|
|
|
+ if ikWords := util.HttpEs(av, "ik_smart", IC.DB.Es.Addr); ikWords != "" {
|
|
|
+ addWord = append(addWord, strings.Split(ikWords, IC.C.JYKeyMark)...)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ addWords = append(addWords, strings.Join(addWord, IC.C.JYKeyMark))
|
|
|
+ addWord = []string{}
|
|
|
+ }
|
|
|
+ words = append(words, addWords...)
|
|
|
+ in.AdditionalWords = strings.Join(addWords, ",")
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ words = append(words, strings.Split(in.KeyWords, IC.C.JYKeyMark)...)
|
|
|
+ for _, awv := range strings.Split(in.AdditionalWords, ",") {
|
|
|
+ for _, av := range strings.Split(awv, IC.C.JYKeyMark) {
|
|
|
+ if strings.TrimSpace(av) != "" {
|
|
|
+ words = append(words, strings.Split(in.KeyWords, IC.C.JYKeyMark)...)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// SearchParamsHandle 搜索条件 处理
|
|
|
-func (kws *KeyWordsSearch) SearchParamsHandle(in *bxcore.SearchReq) {
|
|
|
+func (kws *KeyWordsSearch) SearchParamsHandle(in *bxcore.SearchReq) []string {
|
|
|
//判断用户身份
|
|
|
userInfo := util.GetVipState(IC.MainMysql, IC.Mgo, in.UserId, in.EntId)
|
|
|
//是否是付费用户
|
|
@@ -200,28 +254,22 @@ func (kws *KeyWordsSearch) SearchParamsHandle(in *bxcore.SearchReq) {
|
|
|
if in.KeyWords != "" {
|
|
|
//关键词处理
|
|
|
in.KeyWords = strings.TrimSpace(in.KeyWords)
|
|
|
- //以后可能会出现 关键词 C++ 等带+的关键词
|
|
|
in.InterceptKeyWords, in.InterceptOtherWords, in.KeyWords = util.InterceptSearchKW(in.KeyWords, MC.IntAllDef(IC.C.KeywordsLimit, 35), len(in.Industry) == 0)
|
|
|
- //附加词在关键词的基础上 有效
|
|
|
- //附加词 每组附加词不能超过15个字符
|
|
|
- if in.AdditionalWords != "" {
|
|
|
- var additionalWords []string
|
|
|
- for _, ak := range strings.Split(in.AdditionalWords, ",") {
|
|
|
- if len([]rune(ak)) > 15 {
|
|
|
- additionalWords = append(additionalWords, string([]rune(ak)[:15]))
|
|
|
- } else {
|
|
|
- additionalWords = append(additionalWords, ak)
|
|
|
- }
|
|
|
+ }
|
|
|
+ //附加词 每组附加词不能超过15个字符
|
|
|
+ if in.AdditionalWords != "" {
|
|
|
+ var additionalWords []string
|
|
|
+ for _, ak := range strings.Split(in.AdditionalWords, ",") {
|
|
|
+ if len([]rune(ak)) > 15 {
|
|
|
+ additionalWords = append(additionalWords, string([]rune(ak)[:15]))
|
|
|
+ } else {
|
|
|
+ additionalWords = append(additionalWords, ak)
|
|
|
}
|
|
|
- in.AdditionalWords = strings.ReplaceAll(strings.Join(additionalWords, IC.C.JYKeyMark), " ", IC.C.JYKeyMark) //util.MatchSpace.ReplaceAllString(in.AdditionalWords, IC.C.JYKeyMark)
|
|
|
}
|
|
|
- //格式化关键词
|
|
|
- in.KeyWords = util.GetSearchKeyWordsQueryStr(in)
|
|
|
- //更新关键词搜索历史记录
|
|
|
- go kws.SaveKeyWordsToHistory(in)
|
|
|
- } else {
|
|
|
- in.AdditionalWords = ""
|
|
|
+ in.AdditionalWords = strings.Join(additionalWords, ",") //分组不变
|
|
|
}
|
|
|
+ //更新关键词搜索历史记录
|
|
|
+ go kws.SaveKeyWordsToHistory(in)
|
|
|
//排除词 每组排除词不能超过15个字符
|
|
|
if in.ExclusionWords != "" {
|
|
|
var exclusionWords []string
|
|
@@ -234,6 +282,7 @@ func (kws *KeyWordsSearch) SearchParamsHandle(in *bxcore.SearchReq) {
|
|
|
}
|
|
|
in.ExclusionWords = strings.Join(exclusionWords, IC.C.JYKeyMark) //util.MatchSpace.ReplaceAllString(in.ExclusionWords, IC.C.JYKeyMark)
|
|
|
}
|
|
|
+ return kws.GetSearchKeyWordsQueryStr(in) //格式化关键词
|
|
|
}
|
|
|
|
|
|
// GetBidSearchList 非空搜索 查询
|