Reworked tag matching. Added tag filter groundwork.

This commit is contained in:
2019-10-28 00:58:54 +01:00
parent 2c32ed6549
commit 0e784a274f
7 changed files with 338 additions and 290 deletions

View File

@@ -104,8 +104,8 @@ async function storeActors(release, releaseEntry) {
}
async function storeTags(release, releaseEntry) {
return knex('tags_associated').insert(release.tags.map(tag => ({
tag_id: tag,
return knex('tags_associated').insert(release.tags.map(tagId => ({
tag_id: tagId,
release_id: releaseEntry.id,
})));
}
@@ -264,6 +264,11 @@ async function fetchNewReleases(scraper, site, afterDate, accReleases = [], page
async function fetchReleases() {
const sites = await accumulateIncludedSites();
if (sites.length === 0) {
console.error('None of the specified sites are in the database');
return [];
}
const scenesPerSite = await Promise.map(sites, async (site) => {
const scraper = scrapers[site.slug] || scrapers[site.network.slug];

View File

@@ -9,7 +9,7 @@ async function curateRelease(release) {
.where({ release_id: release.id })
.leftJoin('actors', 'actors.id', 'actors_associated.actor_id'),
knex('tags_associated')
.select('tags.tag', 'tags.slug')
.select('tags.name', 'tags.slug')
.where({ release_id: release.id })
.leftJoin('tags', 'tags.id', 'tags_associated.tag_id'),
knex('media')

View File

@@ -3,9 +3,22 @@
const knex = require('./knex');
async function matchTags(rawTags) {
const tagEntries = await knex('tags').whereIn('tags.tag', rawTags.map(tag => tag.toLowerCase()));
const tagEntries = await knex('tags')
.pluck('aliases.id')
.whereIn('tags.name', rawTags.map(tag => tag.toLowerCase()))
.where(function where() {
this
.whereNull('tags.alias_for')
.orWhereNull('aliases.alias_for');
})
.join('tags as aliases', function join() {
this
.on('tags.alias_for', 'aliases.id')
.orOn('tags.id', 'aliases.id');
})
.groupBy('aliases.id');
return Array.from(new Set(tagEntries.map((tag => tag.alias_for || tag.id)).sort())); // reduce to tag name and filter duplicates
return tagEntries;
}
module.exports = { matchTags };