2020-11-19 15:12:01 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Activity.SearchTest do
|
|
|
|
alias Pleroma.Activity.Search
|
2020-11-19 15:48:51 +00:00
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
use Pleroma.DataCase
|
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"})
|
|
|
|
|
|
|
|
[result] = Search.search(nil, "wednesday")
|
|
|
|
|
|
|
|
assert result.id == post.id
|
|
|
|
end
|
|
|
|
|
2020-11-20 15:26:43 +00:00
|
|
|
test "using plainto_tsquery on postgres < 11" do
|
|
|
|
old_config = Application.get_env(:postgres, :version)
|
|
|
|
Application.put_env(:postgres, :version, 10.0)
|
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
|
|
|
|
assert [result] = Search.search(nil, "wednesday -dudes")
|
|
|
|
|
|
|
|
assert result.id == post.id
|
2020-11-20 15:26:43 +00:00
|
|
|
|
|
|
|
Application.put_env(:postgres, :version, old_config)
|
2020-11-19 15:12:01 +00:00
|
|
|
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"})
|
|
|
|
|
|
|
|
assert [result] = Search.search(nil, "wednesday -dudes")
|
|
|
|
|
|
|
|
assert result.id == other_post.id
|
|
|
|
end
|
|
|
|
end
|