From d9d585d51a2e7eed5dbf5361d7657714b1aebadb Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Thu, 25 Jan 2024 01:58:55 +0100 Subject: [PATCH] Added Manticore migration and meta text field. --- migrations/20240125011700_manticore.js | 35 ++++++++++++++++++++++++++ src/tools/manticore.js | 1 + src/update-search.js | 11 +++----- 3 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 migrations/20240125011700_manticore.js diff --git a/migrations/20240125011700_manticore.js b/migrations/20240125011700_manticore.js new file mode 100644 index 000000000..fb83b15a6 --- /dev/null +++ b/migrations/20240125011700_manticore.js @@ -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'); +}; diff --git a/src/tools/manticore.js b/src/tools/manticore.js index c6936c335..464fcdb6b 100644 --- a/src/tools/manticore.js +++ b/src/tools/manticore.js @@ -81,6 +81,7 @@ async function init() { actors text, tag_ids multi, tags text, + meta text, date timestamp, created_at timestamp, effective_date timestamp, diff --git a/src/update-search.js b/src/update-search.js index 3ef08f832..f306320a2 100644 --- a/src/update-search.js +++ b/src/update-search.js @@ -1,6 +1,7 @@ 'use strict'; const manticore = require('manticoresearch'); +const { format } = require('date-fns'); const knex = require('./knex'); const logger = require('./logger')(__filename); @@ -54,9 +55,6 @@ async function updateManticoreSearch(releaseIds) { parents.alias; `, releaseIds && [releaseIds]); - console.log(releaseIds); - console.log(scenes); - const docs = scenes.rows.map((scene) => ({ replace: { index: 'scenes', @@ -77,20 +75,17 @@ async function updateManticoreSearch(releaseIds) { actors: scene.actors.map((actor) => actor.f2).join(), tag_ids: scene.tags.map((tag) => tag.f1), tags: scene.tags.map((tag) => tag.f2).join(), + meta: scene.date ? format(scene.date, 'y M d') : undefined, stashed: scene.stashed || 0, }, }, })); - console.log('docs', docs); - if (docs.length === 0) { return; } - const data = await indexApi.bulk(docs.map((doc) => JSON.stringify(doc)).join('\n')); - - console.log('data', data); + await indexApi.bulk(docs.map((doc) => JSON.stringify(doc)).join('\n')); } async function updateSqlSearch(releaseIds) {