by Robin at 20240514

This commit is contained in:
Leufolium 2024-05-14 22:58:12 +08:00
parent 5818cc5785
commit a523664f3a
1 changed files with 19 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import (
"service/dbstruct"
"service/library/elasticsearchdb"
"service/library/logger"
"unicode"
"service/api/consts"
streameracctproto "service/api/proto/streamer_acct/proto"
@ -70,7 +71,15 @@ func (es *ElasticSearch) GetStreamerAcctListFuzzilyByName(ctx *gin.Context, req
var nameClause elastic.Query
// 查询文字长度小于短语匹配的进行Term匹配否则进行短语匹配
if len(req.Name) < consts.StreamerAcct_MatchPhraseLen {
len := 0
for _, char := range req.Name {
if unicode.Is(unicode.Han, char) {
len++
} else {
len++
}
}
if len < consts.StreamerAcct_MatchPhraseLen {
nameClause = elastic.NewTermQuery("name", req.Name)
} else {
nameClause = elastic.NewMatchPhraseQuery("name", req.Name)
@ -105,7 +114,15 @@ func (es *ElasticSearch) GetStreamerAcctListFuzzilyByUserId(ctx *gin.Context, re
var nameClause elastic.Query
var userIdStringClause elastic.Query
// 查询文字长度小于短语匹配的进行Term匹配否则进行短语匹配
if len(req.UserIdString) < consts.StreamerAcct_MatchPhraseLen {
len := 0
for _, char := range req.UserIdString {
if unicode.Is(unicode.Han, char) {
len++
} else {
len++
}
}
if len < consts.StreamerAcct_MatchPhraseLen {
nameClause = elastic.NewTermQuery("name", req.UserIdString)
userIdStringClause = elastic.NewTermQuery("user_id_string", req.UserIdString)
} else {