Added years filter. Changed default DMCA to generic content e-mail.

This commit is contained in:
2024-08-18 01:36:37 +02:00
parent 15cfed217b
commit b9b4a8e773
15 changed files with 193 additions and 70 deletions

View File

@@ -181,6 +181,7 @@ function curateOptions(options) {
limit: options?.limit || 30,
page: Number(options?.page) || 1,
aggregate: options.aggregate ?? true,
aggregateYears: (options.aggregate ?? true) && (options.aggregateYears ?? true),
aggregateActors: (options.aggregate ?? true) && (options.aggregateActors ?? true),
aggregateTags: (options.aggregate ?? true) && (options.aggregateTags ?? true),
aggregateChannels: (options.aggregate ?? true) && (options.aggregateChannels ?? true),
@@ -205,6 +206,7 @@ async function queryManticoreSql(filters, options) {
),
max_matches=:maxMatches:,
max_query_time=:maxQueryTime:
:yearsFacet:
:actorsFacet:
:tagsFacet:
:channelsFacet:;
@@ -225,6 +227,7 @@ async function queryManticoreSql(filters, options) {
movies.stashed as stashed,
movies.created_at,
created_at as stashed_at,
year(effective_date) as effective_year,
weight() as _score
`));
@@ -232,13 +235,21 @@ async function queryManticoreSql(filters, options) {
.innerJoin('movies', 'movies.id', 'movies_stashed.movie_id')
.where('stash_id', filters.stashId);
} else {
builder.select(knex.raw('*, weight() as _score'));
builder.select(knex.raw(`
*,
year(effective_date) as effective_year,
weight() as _score
`));
}
if (filters.query) {
builder.whereRaw('match(\'@!title :query:\', movies)', { query: escape(filters.query) });
}
if (filters.years?.length > 0) {
builder.whereIn('effective_year', filters.years);
}
filters.tagIds?.forEach((tagId) => {
builder.where('any(tag_ids)', tagId);
});
@@ -292,6 +303,7 @@ async function queryManticoreSql(filters, options) {
.offset((options.page - 1) * options.limit)
.toString(),
// option threads=1 fixes actors, but drastically slows down performance, wait for fix
yearsFacet: options.aggregateYears ? knex.raw('facet year(effective_date) as years order by years desc limit ?', [aggSize]) : null,
actorsFacet: options.aggregateActors ? knex.raw('facet movies.actor_ids order by count(*) desc limit ?', [aggSize]) : null,
tagsFacet: options.aggregateTags ? knex.raw('facet movies.tag_ids order by count(*) desc limit ?', [aggSize]) : null,
channelsFacet: options.aggregateChannels ? knex.raw('facet movies.channel_id order by count(*) desc limit ?', [aggSize]) : null,
@@ -311,6 +323,10 @@ async function queryManticoreSql(filters, options) {
const results = await utilsApi.sql(curatedSqlQuery);
// console.log(results[0]);
const years = results
.find((result) => (result.columns[0].years || result.columns[0]['movies.years']) && result.columns[1]['count(*)'])
?.data.map((row) => ({ key: row.years || row['movies.years'], doc_count: row['count(*)'] }))
|| [];
const actorIds = results
.find((result) => (result.columns[0].actor_ids || result.columns[0]['movies.actor_ids']) && result.columns[1]['count(*)'])
@@ -333,6 +349,7 @@ async function queryManticoreSql(filters, options) {
movies: results[0].data,
total,
aggregations: {
years,
actorIds,
tagIds,
channelIds,
@@ -356,6 +373,8 @@ export async function fetchMovies(filters, rawOptions, reqUser) {
const result = await queryManticoreSql(filters, options);
const aggYears = options.aggregateYears && result.aggregations.years.map((bucket) => ({ year: bucket.key, count: bucket.doc_count }));
const actorCounts = options.aggregateActors && countAggregations(result.aggregations?.actorIds);
const tagCounts = options.aggregateTags && countAggregations(result.aggregations?.tagIds);
const channelCounts = options.aggregateChannels && countAggregations(result.aggregations?.channelIds);
@@ -371,6 +390,7 @@ export async function fetchMovies(filters, rawOptions, reqUser) {
return {
movies,
aggYears,
aggActors,
aggTags,
aggChannels,

View File

@@ -306,6 +306,7 @@ function curateOptions(options) {
limit: options?.limit || 30,
page: Number(options?.page) || 1,
aggregate: options.aggregate ?? true,
aggregateYears: (options.aggregate ?? true) && (options.aggregateYears ?? true),
aggregateActors: (options.aggregate ?? true) && (options.aggregateActors ?? true),
aggregateTags: (options.aggregate ?? true) && (options.aggregateTags ?? true),
aggregateChannels: (options.aggregate ?? true) && (options.aggregateChannels ?? true),
@@ -332,6 +333,7 @@ async function queryManticoreSql(filters, options, _reqUser) {
),
max_matches=:maxMatches:,
max_query_time=:maxQueryTime:
:yearsFacet:
:actorsFacet:
:tagsFacet:
:channelsFacet:;
@@ -352,6 +354,7 @@ async function queryManticoreSql(filters, options, _reqUser) {
scenes.stashed as stashed,
scenes.created_at,
created_at as stashed_at,
year(effective_date) as effective_year,
weight() as _score
`));
@@ -359,13 +362,21 @@ async function queryManticoreSql(filters, options, _reqUser) {
.innerJoin('scenes', 'scenes.id', 'scenes_stashed.scene_id')
.where('stash_id', filters.stashId);
} else {
builder.select(knex.raw('*, weight() as _score'));
builder.select(knex.raw(`
*,
year(effective_date) as effective_year,
weight() as _score
`));
}
if (filters.query) {
builder.whereRaw('match(\'@!title :query:\', scenes)', { query: escape(filters.query) });
}
if (filters.years?.length > 0) {
builder.whereIn('effective_year', filters.years);
}
filters.tagIds?.forEach((tagId) => {
builder.where('any(tag_ids)', tagId);
});
@@ -452,6 +463,7 @@ async function queryManticoreSql(filters, options, _reqUser) {
.limit(options.limit)
.offset((options.page - 1) * options.limit),
// option threads=1 fixes actors, but drastically slows down performance, wait for fix
yearsFacet: options.aggregateYears ? knex.raw('facet year(effective_date) as years order by years desc limit ?', [aggSize]) : null,
actorsFacet: options.aggregateActors ? knex.raw('facet scenes.actor_ids order by count(*) desc limit ?', [aggSize]) : null,
tagsFacet: options.aggregateTags ? knex.raw('facet scenes.tag_ids order by count(*) desc limit ?', [aggSize]) : null,
channelsFacet: options.aggregateChannels ? knex.raw('facet scenes.channel_id order by count(*) desc limit ?', [aggSize]) : null,
@@ -470,7 +482,12 @@ async function queryManticoreSql(filters, options, _reqUser) {
const results = await utilsApi.sql(curatedSqlQuery);
// console.log(results[0]);
// console.log(util.inspect(results, null, Infinity));
const years = results
.find((result) => (result.columns[0].years || result.columns[0]['scenes.years']) && result.columns[1]['count(*)'])
?.data.map((row) => ({ key: row.years || row['scenes.years'], doc_count: row['count(*)'] }))
|| [];
const actorIds = results
.find((result) => (result.columns[0].actor_ids || result.columns[0]['scenes.actor_ids']) && result.columns[1]['count(*)'])
@@ -493,6 +510,7 @@ async function queryManticoreSql(filters, options, _reqUser) {
scenes: results[0].data,
total,
aggregations: {
years,
actorIds,
tagIds,
channelIds,
@@ -518,6 +536,8 @@ export async function fetchScenes(filters, rawOptions, reqUser) {
const result = await queryManticoreSql(filters, options, reqUser);
console.timeEnd('manticore sql');
const aggYears = options.aggregateYears && result.aggregations.years.map((bucket) => ({ year: bucket.key, count: bucket.doc_count }));
const actorCounts = options.aggregateActors && countAggregations(result.aggregations?.actorIds);
const tagCounts = options.aggregateTags && countAggregations(result.aggregations?.tagIds);
const channelCounts = options.aggregateChannels && countAggregations(result.aggregations?.channelIds);
@@ -539,6 +559,7 @@ export async function fetchScenes(filters, rawOptions, reqUser) {
return {
scenes,
aggYears,
aggActors,
aggTags,
aggChannels,

View File

@@ -8,6 +8,7 @@ export async function curateMoviesQuery(query) {
return {
scope: query.scope || 'latest',
query: query.q,
years: query.years?.split(',')?.map((year) => Number(year)).filter(Boolean) || [],
actorIds: [query.actorId, ...(query.actors?.split(',') || []).map((identifier) => parseActorIdentifier(identifier)?.id)].filter(Boolean),
tagIds: await getIdsBySlug([query.tagSlug, ...(query.tags?.split(',') || [])], 'tags'),
entityId: query.e ? await getIdsBySlug([query.e], 'entities').then(([id]) => id) : query.entityId,
@@ -19,6 +20,7 @@ export async function curateMoviesQuery(query) {
export async function fetchMoviesApi(req, res) {
const {
movies,
aggYears,
aggActors,
aggTags,
aggChannels,
@@ -31,6 +33,7 @@ export async function fetchMoviesApi(req, res) {
res.send(stringify({
movies,
aggYears,
aggActors,
aggTags,
aggChannels,

View File

@@ -7,6 +7,7 @@ import slugify from '../../utils/slugify.js';
import promiseProps from '../../utils/promise-props.js';
export async function curateScenesQuery(query) {
const splitYears = query.years?.split(',') || [];
const splitTags = query.tags?.split(',') || [];
const splitActors = query.actors?.split(',') || [];
const splitEntities = query.e?.split(',') || [];
@@ -27,6 +28,7 @@ export async function curateScenesQuery(query) {
return {
scope: query.scope || 'latest',
query: query.q,
years: splitYears.map((year) => Number(year)).filter(Boolean) || [],
actorIds: [query.actorId, ...splitActors.filter((actor) => actor.charAt(0) !== '!').map((identifier) => parseActorIdentifier(identifier)?.id)].filter(Boolean),
notActorIds: splitActors.filter((actor) => actor.charAt(0) === '!').map((identifier) => parseActorIdentifier(identifier.slice(1))?.id).filter(Boolean),
tagIds,
@@ -43,6 +45,7 @@ export async function curateScenesQuery(query) {
export async function fetchScenesApi(req, res) {
const {
scenes,
aggYears,
aggActors,
aggTags,
aggChannels,
@@ -58,6 +61,7 @@ export async function fetchScenesApi(req, res) {
res.send(stringify({
scenes,
aggYears,
aggActors,
aggTags,
aggChannels,