Showing quality on scene page.
This commit is contained in:
161
src/scenes.js
161
src/scenes.js
@@ -74,6 +74,7 @@ function curateScene(rawScene, assets) {
|
||||
slug: tag.slug,
|
||||
name: tag.name,
|
||||
})),
|
||||
qualities: rawScene.qualities.sort((qualityA, qualityB) => qualityB - qualityA),
|
||||
movies: assets.movies.map((movie) => ({
|
||||
id: movie.id,
|
||||
slug: movie.slug,
|
||||
@@ -263,160 +264,6 @@ function curateOptions(options) {
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
function buildQuery(filters = {}, options) {
|
||||
const query = {
|
||||
bool: {
|
||||
must: [],
|
||||
},
|
||||
};
|
||||
|
||||
let sort = [{ effective_date: 'desc' }];
|
||||
|
||||
if (!filters.scope || filters.scope === 'latest') {
|
||||
query.bool.must.push({
|
||||
range: {
|
||||
effective_date: {
|
||||
lte: Math.round(Date.now() / 1000),
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (filters.scope === 'upcoming') {
|
||||
query.bool.must.push({
|
||||
range: {
|
||||
effective_date: {
|
||||
gt: Math.round(Date.now() / 1000),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
sort = [{ effective_date: 'asc' }];
|
||||
}
|
||||
|
||||
if (filters.scope === 'new') {
|
||||
sort = [{ created_at: 'desc' }, { effective_date: 'asc' }];
|
||||
}
|
||||
|
||||
if (filters.scope === 'likes') {
|
||||
sort = [{ stashed: 'desc' }, { effective_date: 'desc' }];
|
||||
}
|
||||
|
||||
if (filters.scope === 'results') {
|
||||
sort = [{ _score: 'desc' }, { effective_date: 'desc' }];
|
||||
}
|
||||
|
||||
if (filters.query) {
|
||||
query.bool.must.push({ match: { '!title': filters.query } }); // title_filtered is matched instead of title
|
||||
}
|
||||
|
||||
if (filters.tagIds) {
|
||||
filters.tagIds.forEach((tagId) => {
|
||||
query.bool.must.push({ equals: { 'any(tag_ids)': tagId } });
|
||||
});
|
||||
}
|
||||
|
||||
if (filters.entityId) {
|
||||
query.bool.must.push({
|
||||
bool: {
|
||||
should: [
|
||||
{ equals: { channel_id: filters.entityId } },
|
||||
{ equals: { network_id: filters.entityId } },
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (filters.actorIds) {
|
||||
filters.actorIds.forEach((actorId) => {
|
||||
query.bool.must.push({ equals: { 'any(actor_ids)': actorId } });
|
||||
});
|
||||
}
|
||||
|
||||
if (filters.stashId && options.index === 'scenes_stashed') {
|
||||
query.bool.must.push({ equals: { stash_id: filters.stashId } });
|
||||
}
|
||||
|
||||
return { query, sort };
|
||||
}
|
||||
|
||||
function buildAggregates(options) {
|
||||
const aggregates = {};
|
||||
|
||||
if (options.aggregateActors) {
|
||||
aggregates.actorIds = {
|
||||
terms: {
|
||||
field: 'actor_ids',
|
||||
size: config.database.manticore.maxAggregateSize,
|
||||
},
|
||||
sort: [{ 'count(*)': { order: 'desc' } }],
|
||||
};
|
||||
}
|
||||
|
||||
if (options.aggregateTags) {
|
||||
aggregates.tagIds = {
|
||||
terms: {
|
||||
field: 'tag_ids',
|
||||
size: config.database.manticore.maxAggregateSize,
|
||||
},
|
||||
sort: [{ 'count(*)': { order: 'desc' } }],
|
||||
};
|
||||
}
|
||||
|
||||
if (options.aggregateChannels) {
|
||||
aggregates.channelIds = {
|
||||
terms: {
|
||||
field: 'channel_id',
|
||||
size: config.database.manticore.maxAggregateSize,
|
||||
},
|
||||
sort: [{ 'count(*)': { order: 'desc' } }],
|
||||
};
|
||||
}
|
||||
|
||||
return aggregates;
|
||||
}
|
||||
|
||||
async function queryManticoreJson(filters, options, _reqUser) {
|
||||
const { query, sort } = buildQuery(filters, options);
|
||||
|
||||
const result = await searchApi.search({
|
||||
index: options.index,
|
||||
query,
|
||||
limit: options.limit,
|
||||
offset: (options.page - 1) * options.limit,
|
||||
sort,
|
||||
aggs: buildAggregates(options),
|
||||
options: {
|
||||
max_matches: config.database.manticore.maxMatches,
|
||||
max_query_time: config.database.manticore.maxQueryTime,
|
||||
field_weights: {
|
||||
title_filtered: 7,
|
||||
actors: 10,
|
||||
tags: 9,
|
||||
meta: 6,
|
||||
channel_name: 2,
|
||||
channel_slug: 3,
|
||||
network_name: 1,
|
||||
network_slug: 1,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const scenes = result.hits.hits.map((hit) => ({
|
||||
id: hit._id,
|
||||
...hit._source,
|
||||
_score: hit._score,
|
||||
}));
|
||||
|
||||
return {
|
||||
scenes,
|
||||
total: result.hits.total,
|
||||
aggregations: result.aggregations && Object.fromEntries(Object.entries(result.aggregations).map(([key, { buckets }]) => [key, buckets])),
|
||||
};
|
||||
}
|
||||
*/
|
||||
|
||||
async function queryManticoreSql(filters, options, _reqUser) {
|
||||
const aggSize = config.database.manticore.maxAggregateSize;
|
||||
|
||||
@@ -613,12 +460,6 @@ export async function fetchScenes(filters, rawOptions, reqUser) {
|
||||
console.log('filters', filters);
|
||||
console.log('options', options);
|
||||
|
||||
/*
|
||||
const result = config.database.manticore.forceSql || filters.stashId
|
||||
? await queryManticoreSql(filters, options, reqUser)
|
||||
: await queryManticoreJson(filters, options, reqUser);
|
||||
*/
|
||||
|
||||
console.time('manticore sql');
|
||||
const result = await queryManticoreSql(filters, options, reqUser);
|
||||
console.timeEnd('manticore sql');
|
||||
|
||||
Reference in New Issue
Block a user