mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 12:08:00 +01:00
Add tag category counts to index
This commit is contained in:
parent
74daa662ac
commit
f9a6240014
2 changed files with 36 additions and 3 deletions
|
@ -72,7 +72,20 @@ galleries: image_search_json
|
|||
|
||||
tags: image_search_json
|
||||
psql $(DATABASE) -v ON_ERROR_STOP=1 <<-SQL
|
||||
insert into temp_images.image_search_json (image_id, object) select it.image_id, jsonb_build_object('tag_ids', jsonb_agg(it.tag_id), 'tag_count', count(*)) from image_taggings it group by image_id;
|
||||
insert into temp_images.image_search_json (image_id, object) select it.image_id, jsonb_build_object(
|
||||
'tag_ids', jsonb_agg(it.tag_id),
|
||||
'tag_count', count(*),
|
||||
'error_tag_count', count(case when t.category = 'error' then t.category else null end),
|
||||
'rating_tag_count', count(case when t.category = 'rating' then t.category else null end),
|
||||
'origin_tag_count', count(case when t.category = 'origin' then t.category else null end),
|
||||
'character_tag_count', count(case when t.category = 'character' then t.category else null end),
|
||||
'oc_tag_count', count(case when t.category = 'oc' then t.category else null end),
|
||||
'species_tag_count', count(case when t.category = 'species' then t.category else null end),
|
||||
'body_type_tag_count', count(case when t.category = 'body-type' then t.category else null end),
|
||||
'content_fanmade_tag_count', count(case when t.category = 'content-fanmade' then t.category else null end),
|
||||
'content_official_tag_count', count(case when t.category = 'content-official' then t.category else null end),
|
||||
'spoiler_tag_count', count(case when t.category = 'spoiler' then t.category else null end),
|
||||
) from image_taggings it inner join tags t on t.id = it.tag_id group by image_id;
|
||||
SQL
|
||||
|
||||
sources: image_search_json
|
||||
|
|
|
@ -87,7 +87,17 @@ defmodule Philomena.Images.ElasticsearchIndex do
|
|||
namespace: %{type: "keyword"}
|
||||
}
|
||||
},
|
||||
approved: %{type: "boolean"}
|
||||
approved: %{type: "boolean"},
|
||||
error_tag_count: %{type: "integer"},
|
||||
rating_tag_count: %{type: "integer"},
|
||||
origin_tag_count: %{type: "integer"},
|
||||
character_tag_count: %{type: "integer"},
|
||||
oc_tag_count: %{type: "integer"},
|
||||
species_tag_count: %{type: "integer"},
|
||||
body_type_tag_count: %{type: "integer"},
|
||||
content_fanmade_tag_count: %{type: "integer"},
|
||||
content_official_tag_count: %{type: "integer"},
|
||||
spoiler_tag_count: %{type: "integer"}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -151,7 +161,17 @@ defmodule Philomena.Images.ElasticsearchIndex do
|
|||
upvoters: image.upvoters |> Enum.map(&String.downcase(&1.name)),
|
||||
downvoters: image.downvoters |> Enum.map(&String.downcase(&1.name)),
|
||||
deleted_by_user: if(!!image.deleter, do: image.deleter.name),
|
||||
approved: image.approved
|
||||
approved: image.approved,
|
||||
error_tag_count: Enum.count(image.tags, &(&1.category == "error")),
|
||||
rating_tag_count: Enum.count(image.tags, &(&1.category == "rating")),
|
||||
origin_tag_count: Enum.count(image.tags, &(&1.category == "origin")),
|
||||
character_tag_count: Enum.count(image.tags, &(&1.category == "character")),
|
||||
oc_tag_count: Enum.count(image.tags, &(&1.category == "oc")),
|
||||
species_tag_count: Enum.count(image.tags, &(&1.category == "species")),
|
||||
body_type_tag_count: Enum.count(image.tags, &(&1.category == "body-type")),
|
||||
content_fanmade_tag_count: Enum.count(image.tags, &(&1.category == "content-fanmade")),
|
||||
content_official_tag_count: Enum.count(image.tags, &(&1.category == "content-official")),
|
||||
spoiler_tag_count: Enum.count(image.tags, &(&1.category == "spoiler"))
|
||||
}
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue