Make artist search work with external images

This commit is contained in:
Donovan Daniels 2024-10-24 04:10:07 -05:00
parent 8f5fd85f15
commit 6c07ab3065
Signed by: Donovan_DMC
GPG Key ID: 907D29CBFD6157BA
3 changed files with 9 additions and 3 deletions

View File

@ -98,12 +98,18 @@ class APIImage < ApplicationRecord
where(id: APIImage.from("unnest(artists) AS artist").where("artist LIKE ?", name.to_escaped_for_sql_like)) where(id: APIImage.from("unnest(artists) AS artist").where("artist LIKE ?", name.to_escaped_for_sql_like))
end 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) def search(params)
q = super q = super
q = q.attribute_matches(:category, params[:category]) q = q.attribute_matches(:category, params[:category])
q = q.attribute_matches(:original_url, params[:original_url]) q = q.attribute_matches(:original_url, params[:original_url])
q = q.attribute_matches(:is_viewable, params[:viewable]) 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 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"))) q = q.attribute_matches(:id, params[:md5]).or(q.where(id: ExternalAPIImage.where("cached_data->'file'->>'md5' = ?", params[:md5]).select("api_image_id")))
end end

View File

@ -9,7 +9,7 @@
<% end %> <% end %>
<% end %> <% end %>
</td> </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> <td>
<ul class="details"> <ul class="details">
<li>Resolution: <b><%= external.width %>x<%= external.height %></b></li> <li>Resolution: <b><%= external.width %>x<%= external.height %></b></li>

View File

@ -5,7 +5,7 @@
<%= image_tag(image.url, class: "img-fluid img-thumbnail") %> <%= image_tag(image.url, class: "img-fluid img-thumbnail") %>
<% end %> <% end %>
</td> </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> <td>
<ul class="details"> <ul class="details">
<li>Resolution: <b><%= image.width %>x<%= image.height %></b></li> <li>Resolution: <b><%= image.width %>x<%= image.height %></b></li>