all
This commit is contained in:
103
Downloads/Voltaserve/api/search/file_search.go
Normal file
103
Downloads/Voltaserve/api/search/file_search.go
Normal file
@ -0,0 +1,103 @@
|
||||
package search
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"voltaserve/infra"
|
||||
"voltaserve/model"
|
||||
"voltaserve/repo"
|
||||
)
|
||||
|
||||
type FileSearch struct {
|
||||
search *infra.SearchManager
|
||||
index string
|
||||
s3 *infra.S3Manager
|
||||
}
|
||||
|
||||
func NewFileSearch() *FileSearch {
|
||||
return &FileSearch{
|
||||
index: infra.FileSearchIndex,
|
||||
search: infra.NewSearchManager(),
|
||||
s3: infra.NewS3Manager(),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *FileSearch) Index(files []model.File) (err error) {
|
||||
if len(files) == 0 {
|
||||
return nil
|
||||
}
|
||||
if err = s.populateTextField(files); err != nil {
|
||||
return err
|
||||
}
|
||||
var res []infra.SearchModel
|
||||
for _, f := range files {
|
||||
res = append(res, f)
|
||||
}
|
||||
if err := s.search.Index(s.index, res); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *FileSearch) Update(files []model.File) (err error) {
|
||||
if len(files) == 0 {
|
||||
return nil
|
||||
}
|
||||
if err = s.populateTextField(files); err != nil {
|
||||
return err
|
||||
}
|
||||
var res []infra.SearchModel
|
||||
for _, f := range files {
|
||||
res = append(res, f)
|
||||
}
|
||||
if err := s.search.Update(s.index, res); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *FileSearch) Delete(ids []string) error {
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
if err := s.search.Delete(s.index, ids); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *FileSearch) Query(query string) ([]model.File, error) {
|
||||
hits, err := s.search.Query(s.index, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var res []model.File
|
||||
for _, v := range hits {
|
||||
var b []byte
|
||||
b, err = json.Marshal(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
file := repo.NewFile()
|
||||
if err = json.Unmarshal(b, &file); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res = append(res, file)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (s *FileSearch) populateTextField(files []model.File) error {
|
||||
for _, f := range files {
|
||||
if f.GetSnapshots() != nil &&
|
||||
len(f.GetSnapshots()) > 0 &&
|
||||
f.GetSnapshots()[0].HasText() {
|
||||
var text string
|
||||
text, err := s.s3.GetText(f.GetSnapshots()[0].GetText().Key, f.GetSnapshots()[0].GetText().Bucket)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f.SetText(&text)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
81
Downloads/Voltaserve/api/search/group_search.go
Normal file
81
Downloads/Voltaserve/api/search/group_search.go
Normal file
@ -0,0 +1,81 @@
|
||||
package search
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"voltaserve/infra"
|
||||
"voltaserve/model"
|
||||
"voltaserve/repo"
|
||||
)
|
||||
|
||||
type GroupSearch struct {
|
||||
index string
|
||||
search *infra.SearchManager
|
||||
groupRepo repo.GroupRepo
|
||||
}
|
||||
|
||||
func NewGroupSearch() *GroupSearch {
|
||||
return &GroupSearch{
|
||||
index: infra.GroupSearchIndex,
|
||||
search: infra.NewSearchManager(),
|
||||
groupRepo: repo.NewGroupRepo(),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *GroupSearch) Index(groups []model.Group) error {
|
||||
if len(groups) == 0 {
|
||||
return nil
|
||||
}
|
||||
var res []infra.SearchModel
|
||||
for _, g := range groups {
|
||||
res = append(res, g)
|
||||
}
|
||||
if err := s.search.Index(s.index, res); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *GroupSearch) Update(groups []model.Group) error {
|
||||
if len(groups) == 0 {
|
||||
return nil
|
||||
}
|
||||
var res []infra.SearchModel
|
||||
for _, g := range groups {
|
||||
res = append(res, g)
|
||||
}
|
||||
if err := s.search.Update(s.index, res); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *GroupSearch) Delete(ids []string) error {
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
if err := s.search.Delete(s.index, ids); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *GroupSearch) Query(query string) ([]model.Group, error) {
|
||||
hits, err := s.search.Query(s.index, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var res []model.Group
|
||||
for _, v := range hits {
|
||||
var b []byte
|
||||
b, err = json.Marshal(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
group := repo.NewGroup()
|
||||
if err = json.Unmarshal(b, &group); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res = append(res, group)
|
||||
}
|
||||
return res, nil
|
||||
}
|
81
Downloads/Voltaserve/api/search/organization_search.go
Normal file
81
Downloads/Voltaserve/api/search/organization_search.go
Normal file
@ -0,0 +1,81 @@
|
||||
package search
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"voltaserve/infra"
|
||||
"voltaserve/model"
|
||||
"voltaserve/repo"
|
||||
)
|
||||
|
||||
type OrganizationSearch struct {
|
||||
index string
|
||||
search *infra.SearchManager
|
||||
orgRepo repo.OrganizationRepo
|
||||
}
|
||||
|
||||
func NewOrganizationSearch() *OrganizationSearch {
|
||||
return &OrganizationSearch{
|
||||
index: infra.OrganizationSearchIndex,
|
||||
search: infra.NewSearchManager(),
|
||||
orgRepo: repo.NewOrganizationRepo(),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *OrganizationSearch) Index(orgs []model.Organization) error {
|
||||
if len(orgs) == 0 {
|
||||
return nil
|
||||
}
|
||||
var res []infra.SearchModel
|
||||
for _, o := range orgs {
|
||||
res = append(res, o)
|
||||
}
|
||||
if err := s.search.Index(s.index, res); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *OrganizationSearch) Update(orgs []model.Organization) error {
|
||||
if len(orgs) == 0 {
|
||||
return nil
|
||||
}
|
||||
var res []infra.SearchModel
|
||||
for _, o := range orgs {
|
||||
res = append(res, o)
|
||||
}
|
||||
if err := s.search.Update(s.index, res); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *OrganizationSearch) Delete(ids []string) error {
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
if err := s.search.Delete(s.index, ids); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *OrganizationSearch) Query(query string) ([]model.Organization, error) {
|
||||
hits, err := s.search.Query(s.index, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var res []model.Organization
|
||||
for _, v := range hits {
|
||||
var b []byte
|
||||
b, err = json.Marshal(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
org := repo.NewOrganization()
|
||||
if err = json.Unmarshal(b, &org); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res = append(res, org)
|
||||
}
|
||||
return res, nil
|
||||
}
|
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
|
||||
}
|
81
Downloads/Voltaserve/api/search/workspace_search.go
Normal file
81
Downloads/Voltaserve/api/search/workspace_search.go
Normal file
@ -0,0 +1,81 @@
|
||||
package search
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"voltaserve/infra"
|
||||
"voltaserve/model"
|
||||
"voltaserve/repo"
|
||||
)
|
||||
|
||||
type WorkspaceSearch struct {
|
||||
index string
|
||||
search *infra.SearchManager
|
||||
workspaceRepo repo.WorkspaceRepo
|
||||
}
|
||||
|
||||
func NewWorkspaceSearch() *WorkspaceSearch {
|
||||
return &WorkspaceSearch{
|
||||
index: infra.WorkspaceSearchIndex,
|
||||
search: infra.NewSearchManager(),
|
||||
workspaceRepo: repo.NewWorkspaceRepo(),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *WorkspaceSearch) Index(workspaces []model.Workspace) error {
|
||||
if len(workspaces) == 0 {
|
||||
return nil
|
||||
}
|
||||
var res []infra.SearchModel
|
||||
for _, w := range workspaces {
|
||||
res = append(res, w)
|
||||
}
|
||||
if err := s.search.Index(s.index, res); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *WorkspaceSearch) Update(workspaces []model.Workspace) error {
|
||||
if len(workspaces) == 0 {
|
||||
return nil
|
||||
}
|
||||
var res []infra.SearchModel
|
||||
for _, w := range workspaces {
|
||||
res = append(res, w)
|
||||
}
|
||||
if err := s.search.Update(s.index, res); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *WorkspaceSearch) Delete(ids []string) error {
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
if err := s.search.Delete(s.index, ids); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *WorkspaceSearch) Query(query string) ([]model.Workspace, error) {
|
||||
hits, err := s.search.Query(s.index, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var res []model.Workspace
|
||||
for _, v := range hits {
|
||||
var b []byte
|
||||
b, err = json.Marshal(v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
workspace := repo.NewWorkspace()
|
||||
if err = json.Unmarshal(b, &workspace); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res = append(res, workspace)
|
||||
}
|
||||
return res, nil
|
||||
}
|
Reference in New Issue
Block a user