1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Search.DatabaseSearchTest do
6 alias Pleroma.Search.DatabaseSearch
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] = DatabaseSearch.search(nil, "wednesday")
18 assert result.id == post.id
21 test "using plainto_tsquery on postgres < 11" do
22 old_version = :persistent_term.get({Pleroma.Repo, :postgres_version})
23 :persistent_term.put({Pleroma.Repo, :postgres_version}, 10.0)
24 on_exit(fn -> :persistent_term.put({Pleroma.Repo, :postgres_version}, old_version) end)
27 {:ok, post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
28 {:ok, _post2} = CommonAPI.post(user, %{status: "it's wednesday my bros"})
30 # plainto doesn't understand complex queries
31 assert [result] = DatabaseSearch.search(nil, "wednesday -dudes")
33 assert result.id == post.id
36 test "using websearch_to_tsquery" do
38 {:ok, _post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
39 {:ok, other_post} = CommonAPI.post(user, %{status: "it's wednesday my bros"})
41 assert [result] = DatabaseSearch.search(nil, "wednesday -dudes")
43 assert result.id == other_post.id