Skip to content

Commit

Permalink
Improve handling of space characters in search query tokenisation.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Oct 24, 2023
1 parent 740803b commit 43ef393
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@ WITH q AS (
-- Prepare TS_QUERY tokens for querying with either:
-- a) built in Postgres dictionary/tokenizer ($1=query, $2=Postgres dictionary name)
-- b) externally computed and supplied tokens ($3)
SELECT (CASE WHEN $2 != '' THEN PLAINTO_TSQUERY($2::regconfig, $1::TEXT) ELSE $3::TSQUERY END) AS query
SELECT (
CASE WHEN $2 != '' THEN
CASE WHEN POSITION(' ' IN $1::TEXT) > 0 OR POSITION('-' IN $1::TEXT) > 0 THEN
PLAINTO_TSQUERY($2::regconfig, $1) || PLAINTO_TSQUERY($2::regconfig, REPLACE(REPLACE($1, ' ', ''), '-', ''))
ELSE
PLAINTO_TSQUERY($2::regconfig, $1)
END
ELSE
$3::TSQUERY
END
) AS query
),
directMatch AS (
-- Do a direct string match (first 50 chars) of the query or see if there are matches for
Expand Down

0 comments on commit 43ef393

Please sign in to comment.