mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-04 20:53:09 -06:00
Naming, "docs"
This commit is contained in:
parent
1d02a5888f
commit
a8d53824c0
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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"`
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue