Added relevance filter to search REST API.
This commit is contained in:
parent
0265ad35c9
commit
f018735052
|
@ -133,11 +133,12 @@ async function fetchScenes(limit = 100) {
|
|||
return releases.map(release => curateRelease(release));
|
||||
}
|
||||
|
||||
async function searchScenes(query, limit = 100) {
|
||||
async function searchScenes(query, limit = 100, relevance = 0) {
|
||||
const releases = await knex
|
||||
.select(knex.raw('search_results.rank as relevance'))
|
||||
.from(knex.raw('search_releases(:query) as search_results', { query }))
|
||||
.leftJoin('releases', 'releases.id', 'search_results.release_id')
|
||||
.where('search_results.rank', '>=', relevance)
|
||||
.modify(withRelations, false, true)
|
||||
.limit(Math.min(limit, 1000000))
|
||||
.groupBy('search_results.rank')
|
||||
|
|
|
@ -20,7 +20,7 @@ async function fetchScenesApi(req, res) {
|
|||
const query = req.query.query || req.query.q;
|
||||
|
||||
const releases = query
|
||||
? await searchScenes(query, req.query.limit)
|
||||
? await searchScenes(query, req.query.limit, req.query.relevance)
|
||||
: await fetchScenes(req.query.limit);
|
||||
|
||||
res.send({ scenes: releases });
|
||||
|
|
Loading…
Reference in New Issue