Updated search query function to include ranking.
This commit is contained in:
@@ -1020,8 +1020,13 @@ exports.up = knex => Promise.resolve()
|
||||
);
|
||||
$$ LANGUAGE SQL STABLE;
|
||||
|
||||
CREATE FUNCTION search_releases(query text, minimum_rank numeric DEFAULT 0) RETURNS SETOF releases AS $$
|
||||
SELECT releases.* FROM (
|
||||
/* We need both the release entries and their search ranking, and PostGraphile does not seem to allow virtual foreign keys on function results.
|
||||
* Using a view as a proxy for the search results allows us to get both a reference to the releases table, and the ranking */
|
||||
CREATE VIEW releases_search_results AS
|
||||
SELECT NULL::integer as id, NULL::real as rank;
|
||||
|
||||
CREATE FUNCTION search_releases(query text, minimum_rank numeric DEFAULT 0) RETURNS SETOF releases_search_results AS $$
|
||||
SELECT releases.id, ranks.rank FROM (
|
||||
SELECT
|
||||
releases_search.release_id,
|
||||
ts_rank(releases_search.document, to_tsquery('english', regexp_replace(query, '[\\s._-]+', '|', 'gi'))) AS rank
|
||||
@@ -1196,6 +1201,8 @@ exports.up = knex => Promise.resolve()
|
||||
COMMENT ON FUNCTION actors_scenes IS E'@sortable';
|
||||
|
||||
COMMENT ON FUNCTION tags_scenes IS E'@sortable';
|
||||
|
||||
COMMENT ON VIEW releases_search_results is E'@foreignKey (id) REFERENCES releases (id)';
|
||||
`);
|
||||
});
|
||||
|
||||
@@ -1257,6 +1264,8 @@ exports.down = (knex) => { // eslint-disable-line arrow-body-style
|
||||
DROP TABLE IF EXISTS entities_types CASCADE;
|
||||
DROP TABLE IF EXISTS entities CASCADE;
|
||||
|
||||
DROP FUNCTION IF EXISTS search_releases_legacy;
|
||||
DROP FUNCTION IF EXISTS search_releases;
|
||||
DROP FUNCTION IF EXISTS search_sites;
|
||||
DROP FUNCTION IF EXISTS search_entities;
|
||||
DROP FUNCTION IF EXISTS search_actors;
|
||||
@@ -1272,6 +1281,8 @@ exports.down = (knex) => { // eslint-disable-line arrow-body-style
|
||||
DROP FUNCTION IF EXISTS movies_tags;
|
||||
DROP FUNCTION IF EXISTS movies_photos;
|
||||
|
||||
DROP VIEW IF EXISTS releases_search_results;
|
||||
|
||||
DROP TEXT SEARCH CONFIGURATION IF EXISTS traxxx;
|
||||
DROP TEXT SEARCH DICTIONARY IF EXISTS traxxx_dict;
|
||||
`);
|
||||
|
||||
Reference in New Issue
Block a user