Merge pull request 'conflict' (#435) from conflict into test

Reviewed-on: http://121.41.31.146:3000/wishpal_ironfan/service/pulls/435
This commit is contained in:
chenhao 2024-05-14 22:34:35 +08:00
commit bd56e41af7
2 changed files with 23 additions and 5 deletions

View File

@ -60,3 +60,6 @@ const (
AppConfigReflect_Current = 1 // 符合当前版本的version做映射
AppConfigReflect_LessThan = 2 // 小于当前版本的version做映射
)
const (
StreamerAcct_MatchPhraseLen = 3
)

View File

@ -9,6 +9,7 @@ import (
"service/library/elasticsearchdb"
"service/library/logger"
"service/api/consts"
streameracctproto "service/api/proto/streamer_acct/proto"
"github.com/gin-gonic/gin"
@ -70,9 +71,15 @@ func (es *ElasticSearch) GetStreamerAcctListFuzzilyByName(ctx *gin.Context, req
list = make([]*dbstruct.EsStreamerAcct, 0)
delFlagClause := elastic.NewMatchQuery("del_flag", 0)
nameClause := elastic.NewMatchQuery("name", req.Name)
var nameClause elastic.Query
// 查询文字长度小于短语匹配的进行Term匹配否则进行短语匹配
if len(req.Name) < consts.StreamerAcct_MatchPhraseLen {
nameClause = elastic.NewTermQuery("name", req.Name)
} else {
nameClause = elastic.NewMatchPhraseQuery("name", req.Name)
}
query := elastic.NewBoolQuery()
delFlagClause := elastic.NewMatchQuery("del_flag", 0)
query.Must(nameClause, delFlagClause)
res, err := es.clientMix.Search(es.getIndexStreamerAcct()).Query(query).From(req.Offset).Size(req.Limit).Sort("ct", true).Do(ctx)
@ -98,11 +105,19 @@ func (es *ElasticSearch) GetStreamerAcctListFuzzilyByUserId(ctx *gin.Context, re
list = make([]*dbstruct.EsStreamerAcct, 0)
delFlagClause := elastic.NewMatchQuery("del_flag", 0)
nameClause := elastic.NewMatchQuery("name", req.UserIdString)
userIdStringClause := elastic.NewMatchQuery("user_id_string", req.UserIdString)
var nameClause elastic.Query
var userIdStringClause elastic.Query
// 查询文字长度小于短语匹配的进行Term匹配否则进行短语匹配
if len(req.UserIdString) < consts.StreamerAcct_MatchPhraseLen {
nameClause = elastic.NewTermQuery("name", req.UserIdString)
userIdStringClause = elastic.NewTermQuery("user_id_string", req.UserIdString)
} else {
nameClause = elastic.NewMatchQuery("name", req.UserIdString)
userIdStringClause = elastic.NewMatchPhraseQuery("user_id_string", req.UserIdString)
}
orClause := elastic.NewBoolQuery().Should(nameClause, userIdStringClause)
query := elastic.NewBoolQuery().Must()
delFlagClause := elastic.NewMatchQuery("del_flag", 0)
query.Must(orClause, delFlagClause)
res, err := es.clientMix.Search(es.getIndexStreamerAcct()).Query(query).From(req.Offset).Size(req.Limit).Sort("ct", true).Do(ctx)