From a8d53824c0f9e9e8f3656f196a2465ca16d28d81 Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Sun, 15 May 2022 12:40:17 +0200 Subject: [PATCH] Naming, "docs" --- internal/fulltext/bleve.go | 23 +++++++++++++++-------- internal/fulltext/bleve_test.go | 6 +++--- syncapi/routing/search.go | 10 ++-------- syncapi/storage/shared/syncserver.go | 4 ++-- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/internal/fulltext/bleve.go b/internal/fulltext/bleve.go index 96941ea8a..4c08f855c 100644 --- a/internal/fulltext/bleve.go +++ b/internal/fulltext/bleve.go @@ -4,10 +4,12 @@ import ( "github.com/blevesearch/bleve/v2" ) +// Search contains all existing bleve.Index type Search struct { - Index bleve.Index + MessageIndex bleve.Index } +// IndexElement describes the layout of an element to index type IndexElement struct { EventID string Type string @@ -15,32 +17,37 @@ type IndexElement struct { Content string } +// New opens a new/existing fulltext index func New(path string) (*Search, error) { fts := &Search{} var err error - fts.Index, err = openIndex(path) + fts.MessageIndex, err = openIndex(path) if err != nil { return nil, err } return fts, nil } +// Close closes the fulltext index func (f *Search) Close() error { - return f.Index.Close() + return f.MessageIndex.Close() } -func (f *Search) IndexElement(e IndexElement) error { - return f.Index.Index(e.EventID, e) +// Index indexes a given element +func (f *Search) Index(e IndexElement) error { + return f.MessageIndex.Index(e.EventID, e) } -func (f *Search) DeleteElement(eventID string) error { - return f.Index.Delete(eventID) +// Delete deletes an indexed element by the eventID +func (f *Search) Delete(eventID string) error { + return f.MessageIndex.Delete(eventID) } +// Search searches the index given a search term func (f *Search) Search(term string) (*bleve.SearchResult, error) { qry := bleve.NewQueryStringQuery(term) search := bleve.NewSearchRequest(qry) - return f.Index.Search(search) + return f.MessageIndex.Search(search) } func openIndex(path string) (bleve.Index, error) { diff --git a/internal/fulltext/bleve_test.go b/internal/fulltext/bleve_test.go index 59c4d98ea..6c39b2f58 100644 --- a/internal/fulltext/bleve_test.go +++ b/internal/fulltext/bleve_test.go @@ -35,7 +35,7 @@ func TestSearch(t *testing.T) { Content: "lorem ipsum", } - if err = fts.IndexElement(e); err != nil { + if err = fts.Index(e); err != nil { t.Fatal("failed to index element", err) } @@ -47,7 +47,7 @@ func TestSearch(t *testing.T) { Content: "lorem ipsum", } - if err = fts.IndexElement(e); err != nil { + if err = fts.Index(e); err != nil { t.Fatal("failed to index element", err) } @@ -61,7 +61,7 @@ func TestSearch(t *testing.T) { } // remove element - if err = fts.DeleteElement(eventID); err != nil { + if err = fts.Delete(eventID); err != nil { t.Fatal(err) } diff --git a/syncapi/routing/search.go b/syncapi/routing/search.go index 468179bd7..ac8d0c46f 100644 --- a/syncapi/routing/search.go +++ b/syncapi/routing/search.go @@ -7,6 +7,7 @@ import ( "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/internal/fulltext" "github.com/matrix-org/dendrite/userapi/api" + "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" ) @@ -54,14 +55,7 @@ func Search(req *http.Request, device *api.Device, fts *fulltext.Search) util.JS type SearchRequest struct { SearchCategories struct { RoomEvents struct { - Filter struct { - NotRooms []interface{} `json:"not_rooms"` - NotSenders []interface{} `json:"not_senders"` - NotTypes []interface{} `json:"not_types"` - Rooms []interface{} `json:"rooms"` - Senders []interface{} `json:"senders"` - Types []interface{} `json:"types"` - } `json:"filter"` + Filter gomatrixserverlib.StateFilter `json:"filter"` Groupings struct { GroupBy []struct { Key string `json:"key"` diff --git a/syncapi/storage/shared/syncserver.go b/syncapi/storage/shared/syncserver.go index feb06ea70..ab8e36f04 100644 --- a/syncapi/storage/shared/syncserver.go +++ b/syncapi/storage/shared/syncserver.go @@ -408,12 +408,12 @@ func (d *Database) WriteEvent( case gomatrixserverlib.MRoomTopic: e.Content = gjson.GetBytes(ev.Content(), "topic").String() case gomatrixserverlib.MRoomRedaction: - if err := d.FTS.DeleteElement(ev.Redacts()); err != nil { + if err := d.FTS.Delete(ev.Redacts()); err != nil { logrus.WithError(err).Warn("failed to delete entry from fulltext index") } } if e.Content != "" { - if err := d.FTS.IndexElement(e); err != nil { + if err := d.FTS.Index(e); err != nil { logrus.WithError(err).Warn("failed to write to fulltext index") } }