aboutsummaryrefslogtreecommitdiff
path: root/syncapi/routing/routing.go
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2022-09-27 18:06:49 +0200
committerGitHub <noreply@github.com>2022-09-27 18:06:49 +0200
commit87be32ca2671173a4287a938932e543410a32c3a (patch)
tree92d74544fccf5f51873db4f55c04045562990b35 /syncapi/routing/routing.go
parent6c67552bf9eee18f656d731adf646aa09c5d7c92 (diff)
Fulltext implementation using Bleve (#2675)
Based on #2480 This actually indexes events based on their event type. They are removed from the index if we receive a `m.room.redaction` event on the `OutputRoomEvent` stream. An admin endpoint is added to reindex all existing events. Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
Diffstat (limited to 'syncapi/routing/routing.go')
-rw-r--r--syncapi/routing/routing.go28
1 files changed, 26 insertions, 2 deletions
diff --git a/syncapi/routing/routing.go b/syncapi/routing/routing.go
index 6bc495d8..8f84a134 100644
--- a/syncapi/routing/routing.go
+++ b/syncapi/routing/routing.go
@@ -18,15 +18,18 @@ import (
"net/http"
"github.com/gorilla/mux"
+ "github.com/matrix-org/gomatrixserverlib"
+ "github.com/matrix-org/util"
+
+ "github.com/matrix-org/dendrite/clientapi/jsonerror"
"github.com/matrix-org/dendrite/internal/caching"
+ "github.com/matrix-org/dendrite/internal/fulltext"
"github.com/matrix-org/dendrite/internal/httputil"
"github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/syncapi/storage"
"github.com/matrix-org/dendrite/syncapi/sync"
userapi "github.com/matrix-org/dendrite/userapi/api"
- "github.com/matrix-org/gomatrixserverlib"
- "github.com/matrix-org/util"
)
// Setup configures the given mux with sync-server listeners
@@ -40,6 +43,7 @@ func Setup(
rsAPI api.SyncRoomserverAPI,
cfg *config.SyncAPI,
lazyLoadCache caching.LazyLoadCache,
+ fts *fulltext.Search,
) {
v3mux := csMux.PathPrefix("/{apiversion:(?:r0|v3)}/").Subrouter()
@@ -95,4 +99,24 @@ func Setup(
)
}),
).Methods(http.MethodGet, http.MethodOptions)
+
+ v3mux.Handle("/search",
+ httputil.MakeAuthAPI("search", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
+ if !cfg.Fulltext.Enabled {
+ return util.JSONResponse{
+ Code: http.StatusNotImplemented,
+ JSON: jsonerror.Unknown("Search has been disabled by the server administrator."),
+ }
+ }
+ var nextBatch *string
+ if err := req.ParseForm(); err != nil {
+ return jsonerror.InternalServerError()
+ }
+ if req.Form.Has("next_batch") {
+ nb := req.FormValue("next_batch")
+ nextBatch = &nb
+ }
+ return Search(req, device, syncDB, fts, nextBatch)
+ }),
+ ).Methods(http.MethodPost, http.MethodOptions)
}