Naming, "docs"

This commit is contained in:
Till Faelligen 2022-05-15 12:40:17 +02:00
parent 1d02a5888f
commit a8d53824c0
4 changed files with 22 additions and 21 deletions

View file

@ -4,10 +4,12 @@ import (
"github.com/blevesearch/bleve/v2" "github.com/blevesearch/bleve/v2"
) )
// Search contains all existing bleve.Index
type Search struct { type Search struct {
Index bleve.Index MessageIndex bleve.Index
} }
// IndexElement describes the layout of an element to index
type IndexElement struct { type IndexElement struct {
EventID string EventID string
Type string Type string
@ -15,32 +17,37 @@ type IndexElement struct {
Content string Content string
} }
// New opens a new/existing fulltext index
func New(path string) (*Search, error) { func New(path string) (*Search, error) {
fts := &Search{} fts := &Search{}
var err error var err error
fts.Index, err = openIndex(path) fts.MessageIndex, err = openIndex(path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return fts, nil return fts, nil
} }
// Close closes the fulltext index
func (f *Search) Close() error { func (f *Search) Close() error {
return f.Index.Close() return f.MessageIndex.Close()
} }
func (f *Search) IndexElement(e IndexElement) error { // Index indexes a given element
return f.Index.Index(e.EventID, e) func (f *Search) Index(e IndexElement) error {
return f.MessageIndex.Index(e.EventID, e)
} }
func (f *Search) DeleteElement(eventID string) error { // Delete deletes an indexed element by the eventID
return f.Index.Delete(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) { func (f *Search) Search(term string) (*bleve.SearchResult, error) {
qry := bleve.NewQueryStringQuery(term) qry := bleve.NewQueryStringQuery(term)
search := bleve.NewSearchRequest(qry) search := bleve.NewSearchRequest(qry)
return f.Index.Search(search) return f.MessageIndex.Search(search)
} }
func openIndex(path string) (bleve.Index, error) { func openIndex(path string) (bleve.Index, error) {

View file

@ -35,7 +35,7 @@ func TestSearch(t *testing.T) {
Content: "lorem ipsum", Content: "lorem ipsum",
} }
if err = fts.IndexElement(e); err != nil { if err = fts.Index(e); err != nil {
t.Fatal("failed to index element", err) t.Fatal("failed to index element", err)
} }
@ -47,7 +47,7 @@ func TestSearch(t *testing.T) {
Content: "lorem ipsum", Content: "lorem ipsum",
} }
if err = fts.IndexElement(e); err != nil { if err = fts.Index(e); err != nil {
t.Fatal("failed to index element", err) t.Fatal("failed to index element", err)
} }
@ -61,7 +61,7 @@ func TestSearch(t *testing.T) {
} }
// remove element // remove element
if err = fts.DeleteElement(eventID); err != nil { if err = fts.Delete(eventID); err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -7,6 +7,7 @@ import (
"github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/jsonerror"
"github.com/matrix-org/dendrite/internal/fulltext" "github.com/matrix-org/dendrite/internal/fulltext"
"github.com/matrix-org/dendrite/userapi/api" "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util" "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 { type SearchRequest struct {
SearchCategories struct { SearchCategories struct {
RoomEvents struct { RoomEvents struct {
Filter struct { Filter gomatrixserverlib.StateFilter `json:"filter"`
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"`
Groupings struct { Groupings struct {
GroupBy []struct { GroupBy []struct {
Key string `json:"key"` Key string `json:"key"`

View file

@ -408,12 +408,12 @@ func (d *Database) WriteEvent(
case gomatrixserverlib.MRoomTopic: case gomatrixserverlib.MRoomTopic:
e.Content = gjson.GetBytes(ev.Content(), "topic").String() e.Content = gjson.GetBytes(ev.Content(), "topic").String()
case gomatrixserverlib.MRoomRedaction: 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") logrus.WithError(err).Warn("failed to delete entry from fulltext index")
} }
} }
if e.Content != "" { 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") logrus.WithError(err).Warn("failed to write to fulltext index")
} }
} }