Added global search.
This commit is contained in:
@@ -67,7 +67,7 @@ export function sortActorsByGender(actors) {
|
||||
}
|
||||
|
||||
const alphaActors = actors.sort((actorA, actorB) => actorA.name.localeCompare(actorB.name, 'en'));
|
||||
const genderActors = ['transsexual', 'female', 'male', undefined].flatMap((gender) => alphaActors.filter((actor) => actor.gender === gender));
|
||||
const genderActors = ['transsexual', 'female', 'male', undefined, null].flatMap((gender) => alphaActors.filter((actor) => actor.gender === gender));
|
||||
|
||||
return genderActors;
|
||||
}
|
||||
@@ -75,7 +75,15 @@ export function sortActorsByGender(actors) {
|
||||
export async function fetchActorsById(actorIds, options = {}) {
|
||||
const [actors] = await Promise.all([
|
||||
knex('actors_meta')
|
||||
.select('actors_meta.*')
|
||||
.select(
|
||||
'actors_meta.*',
|
||||
'birth_countries.alpha2 as birth_country_alpha2',
|
||||
knex.raw('COALESCE(birth_countries.alias, birth_countries.name) as birth_country_name'),
|
||||
'residence_countries.alpha2 as residence_country_alpha2',
|
||||
knex.raw('COALESCE(residence_countries.alias, residence_countries.name) as residence_country_name'),
|
||||
)
|
||||
.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')
|
||||
.whereIn('actors_meta.id', actorIds)
|
||||
.modify((builder) => {
|
||||
if (options.order) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { fetchActors } from '../actors.js';
|
||||
|
||||
export function curateActorsQuery(query) {
|
||||
console.log('input query', query);
|
||||
|
||||
return {
|
||||
query: query.q,
|
||||
gender: query.gender,
|
||||
|
||||
@@ -25,6 +25,7 @@ async function getIdsBySlug(slugs, domain) {
|
||||
export async function curateScenesQuery(query) {
|
||||
return {
|
||||
scope: query.scope || 'latest',
|
||||
query: query.q,
|
||||
actorIds: [query.actorId, ...(query.actors?.split(',') || []).map((identifier) => parseActorIdentifier(identifier)?.id)].filter(Boolean),
|
||||
tagIds: await getIdsBySlug([query.tagSlug, ...(query.tags?.split(',') || [])], 'tags'),
|
||||
entityId: query.e ? await getIdsBySlug([query.e], 'entities').then(([id]) => id) : query.entityId,
|
||||
|
||||
Reference in New Issue
Block a user