|
|
|
@ -8,6 +8,7 @@ import { curateMedia } from './media.js';
|
|
|
|
|
import { fetchTagsById } from './tags.js';
|
|
|
|
|
import { fetchEntitiesById } from './entities.js';
|
|
|
|
|
import { curateStash } from './stashes.js';
|
|
|
|
|
import escape from '../utils/escape-manticore.js';
|
|
|
|
|
import promiseProps from '../utils/promise-props.js';
|
|
|
|
|
|
|
|
|
|
function curateMovie(rawMovie, assets) {
|
|
|
|
@ -171,179 +172,6 @@ function curateOptions(options) {
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
function buildQuery(filters = {}) {
|
|
|
|
|
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({
|
|
|
|
|
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 } });
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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.requireCover) {
|
|
|
|
|
query.bool.must.push({
|
|
|
|
|
equals: {
|
|
|
|
|
has_cover: 1,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (options.aggregateChannels) {
|
|
|
|
|
aggregates.channelIds = {
|
|
|
|
|
terms: {
|
|
|
|
|
field: 'channel_id',
|
|
|
|
|
size: config.database.manticore.maxAggregateSize,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return aggregates;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function queryManticoreJson(filters, options) {
|
|
|
|
|
const { query, sort } = buildQuery(filters);
|
|
|
|
|
|
|
|
|
|
console.log('query', query.bool.must);
|
|
|
|
|
|
|
|
|
|
console.time('manticore');
|
|
|
|
|
|
|
|
|
|
const result = await searchApi.search({
|
|
|
|
|
index: 'movies',
|
|
|
|
|
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 movies = result.hits.hits.map((hit) => ({
|
|
|
|
|
id: hit._id,
|
|
|
|
|
...hit._source,
|
|
|
|
|
_score: hit._score,
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
movies,
|
|
|
|
|
total: result.hits.total,
|
|
|
|
|
aggregations: result.aggregations && Object.fromEntries(Object.entries(result.aggregations).map(([key, { buckets }]) => [key, buckets])),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
async function queryManticoreSql(filters, options) {
|
|
|
|
|
const aggSize = config.database.manticore.maxAggregateSize;
|
|
|
|
|
|
|
|
|
@ -393,7 +221,7 @@ async function queryManticoreSql(filters, options) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (filters.query) {
|
|
|
|
|
builder.whereRaw('match(\'@!title :query:\', movies)', { query: filters.query });
|
|
|
|
|
builder.whereRaw('match(\'@!title :query:\', movies)', { query: escape(filters.query) });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
filters.tagIds?.forEach((tagId) => {
|
|
|
|
|