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) {
|
async function queryManticoreSql(filters, options, _reqUser) {
|
||||||
const aggSize = config.database.manticore.maxAggregateSize;
|
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
|
// 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,
|
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
|
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,
|
: null,
|
||||||
channelsFacet: options.aggregateChannels ? knex.raw('facet scenes.channel_id as channels_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,
|
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));
|
// console.log(util.inspect(results, null, Infinity));
|
||||||
|
|
||||||
const years = results
|
const years = curateFacet(results, 'years_facet', 'count(*)');
|
||||||
.find((result) => result.columns[0].years_facet && result.columns[1]['count(*)'])
|
const actorIds = curateFacet(results, 'actors_facet');
|
||||||
?.data.map((row) => ({ key: row.years_facet, doc_count: row['count(*)'] }))
|
const tagIds = curateFacet(results, 'tags_facet');
|
||||||
|| [];
|
const actorTagIds = curateFacet(results, 'actor_tags_facet');
|
||||||
|
const channelIds = curateFacet(results, 'channels_facet');
|
||||||
const actorIds = results
|
const studioIds = curateFacet(results, 'studios_facet');
|
||||||
.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 total = Number(results.at(-1).data.find((entry) => entry.Variable_name === 'total_found')?.Value) || 0;
|
const total = Number(results.at(-1).data.find((entry) => entry.Variable_name === 'total_found')?.Value) || 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user