Wrap tsvector attributes with coalesce before join

Fixed a bug where joining multiple tsvector attributes results in NULL
because one of the columns contains NULL. The expected behaviour is to
ignore that column instead, which is achieved by setting it to an empty
string
This commit is contained in:
Mathijs Nelemans 2019-12-07 12:40:05 +01:00
parent 23eb263e07
commit fcdbc4fbe3

View File

@ -546,8 +546,8 @@ const buildSearchQuery = (qb, model, params) => {
case 'pg': {
const searchQuery = searchText.map(attribute =>
_.toLower(attribute) === attribute
? `to_tsvector(${attribute})`
: `to_tsvector("${attribute}")`
? `to_tsvector(coalesce(${attribute}, ''))`
: `to_tsvector(coalesce("${attribute}", ''))`
);
qb.orWhereRaw(`${searchQuery.join(' || ')} @@ plainto_tsquery(?)`, query);