From b4129891dc66e664cf82a587182a7062ab9cc963 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Thu, 25 Feb 2021 15:58:54 +0100 Subject: [PATCH] Improved query curation in release search function. --- migrations/20190325001339_releases.js | 2 +- src/releases.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/migrations/20190325001339_releases.js b/migrations/20190325001339_releases.js index d6cd486f..8bcb2605 100644 --- a/migrations/20190325001339_releases.js +++ b/migrations/20190325001339_releases.js @@ -1024,7 +1024,7 @@ exports.up = knex => Promise.resolve() SELECT releases.* FROM ( SELECT releases_search.release_id, - ts_rank(releases_search.document, to_tsquery('english', array_to_string(regexp_split_to_array(query, E'\\s+'), '|'))) AS rank + ts_rank(releases_search.document, to_tsquery('english', regexp_replace(query, '[\\s._-]+', '|', 'gi'))) AS rank FROM releases_search ) ranks LEFT JOIN releases ON releases.id = ranks.release_id diff --git a/src/releases.js b/src/releases.js index 9ecb6759..a853635c 100644 --- a/src/releases.js +++ b/src/releases.js @@ -134,7 +134,7 @@ async function fetchScenes(limit = 100) { async function searchScenes(query, limit = 100) { const releases = await knex - .from(knex.raw('search_releases(?) as releases', [query])) + .from(knex.raw('search_releases(:query) as releases', { query })) .modify(withRelations, false, true) .limit(Math.min(limit, 1000000));