Added relevance filter to search REST API.

This commit is contained in:
DebaucheryLibrarian 2021-02-26 17:29:02 +01:00
parent 0265ad35c9
commit f018735052
2 changed files with 3 additions and 2 deletions

View File

@ -133,11 +133,12 @@ async function fetchScenes(limit = 100) {
return releases.map(release => curateRelease(release)); return releases.map(release => curateRelease(release));
} }
async function searchScenes(query, limit = 100) { async function searchScenes(query, limit = 100, relevance = 0) {
const releases = await knex const releases = await knex
.select(knex.raw('search_results.rank as relevance')) .select(knex.raw('search_results.rank as relevance'))
.from(knex.raw('search_releases(:query) as search_results', { query })) .from(knex.raw('search_releases(:query) as search_results', { query }))
.leftJoin('releases', 'releases.id', 'search_results.release_id') .leftJoin('releases', 'releases.id', 'search_results.release_id')
.where('search_results.rank', '>=', relevance)
.modify(withRelations, false, true) .modify(withRelations, false, true)
.limit(Math.min(limit, 1000000)) .limit(Math.min(limit, 1000000))
.groupBy('search_results.rank') .groupBy('search_results.rank')

View File

@ -20,7 +20,7 @@ async function fetchScenesApi(req, res) {
const query = req.query.query || req.query.q; const query = req.query.query || req.query.q;
const releases = query const releases = query
? await searchScenes(query, req.query.limit) ? await searchScenes(query, req.query.limit, req.query.relevance)
: await fetchScenes(req.query.limit); : await fetchScenes(req.query.limit);
res.send({ scenes: releases }); res.send({ scenes: releases });