aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRoger Braun <roger@rogerbraun.net>2017-09-16 10:42:24 +0200
committerRoger Braun <roger@rogerbraun.net>2017-09-16 10:42:24 +0200
commit9f0a2a714b498edfbacc638fa79e06e3a8dc4d04 (patch)
tree4ccf0183ecea58048bd1a1a3f4e0ac59d4267e5e /lib
parentd659fcc1957600e7937af7e9a456af8bc452bbd8 (diff)
downloadpleroma-9f0a2a714b498edfbacc638fa79e06e3a8dc4d04.tar.gz
Add basic search.
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex21
-rw-r--r--lib/pleroma/web/router.ex2
2 files changed, 23 insertions, 0 deletions
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index 8b794fb61..6b84d732f 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -287,6 +287,27 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
end
+ def search(%{assigns: %{user: user}} = conn, %{"q" => query}) do
+ q = from u in User,
+ where: fragment("(to_tsvector(?) || to_tsvector(?)) @@ plainto_tsquery(?)", u.nickname, u.name, ^query),
+ limit: 20
+ accounts = Repo.all(q)
+
+ q = from a in Activity,
+ where: fragment("?->>'type' = 'Create'", a.data),
+ where: fragment("to_tsvector(?->'object'->>'content') @@ plainto_tsquery(?)", a.data, ^query),
+ limit: 20
+ statuses = Repo.all(q)
+
+ res = %{
+ "accounts" => AccountView.render("accounts.json", users: accounts, for: user, as: :user),
+ "statuses" => StatusView.render("index.json", activities: statuses, for: user, as: :activity),
+ "hashtags" => []
+ }
+
+ json(conn, res)
+ end
+
def relationship_noop(%{assigns: %{user: user}} = conn, %{"id" => id}) do
Logger.debug("Unimplemented, returning unmodified relationship")
with %User{} = target <- Repo.get(User, id) do
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index 3de77d220..e8460db16 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -87,6 +87,8 @@ defmodule Pleroma.Web.Router do
get "/accounts/:id/followers", MastodonAPIController, :followers
get "/accounts/:id/following", MastodonAPIController, :following
get "/accounts/:id", MastodonAPIController, :user
+
+ get "/search", MastodonAPIController, :search
end
scope "/api", Pleroma.Web do