1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Activity.SearchTest do
6 alias Pleroma.Activity.Search
7 alias Pleroma.Web.CommonAPI
10 use Pleroma.DataCase, async: true
12 test "it finds something" do
14 {:ok, post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
16 [result] = Search.search(nil, "wednesday")
18 assert result.id == post.id
21 test "it finds local-only posts for authenticated users" do
23 reader = insert(:user)
24 {:ok, post} = CommonAPI.post(user, %{status: "it's wednesday my dudes", visibility: "local"})
26 [result] = Search.search(reader, "wednesday")
28 assert result.id == post.id
31 test "it does not find local-only posts for anonymous users" do
33 {:ok, _post} = CommonAPI.post(user, %{status: "it's wednesday my dudes", visibility: "local"})
35 assert [] = Search.search(nil, "wednesday")
38 test "using plainto_tsquery on postgres < 11" do
39 old_version = :persistent_term.get({Pleroma.Repo, :postgres_version})
40 :persistent_term.put({Pleroma.Repo, :postgres_version}, 10.0)
41 on_exit(fn -> :persistent_term.put({Pleroma.Repo, :postgres_version}, old_version) end)
44 {:ok, post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
45 {:ok, _post2} = CommonAPI.post(user, %{status: "it's wednesday my bros"})
47 # plainto doesn't understand complex queries
48 assert [result] = Search.search(nil, "wednesday -dudes")
50 assert result.id == post.id
53 test "using websearch_to_tsquery" do
55 {:ok, _post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
56 {:ok, other_post} = CommonAPI.post(user, %{status: "it's wednesday my bros"})
58 assert [result] = Search.search(nil, "wednesday -dudes")
60 assert result.id == other_post.id