From 9a1e5f5d48ef9f3b5a817c02dc8820aa99a6f693 Mon Sep 17 00:00:00 2001 From: lain Date: Fri, 20 Nov 2020 16:26:43 +0100 Subject: [PATCH] Search: Change search method based on detected pg version --- lib/pleroma/activity/search.ex | 7 ++++++- test/pleroma/activity/search_test.exs | 9 +++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/activity/search.ex b/lib/pleroma/activity/search.ex index cc98e2d06..ea9783225 100644 --- a/lib/pleroma/activity/search.ex +++ b/lib/pleroma/activity/search.ex @@ -19,7 +19,12 @@ defmodule Pleroma.Activity.Search do offset = Keyword.get(options, :offset, 0) 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.with_preloaded_object() diff --git a/test/pleroma/activity/search_test.exs b/test/pleroma/activity/search_test.exs index 15591b726..37c0feeea 100644 --- a/test/pleroma/activity/search_test.exs +++ b/test/pleroma/activity/search_test.exs @@ -18,8 +18,9 @@ defmodule Pleroma.Activity.SearchTest do assert result.id == post.id end - test "using plainto_tsquery" do - clear_config([:instance, :search_function], :plain) + test "using plainto_tsquery on postgres < 11" do + old_config = Application.get_env(:postgres, :version) + Application.put_env(:postgres, :version, 10.0) user = insert(:user) {: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.id == post.id + + Application.put_env(:postgres, :version, old_config) end test "using websearch_to_tsquery" do - clear_config([:instance, :search_function], :websearch) - 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"})