Make artist search work with external images
This commit is contained in:
parent
8f5fd85f15
commit
6c07ab3065
@ -98,12 +98,18 @@ class APIImage < ApplicationRecord
|
||||
where(id: APIImage.from("unnest(artists) AS artist").where("artist LIKE ?", name.to_escaped_for_sql_like))
|
||||
end
|
||||
|
||||
def external_artists_like(name)
|
||||
where(id: ExternalAPIImage.from("external_api_images, jsonb_array_elements_text(cached_data->'tags'->'artist') AS artist").where("artist LIKE ?", name.to_escaped_for_sql_like).select("api_image_id"))
|
||||
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(:is_viewable, params[:viewable])
|
||||
q = q.artists_like(params[:artist]) if params[:artist].present?
|
||||
if params[:artist].present? # rubocop:disable Style/IfUnlessModifier
|
||||
q = q.artists_like(params[:artist]).or(external_artists_like(params[:artist]))
|
||||
end
|
||||
if params[:md5].present? # rubocop:disable Style/IfUnlessModifier
|
||||
q = q.attribute_matches(:id, params[:md5]).or(q.where(id: ExternalAPIImage.where("cached_data->'file'->>'md5' = ?", params[:md5]).select("api_image_id")))
|
||||
end
|
||||
|
@ -9,7 +9,7 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= external.artists.join(", ") %></td>
|
||||
<td><%= external.artists.map { |art| link_to(art, yiff_rest_api_v2_manage_images_path(search: @sp.merge(artist: art))) }.join(", ").html_safe %></td>
|
||||
<td>
|
||||
<ul class="details">
|
||||
<li>Resolution: <b><%= external.width %>x<%= external.height %></b></li>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<%= image_tag(image.url, class: "img-fluid img-thumbnail") %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= image.artists.join(", ") %></td>
|
||||
<td><%= image.artists.map { |art| link_to(art, yiff_rest_api_v2_manage_images_path(search: @sp.merge(artist: art))) }.join(", ").html_safe %></td>
|
||||
<td>
|
||||
<ul class="details">
|
||||
<li>Resolution: <b><%= image.width %>x<%= image.height %></b></li>
|
||||
|
Loading…
Reference in New Issue
Block a user