X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Fmastodon_api%2Fmastodon_api_controller.ex;h=fcc87d414543d7e42ca895ac2a6755965388da95;hb=73bdfd6c2b92533b5d48c2801a8e6548e8a2551a;hp=8b794fb61587a3e27bb828853b497973a54ae22b;hpb=50409326a853db7bd9f538f0ddbec805c134920f;p=akkoma diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 8b794fb61..fcc87d414 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('english', ?) || to_tsvector('english', ?)) @@ plainto_tsquery('english', ?)", 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('english', ?->'object'->>'content') @@ plainto_tsquery('english', ?)", 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