mirror of https://gitee.com/answerdev/answer.git
Merge branch 'fix/search' into 'test'
fix(search_repo): See merge request opensource/answer!290
This commit is contained in:
commit
e13c39cf0d
|
@ -157,11 +157,12 @@ func (sr *searchRepo) SearchContents(ctx context.Context, words []string, tagIDs
|
||||||
}
|
}
|
||||||
sql := fmt.Sprintf("(%s UNION ALL %s)", ubSQL, bSQL)
|
sql := fmt.Sprintf("(%s UNION ALL %s)", ubSQL, bSQL)
|
||||||
|
|
||||||
querySQL, _, err := builder.MySQL().Select("*").From(sql, "t").OrderBy(sr.parseOrder(ctx, order)).Limit(size, page-1).ToSQL()
|
countSQL, _, err := builder.MySQL().Select("count(*) total").From(sql, "c").ToSQL()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
countSQL, _, err := builder.MySQL().Select("count(*) total").From(sql, "c").ToSQL()
|
|
||||||
|
querySQL, _, err := builder.MySQL().Select("*").From(sql, "t").OrderBy(sr.parseOrder(ctx, order)).Limit(size, page-1).ToSQL()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -197,15 +198,17 @@ func (sr *searchRepo) SearchContents(ctx context.Context, words []string, tagIDs
|
||||||
|
|
||||||
// SearchQuestions search question data
|
// SearchQuestions search question data
|
||||||
func (sr *searchRepo) SearchQuestions(ctx context.Context, words []string, notAccepted bool, views, answers int, page, size int, order string) (resp []schema.SearchResp, total int64, err error) {
|
func (sr *searchRepo) SearchQuestions(ctx context.Context, words []string, notAccepted bool, views, answers int, page, size int, order string) (resp []schema.SearchResp, total int64, err error) {
|
||||||
if words = filterWords(words); len(words) == 0 {
|
words = filterWords(words)
|
||||||
return
|
|
||||||
}
|
|
||||||
var (
|
var (
|
||||||
qfs = qFields
|
qfs = qFields
|
||||||
args = []interface{}{}
|
args = []interface{}{}
|
||||||
)
|
)
|
||||||
if order == "relevance" {
|
if order == "relevance" {
|
||||||
qfs, args = addRelevanceField([]string{"title", "original_text"}, words, qfs)
|
if len(words) > 0 {
|
||||||
|
qfs, args = addRelevanceField([]string{"title", "original_text"}, words, qfs)
|
||||||
|
} else {
|
||||||
|
order = "newest"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
b := builder.MySQL().Select(qfs...).From("question")
|
b := builder.MySQL().Select(qfs...).From("question")
|
||||||
|
@ -257,11 +260,12 @@ func (sr *searchRepo) SearchQuestions(ctx context.Context, words []string, notAc
|
||||||
queryArgs := []interface{}{}
|
queryArgs := []interface{}{}
|
||||||
countArgs := []interface{}{}
|
countArgs := []interface{}{}
|
||||||
|
|
||||||
querySQL, _, err := b.OrderBy(sr.parseOrder(ctx, order)).Limit(size, page-1).ToSQL()
|
countSQL, _, err := builder.MySQL().Select("count(*) total").From(b, "c").ToSQL()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
countSQL, _, err := builder.MySQL().Select("count(*) total").From(b, "c").ToSQL()
|
|
||||||
|
querySQL, _, err := b.OrderBy(sr.parseOrder(ctx, order)).Limit(size, page-1).ToSQL()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -293,15 +297,18 @@ func (sr *searchRepo) SearchQuestions(ctx context.Context, words []string, notAc
|
||||||
|
|
||||||
// SearchAnswers search answer data
|
// SearchAnswers search answer data
|
||||||
func (sr *searchRepo) SearchAnswers(ctx context.Context, words []string, tagIDs []string, accepted bool, questionID string, page, size int, order string) (resp []schema.SearchResp, total int64, err error) {
|
func (sr *searchRepo) SearchAnswers(ctx context.Context, words []string, tagIDs []string, accepted bool, questionID string, page, size int, order string) (resp []schema.SearchResp, total int64, err error) {
|
||||||
if words = filterWords(words); len(words) == 0 {
|
words = filterWords(words)
|
||||||
return
|
|
||||||
}
|
|
||||||
var (
|
var (
|
||||||
afs = aFields
|
afs = aFields
|
||||||
args = []interface{}{}
|
args = []interface{}{}
|
||||||
)
|
)
|
||||||
if order == "relevance" {
|
if order == "relevance" {
|
||||||
afs, args = addRelevanceField([]string{"`answer`.`original_text`"}, words, afs)
|
if len(words) > 0 {
|
||||||
|
afs, args = addRelevanceField([]string{"`answer`.`original_text`"}, words, afs)
|
||||||
|
} else {
|
||||||
|
order = "newest"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
b := builder.MySQL().Select(afs...).From("`answer`").
|
b := builder.MySQL().Select(afs...).From("`answer`").
|
||||||
|
@ -346,14 +353,16 @@ func (sr *searchRepo) SearchAnswers(ctx context.Context, words []string, tagIDs
|
||||||
queryArgs := []interface{}{}
|
queryArgs := []interface{}{}
|
||||||
countArgs := []interface{}{}
|
countArgs := []interface{}{}
|
||||||
|
|
||||||
querySQL, _, err := b.OrderBy(sr.parseOrder(ctx, order)).Limit(size, page-1).ToSQL()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
countSQL, _, err := builder.MySQL().Select("count(*) total").From(b, "c").ToSQL()
|
countSQL, _, err := builder.MySQL().Select("count(*) total").From(b, "c").ToSQL()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
querySQL, _, err := b.OrderBy(sr.parseOrder(ctx, order)).Limit(size, page-1).ToSQL()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
queryArgs = append(queryArgs, querySQL)
|
queryArgs = append(queryArgs, querySQL)
|
||||||
queryArgs = append(queryArgs, args...)
|
queryArgs = append(queryArgs, args...)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue