all
This commit is contained in:
40
Downloads/Voltaserve/api/search/user_search.go
Normal file
40
Downloads/Voltaserve/api/search/user_search.go
Normal file
@ -0,0 +1,40 @@
|
||||
package search
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"voltaserve/infra"
|
||||
"voltaserve/model"
|
||||
"voltaserve/repo"
|
||||
)
|
||||
|
||||
type UserSearch struct {
|
||||
index string
|
||||
search *infra.SearchManager
|
||||
}
|
||||
|
||||
func NewUserSearch() *UserSearch {
|
||||
return &UserSearch{
|
||||
index: infra.UserSearchIndex,
|
||||
search: infra.NewSearchManager(),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *UserSearch) Query(query string) ([]model.User, error) {
|
||||
hits, err := s.search.Query(s.index, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res := []model.User{}
|
||||
for _, v := range hits {
|
||||
b, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
user := repo.NewUser()
|
||||
if err := json.Unmarshal(b, &user); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res = append(res, user)
|
||||
}
|
||||
return res, nil
|
||||
}
|
Reference in New Issue
Block a user