Refined orte

This commit is contained in:
Simon Martens
2025-09-27 17:44:34 +02:00
parent d48bba8e92
commit e8ff6d3d37
20 changed files with 882 additions and 906 deletions

View File

@@ -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
}