Refactored PG search function to allow superflous words in search query.

This commit is contained in:
DebaucheryLibrarian 2021-02-25 02:52:45 +01:00
parent 3ad1f3d1e3
commit 7818328378
8 changed files with 17 additions and 4 deletions

View File

@ -108,7 +108,6 @@ export default {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
grid-gap: 0 .5rem;
flex-grow: 1;
margin: 0 0 1rem 0;
}

View File

@ -37,6 +37,7 @@ function initUiActions(_store, _router) {
releases: searchReleases(
query: $query
first: $limit
minimalRank: "0.025"
) {
id
title

View File

@ -1012,7 +1012,7 @@ exports.up = knex => Promise.resolve()
.then(() => { // eslint-disable-line arrow-body-style
// allow vim fold
return knex.raw(`
CREATE FUNCTION search_releases(query text) RETURNS SETOF releases AS $$
CREATE FUNCTION search_releases_legacy(query text) RETURNS SETOF releases AS $$
SELECT * FROM releases WHERE releases.id IN (
SELECT release_id FROM releases_search AS search
WHERE search.document @@ plainto_tsquery('traxxx', regexp_replace(query, '\\.|-|(XXX\\.[\\d+|hd|sd].*$)', ' ', 'ig'))
@ -1020,6 +1020,18 @@ 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 (
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
FROM releases_search
) ranks
LEFT JOIN releases ON releases.id = ranks.release_id
WHERE ranks.rank > minimum_rank
ORDER BY ranks.rank DESC;
$$ LANGUAGE SQL STABLE;
CREATE FUNCTION search_entities(search text) RETURNS SETOF entities AS $$
SELECT * FROM entities
WHERE

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View File

@ -1416,6 +1416,7 @@ const aliases = [
{
name: 'dp',
for: 'dp',
secondary: true,
},
{
name: 'double dildo deepthroat',

View File

@ -218,7 +218,7 @@ async function updateReleasesSearch(releaseIds) {
SELECT
releases.id AS release_id,
TO_TSVECTOR(
'traxxx',
'english',
COALESCE(releases.title, '') || ' ' ||
entities.name || ' ' ||
entities.slug || ' ' ||
@ -238,7 +238,7 @@ async function updateReleasesSearch(releaseIds) {
LEFT JOIN releases_actors AS local_actors ON local_actors.release_id = releases.id
LEFT JOIN releases_tags AS local_tags ON local_tags.release_id = releases.id
LEFT JOIN actors ON local_actors.actor_id = actors.id
LEFT JOIN tags ON local_tags.tag_id = tags.id AND tags.priority >= 7
LEFT JOIN tags ON local_tags.tag_id = tags.id AND tags.priority >= 6
LEFT JOIN tags as tags_aliases ON local_tags.tag_id = tags_aliases.alias_for AND tags_aliases.secondary = true
${releaseIds ? 'WHERE releases.id = ANY(?)' : ''}
GROUP BY releases.id, entities.name, entities.slug, entities.alias, parents.name, parents.slug, parents.alias;