pmatseykanets / laravel-scout-postgres

PostgreSQL Full Text Search Engine for Laravel Scout
MIT License
159 stars 36 forks source link

Scout Import fails with eager loaded relationships #12

Open nhuebnereagle opened 7 years ago

nhuebnereagle commented 7 years ago

First - Thank you for making a PostgreSql extension for Scout! I was able to resolve the issue, but still reporting it in case it's something in Scout or the driver. If I need to bring this over to Scout, let me know and I can do that.

The following code in my model was causing a PostgreSql error. This code automatically loads my relationships when I pull back a record:

Model Relationships Causing Error

protected $with = [
    'category',
    'attachments',
];

Here's the error I would get when attempting a Scout Import using the Command Line command:

PostgreSql Error

SQLSTATE[HY093]: Invalid parameter number: parameter was not defined (SQL: select to_tsvector(COALESCE(english, get_current_ts_config()), 177) || to_tsvector(COALESCE(english, get_current_ts_config()), 2017-05-25 09:46:03) || to_tsvector(COALESCE(english, get_current_ts_config()), 2017-05-25 09:46:03) || to_tsvector(COALESCE(english, get_current_ts_config()), ) || to_tsvector(COALESCE(english, get_current_ts_config()), ) || to_tsvector(COALESCE(english, get_current_ts_config()), ) || to_tsvector(COALESCE(english, get_current_ts_config()), 1) || to_tsvector(COALESCE(english, get_current_ts_config()), Videos) || to_tsvector(COALESCE(english, get_current_ts_config()), 23) || to_tsvector(COALESCE(english, get_current_ts_config()), <pTest Article Content</p>) || to_tsvector(COALESCE(english, get_current_ts_config()), ) || to_tsvector(COALESCE(english, get_current_ts_config()), 23) || to_tsvector(COALESCE(2017-05-23 16:26:58, get_current_ts_config()), 2017-05-23 16:26:58) || to_tsvector(COALESCE(, get_current_ts_config()), ) AS tsvector limit 1)

After commenting out the above code from my model I was able to import successfully:

Success

#> php artisan scout:import "App\Data\Models\HelpCenter\Article" 

Imported [App\Data\Models\HelpCenter\Article] models up to ID: 235
All [App\Data\Models\HelpCenter\Article] records have been imported.
countnoobula commented 6 years ago

My understanding of the problem is that the library doesn't supported nested arrays in toSearchableArray returns.

I haven't had capacity to look at resolving this, but have encountered this several times while working with this library.

alekciy commented 3 years ago

I have the same problem. @countnoobula right. Nested array (model property is array).