diff --git a/app/controllers/yiff_rest/api_v2/images_controller.rb b/app/controllers/yiff_rest/api_v2/images_controller.rb index 9a2939b..9c891b2 100644 --- a/app/controllers/yiff_rest/api_v2/images_controller.rb +++ b/app/controllers/yiff_rest/api_v2/images_controller.rb @@ -69,7 +69,7 @@ module YiffRest end def search_images_params - permit_search_params(%i[category md5 original_url artists]) + permit_search_params(%i[category md5 original_url artist]) end def create_params diff --git a/app/models/api_image.rb b/app/models/api_image.rb index 2ffc211..3ebb182 100644 --- a/app/models/api_image.rb +++ b/app/models/api_image.rb @@ -75,11 +75,15 @@ class APIImage < ApplicationRecord data end + def artists_like(name) + where(id: APIImage.from("unnest(artists) AS artist").where("artist LIKE ?", name.to_escaped_for_sql_like)) + end + def search(params) q = super q = q.attribute_matches(:category, params[:category]) q = q.attribute_matches(:original_url, params[:original_url]) - q = q.attribute_matches(:artists, params[:artists]) + q = q.artists_like(params[:artist]) if params[:artist].present? q.order(created_at: :desc) end end