mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-13 04:34:47 +00:00
Search: Change search method based on detected pg version
This commit is contained in:
parent
a407e33c78
commit
9a1e5f5d48
2 changed files with 11 additions and 5 deletions
|
@ -19,7 +19,12 @@ defmodule Pleroma.Activity.Search do
|
||||||
offset = Keyword.get(options, :offset, 0)
|
offset = Keyword.get(options, :offset, 0)
|
||||||
author = Keyword.get(options, :author)
|
author = Keyword.get(options, :author)
|
||||||
|
|
||||||
search_function = Pleroma.Config.get([:instance, :search_function], :plain)
|
search_function =
|
||||||
|
if Application.get_env(:postgres, :version) >= 11 do
|
||||||
|
:websearch
|
||||||
|
else
|
||||||
|
:plain
|
||||||
|
end
|
||||||
|
|
||||||
Activity
|
Activity
|
||||||
|> Activity.with_preloaded_object()
|
|> Activity.with_preloaded_object()
|
||||||
|
|
|
@ -18,8 +18,9 @@ defmodule Pleroma.Activity.SearchTest do
|
||||||
assert result.id == post.id
|
assert result.id == post.id
|
||||||
end
|
end
|
||||||
|
|
||||||
test "using plainto_tsquery" do
|
test "using plainto_tsquery on postgres < 11" do
|
||||||
clear_config([:instance, :search_function], :plain)
|
old_config = Application.get_env(:postgres, :version)
|
||||||
|
Application.put_env(:postgres, :version, 10.0)
|
||||||
|
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
{:ok, post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
|
{:ok, post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
|
||||||
|
@ -29,11 +30,11 @@ defmodule Pleroma.Activity.SearchTest do
|
||||||
assert [result] = Search.search(nil, "wednesday -dudes")
|
assert [result] = Search.search(nil, "wednesday -dudes")
|
||||||
|
|
||||||
assert result.id == post.id
|
assert result.id == post.id
|
||||||
|
|
||||||
|
Application.put_env(:postgres, :version, old_config)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "using websearch_to_tsquery" do
|
test "using websearch_to_tsquery" do
|
||||||
clear_config([:instance, :search_function], :websearch)
|
|
||||||
|
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
{:ok, _post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
|
{:ok, _post} = CommonAPI.post(user, %{status: "it's wednesday my dudes"})
|
||||||
{:ok, other_post} = CommonAPI.post(user, %{status: "it's wednesday my bros"})
|
{:ok, other_post} = CommonAPI.post(user, %{status: "it's wednesday my bros"})
|
||||||
|
|
Loading…
Reference in a new issue