Rebuild search index in admin options (#647)
Signed-off-by: Thomas Miceli <tho.miceli@gmail.com>
This commit is contained in:
@@ -2,10 +2,11 @@ package index
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/thomiceli/opengist/internal/config"
|
||||
"path/filepath"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/thomiceli/opengist/internal/config"
|
||||
)
|
||||
|
||||
var atomicIndexer atomic.Pointer[Indexer]
|
||||
@@ -13,6 +14,7 @@ var atomicIndexer atomic.Pointer[Indexer]
|
||||
type Indexer interface {
|
||||
Init() error
|
||||
Close()
|
||||
Reset() error
|
||||
Add(gist *Gist) error
|
||||
Remove(gistID uint) error
|
||||
Search(query string, metadata SearchGistMetadata, userId uint, page int) ([]uint, uint64, map[string]int, error)
|
||||
@@ -84,6 +86,19 @@ func Close() {
|
||||
atomicIndexer.Store(nil)
|
||||
}
|
||||
|
||||
func ResetIndex() error {
|
||||
if !IndexEnabled() {
|
||||
return nil
|
||||
}
|
||||
|
||||
idx := atomicIndexer.Load()
|
||||
if idx == nil {
|
||||
return fmt.Errorf("indexer is not initialized")
|
||||
}
|
||||
|
||||
return (*idx).Reset()
|
||||
}
|
||||
|
||||
func AddInIndex(gist *Gist) error {
|
||||
if !IndexEnabled() {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user