-
Notifications
You must be signed in to change notification settings - Fork 347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typesense: ObjectNotFound error when there are no models yet #914
Comments
Thank you for reporting this issue! As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub. If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team. Thank you! |
Hey there, the reason for that behavior is that the I'm not sure what else should be done here, would you prefer a different kind of error to be thrown? Checking for the existence of the collection shouldn't be done when searching, it will bog down search performance with another API call |
When the |
Sure, I'll have to check the flow and how it's handled though and report back |
Dug some more into it: When you run
The key issue is that the callback function containing Prior to PR #898, Typesense was checking for (and creating if needed) the collection on both indexing AND searching operations. Now collections are only created during indexing, but with empty tables, that code path isn't reached. |
@tharropoulos Could we maybe add Typesense support to https://github.com/laravel/scout/blob/10.x/src/Console/IndexCommand.php or https://github.com/laravel/scout/blob/10.x/src/Console/SyncIndexSettingsCommand.php so that it is possible to create the necessary typesense collections via an artisan command? 🤔 |
Sure, if @jasonbosco and @taylorotwell are down for that, since this will change the public-facing API |
I'm not happy about allowing users to create indexes manually as it may create confusion. Previously, the indexes were created automatically (and still are) if there were any documents to be indexed. Adding another command that essentially creates two branches of creating collections isn't something I'm really for. |
My two cents is that there is a gap here. I can see two different paths forward that maintain what you desire:
The lack of data shouldn't be the determining factor on our ability to perform a search. If skipping the presence check is the desire, you could naively perform the search, and on a ObjectNotFound exception, you could then create the index and return no results. |
I'd prefer actually creating it on that error, instead of returning a mocked response, as the Typesense API may change in the future. #917 Does this fall line with what you were describing? |
It does |
Nice, I'll open it up for review tomorrow |
* fix(typesense): handle missing collection during search - wrap `search` operation in try-catch block to handle `ObjectNotFound` exception - automatically create collection when not found and retry search - improve error recovery flow for typesense engine * chore: lint
It should now create the collection if it's not found when searching in it. @gdebrauwer could you try checking it out as well to verify that it solves this issue? |
Scout Version
10.13.1
Scout Driver
Typesense
Laravel Version
11.44.0
PHP Version
8.4
Database Driver & Version
No response
SDK Version
No response
Meilisearch CLI Version
No response
Description
I have a model that I made searchable. The table of that model is still empty. If I run
php artisan scout:import
, then nothing happens because there are no models to import in Typesense.The issue starts to occur when you try to search using Scout while there are still no models yet. Typesense throws an
ObjectNotFound
error because it can not find a Typesense collection for that model class. This is caused by changes of #898. It does not make sense that Scout throws an exception when searching just because there are no models yet.Steps To Reproduce
php artisan scout:import
YourModel::search('foo')->get()
-> You will get anObjectNotFound
typesense exceptionYourModel::search('foo')->get()
again -> You don't get an error anymoreThe text was updated successfully, but these errors were encountered: