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,