db: add tsvector indexes on commentary, dmail, and wiki page text columns.

This commit is contained in:
evazion
2022-10-10 00:32:40 -05:00
parent 01d10a54f8
commit 4066ee52b1
3 changed files with 118 additions and 6 deletions

View File

@@ -191,11 +191,9 @@ module Searchable
# https://www.postgresql.org/docs/current/textsearch-controls.html#TEXTSEARCH-PARSING-DOCUMENTS
# https://www.postgresql.org/docs/current/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES
def where_tsvector_matches(columns, query)
tsvectors = Array.wrap(columns).map do |column|
to_tsvector("pg_catalog.english", arel_table[column])
end.reduce(:concat)
where("(#{tsvectors.to_sql}) @@ websearch_to_tsquery('pg_catalog.english', :query)", query: query)
Array.wrap(columns).map do |column|
where("(#{to_tsvector('english', arel_table[column]).to_sql}) @@ websearch_to_tsquery('pg_catalog.english', :query)", query: query)
end.reduce(:or)
end
# value: "5", ">5", "<5", ">=5", "<=5", "5..10", "5,6,7"