public function reindexByActiveQuery(ActiveQueryInterface $activeQuery)
    {
        $indices = null;
        $records = $this->activeQueryChunker->chunk(
            $activeQuery,
            self::CHUNK_SIZE,
            function ($activeRecordEntities) use (&$indices) {
                $records = $this->getAlgoliaRecordsFromSearchableModelArray($activeRecordEntities);

                // The converting ActiveRecords to Algolia ones already does the type checking
                // so it's safe to init indices here during the first chunk.
                if ($indices === null) {
                    $indices = $this->initIndices($activeRecordEntities[0]);
                }

                return $records;
            }
        );

        return $this->processIndices($indices, function (Index $index) use ($records) {
            return $this->reindexAtomically($index, $records);
        });
    }