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

Defer to model's way of limiting the model set #292

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

srlbarron
Copy link

This will allow optimization per model

Avoid indexing models you don't want to be indexed anymore.

When the indexing process hits shouldBeSearchable it is already iterating through a lot of "probably" unnecessary models.

Q A
Bug fix? no
New feature? yes
BC breaks? no
Related Issue
Need Doc update yes

Describe your change

When using aggregators, this implelents MakeAllSearchable independently of how each model is implementing it.

What problem is this fixing?

At the moment, this only looks for soft deletes in order to limit the set algolia needs to evaluate before indexing it.
With this change, the aggregator will look for a per model implementation of MakeAllSearchableUsing in order for add extra rules to limit the set Algolia need to iterate to index.

class MyModel extends model;

use Searchable;

   public function makeAllSearchableUsing($query)
   {
        return $query->where('active', 1);
   }

Copy link
Contributor

@DevinCodes DevinCodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR! Unfortunately, we can't move forward with this for the time being, please see my comment.

If you can open a PR on Laravel Scout to change the access level of the related method we could include this in a later version. WDYT?

$instance->newQuery()->when($softDeletes, function ($query) {
$instance->newQuery()
->when(true, function ($query) use ($instance) {
$instance->makeAllSearchableUsing($query);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This currently fails, since makeAllSearchableUsing is not available to call outside of the class: it's defined as a protected method in Laravel Scout. As long as it's protected, we can't use this method here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

laravel/scout#577

Thank you!

srlbarron added a commit to srlbarron/scout that referenced this pull request Jan 27, 2022
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.

2 participants