Excluding actor-specific tags from aggregated tag filter.

This commit is contained in:
2026-03-05 02:00:10 +01:00
parent eefc213144
commit 07f290ad85
2 changed files with 21 additions and 7 deletions

View File

@@ -81,7 +81,7 @@
<ul
class="row tags nolist"
:title="scene.tags.map((tag) => tag.name).join(', ')"
:title="sceneTags.map((tag) => tag.name).join(', ')"
>
<li
v-if="scene.shootId"
@@ -94,7 +94,7 @@
</li>
<li
v-for="tag in scene.tags"
v-for="tag in sceneTags"
:key="`tag-${scene.id}-${tag.id}`"
class="tag"
:class="{ piss: tag.slug === 'pissing' }"
@@ -135,7 +135,9 @@ const { user } = pageContext;
const pageStash = pageContext.pageProps.stash;
const currentStash = pageStash || pageContext.assets?.primaryStash;
const priorityTags = props.scene.tags.map((tag) => tag.name).slice(0, 2);
const sceneTags = Object.values(Object.fromEntries(props.scene.tags.map((tag) => [tag.id, tag])));
const priorityTags = sceneTags.map((tag) => tag.name).slice(0, 2);
const favorited = ref(props.scene.stashes.some((sceneStash) => sceneStash.id === currentStash?.id));
</script>

View File

@@ -456,6 +456,11 @@ async function queryManticoreSql(filters, options, _reqUser) {
year(scenes.effective_date) as effective_year,
weight() as _score
`));
// manticore only supports one joined table, so we can't use it inside stashes; probably not needed anyway (stashes only need global tags?)
builder
.leftJoin('scenes_tags', 'scenes_tags.scene_id', 'scenes_.id')
.groupBy('scenes.id');
}
if (filters.query) {
@@ -560,7 +565,12 @@ async function queryManticoreSql(filters, options, _reqUser) {
// option threads=1 fixes actors, but drastically slows down performance, wait for fix
yearsFacet: options.aggregateYears ? knex.raw('facet effective_year as years order by effective_year desc limit ?', [aggSize]) : null,
actorsFacet: options.aggregateActors ? knex.raw('facet scenes.actor_ids order by count(*) desc limit ?', [aggSize]) : null,
tagsFacet: options.aggregateTags ? knex.raw('facet scenes.tag_ids order by count(*) desc limit ?', [aggSize]) : null,
// don't facet tags associated to other actors, actor ID 0 means global
tagsFacet: options.aggregateTags // eslint-disable-line no-nested-ternary
? (filters.stashId // we can't join the tags table as well as the stashes table
? knex.raw('facet scenes.tag_ids order by count(*) desc limit ?', [aggSize])
: knex.raw(`facet IF(IN(scenes_tags.actor_id, ${[0, ...filters?.actorIds || []]}), scenes_tags.tag_id, 0) as tags_facet distinct id order by count(distinct id) desc limit ?`, [aggSize]))
: null,
channelsFacet: options.aggregateChannels ? knex.raw('facet scenes.channel_id order by count(*) desc limit ?', [aggSize]) : null,
studiosFacet: options.aggregateChannels ? knex.raw('facet scenes.studio_id order by count(*) desc limit ?', [aggSize]) : null,
maxMatches: config.database.manticore.maxMatches,
@@ -570,7 +580,9 @@ async function queryManticoreSql(filters, options, _reqUser) {
// manticore does not seem to accept table.column syntax if 'table' is primary (yet?), crude work-around
const curatedSqlQuery = filters.stashId
? sqlQuery
: sqlQuery.replace(/scenes\./g, '');
: sqlQuery
.replace(/scenes\./g, '')
.replace(/scenes_\./g, 'scenes.');
if (process.env.NODE_ENV === 'development' && argv.debug) {
console.log(curatedSqlQuery);
@@ -591,8 +603,8 @@ async function queryManticoreSql(filters, options, _reqUser) {
|| [];
const tagIds = results
.find((result) => (result.columns[0].tag_ids || result.columns[0]['scenes.tag_ids']) && result.columns[1]['count(*)'])
?.data.map((row) => ({ key: row.tag_ids || row['scenes.tag_ids'], doc_count: row['count(*)'] }))
.find((result) => (result.columns[0].tag_id || result.columns[0].tags_facet || result.columns[0]['scenes.tag_ids']) && (result.columns[1]['count(distinct id)'] || result.columns[1]['count(*)']))
?.data.map((row) => ({ key: row.tag_id || row.tags_facet || row['scenes.tag_ids'], doc_count: row['count(distinct id)'] || row['count(*)'] }))
|| [];
const channelIds = results