diff --git a/src/actors.js b/src/actors.js index de1cbc7..3f60143 100644 --- a/src/actors.js +++ b/src/actors.js @@ -369,11 +369,13 @@ async function queryManticoreSql(filters, options, _reqUser) { builder.select(knex.raw('*, weight() as _score')); } + builder.where('alias_for', 0); + if (filters.query) { if (filters.query.charAt(0) === '#') { builder.where('id', Number(escape(filters.query.slice(1)))); } else { - builder.whereRaw('match(\'@name :query:\', actors)', { query: escape(filters.query) }); + builder.whereRaw('match(\'@(name,aliases) :query:\', actors)', { query: escape(filters.query) }); } } diff --git a/src/sync.js b/src/sync.js index d184fd7..a0556c9 100644 --- a/src/sync.js +++ b/src/sync.js @@ -382,11 +382,14 @@ export async function syncManticoreActors(actorIds) { const actors = await knex.raw(` SELECT actors.*, - actors_meta.*, - date_of_birth AT TIME ZONE 'Europe/Amsterdam' AT TIME ZONE 'UTC' as dob + actors_meta.stashed, actors_meta.scenes, + STRING_AGG(DISTINCT aliases.name, ',') FILTER (WHERE LOWER(aliases.name) != LOWER(actors.name)) as alias, + actors.date_of_birth AT TIME ZONE 'Europe/Amsterdam' AT TIME ZONE 'UTC' as dob FROM actors LEFT JOIN actors_meta ON actors_meta.actor_id = actors.id + LEFT JOIN actors AS aliases ON aliases.alias_for = actors.id ${actorIds ? 'WHERE actors.id = ANY(?)' : ''} + GROUP BY actors.id, actors_meta.stashed, actors_meta.scenes `, actorIds && [actorIds]); const actorsById = Object.fromEntries(actors.rows.map((actor) => [actor.id, actor])); @@ -408,7 +411,9 @@ export async function syncManticoreActors(actorIds) { index: 'actors', id: actor.id, doc: { - entity_id: actor.entity_id, + entity_id: actor.entity_id || undefined, + alias_for: actor.alias_for || undefined, + aliases: actor.alias, name: actor.name, slug: actor.slug, gender: actor.gender || undefined, diff --git a/tools/manticore-actors.js b/tools/manticore-actors.js index 7f61e06..1173651 100644 --- a/tools/manticore-actors.js +++ b/tools/manticore-actors.js @@ -10,8 +10,10 @@ async function init() { await utilsApi.sql(`create table actors( id int, name text, + aliases text, slug string, entity_id int, + alias_for int, gender string, date_of_birth timestamp, country string,