answer/internal/service/search/views.go

48 lines
861 B
Go
Raw Normal View History

2022-09-27 17:59:05 +08:00
package search
import (
"context"
"github.com/segmentfault/answer/internal/schema"
"github.com/segmentfault/answer/internal/service/search_common"
"regexp"
"strings"
)
type ViewsSearch struct {
2022-10-09 18:44:56 +08:00
repo search_common.SearchRepo
exp string
q string
order string
2022-09-27 17:59:05 +08:00
}
func NewViewsSearch(repo search_common.SearchRepo) *ViewsSearch {
return &ViewsSearch{
repo: repo,
}
}
func (s *ViewsSearch) Parse(dto *schema.SearchDTO) (ok bool) {
exp := ""
w := dto.Query
q := w
p := `(?m)^views:([0-9]+)`
re := regexp.MustCompile(p)
res := re.FindStringSubmatch(q)
if len(res) == 2 {
exp = res[1]
trimLen := len(res[0])
q = w[trimLen:]
ok = true
}
q = strings.TrimSpace(q)
s.exp = exp
s.q = q
2022-10-09 18:44:56 +08:00
s.order = dto.Order
2022-09-27 17:59:05 +08:00
return
}
func (s *ViewsSearch) Search(ctx context.Context) (resp []schema.SearchResp, total int64, err error) {
return
}