pmatseykanets / laravel-scout-postgres

PostgreSQL Full Text Search Engine for Laravel Scout
MIT License
161 stars 38 forks source link

Cast nulls to empty strings in `$fields` array, as well as `$select` string #3

Closed mikeu closed 7 years ago

mikeu commented 7 years ago

Resolves an issue in PostgresEngine::toVector, where a null value in any searchable model field would result in a null searchable column.

Because null values were only mapped to empty strings in the $select string, but not in the $fields array, select statements such as

SELECT setweight(to_tsvector('x'), 'A') || setweight(to_tsvector(null), 'B') AS tsvector

could be generated. But that null value in the second element propagates all the way up so that the end result is equivalent to

SELECT null AS tsvector

To resolve this, I just moved the call to map on the searchable fields collection, so that its results are stored in the $fields array.

pmatseykanets commented 7 years ago

Great catch! Thank you so much. Tagged 0.2.1 with this patch and a test for it.

Thanks again.