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:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user