A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
fix: search sql parse error when query words is empty
kumfoc3f42f1d9e8d
diff --git a/internal/repo/search_common/search_repo.go b/internal/repo/search_common/search_repo.goindex dfa79f3c..b2db83c3 100644--- a/internal/repo/search_common/search_repo.go+++ b/internal/repo/search_common/search_repo.go@@ -67,6 +67,9 @@ func NewSearchRepo(data *data.Data, uniqueIDRepo unique.UniqueIDRepo, userCommon// SearchContents search question and answer datafunc (sr *searchRepo) SearchContents(ctx context.Context, words []string, tagID, userID string, votes int, page, size int, order string) (resp []schema.SearchResp, total int64, err error) {+ if words = filterWords(words); len(words) == 0 {+ return+ }var (b *builder.Builderub *builder.Builder@@ -181,6 +184,9 @@ func (sr *searchRepo) SearchContents(ctx context.Context, words []string, tagID,// SearchQuestions search question datafunc (sr *searchRepo) SearchQuestions(ctx context.Context, words []string, limitNoAccepted bool, answers, page, size int, order string) (resp []schema.SearchResp, total int64, err error) {+ if words = filterWords(words); len(words) == 0 {+ return+ }var (qfs = qFieldsargs = []interface{}{}@@ -259,6 +265,9 @@ func (sr *searchRepo) SearchQuestions(ctx context.Context, words []string, limit// SearchAnswers search answer datafunc (sr *searchRepo) SearchAnswers(ctx context.Context, words []string, limitAccepted bool, questionID string, page, size int, order string) (resp []schema.SearchResp, total int64, err error) {+ if words = filterWords(words); len(words) == 0 {+ return+ }var (afs = aFieldsargs = []interface{}{}@@ -475,3 +484,12 @@ func addRelevanceField(searchFields, words, fields []string) (res []string, argsres = append(res, "("+strings.Join(relevanceRes, " + ")+") as relevance")return}++func filterWords(words []string) (res []string) {+ for _, word := range words {+ if strings.TrimSpace(word) != "" {+ res = append(res, word)+ }+ }+ return+}