eventstore: replace bluge with bleve.

bluge seems to be abandoned and bleve should work better, who knows.
This commit is contained in:
fiatjaf
2025-11-22 09:16:40 -03:00
parent 8aa9c7e945
commit 98959e73e7
18 changed files with 266 additions and 329 deletions

61
eventstore/bleve/lib.go Normal file
View File

@@ -0,0 +1,61 @@
package bleve
import (
"errors"
"fmt"
"sync"
"fiatjaf.com/nostr"
"fiatjaf.com/nostr/eventstore"
bleve "github.com/blevesearch/bleve/v2"
bleveMapping "github.com/blevesearch/bleve/v2/mapping"
)
var _ eventstore.Store = (*BleveBackend)(nil)
type BleveBackend struct {
sync.Mutex
// Path is where the index will be saved
Path string
// RawEventStore is where we'll fetch the raw events from
// bleve will only store ids, so the actual events must be somewhere else
RawEventStore eventstore.Store
index bleve.Index
}
func (b *BleveBackend) Close() {
if b.index != nil {
b.index.Close()
}
}
func (b *BleveBackend) Init() error {
if b.Path == "" {
return fmt.Errorf("missing Path")
}
if b.RawEventStore == nil {
return fmt.Errorf("missing RawEventStore")
}
// try to open existing index
index, err := bleve.Open(b.Path)
if err == bleve.ErrorIndexPathDoesNotExist {
// create new index with default mapping
mapping := bleveMapping.NewIndexMapping()
index, err = bleve.New(b.Path, mapping)
if err != nil {
return fmt.Errorf("error creating index: %w", err)
}
} else if err != nil {
return fmt.Errorf("error opening index: %w", err)
}
b.index = index
return nil
}
func (b *BleveBackend) CountEvents(nostr.Filter) (uint32, error) {
return 0, errors.New("not supported")
}