Beispiel #1
0
 public function fire(Job $job, $models)
 {
     $loggerContainerBinding = $this->config->get('logger', 'menthol.flexible.logger');
     $logger = $this->app->make($loggerContainerBinding);
     foreach ($models as $model) {
         list($class, $id) = explode(':', $model);
         $logger->info('Indexing ' . $class . ' with ID: ' . $id);
         try {
             $model = $class::findOrFail($id);
             if (method_exists($model, 'getProxy')) {
                 $model->refreshDoc($model);
             }
         } catch (Exception $e) {
             $logger->error('Indexing ' . $class . ' with ID: ' . $id . ' failed: ' . $e->getMessage());
             $job->release(60);
         }
     }
     $job->delete();
 }
Beispiel #2
0
 /**
  * Initialize the default index settings and mappings
  *
  * @return array
  */
 private function getDefaultIndexParams()
 {
     $analyzers = self::$config->get('elasticsearch.analyzers');
     $params = self::$config->get('elasticsearch.defaults.index');
     $mapping = [];
     $mapping_options = array_combine($analyzers, array_map(function ($type) {
         $config = $this->getProxy()->getConfig();
         // Maintain backwards compatibility by allowing a plain array of analyzer => fields
         $field_mappings = Utils::findKey($config, $type, false) ?: [];
         // Also read from a dedicated array key called 'analyzers'
         if (isset($config['analyzers'])) {
             $field_mappings = array_merge($field_mappings, Utils::findKey($config['analyzers'], $type, false) ?: []);
         }
         return $field_mappings;
     }, $analyzers));
     foreach (array_unique(array_flatten(array_values($mapping_options))) as $field) {
         // Extract path segments from dot separated field
         $pathSegments = explode('.', $field);
         // Last element is the field name
         $fieldName = array_pop($pathSegments);
         // Apply default field mapping
         $fieldMapping = ['type' => "multi_field", 'fields' => [$fieldName => ['type' => 'string', 'index' => 'not_analyzed'], 'analyzed' => ['type' => 'string', 'index' => 'analyzed']]];
         // Check if we need to add additional mappings
         foreach ($mapping_options as $type => $fields) {
             if (in_array($field, $fields)) {
                 $fieldMapping['fields'][$type] = ['type' => 'string', 'index' => 'analyzed', 'analyzer' => "flexible_{$type}_index"];
             }
         }
         if (!empty($pathSegments)) {
             $mapping = Utils::array_merge_recursive_distinct($mapping, $this->getNestedFieldMapping($fieldName, $fieldMapping, $pathSegments));
         } else {
             $mapping[$fieldName] = $fieldMapping;
         }
     }
     if (!empty($mapping)) {
         $params['mappings']['_default_']['properties'] = $mapping;
     }
     $params['index'] = $this->getName();
     $params['type'] = $this->getProxy()->getType();
     return $params;
 }