Add To Index

Add all documents in this collection to to the Elasticsearch document index.

@return null|array
494783
public function addToIndex()
    {
        if ($this->isEmpty()) {
            return null;
        }

        $params = array();

        foreach ($this->all() as $item) {
            $params['body'][] = array(
                'index' => array(
                    '_id' => $item->getKey(),
                    '_type' => $item->getTypeName(),
                    '_index' => $item->getIndexName(),
                ),
            );

            $params['body'][] = $item->getIndexDocumentData();
        }

        return $this->getElasticSearchClient()->bulk($params);
    }
1029482
public   String addDocumentWithId(String indexName,  Object bean, Object docId, Object parentId) throws ElasticSearchException{
		return addDocumentWithId(  indexName,  _doc,  bean,   docId,   parentId);
	}
103828
public function add()
    {
        /** @var \Qobo\Calendar\Model\Table\CalendarEventsTable $calendarEventsTable */
        $calendarEventsTable = TableRegistry::get('Qobo/Calendar.CalendarEvents');
        $calendar = $this->Calendars->newEntity();

        $eventTypes = $calendarEventsTable->getEventTypes(['user' => $this->Auth->user()]);

        if ($this->request->is('post')) {
            $data = $this->request->getData();
            $data = is_array($data) ? $data : [];
            if (!empty($data['event_types'])) {
                $data['event_types'] = json_encode($data['event_types']);
            }

            $calendar = $this->Calendars->patchEntity($calendar, $data);

            if ($this->Calendars->save($calendar)) {
                $this->Flash->success((string)__('The calendar has been saved.'));

                return $this->redirect(['action' => 'index']);
            }

            $this->Flash->error((string)__('The calendar could not be saved. Please, try again.'));
        }

        $this->set(compact('calendar', 'eventTypes'));
        $this->set('_serialize', 'calendar');
    }
99070
public function add()
    {
        $cmsTerm = $this->CmsTerm->newEntity();
        if ($this->request->is('post')) {
            $cmsTerm = $this->CmsTerm->patchEntity($cmsTerm, $this->request->data);
            if ($this->CmsTerm->save($cmsTerm)) {
                $this->Flash->success('The cms term has been saved.');
                return $this->redirect(['action' => 'index']);
            } else {
                $this->Flash->error('The cms term could not be saved. Please, try again.');
            }
        }
        $this->set(compact('cmsTerm'));
        $this->set('_serialize', ['cmsTerm']);
    }
24006
public String addDocumentWithParentId(String indexName,   Object bean, Object parentId) throws ElasticSearchException{
		return addDocumentWithParentId( indexName,    _doc,bean,  parentId);
	}
1313973
public function createIndex($index = null)
    {
        if (!$this->elasticsearch->indices()->exists(['index' => $index['index']])) {
            return $this->elasticsearch->indices()->create($index);
        }
    }
794717
public function add()
    {
        $user = $this->Users->newEntity();

        if ($this->request->is('post')) {
            $user = $this->Users->patchEntity($user, $this->request->getData());

            if ($this->Users->save($user)) {
                $this->Flash->success(I18N_OPERATION_OK);

                return $this->redirect(['action' => 'index']);
            }

            $this->Flash->error(I18N_OPERATION_NOT_OK);
        }

        $this->set(compact('user'));
    }
111509
public function add() {
        $cmsTermTaxonomy = $this->CmsTermTaxonomy->newEntity();
        if ($this->request->is('post')) {
            $cmsTermTaxonomy = $this->CmsTermTaxonomy->patchEntity($cmsTermTaxonomy, $this->request->data);
            if ($this->CmsTermTaxonomy->save($cmsTermTaxonomy)) {
                $this->Flash->success('The cms term taxonomy has been saved.');
                return $this->redirect(['action' => 'index']);
            } else {
                $this->Flash->error('The cms term taxonomy could not be saved. Please, try again.');
            }
        }
        $cmsTerm = $this->CmsTermTaxonomy->CmsTerm->find('list', ['limit' => 200]);
        $this->set(compact('cmsTermTaxonomy', 'cmsTerm'));
        $this->set('_serialize', ['cmsTermTaxonomy']);
    }
729105
private function addMappings()
    {
        $indicesSettings = $this->indexSettings->getIndicesConfig();

        foreach ($this->_data as $requestName => $requestConfig) {
            $index = $requestConfig['index'];
            $this->_data[$requestName]['mapping'] = $indicesSettings[$index]['mapping'];
        }

        return $this;
    }
