-
Notifications
You must be signed in to change notification settings - Fork 334
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
Collection Engine #488
Collection Engine #488
Conversation
Co-authored-by: Nuno Maduro <enunomaduro@gmail.com>
Co-authored-by: Joseph Silber <contact@josephsilber.com>
->orderBy($builder->model->getKeyName(), 'desc') | ||
->get(); | ||
|
||
$models = $models->values(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why ->values()
is necessary?
return $models; | ||
} | ||
|
||
$columns = array_keys($models->first()->toSearchableArray()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it's relevant, but toSearchableArray
might be dynamic and depend on the model record. It might be better to execute it per record, and not only based on the first record.
Over the weekend, I was hacking on something where I wanted to quickly use Scout without setting up any other external dependencies like Algolia or MeiliSearch.
I cooked up this quick driver that is intended for usage in local development and small staging environments only. It is not performant on large datasets and does not have robust fuzzy matching or anything. However, it is perfectly adequate in local development environments where you often don't have more than a couple hundred models.
However, this driver uses Eloquent's cursor method to retrieve filtered results and then uses
Str::contains
against theLazyCollection
to match against all of the searchable columns. Note it is not possible to do those checks in the database because we do not know the data types of the columns and some RDBMS like Postgres will throw an error if you try to execute awhere like
clause against an integer column like an ID.So, in summary, this driver gives you a quick way to use Scout locally and get some generally sensible results from it just so you can continue building your application's search UI and functionality without worrying about the robustness of the search results themselves.
I decided against calling this a
database
engine because it does not perform any sort of FULLTEXT column searching or use database search features. It iterates through aLazyCollection
of all models of a given type and filters their column's values against the query within PHP.