studioespresso / craft-scout

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.
MIT License
81 stars 55 forks source link

Algolia not updated on save #279

Closed nitech closed 11 months ago

nitech commented 11 months ago

When I save a product in Craft Commerce, the Algolia index is not updated. When I run a ./craft scout/index/refresh dev_products command the index is however updated.

Not sure when this happened, but possibly during one of the latest updates I did to this Craft instance. Running latest Craft, Commerce and Scout.

Defining indices thus:

'indices' => (new SitemoduleServiceService)->getIndicies()

    public function getIndicies(){
        $indicies = [];

        // environment always dev unless in production. So localdev, dev and stg becomes dev
        $env = "dev";
        if (getenv('ENVIRONMENT') == "prod") $env = "prod";

        // todo: add site 6 for Products and Product Families

        // products only relevant for site 5:
        $indicies[] = 
            \rias\scout\ScoutIndex::create("{$env}_products")
            ->elementType(\craft\commerce\elements\Product::class)
            ->criteria(function (\craft\commerce\elements\db\ProductQuery $query) use ($site, $productType) {
                $query->siteId = 5; // $site->id;
                return $query;
            })
            ->transformer(function (\craft\commerce\elements\Product $product) {
                return $this->transformProductData($product);
            });     

        // product families only relevant for site 5:
        $indicies[] = 
            \rias\scout\ScoutIndex::create("{$env}_product_families")
            ->elementType(\craft\elements\Category::class)
            ->criteria(function (\craft\elements\db\CategoryQuery $query) use ($site, $productType) {
                $query->siteId = 5; // $site->id;
                $query->group("productFamily");
                return $query;
            })
            ->transformer(function (\craft\elements\Category $category) {
                return $this->transformCategoryData($category);
            });              

        // entries on each site
        foreach (Craft::$app->getSites()->getAllSites() as $site) {
            $indicies[] = 
                \rias\scout\ScoutIndex::create("{$env}_{$site->handle}_entries")
                ->elementType(\craft\elements\Entry::class)
                ->criteria(function (\craft\elements\db\EntryQuery $query) use ($site) {
                    $query->siteId = $site->id;

                    // exclude a couple of section types 
                    $query->section("and, not people, not locations, not categoryIndex");
                    return $query;
                })
                ->transformer(function (\craft\elements\Entry $entry) {
                    return $this->transformEntryData($entry);
                });   
        }  

        return $indicies;
    }

Wondering whether it has something to do with me disabling a queue runner that was acting up after I had dome some updates to Craft

janhenckens commented 11 months ago

Hey @nitech, could you confirm that site 5 is not your primary site and wether or not your are running with the queue option enabled? And can you check if refreshing the index through the utility updates the product?

(this feels related to #266 but I'll leave this open for now)

nitech commented 11 months ago

Site 5 is not my primary site. Queue option is enabled. Refreshing through utility updates the product.

266 fixed the problem

janhenckens commented 11 months ago

Good to hear @nitech! I'll close your issue but feel free to reopen if need be.