Maps an array of searchable models into an Algolia friendly array.

@param SearchableInterface[] $searchableModels

@return array
333092
private function getAlgoliaRecordsFromSearchableModelArray(array $searchableModels)
    {
        if (empty($searchableModels)) {
            throw new \InvalidArgumentException('The given array should not be empty');
        }

        // Use the first element of the array to define what kind of models we are indexing.
        $arrayType = \get_class($searchableModels[0]);
        $this->checkImplementsSearchableInterface($arrayType);

        return \array_map(function (SearchableInterface $searchableModel) use ($arrayType) {
            if (! $searchableModel instanceof $arrayType) {
                throw new \InvalidArgumentException('The given array should not contain multiple different classes');
            }

            $algoliaRecord = $searchableModel->getAlgoliaRecord();
            $algoliaRecord['objectID'] = $searchableModel->getObjectID();

            return $algoliaRecord;
        }, $searchableModels);
    }
1262455
public function pushToIndices(SearchableInterface $searchableModel)
    {
        $indices = $this->initIndices($searchableModel);
        $record = $searchableModel->getAlgoliaRecord();

        return $this->processIndices($indices, function (Index $index) use ($record, $searchableModel) {
            return $index->addObject($record, $searchableModel->getObjectID());
        });
    }
264734
public function loadModelDefinitions($models)
    {
        // load model definitions
        if (empty($models) || !is_array($models)) {
            throw new ModelNotFoundException(self::class, 'Models should be passed as an array of class names!');
        }

        foreach ($models as $model) {
            /** @var FactoryInterface $model */
            if (!in_array(FactoryInterface::class, class_implements($model))) {
                throw new ModelException($model, 'Could not find interface implementation: ' . FactoryInterface::class);
            }

            $fmModel = $this->define($model);
            $definitions = $model::definitions();

            if (!empty($definitions[0]) and is_array($definitions[0])) {
                $fmModel->setDefinitions($definitions[0]);
                if (!empty($definitions[1])) {
                    $fmModel->setCallback($definitions[1]);
                }
            }
        }
    }
203645
public function update($models)
    {
        $this->initIndex($models->first());
        $this->tnt->selectIndex("{$models->first()->searchableAs()}.index");
        $index = $this->tnt->getIndex();
        $index->setPrimaryKey($models->first()->getKeyName());

        $index->indexBeginTransaction();
        $models->each(function ($model) use ($index) {
            $array = $model->toSearchableArray();

            if (empty($array)) {
                return;
            }

            if ($model->getKey()) {
                $index->update($model->getKey(), $array);
            } else {
                $index->insert($array);
            }
        });
        $index->indexEndTransaction();
    }
1146809
public function getSearchableFieldsMeta()
    {
        if (!empty($this->searchableFieldsMeta)) {
            return $this->searchableFieldsMeta;
        }

        if ($searchableFieldsMeta = $this->getPropertyContainer()->getFields('hasMany')) {

            $searchableFieldsMeta = array_filter($searchableFieldsMeta, function (PropertyContract $property) {
                return $property->getBehavior()->isPersistent();
            });
        }
        $this->searchableFieldsMeta = $searchableFieldsMeta;

        return $this->searchableFieldsMeta;
    }
972204
public function findByModNames(array $modNames): array
    {
        $result = [];
        if (count($modNames) > 0) {
            $queryBuilder = $this->entityManager->createQueryBuilder();
            $queryBuilder->select(['mc', 'm'])
                         ->from(ModCombination::class, 'mc')
                         ->innerJoin('mc.mod', 'm')
                         ->andWhere('m.name IN (:modNames)')
                         ->addOrderBy('mc.order', 'ASC')
                         ->setParameter('modNames', array_values($modNames));

            $result = $queryBuilder->getQuery()->getResult();
        }
        return $result;
    }
24607
public function getSearchableKeys()
    {
        return array_values(array_map(function ($value, $key) {
            return (is_array($value) || is_numeric($key) === false) ? $key : $value;
        }, $this->searchable, array_keys($this->searchable)));
    }
706160
protected function prepareDataProvider($searchModel)
    {
        if ($this->prepareDataProvider !== null) {
            return call_user_func($this->prepareDataProvider, $searchModel);
        }

        return new ActiveDataProvider([
            'query' => $searchModel::find(),
        ]);
    }
1374578
public static function buildTemplates($models)
    {
        $result = [];
        foreach($models as $model) {
            $result[] = self::buildTemplate($model);
        }

        return $result;
    }
886311
protected function getEagerModelKeys(array $models)
    {
        // First we need to gather all of the keys from the parent models so we know what
        // to query for via the eager loading query. We will add them to an array then
        // execute a "where in" statement to gather up all of those related records.
        $keys = collect($models)->map(function ($model) {
            return $model->{$this->foreignKey};
        })->filter()->all();

        // If there are no keys that were not null we will just return an array with either
        // null or 0 in (depending on if incrementing keys are in use) so the query wont
        // fail plus returns zero results, which should be what the developer expects.
        if (count($keys) === 0) {
            return [$this->relationHasIncrementingId() ? 0 : null];
        }

        return array_values(array_unique($keys));
    }
874284
protected function getEagerModelKeys(array $models)
    {
        $keys = array();

        foreach ($models as $model) {
            if (! is_null($value = $model->{$this->foreignKey})) {
                $keys[] = $value;
            }
        }

        if (count($keys) == 0) {
            return array(0);
        }

        return array_values(array_unique($keys));
    }
1335297
public static function extractModelAndKeys($model, array $keys = null)
    {
        if (! is_null($keys)) {
            if (is_string($model)) {
                $model = new $model;
            }

            return [$model, $keys];
        }

        if ($model instanceof Model) {
            return [$model, [$model->getKey()]];
        }

        if ($model instanceof Collection) {
            $keys = $model->map(function ($model) {
                return $model->getKey();
            });

            return [$model->first(), $keys];
        }
    }
477481
public static function idToArrayIndex(&$models)
    {
        $result = [];
        foreach ($models as $index => &$model) {
            $result[$model->id] = $index;
        }
        return $result;
    }
1006073
public function getModels ($entities)
    {
        $models = array();

        foreach ($entities as $entity) {
            $models[] = $this->getModel($entity);
        }

        return $models;
    }
114545
public static function getPrimaryModel($models)
    {
        if (empty($models)) {
            return false;
        }
        \d($models);
        exit;
        foreach ($models as $tabKey => $model) {
            if ($tabKey === static::getPrimaryTabularId(static::baseClassName())) {
                return $model;
            }
        }

        return false;
    }
760546
private function createTags(Collection $models): array
    {
        $tags = [];

        /** @var Model $model */
        foreach ($models as $model) {
            $tags[] = static::createTagFromModel($model);
        }

        return $tags;
    }
752394
public function getModelCacheKeys(Cacheable $model)
    {
        // Build list of cache keys we need to clear.
        $cacheKeys = [
            implode(':', [$model->getTable(), 'index']),
        ];

        // If the model has an primary key add the cache key.
        if (!empty($model->getPrimaryKeyValue())) {
            $cacheKeys[] = implode(':', [$model->getTable(), $model->getPrimaryKeyValue()]);
        }

        // Add the cache keys for the model attributes.
        $this->addAttributeCacheKeys($cacheKeys, $model);

        return $cacheKeys;
    }