Skip to content

Commit

Permalink
modify recover search index
Browse files Browse the repository at this point in the history
  • Loading branch information
sunwei committed Nov 19, 2024
1 parent c3dfbc0 commit 88e7b53
Showing 1 changed file with 0 additions and 26 deletions.
26 changes: 0 additions & 26 deletions internal/domain/content/entity/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"os"
"path/filepath"
"strings"
"sync"
)

type TypeService interface {
Expand All @@ -27,17 +26,13 @@ type Search struct {
Repo repository.Repository
Log loggers.Logger

mu sync.RWMutex
IndicesMap map[string]map[string]bleve.Index
}

// TypeQuery conducts a search and returns a set of Ponzu "targets", Type:ID pairs,
// and an error. If there is no search index for the typeName (Type) provided,
// db.ErrNoIndex will be returned as the error
func (s *Search) TypeQuery(typeName, query string, count, offset int) ([]content.Identifier, error) {
s.mu.RLock()
defer s.mu.Unlock()

s.setup()

idx, ok := s.IndicesMap[s.getSearchDir(typeName)][typeName]
Expand All @@ -59,20 +54,12 @@ func (s *Search) TypeQuery(typeName, query string, count, offset int) ([]content
results = append(results, valueobject.CreateIndex(hit.ID))
}

if closeErr := idx.Close(); closeErr != nil {
s.Log.Printf("Failed to close index: %v", closeErr)
}
delete(s.IndicesMap, s.getSearchDir(typeName))

return results, nil
}

// UpdateIndex sets data into a content type's search index at the given
// identifier
func (s *Search) UpdateIndex(ns, id string, data []byte) error {
s.mu.RLock()
defer s.mu.Unlock()

s.setup()

idx, ok := s.IndicesMap[s.getSearchDir(ns)][ns]
Expand All @@ -93,11 +80,6 @@ func (s *Search) UpdateIndex(ns, id string, data []byte) error {
i := valueobject.NewIndex(ns, id)
err = idx.Index(i.String(), p)

if closeErr := idx.Close(); closeErr != nil {
s.Log.Printf("Failed to close index: %v", closeErr)
}
delete(s.IndicesMap, s.getSearchDir(ns))

return err
}

Expand All @@ -107,9 +89,6 @@ func (s *Search) UpdateIndex(ns, id string, data []byte) error {
// DeleteIndex removes data from a content type's search index at the
// given identifier
func (s *Search) DeleteIndex(id string) error {
s.mu.RLock()
defer s.mu.Unlock()

s.setup()

// check if there is a search index to work with
Expand All @@ -121,11 +100,6 @@ func (s *Search) DeleteIndex(id string) error {
// add data to search index
err := idx.Delete(id)

if closeErr := idx.Close(); closeErr != nil {
s.Log.Printf("Failed to close index: %v", closeErr)
}
delete(s.IndicesMap, s.getSearchDir(ns))

return err
}

Expand Down

0 comments on commit 88e7b53

Please sign in to comment.