Added function for scene facet composition.
This commit is contained in:
@@ -402,6 +402,14 @@ function curateOptions(options) {
|
||||
};
|
||||
}
|
||||
|
||||
function curateFacet(results, field, count = 'count(distinct id)') {
|
||||
return results
|
||||
.find((result) => result.columns[0][field] && result.columns[1][count])
|
||||
?.data.map((row) => ({ key: row[field], doc_count: row[count] }))
|
||||
.filter((row) => !!row.key)
|
||||
|| [];
|
||||
}
|
||||
|
||||
async function queryManticoreSql(filters, options, _reqUser) {
|
||||
const aggSize = config.database.manticore.maxAggregateSize;
|
||||
|
||||
@@ -569,7 +577,7 @@ async function queryManticoreSql(filters, options, _reqUser) {
|
||||
// don't facet tags associated to other actors, actor ID 0 means global
|
||||
tagsFacet: options.aggregateTags ? knex.raw('facet scenes.tag_ids as tags_facet order by count(distinct id) desc limit ?', [aggSize]) : null,
|
||||
actorTagsFacet: options.aggregateTags && !filters.stashId // eslint-disable-line no-nested-ternary
|
||||
? knex.raw(`facet IF(IN(scenes_tags.actor_id, ${[0, ...filters?.actorIds || []]}), scenes_tags.tag_id, 0) actor_tags_facet distinct id order by count(distinct id) desc limit ?`, [aggSize])
|
||||
? knex.raw(`facet IF(IN(scenes_tags.actor_id, ${[0, ...filters?.actorIds || []]}), scenes_tags.tag_id, 0) as actor_tags_facet distinct id order by count(distinct id) desc limit ?`, [aggSize])
|
||||
: null,
|
||||
channelsFacet: options.aggregateChannels ? knex.raw('facet scenes.channel_id as channels_facet distinct id order by count(distinct id) desc limit ?', [aggSize]) : null,
|
||||
studiosFacet: options.aggregateChannels ? knex.raw('facet scenes.studio_id as studios_facet distinct id order by count(distinct id) desc limit ?', [aggSize]) : null,
|
||||
@@ -592,35 +600,12 @@ async function queryManticoreSql(filters, options, _reqUser) {
|
||||
|
||||
// console.log(util.inspect(results, null, Infinity));
|
||||
|
||||
const years = results
|
||||
.find((result) => result.columns[0].years_facet && result.columns[1]['count(*)'])
|
||||
?.data.map((row) => ({ key: row.years_facet, doc_count: row['count(*)'] }))
|
||||
|| [];
|
||||
|
||||
const actorIds = results
|
||||
.find((result) => result.columns[0].actors_facet && result.columns[1]['count(distinct id)'])
|
||||
?.data.map((row) => ({ key: row.actors_facet, doc_count: row['count(distinct id)'] }))
|
||||
|| [];
|
||||
|
||||
const tagIds = results
|
||||
.find((result) => result.columns[0].tags_facet && result.columns[1]['count(distinct id)'])
|
||||
?.data.map((row) => ({ key: row.tags_facet, doc_count: row['count(distinct id)'] || row['count(*)'] }))
|
||||
|| [];
|
||||
|
||||
const actorTagIds = results
|
||||
.find((result) => result.columns[0].actor_tags_facet && result.columns[1]['count(distinct id)'])
|
||||
?.data.map((row) => ({ key: row.actor_tags_facet, doc_count: row['count(distinct id)'] || row['count(*)'] }))
|
||||
|| [];
|
||||
|
||||
const channelIds = results
|
||||
.find((result) => result.columns[0].channels_facet && result.columns[1]['count(distinct id)'])
|
||||
?.data.map((row) => ({ key: row.channels_facet || row['scenes.channel_id'], doc_count: row['count(distinct id)'] }))
|
||||
|| [];
|
||||
|
||||
const studioIds = results
|
||||
.find((result) => result.columns[0].studios_facet && result.columns[1]['count(distinct id)'])
|
||||
?.data.map((row) => ({ key: row.studios_facet, doc_count: row['count(distinct id)'] })).filter((row) => !!row.key)
|
||||
|| [];
|
||||
const years = curateFacet(results, 'years_facet', 'count(*)');
|
||||
const actorIds = curateFacet(results, 'actors_facet');
|
||||
const tagIds = curateFacet(results, 'tags_facet');
|
||||
const actorTagIds = curateFacet(results, 'actor_tags_facet');
|
||||
const channelIds = curateFacet(results, 'channels_facet');
|
||||
const studioIds = curateFacet(results, 'studios_facet');
|
||||
|
||||
const total = Number(results.at(-1).data.find((entry) => entry.Variable_name === 'total_found')?.Value) || 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user