aboutsummaryrefslogtreecommitdiff
path: root/internal/fulltext/bleve.go
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2023-03-17 12:09:45 +0100
committerGitHub <noreply@github.com>2023-03-17 11:09:45 +0000
commit5579121c6f27105342a2aea05cf9a3119d73cecb (patch)
tree1d8b7bec90079b6f693585d306c19019ea426870 /internal/fulltext/bleve.go
parentd88f71ab71a60348518f7fa6735ac9f0bfb472c3 (diff)
Preparations for removing `BaseDendrite` (#3016)
Preparations to actually remove/replace `BaseDendrite`. Quite a few changes: - SyncAPI accepts an `fulltext.Indexer` interface (fulltext is removed from `BaseDendrite`) - Caches are removed from `BaseDendrite` - Introduces a `Router` struct (likely to change) - also fixes #2903 - Introduces a `sqlutil.ConnectionManager`, which should remove `base.DatabaseConnection` later on - probably more
Diffstat (limited to 'internal/fulltext/bleve.go')
-rw-r--r--internal/fulltext/bleve.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/internal/fulltext/bleve.go b/internal/fulltext/bleve.go
index 7187861d..08cef8a9 100644
--- a/internal/fulltext/bleve.go
+++ b/internal/fulltext/bleve.go
@@ -18,10 +18,10 @@
package fulltext
import (
+ "context"
"strings"
"github.com/blevesearch/bleve/v2"
-
// side effect imports to allow all possible languages
_ "github.com/blevesearch/bleve/v2/analysis/lang/ar"
_ "github.com/blevesearch/bleve/v2/analysis/lang/cjk"
@@ -55,6 +55,13 @@ type Search struct {
FulltextIndex bleve.Index
}
+type Indexer interface {
+ Index(elements ...IndexElement) error
+ Delete(eventID string) error
+ Search(term string, roomIDs, keys []string, limit, from int, orderByStreamPos bool) (*bleve.SearchResult, error)
+ Close() error
+}
+
// IndexElement describes the layout of an element to index
type IndexElement struct {
EventID string
@@ -77,12 +84,18 @@ func (i *IndexElement) SetContentType(v string) {
}
// New opens a new/existing fulltext index
-func New(cfg config.Fulltext) (fts *Search, err error) {
+func New(ctx context.Context, cfg config.Fulltext) (fts *Search, err error) {
fts = &Search{}
fts.FulltextIndex, err = openIndex(cfg)
if err != nil {
return nil, err
}
+ go func() {
+ // Wait for the context (should be from process.ProcessContext) to be
+ // done, indicating that Dendrite is shutting down.
+ <-ctx.Done()
+ _ = fts.Close()
+ }()
return fts, nil
}