From 0eef74dd609c0a97de4c5bdcf40cb07cf54372ad Mon Sep 17 00:00:00 2001 From: zouap Date: Fri, 4 Mar 2022 09:42:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/search.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) 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