forked from DebaucheryLibrarian/traxxx
Sharing title filter function between manticore update module and sync tool, fixing sync tool title filter word boundaries.
This commit is contained in:
parent
f11a009395
commit
36a51f0491
|
@ -6,6 +6,7 @@ const args = require('yargs').argv;
|
|||
const { format } = require('date-fns');
|
||||
|
||||
const knex = require('../knex');
|
||||
const filterTitle = require('../utils/filter-title');
|
||||
|
||||
const mantiClient = new manticore.ApiClient();
|
||||
|
||||
|
@ -116,7 +117,7 @@ async function init() {
|
|||
const docs = scenes.map((scene) => {
|
||||
const flatActors = scene.actors.flatMap((actor) => actor.f2.match(/[\w']+/g)); // match word characters to filter out brackets etc.
|
||||
const flatTags = scene.tags.filter((tag) => tag.f3 > 6).flatMap((tag) => (tag.f4 ? `${tag.f2} ${tag.f4}` : tag.f2).match(/[\w']+/g)); // only make top tags searchable to minimize cluttered results
|
||||
const filteredTitle = scene.title && [...flatActors, ...flatTags].reduce((accTitle, tag) => accTitle.replace(new RegExp(tag.replace(/[^\w\s]+/g, ''), 'i'), ''), scene.title).trim().replace(/\s{2,}/, ' ');
|
||||
const filteredTitle = filterTitle(scene.title, [...flatActors, ...flatTags]);
|
||||
|
||||
return {
|
||||
replace: {
|
||||
|
|
|
@ -7,6 +7,7 @@ const knex = require('./knex');
|
|||
const logger = require('./logger')(__filename);
|
||||
const bulkInsert = require('./utils/bulk-insert');
|
||||
const chunk = require('./utils/chunk');
|
||||
const filterTitle = require('./utils/filter-title');
|
||||
|
||||
const mantiClient = new manticore.ApiClient();
|
||||
const indexApi = new manticore.IndexApi(mantiClient);
|
||||
|
@ -123,7 +124,7 @@ async function updateManticoreSceneSearch(releaseIds) {
|
|||
const docs = scenes.rows.map((scene) => {
|
||||
const flatActors = scene.actors.flatMap((actor) => actor.f2.split(' '));
|
||||
const flatTags = scene.tags.filter((tag) => tag.f3 > 6).flatMap((tag) => [tag.f2].concat(tag.f4)).filter(Boolean); // only make top tags searchable to minimize cluttered results
|
||||
const filteredTitle = scene.title && [...flatActors, ...flatTags].reduce((accTitle, tag) => accTitle.replace(new RegExp(`\\b${tag.replace(/[^\w\s]+/g, '')}\\b`, 'gi'), ''), scene.title).trim().replace(/\s{2,}/, ' ');
|
||||
const filteredTitle = filterTitle(scene.title, [...flatActors, ...flatTags]);
|
||||
|
||||
return {
|
||||
replace: {
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
function filterTitle(title, keys) {
|
||||
if (!title) {
|
||||
return title;
|
||||
}
|
||||
|
||||
return keys.reduce((accTitle, tag) => accTitle.replace(new RegExp(`\\b${tag.replace(/[^\w\s]+/g, '')}\\b`, 'gi'), ''), title).trim().replace(/\s{2,}/, ' ');
|
||||
}
|
||||
|
||||
module.exports = filterTitle;
|
Loading…
Reference in New Issue