Search fields (#100)

This commit is contained in:
liamwhite 2021-12-20 14:44:52 -05:00 committed by GitHub
parent 12ce4f82e1
commit bcf295b1fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 6 deletions

View file

@ -5,7 +5,7 @@ defmodule Philomena.Analyzers.Webm do
%{ %{
extension: "webm", extension: "webm",
mime_type: "video/webm", mime_type: "video/webm",
animated?: true, animated?: stats.animated?,
duration: stats.duration, duration: stats.duration,
dimensions: stats.dimensions dimensions: stats.dimensions
} }
@ -14,16 +14,16 @@ defmodule Philomena.Analyzers.Webm do
defp stats(file) do defp stats(file) do
case System.cmd("mediastat", [file]) do case System.cmd("mediastat", [file]) do
{output, 0} -> {output, 0} ->
[_size, _frames, width, height, num, den] = [_size, frames, width, height, num, den] =
output output
|> String.trim() |> String.trim()
|> String.split(" ") |> String.split(" ")
|> Enum.map(&String.to_integer/1) |> Enum.map(&String.to_integer/1)
%{dimensions: {width, height}, duration: num / den} %{animated?: frames > 1, dimensions: {width, height}, duration: num / den}
_ -> _ ->
%{dimensions: {0, 0}, duration: 0.0} %{animated?: false, dimensions: {0, 0}, duration: 0.0}
end end
end end
end end

View file

@ -18,6 +18,7 @@ defmodule Philomena.Images.ElasticsearchIndex do
mappings: %{ mappings: %{
dynamic: false, dynamic: false,
properties: %{ properties: %{
animated: %{type: "boolean"},
anonymous: %{type: "boolean"}, anonymous: %{type: "boolean"},
aspect_ratio: %{type: "float"}, aspect_ratio: %{type: "float"},
comment_count: %{type: "integer"}, comment_count: %{type: "integer"},
@ -38,6 +39,8 @@ defmodule Philomena.Images.ElasticsearchIndex do
file_name: %{type: "keyword"}, file_name: %{type: "keyword"},
fingerprint: %{type: "keyword"}, fingerprint: %{type: "keyword"},
first_seen_at: %{type: "date"}, first_seen_at: %{type: "date"},
fps: %{type: "float"},
frames: %{type: "integer"},
height: %{type: "integer"}, height: %{type: "integer"},
hidden_by_user_ids: %{type: "keyword"}, hidden_by_user_ids: %{type: "keyword"},
hidden_by_users: %{type: "keyword"}, hidden_by_users: %{type: "keyword"},
@ -48,6 +51,7 @@ defmodule Philomena.Images.ElasticsearchIndex do
orig_sha512_hash: %{type: "keyword"}, orig_sha512_hash: %{type: "keyword"},
original_format: %{type: "keyword"}, original_format: %{type: "keyword"},
pixels: %{type: "integer"}, pixels: %{type: "integer"},
processed: %{type: "boolean"},
score: %{type: "integer"}, score: %{type: "integer"},
size: %{type: "integer"}, size: %{type: "integer"},
sha512_hash: %{type: "keyword"}, sha512_hash: %{type: "keyword"},
@ -55,6 +59,7 @@ defmodule Philomena.Images.ElasticsearchIndex do
tag_count: %{type: "integer"}, tag_count: %{type: "integer"},
tag_ids: %{type: "keyword"}, tag_ids: %{type: "keyword"},
tags: %{type: "text", analyzer: "keyword"}, tags: %{type: "text", analyzer: "keyword"},
thumbnails_generated: %{type: "boolean"},
true_uploader: %{type: "keyword"}, true_uploader: %{type: "keyword"},
true_uploader_id: %{type: "keyword"}, true_uploader_id: %{type: "keyword"},
updated_at: %{type: "date"}, updated_at: %{type: "date"},
@ -100,7 +105,8 @@ defmodule Philomena.Images.ElasticsearchIndex do
height: image.image_height, height: image.image_height,
pixels: image.image_width * image.image_height, pixels: image.image_width * image.image_height,
size: image.image_size, size: image.image_size,
duration: image.image_duration, animated: image.image_is_animated,
duration: if(image.image_is_animated, do: image.image_duration, else: 0),
tag_count: length(image.tags), tag_count: length(image.tags),
aspect_ratio: image.image_aspect_ratio, aspect_ratio: image.image_aspect_ratio,
wilson_score: wilson_score(image), wilson_score: wilson_score(image),
@ -115,6 +121,8 @@ defmodule Philomena.Images.ElasticsearchIndex do
source_url: image.source_url |> to_string |> String.downcase(), source_url: image.source_url |> to_string |> String.downcase(),
file_name: image.image_name, file_name: image.image_name,
original_format: image.image_format, original_format: image.image_format,
processed: image.processed,
thumbnails_generated: image.thumbnails_generated,
fingerprint: image.fingerprint, fingerprint: image.fingerprint,
uploader_id: if(!!image.user_id and !image.anonymous, do: image.user_id), uploader_id: if(!!image.user_id and !image.anonymous, do: image.user_id),
true_uploader_id: image.user_id, true_uploader_id: image.user_id,

View file

@ -74,6 +74,7 @@ defmodule Philomena.Images.Query do
date_fields: ~W(created_at updated_at first_seen_at), date_fields: ~W(created_at updated_at first_seen_at),
literal_fields: literal_fields:
~W(faved_by orig_sha512_hash sha512_hash uploader source_url original_format mime_type), ~W(faved_by orig_sha512_hash sha512_hash uploader source_url original_format mime_type),
bool_fields: ~W(animated processed thumbnails_generated),
ngram_fields: ~W(description), ngram_fields: ~W(description),
custom_fields: ~W(gallery_id), custom_fields: ~W(gallery_id),
default_field: {"namespaced_tags.name", :term}, default_field: {"namespaced_tags.name", :term},
@ -106,7 +107,7 @@ defmodule Philomena.Images.Query do
~W(fingerprint upvoted_by downvoted_by true_uploader hidden_by deleted_by_user), ~W(fingerprint upvoted_by downvoted_by true_uploader hidden_by deleted_by_user),
ngram_fields: fields[:ngram_fields] ++ ~W(deletion_reason), ngram_fields: fields[:ngram_fields] ++ ~W(deletion_reason),
ip_fields: ~W(ip), ip_fields: ~W(ip),
bool_fields: ~W(deleted), bool_fields: fields[:bool_fields] ++ ~W(deleted),
aliases: aliases:
Map.merge(fields[:aliases], %{ Map.merge(fields[:aliases], %{
"upvoted_by" => "upvoters", "upvoted_by" => "upvoters",

View file

@ -1,5 +1,6 @@
defmodule Philomena.ThumbnailWorker do defmodule Philomena.ThumbnailWorker do
alias Philomena.Images.Thumbnailer alias Philomena.Images.Thumbnailer
alias Philomena.Images
def perform(image_id) do def perform(image_id) do
Thumbnailer.generate_thumbnails(image_id) Thumbnailer.generate_thumbnails(image_id)
@ -9,5 +10,9 @@ defmodule Philomena.ThumbnailWorker do
"image:process", "image:process",
%{image_id: image_id} %{image_id: image_id}
) )
image_id
|> Images.get_image!()
|> Images.reindex_image()
end end
end end

View file

@ -26,6 +26,7 @@ h1 Search
a data-search-add="width:1920" data-search-select-last="4" data-search-show-help="numeric" Image width a data-search-add="width:1920" data-search-select-last="4" data-search-show-help="numeric" Image width
a data-search-add="height:1080" data-search-select-last="4" data-search-show-help="numeric" Image height a data-search-add="height:1080" data-search-select-last="4" data-search-show-help="numeric" Image height
a data-search-add="aspect_ratio:1" data-search-select-last="1" data-search-show-help="numeric" Aspect ratio a data-search-add="aspect_ratio:1" data-search-select-last="1" data-search-show-help="numeric" Aspect ratio
a data-search-add="animated:false" data-search-select-last="5" data-search-show-help="boolean" Animated
a data-search-add="duration:10" data-search-select-last="2" data-search-show-help="numeric" Duration (seconds) a data-search-add="duration:10" data-search-select-last="2" data-search-show-help="numeric" Duration (seconds)
a data-search-add="pixels.gte:5000000" data-search-select-last="7" data-search-show-help="numeric" Pixels a data-search-add="pixels.gte:5000000" data-search-select-last="7" data-search-show-help="numeric" Pixels
a data-search-add="size.lt:1048576" data-search-select-last="7" data-search-show-help="numeric" File size (bytes) a data-search-add="size.lt:1048576" data-search-select-last="7" data-search-show-help="numeric" File size (bytes)
@ -46,6 +47,20 @@ h1 Search
a href="/pages/search_syntax" Help a href="/pages/search_syntax" Help
.block__content .block__content
.hidden.walloftext data-search-help="boolean"
strong.js-search-help-subject>
' is a Boolean-valued field. It only accepts the values
code> true
' and
code false
|.
br
br
em<> Example:
' to find images which are not animated, you would use
code animated:false
| .
.hidden.walloftext data-search-help="numeric" .hidden.walloftext data-search-help="numeric"
strong.js-search-help-subject> strong.js-search-help-subject>
| is a numerical range field. Four qualifiers, | is a numerical range field. Four qualifiers,