Reworked tag matching. Added tag filter groundwork.

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

View File

@ -1,5 +1,32 @@
<template> <template>
<div class="content-inner"> <div class="content-inner">
<div class="filters-bar">
Content:
<ul class="filters">
<li>
<label>
<input
type="checkbox"
>Lesbian
</label>
</li>
<li>
<label>
<input
type="checkbox"
>Gay
</label>
</li>
<li>
<label>
<input
type="checkbox"
>Transsexual
</label>
</li>
</ul>
</div>
<h2 class="heading">Latest releases</h2> <h2 class="heading">Latest releases</h2>
<ul class="scenes nolist"> <ul class="scenes nolist">
@ -82,13 +109,13 @@
</span> </span>
<span <span
:title="release.tags.map(tag => tag.tag).join(', ')" :title="release.tags.map(tag => tag.name).join(', ')"
class="scene-row" class="scene-row"
> >
<ul class="scene-tags nolist"> <ul class="scene-tags nolist">
<li <li
v-for="tag in release.tags" v-for="tag in release.tags"
:key="tag.tag" :key="`tag-${tag.id}`"
class="scene-tag" class="scene-tag"
> >
<a <a
@ -96,7 +123,7 @@
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"
class="tag-link" class="tag-link"
>{{ tag.tag }}</a> >{{ tag.name }}</a>
</li> </li>
</ul> </ul>
</span> </span>

View File

@ -76,7 +76,7 @@
<ul class="row tags"> <ul class="row tags">
<li <li
v-for="tag in release.tags" v-for="tag in release.tags"
:key="tag.tag" :key="`tag-${tag.id}`"
class="tag" class="tag"
> >
<a <a
@ -84,7 +84,7 @@
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"
class="tag-link" class="tag-link"
>{{ tag.tag }}</a> >{{ tag.name }}</a>
</li> </li>
</ul> </ul>
</div> </div>

View File

@ -34,7 +34,7 @@ exports.up = knex => Promise.resolve()
})) }))
.then(() => knex.schema.createTable('tags', (table) => { .then(() => knex.schema.createTable('tags', (table) => {
table.increments('id', 12); table.increments('id', 12);
table.string('tag'); table.string('name');
table.integer('group_id', 12) table.integer('group_id', 12)
.references('id') .references('id')
@ -53,6 +53,7 @@ exports.up = knex => Promise.resolve()
table.string('name'); table.string('name');
table.string('url'); table.string('url');
table.text('description'); table.text('description');
table.enum('orientation', ['gay', 'bi', 'lesbian', 'trans']);
table.string('slug', 32) table.string('slug', 32)
.unique(); .unique();
@ -68,6 +69,7 @@ exports.up = knex => Promise.resolve()
table.string('name'); table.string('name');
table.string('url'); table.string('url');
table.text('description'); table.text('description');
table.enum('orientation', ['gay', 'bi', 'lesbian', 'trans']);
table.string('parameters'); table.string('parameters');
table.string('slug', 32) table.string('slug', 32)
@ -107,6 +109,7 @@ exports.up = knex => Promise.resolve()
table.integer('rating') table.integer('rating')
.unsigned(); .unsigned();
table.enum('orientation', ['gay', 'bi', 'lesbian', 'trans']);
table.boolean('deep'); table.boolean('deep');
table.datetime('created_at') table.datetime('created_at')

File diff suppressed because it is too large Load Diff

View File

@ -104,8 +104,8 @@ async function storeActors(release, releaseEntry) {
} }
async function storeTags(release, releaseEntry) { async function storeTags(release, releaseEntry) {
return knex('tags_associated').insert(release.tags.map(tag => ({ return knex('tags_associated').insert(release.tags.map(tagId => ({
tag_id: tag, tag_id: tagId,
release_id: releaseEntry.id, release_id: releaseEntry.id,
}))); })));
} }
@ -264,6 +264,11 @@ async function fetchNewReleases(scraper, site, afterDate, accReleases = [], page
async function fetchReleases() { async function fetchReleases() {
const sites = await accumulateIncludedSites(); 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 scenesPerSite = await Promise.map(sites, async (site) => {
const scraper = scrapers[site.slug] || scrapers[site.network.slug]; const scraper = scrapers[site.slug] || scrapers[site.network.slug];

View File

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

View File

@ -3,9 +3,22 @@
const knex = require('./knex'); const knex = require('./knex');
async function matchTags(rawTags) { 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 }; module.exports = { matchTags };