Serializing aliased actors as searchable text field in manticore.

This commit is contained in:
2026-06-09 06:18:05 +02:00
parent ab1e642c36
commit e5e1c5f82b
3 changed files with 13 additions and 4 deletions

View File

@@ -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) });
}
}

View File

@@ -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,

View File

@@ -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,