2020-11-19 15:12:01 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2022-02-26 06:11:42 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2020-11-19 15:12:01 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-11-17 19:29:49 +00:00
|
|
|
defmodule Pleroma.Search.DatabaseSearchTest do
|
2023-11-12 12:19:54 +00:00
|
|
|
alias Pleroma.Search.DatabaseSearch, as: Search
|
2020-11-19 15:48:51 +00:00
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
2020-12-21 11:21:40 +00:00
|
|
|
use Pleroma.DataCase, async: true
|
2020-11-19 15:12:01 +00:00
|
|
|
|
|
|
|
test "it finds something" do
|
|
|
|
user = insert(:user)
|
|
|
|
{:ok, post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
|
|
|
|
|
2023-11-12 12:19:54 +00:00
|
|
|
[result] = Search.search(nil, "wednesday")
|
2020-11-19 15:12:01 +00:00
|
|
|
|
|
|
|
assert result.id == post.id
|
|
|
|
end
|
|
|
|
|
2022-05-05 14:44:34 +00:00
|
|
|
test "it finds local-only posts for authenticated users" do
|
|
|
|
user = insert(:user)
|
|
|
|
reader = insert(:user)
|
|
|
|
{:ok, post} = CommonAPI.post(user, %{status: "it's wednesday my dudes", visibility: "local"})
|
|
|
|
|
|
|
|
[result] = Search.search(reader, "wednesday")
|
|
|
|
|
|
|
|
assert result.id == post.id
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it does not find local-only posts for anonymous users" do
|
|
|
|
user = insert(:user)
|
|
|
|
{:ok, _post} = CommonAPI.post(user, %{status: "it's wednesday my dudes", visibility: "local"})
|
|
|
|
|
|
|
|
assert [] = Search.search(nil, "wednesday")
|
|
|
|
end
|
|
|
|
|
2020-11-20 15:26:43 +00:00
|
|
|
test "using plainto_tsquery on postgres < 11" do
|
2020-11-23 14:29:55 +00:00
|
|
|
old_version = :persistent_term.get({Pleroma.Repo, :postgres_version})
|
|
|
|
:persistent_term.put({Pleroma.Repo, :postgres_version}, 10.0)
|
2020-12-01 16:45:25 +00:00
|
|
|
on_exit(fn -> :persistent_term.put({Pleroma.Repo, :postgres_version}, old_version) end)
|
2020-11-19 15:12:01 +00:00
|
|
|
|
|
|
|
user = insert(:user)
|
|
|
|
{:ok, post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
|
|
|
|
{:ok, _post2} = CommonAPI.post(user, %{status: "it's wednesday my bros"})
|
|
|
|
|
|
|
|
# plainto doesn't understand complex queries
|
2023-11-12 12:19:54 +00:00
|
|
|
assert [result] = Search.search(nil, "wednesday -dudes")
|
2020-11-19 15:12:01 +00:00
|
|
|
|
|
|
|
assert result.id == post.id
|
|
|
|
end
|
|
|
|
|
|
|
|
test "using websearch_to_tsquery" do
|
|
|
|
user = insert(:user)
|
|
|
|
{:ok, _post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
|
|
|
|
{:ok, other_post} = CommonAPI.post(user, %{status: "it's wednesday my bros"})
|
|
|
|
|
2023-11-12 12:19:54 +00:00
|
|
|
assert [result] = Search.search(nil, "wednesday -dudes")
|
2020-11-19 15:12:01 +00:00
|
|
|
|
|
|
|
assert result.id == other_post.id
|
|
|
|
end
|
|
|
|
end
|