mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-29 09:05:30 +00:00
Refined orte
This commit is contained in:
@@ -2,6 +2,7 @@ package searchprovider
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
@@ -161,3 +162,29 @@ func default_mapping() (*mapping.IndexMappingImpl, error) {
|
||||
indexMapping.DefaultAnalyzer = "customNgramAnalyzer"
|
||||
return indexMapping, nil
|
||||
}
|
||||
|
||||
// ClearAllIndices closes and removes all search indices
|
||||
func (sp *SearchProvider) ClearAllIndices() error {
|
||||
// Close all open indices
|
||||
sp.indeces.Range(func(key, value interface{}) bool {
|
||||
if index, ok := value.(bleve.Index); ok {
|
||||
index.Close()
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
// Clear the sync.Map
|
||||
sp.indeces = sync.Map{}
|
||||
|
||||
// Remove all .bleve directories from disk
|
||||
files, err := filepath.Glob(filepath.Join(sp.basepath, "*.bleve"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
os.RemoveAll(file)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user