diff --git a/routers/search.go b/routers/search.go index 76e5f1de3..20663c960 100644 --- a/routers/search.go +++ b/routers/search.go @@ -251,10 +251,9 @@ func dealLongText(text string, Key string, MatchedQueries []string) string { } textRune := []rune(text) - textRuneStr := string(textRune) stringlen := len(textRune) if isNeedToDealText && stringlen > 200 { - index := strings.Index(textRuneStr, "color=") + index := chineseIndex(textRune, []rune("color=")) if index > 0 { start := index - 50 if start < 0 { @@ -278,6 +277,24 @@ func dealLongText(text string, Key string, MatchedQueries []string) string { } +func chineseIndex(text []rune, childText []rune) int { + for i, v := range text { + if v == childText[0] { + re := true + for j, k := range childText { + if k != text[i+j] { + re = false + break + } + } + if re { + return i + } + } + } + return -1 +} + func searchUserOrOrg(ctx *context.Context, TableName string, Key string, Page int, PageSize int, IsQueryUser bool, OnlyReturnNum bool) { /* 用户或者组织 ES名称: user-es-index