Serializing aliased actors as searchable text field in manticore.
This commit is contained in:
@@ -369,11 +369,13 @@ async function queryManticoreSql(filters, options, _reqUser) {
|
|||||||
builder.select(knex.raw('*, weight() as _score'));
|
builder.select(knex.raw('*, weight() as _score'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
builder.where('alias_for', 0);
|
||||||
|
|
||||||
if (filters.query) {
|
if (filters.query) {
|
||||||
if (filters.query.charAt(0) === '#') {
|
if (filters.query.charAt(0) === '#') {
|
||||||
builder.where('id', Number(escape(filters.query.slice(1))));
|
builder.where('id', Number(escape(filters.query.slice(1))));
|
||||||
} else {
|
} else {
|
||||||
builder.whereRaw('match(\'@name :query:\', actors)', { query: escape(filters.query) });
|
builder.whereRaw('match(\'@(name,aliases) :query:\', actors)', { query: escape(filters.query) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
11
src/sync.js
11
src/sync.js
@@ -382,11 +382,14 @@ export async function syncManticoreActors(actorIds) {
|
|||||||
const actors = await knex.raw(`
|
const actors = await knex.raw(`
|
||||||
SELECT
|
SELECT
|
||||||
actors.*,
|
actors.*,
|
||||||
actors_meta.*,
|
actors_meta.stashed, actors_meta.scenes,
|
||||||
date_of_birth AT TIME ZONE 'Europe/Amsterdam' AT TIME ZONE 'UTC' as dob
|
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
|
FROM actors
|
||||||
LEFT JOIN actors_meta ON actors_meta.actor_id = actors.id
|
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(?)' : ''}
|
${actorIds ? 'WHERE actors.id = ANY(?)' : ''}
|
||||||
|
GROUP BY actors.id, actors_meta.stashed, actors_meta.scenes
|
||||||
`, actorIds && [actorIds]);
|
`, actorIds && [actorIds]);
|
||||||
|
|
||||||
const actorsById = Object.fromEntries(actors.rows.map((actor) => [actor.id, actor]));
|
const actorsById = Object.fromEntries(actors.rows.map((actor) => [actor.id, actor]));
|
||||||
@@ -408,7 +411,9 @@ export async function syncManticoreActors(actorIds) {
|
|||||||
index: 'actors',
|
index: 'actors',
|
||||||
id: actor.id,
|
id: actor.id,
|
||||||
doc: {
|
doc: {
|
||||||
entity_id: actor.entity_id,
|
entity_id: actor.entity_id || undefined,
|
||||||
|
alias_for: actor.alias_for || undefined,
|
||||||
|
aliases: actor.alias,
|
||||||
name: actor.name,
|
name: actor.name,
|
||||||
slug: actor.slug,
|
slug: actor.slug,
|
||||||
gender: actor.gender || undefined,
|
gender: actor.gender || undefined,
|
||||||
|
|||||||
@@ -10,8 +10,10 @@ async function init() {
|
|||||||
await utilsApi.sql(`create table actors(
|
await utilsApi.sql(`create table actors(
|
||||||
id int,
|
id int,
|
||||||
name text,
|
name text,
|
||||||
|
aliases text,
|
||||||
slug string,
|
slug string,
|
||||||
entity_id int,
|
entity_id int,
|
||||||
|
alias_for int,
|
||||||
gender string,
|
gender string,
|
||||||
date_of_birth timestamp,
|
date_of_birth timestamp,
|
||||||
country string,
|
country string,
|
||||||
|
|||||||
Reference in New Issue
Block a user