by Robin at 20240514

This commit is contained in:
Leufolium 2024-05-14 22:31:33 +08:00
parent f6ee79f147
commit 4077eb2380
2 changed files with 23 additions and 5 deletions

View File

@ -55,3 +55,6 @@ const (
ZoneMomentPriorityInZone_Increment = 2000000000
ZoneMomentPriorityInZone_Decrement = -2000000000
)
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)