commentaries: perform full-text search instead of substring search.

Switch `/artist_commentaries?search[text_matches]` to do a full-text
search instead of a substring search. This is more consistent with text
search in other places.
This commit is contained in:
evazion
2022-09-22 01:17:26 -05:00
parent 29a4ca0818
commit b56b6c554b
2 changed files with 2 additions and 19 deletions

View File

@@ -29,12 +29,7 @@ class ArtistCommentary < ApplicationRecord
module SearchMethods
def text_matches(query)
query = "*#{query}*" unless query =~ /\*/
where_ilike(:original_title, query)
.or(where_ilike(:original_description, query))
.or(where_ilike(:translated_title, query))
.or(where_ilike(:translated_description, query))
where_text_matches(%i[original_title original_description translated_title translated_description], query)
end
def search(params)

View File

@@ -4,21 +4,9 @@ class ArtistCommentaryVersion < ApplicationRecord
belongs_to :post
belongs_to_updater
def self.text_matches(query)
query = "*#{query}*" unless query =~ /\*/
where_ilike(:original_title, query)
.or(where_ilike(:original_description, query))
.or(where_ilike(:translated_title, query))
.or(where_ilike(:translated_description, query))
end
def self.search(params)
q = search_attributes(params, :id, :created_at, :updated_at, :original_title, :original_description, :translated_title, :translated_description, :post, :updater)
if params[:text_matches].present?
q = q.text_matches(params[:text_matches])
end
q = q.where_text_matches(%i[original_title original_description translated_title translated_description], params[:text_matches])
q.apply_default_order(params)
end