Replies: 3 comments
-
I just realized that Scout sets a singleton with the configured <?php
namespace modules\appmodule\console\controllers;
use Algolia\AlgoliaSearch\SearchClient;
use Craft;
use rias\scout\Scout;
use Tightenco\Collect\Support\Collection;
use yii\console\ExitCode;
use yii\helpers\Console;
class AlgoliaController extends \craft\console\Controller
{
public function actionRandomizeProducts()
{
$indexName = getenv('ALGOLIA_INDEX_PREFIX') . 'products';
$scoutSettings = Scout::$plugin->getSettings();
$scoutIndex = $scoutSettings->getIndices()
->firstWhere('indexName', $indexName);
$index = Craft::$container->get(SearchClient::class)->initIndex($indexName);
$ids = $scoutIndex->criteria->ids();
$updates = Collection::make($ids)
->map(function ($id) use ($ids) {
return [
'objectID' => $id,
'random' => rand(0, count($ids)),
];
});
$index->partialUpdateObjects($updates->all());
return ExitCode::OK;
}
} …seems like alot of duplicated effort though. Seems like I should be able to get the |
Beta Was this translation helpful? Give feedback.
-
I'd be happy with a method |
Beta Was this translation helpful? Give feedback.
-
thanks @riasvdv, I'll amend this PR. |
Beta Was this translation helpful? Give feedback.
-
I want to call arbitrary
Algolia\AlgoliaSearch\SearchIndex
methods (e.g. via CLI command), but want to leverage Scout's settings for configuring the client/index.Related: #122
Beta Was this translation helpful? Give feedback.
All reactions