1193068
private function add_index($test, &$out, &$exts)
    {
        if (!empty($test['index'])) {
            array_push($exts, 'index');
            $out .= ' :index ' . intval($test['index']) . ($test['last'] ? ' :last' : '');
        }
    }
270429
protected function populateIndex($index)
    {
        $this->line('Populating the index « '.$index.' » ...');

        // Replaces the current default index by the one we want to populate
        $defaultIndex = Plastic::getDefaultIndex();
        Plastic::setDefaultIndex($index);

        // Disables query logging to prevent memory leak
        $logging = DB::connection()->logging();
        DB::connection()->disableQueryLog();

        // Populates from models
        $models = $this->models($index);
        $chunkSize = $this->chunkSize();
        foreach ($models as $model) {
            $this->line('Indexing documents of model « '.$model.' » ...');
            $model::chunk($chunkSize, function ($items) {
                $this->line('Indexing chunk of '.$items->count().' documents ...');
                Plastic::persist()->bulkSave($items);
            });
        }

        // Restores query logging
        if ($logging) {
            DB::connection()->enableQueryLog();
        }

        // Restores the current default index
        Plastic::setDefaultIndex($defaultIndex);
    }
1166384
public function IndexBy()
    {
        $this->match(Lexer::T_INDEX);
        $this->match(Lexer::T_BY);
        $pathExpr = $this->StateFieldPathExpression();

        // Add the INDEX BY info to the query component
        $this->queryComponents[$pathExpr->identificationVariable]['map'] = $pathExpr->field;

        return new AST\IndexBy($pathExpr);
    }
1267782
public function add_fields($query) {
        $documentclass = $this->get_document_classname();
        $fields = $documentclass::get_default_fields_definition();

        $dismax = false;
        if ($query instanceof \SolrDisMaxQuery) {
            $dismax = true;
        }

        foreach ($fields as $key => $field) {
            $query->addField($key);
            if ($dismax && !empty($field['mainquery'])) {
                // Add fields the main query should be run against.
                $query->addQueryField($key);
            }
        }
    }
53684
public function updateIndex()
    {
        $params = $this->getBasicEsParams();

        // Get our document body data.
        $params['body']['doc'] = $this->getIndexDocumentData();

        return $this->getElasticSearchClient()->update($params);
    }
376513
public function addDocuments(array $documents, string $opType = null): self
    {
        foreach ($documents as $document) {
            $this->addDocument($document, $opType);
        }

        return $this;
    }
762494
protected function _addIndex(Index $indexCandidate)
    {
        $indexName               = $indexCandidate->getName();
        $indexName               = $this->normalizeIdentifier($indexName);
        $replacedImplicitIndexes = [];

        foreach ($this->implicitIndexes as $name => $implicitIndex) {
            if (! $implicitIndex->isFullfilledBy($indexCandidate) || ! isset($this->_indexes[$name])) {
                continue;
            }

            $replacedImplicitIndexes[] = $name;
        }

        if ((isset($this->_indexes[$indexName]) && ! in_array($indexName, $replacedImplicitIndexes, true)) ||
            ($this->_primaryKeyName !== false && $indexCandidate->isPrimary())
        ) {
            throw SchemaException::indexAlreadyExists($indexName, $this->_name);
        }

        foreach ($replacedImplicitIndexes as $name) {
            unset($this->_indexes[$name], $this->implicitIndexes[$name]);
        }

        if ($indexCandidate->isPrimary()) {
            $this->_primaryKeyName = $indexName;
        }

        $this->_indexes[$indexName] = $indexCandidate;

        return $this;
    }
1304482
private function createIndex()
    {
        $basepath   = $this->config["basePath"];
        $pattern    = $this->config["pattern"];
        $path       = "$basepath/$pattern";

        $index = [];
        foreach (glob_recursive($path) as $file) {
            $filepath = substr($file, strlen($basepath) + 1);

            // Find content files
            $matches = [];
            preg_match($this->filenamePattern, basename($filepath), $matches);
            $dirpart = dirname($filepath) . "/";
            if ($dirpart === "./") {
                $dirpart = null;
            }
            $key = $dirpart . $matches[2];
            
            // Create level depending on the file id
            // TODO ciamge doc, can be replaced by __toc__ in meta?
            $id = (int) $matches[1];
            $level = 2;
            if ($id % 100 === 0) {
                $level = 0;
            } elseif ($id % 10 === 0) {
                $level = 1;
            }

            $index[$key] = [
                "file"     => $filepath,
                "section"  => $matches[1],
                "level"    => $level,  // TODO ?
                "internal" => $this->isInternalRoute($filepath),
                "tocable"  => $this->allowInToc($filepath),
            ];
        }

        return $index;
    }