1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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
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 "using plainto_tsquery on postgres < 11" do
22 old_config = Application.get_env(:postgres, :version)
23 Application.put_env(:postgres, :version, 10.0)
26 {:ok, post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
27 {:ok, _post2} = CommonAPI.post(user, %{status: "it's wednesday my bros"})
29 # plainto doesn't understand complex queries
30 assert [result] = Search.search(nil, "wednesday -dudes")
32 assert result.id == post.id
34 Application.put_env(:postgres, :version, old_config)
37 test "using websearch_to_tsquery" do
39 {:ok, _post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
40 {:ok, other_post} = CommonAPI.post(user, %{status: "it's wednesday my bros"})
42 assert [result] = Search.search(nil, "wednesday -dudes")
44 assert result.id == other_post.id