Added Manticore migration and meta text field.

This commit is contained in:
DebaucheryLibrarian 2024-01-25 01:58:55 +01:00
parent 86ffcc3316
commit d9d585d51a
3 changed files with 39 additions and 8 deletions

View File

@ -0,0 +1,35 @@
const config = require('config');
const manticore = require('manticoresearch');
const mantiClient = new manticore.ApiClient();
mantiClient.basePath = `http://${config.database.manticore.host}:${config.database.manticore.httpPort}`;
const utilsApi = new manticore.UtilsApi(mantiClient);
exports.up = async () => {
await utilsApi.sql(`create table scenes (
id int,
title text,
entry_id text,
channel_id int,
channel_name text,
channel_slug text,
network_id int,
network_name text,
network_slug text,
actor_ids multi,
actors text,
tag_ids multi,
tags text,
meta text,
date timestamp,
created_at timestamp,
effective_date timestamp,
stashed int
)`);
};
exports.down = async () => {
await utilsApi.sql('drop table scenes');
};

View File

@ -81,6 +81,7 @@ async function init() {
actors text, actors text,
tag_ids multi, tag_ids multi,
tags text, tags text,
meta text,
date timestamp, date timestamp,
created_at timestamp, created_at timestamp,
effective_date timestamp, effective_date timestamp,

View File

@ -1,6 +1,7 @@
'use strict'; 'use strict';
const manticore = require('manticoresearch'); const manticore = require('manticoresearch');
const { format } = require('date-fns');
const knex = require('./knex'); const knex = require('./knex');
const logger = require('./logger')(__filename); const logger = require('./logger')(__filename);
@ -54,9 +55,6 @@ async function updateManticoreSearch(releaseIds) {
parents.alias; parents.alias;
`, releaseIds && [releaseIds]); `, releaseIds && [releaseIds]);
console.log(releaseIds);
console.log(scenes);
const docs = scenes.rows.map((scene) => ({ const docs = scenes.rows.map((scene) => ({
replace: { replace: {
index: 'scenes', index: 'scenes',
@ -77,20 +75,17 @@ async function updateManticoreSearch(releaseIds) {
actors: scene.actors.map((actor) => actor.f2).join(), actors: scene.actors.map((actor) => actor.f2).join(),
tag_ids: scene.tags.map((tag) => tag.f1), tag_ids: scene.tags.map((tag) => tag.f1),
tags: scene.tags.map((tag) => tag.f2).join(), tags: scene.tags.map((tag) => tag.f2).join(),
meta: scene.date ? format(scene.date, 'y M d') : undefined,
stashed: scene.stashed || 0, stashed: scene.stashed || 0,
}, },
}, },
})); }));
console.log('docs', docs);
if (docs.length === 0) { if (docs.length === 0) {
return; return;
} }
const data = await indexApi.bulk(docs.map((doc) => JSON.stringify(doc)).join('\n')); await indexApi.bulk(docs.map((doc) => JSON.stringify(doc)).join('\n'));
console.log('data', data);
} }
async function updateSqlSearch(releaseIds) { async function updateSqlSearch(releaseIds) {