Skip to content
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

Merged
merged 6 commits into from
Jun 28, 2021
Merged

Collection Engine #488

merged 6 commits into from
Jun 28, 2021

Conversation

taylorotwell
Copy link
Member

@taylorotwell taylorotwell commented Jun 28, 2021

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 the LazyCollection 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 a where 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 a LazyCollection of all models of a given type and filters their column's values against the query within PHP.

src/Engines/CollectionEngine.php Show resolved Hide resolved
src/EngineManager.php Outdated Show resolved Hide resolved
Co-authored-by: Nuno Maduro <enunomaduro@gmail.com>
src/Engines/CollectionEngine.php Outdated Show resolved Hide resolved
src/Engines/CollectionEngine.php Show resolved Hide resolved
taylorotwell and others added 2 commits June 28, 2021 10:36
Co-authored-by: Joseph Silber <contact@josephsilber.com>
@taylorotwell taylorotwell merged commit a0447cf into 9.x Jun 28, 2021
@taylorotwell taylorotwell deleted the collection-engine branch June 28, 2021 21:40
->orderBy($builder->model->getKeyName(), 'desc')
->get();

$models = $models->values();
Copy link
Contributor

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());
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants