Added global search.

This commit is contained in:
2024-02-22 05:08:06 +01:00
parent fc240710f3
commit 09df134558
15 changed files with 461 additions and 272 deletions

View File

@@ -82,15 +82,19 @@ export async function fetchScenesById(sceneIds) {
.select(
'actors_meta.*',
'releases_actors.release_id',
/* why would we need this for scenes?
'birth_countries.alpha2 as birth_country_alpha2',
'birth_countries.name as birth_country_name',
knex.raw('COALESCE(birth_countries.alias, birth_countries.name) as birth_country_name'),
'residence_countries.alpha2 as residence_country_alpha2',
'residence_countries.name as residence_country_name',
knex.raw('COALESCE(residence_countries.alias, residence_countries.name) as residence_country_name'),
*/
)
.whereIn('release_id', sceneIds)
.leftJoin('actors_meta', 'actors_meta.id', 'releases_actors.actor_id')
.leftJoin('countries as birth_countries', 'birth_countries.alpha2', 'actors_meta.birth_country_alpha2')
.leftJoin('countries as residence_countries', 'residence_countries.alpha2', 'actors_meta.residence_country_alpha2'),
.leftJoin('actors_meta', 'actors_meta.id', 'releases_actors.actor_id'),
/*
.leftJoin('countries as birth_countries', 'birth_countries.alpha2', 'actors_meta.birth_country_alpha2')
.leftJoin('countries as residence_countries', 'residence_countries.alpha2', 'actors_meta.residence_country_alpha2'),
*/
knex('releases_directors')
.whereIn('release_id', sceneIds)
.leftJoin('actors as directors', 'directors.id', 'releases_directors.director_id'),
@@ -187,6 +191,27 @@ function buildQuery(filters = {}) {
sort = [{ stashed: 'desc' }, { effective_date: 'desc' }];
}
if (filters.scope === 'results') {
sort = [{ _score: 'desc' }, { effective_date: 'desc' }];
}
if (filters.query) {
query.bool.must.push({
bool: {
should: [
{ match: { title_filtered: filters.query } },
{ match: { actors: filters.query } },
{ match: { tags: filters.query } },
{ match: { channel_name: filters.query } },
{ match: { network_name: filters.query } },
{ match: { channel_slug: filters.query } },
{ match: { network_slug: filters.query } },
{ match: { meta: filters.query } }, // date
],
},
});
}
if (filters.tagIds) {
filters.tagIds.forEach((tagId) => {
query.bool.must.push({ equals: { 'any(tag_ids)': tagId } });
@@ -269,6 +294,10 @@ export async function fetchScenes(filters, rawOptions) {
const options = curateOptions(rawOptions);
const { query, sort } = buildQuery(filters);
console.log('filters', filters);
console.log('options', options);
console.log('query', query.bool.must);
const result = await searchApi.search({
index: 'scenes',
query,
@@ -276,9 +305,24 @@ export async function fetchScenes(filters, rawOptions) {
offset: (options.page - 1) * options.limit,
sort,
aggs: buildAggregates(options),
max_matches: 5000,
options: {
max_matches: 1000,
max_query_time: 10000,
field_weights: {
title_filtered: 7,
actors: 10,
tags: 9,
meta: 6,
channel_name: 2,
channel_slug: 3,
network_name: 1,
network_slug: 1,
},
},
});
console.log(result.hits.hits);
const actorCounts = options.aggregateActors && countAggregations(result.aggregations?.actorIds?.buckets);
const tagCounts = options.aggregateTags && countAggregations(result.aggregations?.tagIds?.buckets);
const channelCounts = options.aggregateChannels && countAggregations(result.aggregations?.channelIds?.buckets);