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

MakeSearchable runs twice when updating aggregated model #237

Open
aniplaylist opened this issue May 26, 2020 · 7 comments
Open

MakeSearchable runs twice when updating aggregated model #237

aniplaylist opened this issue May 26, 2020 · 7 comments
Labels
enhancement New feature or request

Comments

@aniplaylist
Copy link

aniplaylist commented May 26, 2020

Hello,

I have just set up an Aggregator on my project with two Models in it.

Whenever I'm updating one of these two models the MakeSearchable Job is run twice :

  • Once for the Model
  • Once for the Aggregator

Is this the expected behaviour? Isn't this consuming two indexing operations on Algolia instead of one?

Two jobs seen on Horizon :

horizon-jobs

Model :

jobs-103-model

Aggregator :

jobs-104-aggregator

@nunomaduro
Copy link
Contributor

Correct. If both the model, and the aggregator are searchable that is the normal behaviour.

You really need to make the models searchable? If not, you can remove the Searchable trait from those models, and the aggregator will still work consuming just one indexing operation per update.

@aniplaylist
Copy link
Author

Just tried removing the Searchable trait from my model but MakeSearchable job is not triggered anymore (not even once) and the entry I updated is removed from my index

@nunomaduro
Copy link
Contributor

That is because you probably forgot to call the bootSearchable in your service provider as specified here: algolia.com/doc/framework-integration/laravel/advanced-use-cases/multiple-models-in-one-index/?language=php#aggregators---multiple-models-in-one-index.

@aniplaylist
Copy link
Author

aniplaylist commented May 26, 2020

I didn't forget 🤔

<?php

namespace App\Providers;

use App\Search\Results;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Results::bootSearchable();
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
    }
}

@nunomaduro nunomaduro reopened this May 26, 2020
@tech-commoprices
Copy link

Hi @aniplaylist , just ran into the same issue.

Simply change the shouldBeSearchable method on your Aggregator to make it look like this :

    public function shouldBeSearchable()
    {
        return $this->model->shouldBeSearchable();
    }

@tech-commoprices
Copy link

It could be useful to put this in the docs btw :-)

@nunomaduro nunomaduro added the enhancement New feature or request label Jun 3, 2020
@nunomaduro
Copy link
Contributor

Thanks! We are aware of this issue, no ETA for having this on the package at the moment.

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

No branches or pull requests

2 participants