A platform for community discussion. Free, open, simple.
FIX: add support for PG 14 and up (#20137)
Sam1dba1aca271d
diff --git a/lib/search.rb b/lib/search.rbindex 2afd2d1bae0..ae9ec947e37 100644--- a/lib/search.rb+++ b/lib/search.rb@@ -1262,6 +1262,9 @@ class Searchts_config = ActiveRecord::Base.connection.quote(ts_config) if ts_configescaped_term = wrap_unaccent("'#{escape_string(term)}'")tsquery = "TO_TSQUERY(#{ts_config || default_ts_config}, #{escaped_term})"+ # PG 14 and up default to using the followed by operator+ # this restores the old behavior+ tsquery = "REPLACE(#{tsquery}::text, '<->', '&')::tsquery"tsquery = "REPLACE(#{tsquery}::text, '&', '#{escape_string(joiner)}')::tsquery" if joinertsqueryenddiff --git a/spec/lib/search_spec.rb b/spec/lib/search_spec.rbindex 758d72e4f0a..53e2a6edbf8 100644--- a/spec/lib/search_spec.rb+++ b/spec/lib/search_spec.rb@@ -969,7 +969,7 @@ RSpec.describe Search doit "aggregates searches in a topic by returning the post with the lowest post number" dopost = Fabricate(:post, topic: topic, raw: "this is a play post")- post2 = Fabricate(:post, topic: topic, raw: "play play playing played play")+ _post2 = Fabricate(:post, topic: topic, raw: "play play playing played play")post3 = Fabricate(:post, raw: "this is a play post")5.times { Fabricate(:post, topic: topic, raw: "play playing played") }@@ -1876,7 +1876,7 @@ RSpec.describe Search do)post2 = Fabricate(:post, raw: "test URL post with")- expect(Search.execute("test post with 'a URL).posts").posts).to eq([post2, post])+ expect(Search.execute("test post URL l").posts).to eq([post2, post])expect(Search.execute(%{"test post with 'a URL"}).posts).to eq([post])expect(Search.execute(%{"https://some.site.com/search?q=test.test.test"}).posts).to eq([post])expect(@@ -2311,11 +2311,11 @@ RSpec.describe Search doit "escapes the term correctly" doexpect(Search.ts_query(term: 'Title with trailing backslash\\')).to eq(- "TO_TSQUERY('english', '''Title with trailing backslash\\\\\\\\'':*')",+ "REPLACE(TO_TSQUERY('english', '''Title with trailing backslash\\\\\\\\'':*')::text, '<->', '&')::tsquery",)expect(Search.ts_query(term: "Title with trailing quote'")).to eq(- "TO_TSQUERY('english', '''Title with trailing quote'''''':*')",+ "REPLACE(TO_TSQUERY('english', '''Title with trailing quote'''''':*')::text, '<->', '&')::tsquery",)endend