FIX: Similar topics was failing on tsquery-meaningful punctuation (PR #10938)

see commit messages

Supersedes #10913

GitHub

the private … public… context switch is a bit confusing, can you move the private stuff to the end of the file?

@riking @oblakeerickson Something else is at play here… If I run the query manually in psql, I get

discourse_development=# SELECT REPLACE(TO_TSQUERY('english', '''Title with trailing backslash\\'':*A & ''no body'':*B')::text, '&', '|')::tsquery
;
                       replace                       
-----------------------------------------------------
 'titl':*A | 'trail':*A | 'backslash':*A | 'bodi':*B
(1 row)

However, running it via ActiveRecord causes the same query to blow up.

(byebug) ActiveRecord::Base.connection.execute("SELECT REPLACE(TO_TSQUERY('english', '''Title with trailing backslash\\'':*A & ''no body'':*B')::text, '&', '|')::tsquery")
*** ActiveRecord::StatementInvalid Exception: PG::SyntaxError: ERROR:  syntax error in tsquery: "'Title with trailing backslash\':*A & 'no body':*B"

I’ll see if I can figure out why next week.

Fixed in https://github.com/discourse/discourse/pull/10938. Thank you @oblakeerickson and @riking for investigating.