Exemple #1
0
 public function populateIndex(BulkOperation $bulk, array $databoxes)
 {
     foreach ($databoxes as $databox) {
         /** @var databox $databox */
         $databoxId = $databox->get_sbas_id();
         $visitor = new TermVisitor(function ($term) use($bulk, $databoxId) {
             // Path and id are prefixed with a databox identifier to not
             // collide with other databoxes terms
             // Term structure
             $id = sprintf('%s_%s', $databoxId, $term['id']);
             unset($term['id']);
             $term['path'] = sprintf('/%s%s', $databoxId, $term['path']);
             $term['databox_id'] = $databoxId;
             // Index request
             $params = array();
             $params['id'] = $id;
             $params['type'] = self::TYPE_NAME;
             $params['body'] = $term;
             $bulk->index($params, null);
         });
         $document = Helper::thesaurusFromDatabox($databox);
         $this->navigator->walk($document, $visitor);
     }
 }
Exemple #2
0
 private function apply(Closure $work)
 {
     $this->disableShardRefreshing();
     try {
         // Prepare the bulk operation
         $bulk = new BulkOperation($this->client, $this->logger);
         $bulk->setDefaultIndex($this->options->getIndexName());
         $bulk->setAutoFlushLimit(1000);
         // Do the work
         $work($bulk);
         // Flush just in case, it's a noop when already done
         $bulk->flush();
         $this->restoreShardRefreshing();
     } catch (\Exception $e) {
         $this->restoreShardRefreshing();
         throw $e;
     }
 }
 private function indexFromFetcher(BulkOperation $bulk, Fetcher $fetcher, array &$submited_records)
 {
     /** @var RecordInterface $record */
     while ($record = $fetcher->fetch()) {
         $op_identifier = $this->getUniqueOperationId($record['id']);
         $params = array();
         $params['id'] = $record['id'];
         unset($record['id']);
         $params['type'] = self::TYPE_NAME;
         $params['body'] = $record;
         $submited_records[$op_identifier] = $record;
         $bulk->index($params, $op_identifier);
     }
 }