Create Indexer interface

This commit is contained in:
Till Faelligen 2023-03-15 13:31:24 +01:00
parent 8c404440ef
commit e493f4e800
No known key found for this signature in database
GPG key ID: ACCDC9606D472758
6 changed files with 21 additions and 6 deletions

View file

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

View file

@ -15,8 +15,9 @@
package fulltext
import (
"github.com/matrix-org/dendrite/setup/config"
"time"
"github.com/matrix-org/dendrite/setup/config"
)
type Search struct{}
@ -28,6 +29,13 @@ type IndexElement struct {
StreamPosition int64
}
type Indexer interface {
Index(elements ...IndexElement) error
Delete(eventID string) error
Search(term string, roomIDs, keys []string, limit, from int, orderByStreamPos bool) (SearchResult, error)
Close() error
}
type SearchResult struct {
Status interface{} `json:"status"`
Request *interface{} `json:"request"`
@ -48,7 +56,7 @@ func (f *Search) Close() error {
return nil
}
func (f *Search) Index(e IndexElement) error {
func (f *Search) Index(e ...IndexElement) error {
return nil
}

View file

@ -50,7 +50,7 @@ type OutputClientDataConsumer struct {
stream streams.StreamProvider
notifier *notifier.Notifier
serverName gomatrixserverlib.ServerName
fts *fulltext.Search
fts fulltext.Indexer
cfg *config.SyncAPI
}

View file

@ -51,7 +51,7 @@ type OutputRoomEventConsumer struct {
pduStream streams.StreamProvider
inviteStream streams.StreamProvider
notifier *notifier.Notifier
fts *fulltext.Search
fts fulltext.Indexer
}
// NewOutputRoomEventConsumer creates a new OutputRoomEventConsumer. Call Start() to begin consuming from room servers.

View file

@ -43,7 +43,7 @@ func Setup(
rsAPI api.SyncRoomserverAPI,
cfg *config.SyncAPI,
lazyLoadCache caching.LazyLoadCache,
fts *fulltext.Search,
fts fulltext.Indexer,
) {
v1unstablemux := csMux.PathPrefix("/{apiversion:(?:v1|unstable)}/").Subrouter()
v3mux := csMux.PathPrefix("/{apiversion:(?:r0|v3)}/").Subrouter()

View file

@ -37,7 +37,7 @@ import (
)
// nolint:gocyclo
func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts *fulltext.Search, from *string) util.JSONResponse {
func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts fulltext.Indexer, from *string) util.JSONResponse {
start := time.Now()
var (
searchReq SearchRequest