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 54 forks source link

[4.1.0-beta.1] Queue Error When Saving an Entry When Using getElements #297

Closed simonkuran closed 2 months ago

simonkuran commented 2 months ago

Thanks @janhenckens for the work on #69! I have a test setup and I'm getting an error when saving an entry. When updating the index via php craft scout/index it works. However, when I then save an entry I get an "Indexing element Failed" error in the CP queue. In the queue log file I get a {main} {"memory":7540904,"exception":"[object] (Error(code: 0): Call to a member function id() on array at /var/www/html/vendor/studioespresso/craft-scout/src/jobs/MakeSearchable.php:81)"} error.

Here's the core of my scout.php file:

use \craft\base\Element;
use \craft\elements\Entry;
use \Solspace\Calendar\Elements\Event;

return [
    'indices' => [
        \rias\scout\ScoutIndex::create('global')
        ->getElements(function () {
            return [
                Entry::find()->section('blog'),
                Event::find()
            ];
        })
        ->transformer(function (Element $element) {
            $moduleBody = $element->modules->type('body')->all();
            $moduleBodyContent = [];
            foreach($moduleBody as $block) {
                $moduleBodyContent[] = $block->body;
            }

            return [
                'title' => $element->title,
                'postDate' => $element->postDate,
                'moduleBody' => $moduleBodyContent,
            ];
        })
        ->indexSettings(
            \rias\scout\IndexSettings::create()
                ->minWordSizefor1Typo(4)
        )
    ],
];

When I use a a single element type like this I don't get any errors:

->elementType(Entry::class)
->criteria(function (\craft\elements\db\EntryQuery $query) {
    return $query->section('blog');
})
janhenckens commented 2 months ago

Thanks for testing @simonkuran! I can reproduce so I'll look into it, hope to be able to give you and update by the end of the week.

elivz commented 2 months ago

I am seeing the same issue. Appears to have started with Scout v3.3.3.

janhenckens commented 2 months ago

I am seeing the same issue. Appears to have started with Scout v3.3.3.

This specific issue was through a change that was introduced last week and is only present in 4.1.0-beta.1 for now. Are you running that version as well @elivz?

janhenckens commented 2 months ago

@simonkuran Could to try updating to 4.1.0-beta.2 and see if that fixes this for you? Thanks!

elivz commented 2 months ago

Interesting, no I was on 3.3.3 but getting the exact same error in the logs (including the same line number). I downgraded to 3.3.2 which cleared up my error logs. I can try to do a little more testing on Monday with newer versions.

simonkuran commented 2 months ago

@janhenckens 4.1.0-beta.2 is working well for me. Thanks for fixing this so quickly.

janhenckens commented 2 months ago

@janhenckens 4.1.0-beta.2 is working well for me. Thanks for fixing this so quickly.

Thanks for testing!

janhenckens commented 2 months ago

Interesting, no I was on 3.3.3 but getting the exact same error in the logs (including the same line number). I downgraded to 3.3.2 which cleared up my error logs. I can try to do a little more testing on Monday with newer versions.

Could you try to update to the latest stable version (4.0.0) and report a new issue with your scout config if you're still having the problem? Thanks!