From f1f618d3a7e56c4f8c7d187bb6c7c4247f187346 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Sun, 24 Mar 2024 22:16:58 +0100 Subject: [PATCH] Added entity_ids column to manticore scenes table. --- migrations/20240125011700_manticore.js | 1 + src/tools/manticore-scenes.js | 135 +------------------------ src/update-search.js | 1 + 3 files changed, 5 insertions(+), 132 deletions(-) diff --git a/migrations/20240125011700_manticore.js b/migrations/20240125011700_manticore.js index 948dff972..43ea6b0df 100644 --- a/migrations/20240125011700_manticore.js +++ b/migrations/20240125011700_manticore.js @@ -18,6 +18,7 @@ const scenesFields = ` network_id int, network_name text, network_slug text, + entity_ids multi, actor_ids multi, actors text, tag_ids multi, diff --git a/src/tools/manticore-scenes.js b/src/tools/manticore-scenes.js index 1d92a43be..b4a6e17f1 100644 --- a/src/tools/manticore-scenes.js +++ b/src/tools/manticore-scenes.js @@ -11,8 +11,6 @@ const mantiClient = new manticore.ApiClient(); mantiClient.basePath = `http://${config.database.manticore.host}:${config.database.manticore.httpPort}`; -const searchApi = new manticore.SearchApi(mantiClient); - const utilsApi = new manticore.UtilsApi(mantiClient); const indexApi = new manticore.IndexApi(mantiClient); @@ -80,12 +78,14 @@ async function init() { network_id int, network_name text, network_slug text, + entity_ids multi, actor_ids multi, actors text, tag_ids multi, tags text, meta text, date timestamp, + is_showcased bool, created_at timestamp, effective_date timestamp, stashed int @@ -115,6 +115,7 @@ async function init() { network_id: scene.network_id || undefined, network_slug: scene.network_slug || undefined, network_name: scene.network_name || undefined, + entity_ids: [scene.channel_id, scene.network_id], // manticore does not support OR, this allows IN actor_ids: scene.actors.map((actor) => actor.f1), actors: scene.actors.map((actor) => actor.f2).join(), tag_ids: scene.tags.map((tag) => tag.f1), @@ -131,136 +132,6 @@ async function init() { console.log('data', data); } - /* - const searchRequest = new manticore.SearchRequest(); - - searchRequest.index = 'scenes'; - searchRequest.attr_filter = new manticore.InFilter('ratings', [600]); - - const result = await searchApi.search(searchRequest); - */ - - const result = await searchApi.search({ - index: 'scenes', - query: { - bool: { - must: [ - /* - { - match: { - '*': 'going-all-out-with-a-gangbang_1080p.mp4', - }, - }, - */ - { - range: { - effective_date: { - lte: Math.round(Date.now() / 1000), - }, - }, - }, - /* - { - equals: { - actor_ids: 81930, - }, - }, - */ - ], - must_not: [ - { - in: { - tag_ids: [101, 180, 32], - }, - }, - ], - }, - }, - limit: 30, - sort: [{ effective_date: 'desc' }], - /* - aggs: { - tags: { - terms: { - field: 'tag_ids', - size: 100, - }, - }, - actors: { - terms: { - field: 'actor_ids', - size: 100, - }, - }, - }, - */ - }); - - console.log(result); - - /* - if (result.hits) { - result.hits.hits.map((hit) => console.log(hit)); - - // console.log(result.aggregations.actors); - // console.log(result.aggregations.tags); - - const sceneIds = result.hits.hits.map((hit) => hit._id); - - console.time('fetch'); - - const [scenes, actors, tags, posters, photos] = await Promise.all([ - knex('releases').whereIn('id', sceneIds), - knex('releases_actors') - .whereIn('release_id', sceneIds) - .leftJoin('actors', 'actors.id', 'releases_actors.actor_id'), - knex('releases_tags') - .whereIn('release_id', sceneIds) - .leftJoin('tags', 'tags.id', 'releases_tags.tag_id'), - knex('releases_posters') - .whereIn('release_id', sceneIds) - .leftJoin('media', 'media.id', 'releases_posters.media_id'), - knex('releases_photos') - .whereIn('release_id', sceneIds) - .leftJoin('media', 'media.id', 'releases_photos.media_id'), - ]); - - console.timeEnd('fetch'); - - console.time('join'); - - const joinedScenes = await knex('releases') - .select(knex.raw(` - releases.*, - COALESCE(json_agg(DISTINCT actors) FILTER (WHERE actors.id IS NOT NULL), '[]') as actors, - COALESCE(json_agg(DISTINCT tags) FILTER (WHERE tags.id IS NOT NULL), '[]') as tags, - COALESCE(json_agg(DISTINCT posters) FILTER (WHERE posters.id IS NOT NULL), '[]') as posters, - COALESCE(json_agg(DISTINCT photos) FILTER (WHERE photos.id IS NOT NULL), '[]') as photos - `)) - .whereIn('releases.id', sceneIds) - .leftJoin('releases_actors', 'releases_actors.release_id', 'releases.id') - .leftJoin('actors', 'actors.id', 'releases_actors.actor_id') - .leftJoin('releases_tags', 'releases_tags.release_id', 'releases.id') - .leftJoin('tags', 'tags.id', 'releases_tags.tag_id') - .leftJoin('releases_posters', 'releases_posters.release_id', 'releases.id') - .leftJoin('media as posters', 'posters.id', 'releases_posters.media_id') - .leftJoin('releases_photos', 'releases_photos.release_id', 'releases.id') - .leftJoin('media as photos', 'photos.id', 'releases_photos.media_id') - .groupBy('releases.id'); - - // console.log(joinedScenes[0]); - - console.timeEnd('join'); - - console.log(sceneIds); - console.log(scenes); - console.log(actors); - console.log(tags); - console.log(posters); - console.log(photos); - } - */ - knex.destroy(); } diff --git a/src/update-search.js b/src/update-search.js index 43537bf55..fe287435b 100644 --- a/src/update-search.js +++ b/src/update-search.js @@ -133,6 +133,7 @@ async function updateManticoreSceneSearch(releaseIds) { network_id: scene.network_id || undefined, network_slug: scene.network_slug || undefined, network_name: scene.network_name || undefined, + entity_ids: [scene.channel_id, scene.network_id], // manticore does not support OR, this allows IN actor_ids: scene.actors.map((actor) => actor.f1), actors: scene.actors.map((actor) => actor.f2).join(), tag_ids: scene.tags.map((tag) => tag.f1),