setParam() public méthode

Possible options: _uid _id _type _source _all _analyzer _boost _parent _routing _index _size properties
public setParam ( string $key, mixed $value )
$key string Key name
$value mixed Key value
 /**
  * @return Status
  */
 public function validate()
 {
     $this->outputIndented("Validating mappings...");
     if ($this->optimizeIndexForExperimentalHighlighter && !in_array('experimental highlighter', $this->availablePlugins)) {
         $this->output("impossible!\n");
         return Status::newFatal(new RawMessage("wgCirrusSearchOptimizeIndexForExperimentalHighlighter is set to true but the " . "'experimental highlighter' plugin is not installed on all hosts."));
     }
     $requiredMappings = $this->mappingConfig;
     if (!$this->checkMapping($requiredMappings)) {
         /** @var Mapping[] $actions */
         $actions = array();
         // TODO Conflict resolution here might leave old portions of mappings
         foreach ($this->types as $typeName => $type) {
             $action = new Mapping($type);
             foreach ($requiredMappings[$typeName] as $key => $value) {
                 $action->setParam($key, $value);
             }
             $actions[] = $action;
         }
         try {
             foreach ($actions as $action) {
                 $action->send();
             }
             $this->output("corrected\n");
         } catch (ExceptionInterface $e) {
             $this->output("failed!\n");
             $message = ElasticsearchIntermediary::extractMessage($e);
             return Status::newFatal(new RawMessage("Couldn't update mappings.  Here is elasticsearch's error message: {$message}\n"));
         }
     }
     return Status::newGood();
 }
Exemple #2
0
 public function testParent()
 {
     $index = $this->_createIndex();
     $typeBlog = new Type($index, 'blog');
     $typeComment = new Type($index, 'comment');
     $mapping = new Mapping();
     $mapping->setParam('_parent', array('type' => 'blog'));
     $typeComment->setMapping($mapping);
     $entry1 = new Document(1);
     $entry1->set('title', 'Hello world');
     $typeBlog->addDocument($entry1);
     $entry2 = new Document(2);
     $entry2->set('title', 'Foo bar');
     $typeBlog->addDocument($entry2);
     $entry3 = new Document(3);
     $entry3->set('title', 'Till dawn');
     $typeBlog->addDocument($entry3);
     $comment = new Document(1);
     $comment->set('author', 'Max');
     $comment->setParent(2);
     // Entry Foo bar
     $typeComment->addDocument($comment);
     $index->optimize();
     $query = new HasChild('Max', 'comment');
     $resultSet = $typeBlog->search($query);
     $this->assertEquals(1, $resultSet->count());
     $this->assertEquals(array('title' => 'Foo bar'), $resultSet->current()->getData());
 }
 /**
  * @return Status
  */
 public function validate()
 {
     $this->outputIndented("Validating mappings...");
     if ($this->optimizeIndexForExperimentalHighlighter && !in_array('experimental highlighter', $this->availablePlugins)) {
         $this->output("impossible!\n");
         return Status::newFatal(new RawMessage("wgCirrusSearchOptimizeIndexForExperimentalHighlighter is set to true but the " . "'experimental highlighter' plugin is not installed on all hosts."));
     }
     $requiredMappings = $this->mappingConfig;
     if (!$this->checkMapping($requiredMappings)) {
         /** @var Mapping[] $actions */
         $actions = array();
         // TODO Conflict resolution here might leave old portions of mappings
         foreach ($this->types as $typeName => $type) {
             $action = new Mapping($type);
             foreach ($requiredMappings[$typeName] as $key => $value) {
                 $action->setParam($key, $value);
             }
             $actions[] = $action;
         }
         try {
             // @todo Use $action->send(array('master_timeout' => ...))
             // after updating to version of Elastica library that supports it.
             // See https://github.com/ruflin/Elastica/pull/1004
             foreach ($actions as $action) {
                 $action->getType()->request('_mapping', Request::PUT, $action->toArray(), array('master_timeout' => $this->masterTimeout));
             }
             $this->output("corrected\n");
         } catch (ExceptionInterface $e) {
             $this->output("failed!\n");
             $message = ElasticsearchIntermediary::extractMessage($e);
             return Status::newFatal(new RawMessage("Couldn't update mappings.  Here is elasticsearch's error message: {$message}\n"));
         }
     }
     return Status::newGood();
 }
 /**
  * @return \Elastica\Type\Mapping
  */
 public function getElasticaMapping()
 {
     $mapping = new Mapping();
     $mapping->setProperties($this->getElasticaFields());
     $mapping->setParam('date_detection', false);
     return $mapping;
 }
Exemple #5
0
 /**
  * @param \Elastica\Index $index
  * @param string $mappingName
  * @param array $mappingData
  *
  * @return void
  */
 protected function sendMapping(Index $index, $mappingName, array $mappingData)
 {
     $type = $index->getType($mappingName);
     $this->messenger->info(sprintf('Send mapping type "%s" (index: "%s")', $mappingName, $index->getName()));
     $mapping = new Mapping($type);
     foreach ($mappingData as $key => $value) {
         $mapping->setParam($key, $value);
     }
     $mapping->send();
 }
Exemple #6
0
 public function testParentMapping()
 {
     $index = $this->_createIndex();
     $parenttype = new Type($index, 'parenttype');
     $parentmapping = new Mapping($parenttype, array('name' => array('type' => 'string', 'store' => 'yes')));
     $parenttype->setMapping($parentmapping);
     $childtype = new Type($index, 'childtype');
     $childmapping = new Mapping($childtype, array('name' => array('type' => 'string', 'store' => 'yes')));
     $childmapping->setParam('_parent', array('type' => 'parenttype'));
     $childtype->setMapping($childmapping);
 }
Exemple #7
0
 /**
  * @param Schema $schema
  * @param string $defaultAnalyzer
  * @return Mapping
  */
 public function create(Schema $schema, $defaultAnalyzer = null)
 {
     $this->defaultAnalyzer = $defaultAnalyzer;
     $rootObject = new \stdClass();
     $rootObject->dynamic_templates = [];
     $mapping = new Mapping(null, $this->mapSchema($schema, $rootObject));
     foreach (get_object_vars($rootObject) as $k => $v) {
         if (!empty($v)) {
             $mapping->setParam($k, $v);
         }
     }
     return $mapping;
 }
Exemple #8
0
 /**
  * {@inheritDoc}
  */
 public function createType(ClassMetadata $metadata)
 {
     $type = $this->getIndex($metadata->index)->getType($metadata->type);
     $properties = $this->getMapping($metadata->fieldMappings);
     $rootProperties = $this->getRootMapping($metadata->rootMappings);
     $mapping = new Mapping($type, $properties);
     $mapping->disableSource($metadata->source);
     if (isset($metadata->boost)) {
         $mapping->setParam('_boost', array('name' => '_boost', 'null_value' => $metadata->boost));
     }
     if (isset($metadata->parent)) {
         $mapping->setParent($metadata->parent);
     }
     foreach ($rootProperties as $key => $value) {
         $mapping->setParam($key, $value);
     }
     $mapping->send();
     return $type;
 }
 /**
  * Create Elastica Analysis.
  *
  * @param object $index Elastica Index
  * @param array $posttypes Array containing all post types
  * @param array $terms Array containing all terms
  * @return object $index Elastica Index
  *
  * @since 3.0.0
  */
 protected function analysis($index, $posttypes, $terms)
 {
     //Check integrity
     if (empty($index)) {
         return null;
     }
     //Check integrity
     if (empty($posttypes) && empty($terms)) {
         return null;
     }
     //Define properties
     $props = array('id' => array('type' => 'integer', 'include_in_all' => false), 'tags' => array('type' => 'string', 'index' => 'analyzed'), 'parent' => array('type' => 'integer', 'index' => 'analyzed'), 'title' => array('type' => 'string', 'index' => 'analyzed'), 'content' => array('type' => 'string', 'index' => 'analyzed'), 'excerpt' => array('type' => 'string', 'index' => 'analyzed'), 'author' => array('type' => 'integer', 'index' => 'analyzed'), 'date' => array('type' => 'date', 'format' => 'date_time_no_millis'), 'tags_suggest' => array('type' => 'completion', 'analyzer' => 'simple', 'search_analyzer' => 'simple', 'payloads' => false), '_boost' => array('type' => 'float', 'include_in_all' => false));
     /**
      * Update props analysis.
      *
      * @param array $props
      *
      * @since 3.3.0
      */
     do_action('tto_plugin_search_analysis', $props);
     //Set analysis
     if (isset($posttypes) && !empty($posttypes)) {
         foreach ($posttypes as $k) {
             if (empty($k)) {
                 continue;
             }
             $index->create(array('number_of_shards' => 4, 'number_of_replicas' => 1, 'analysis' => array('analyzer' => array('indexAnalyzer' => array('type' => 'custom', 'tokenizer' => 'standard', 'filter' => array('lowercase', 'asciifolding', 'filter_' . $k)), 'searchAnalyzer' => array('type' => 'custom', 'tokenizer' => 'standard', 'filter' => array('standard', 'lowercase', 'asciifolding', 'filter_' . $k))), 'filter' => array('filter_' . $k => array('type' => 'standard', 'language' => TTO_LOCAL, 'ignoreCase' => true)))), true);
             //Define new Type
             $type = $index->getType($k);
             //Define a new Elastica Mapper
             $mapping = new Mapping();
             $mapping->setType($type);
             //$mapping->setParam('analyzer', 'indexAnalyzer');
             //$mapping->setParam('search_analyzer', 'searchAnalyzer');
             //Define boost field
             /*$mapping->setParam('_boost', array(
                   'name' => '_boost',
                   'null_value' => 1.0
               ));*/
             //Set mapping
             $mapping->setProperties($props);
             //Send mapping to type
             $mapping->send();
         }
     }
     //Set analysis
     if (isset($terms) && !empty($terms)) {
         foreach ($terms as $t) {
             if (empty($t)) {
                 continue;
             }
             $index->create(array('number_of_shards' => 4, 'number_of_replicas' => 1, 'analysis' => array('analyzer' => array('indexAnalyzer' => array('type' => 'custom', 'tokenizer' => 'standard', 'filter' => array('lowercase', 'asciifolding', 'filter_' . $t)), 'searchAnalyzer' => array('type' => 'custom', 'tokenizer' => 'standard', 'filter' => array('standard', 'lowercase', 'asciifolding', 'filter_' . $t))), 'filter' => array('filter_' . $t => array('type' => 'standard', 'language' => TTO_LOCAL, 'ignoreCase' => true)))), true);
             //Define new Type
             $type = $index->getType($t);
             //Define a new Elastica Mapper
             $mapping = new Mapping();
             $mapping->setType($type);
             $mapping->setParam('index_analyzer', 'indexAnalyzer');
             $mapping->setParam('search_analyzer', 'searchAnalyzer');
             //Define boost field
             $mapping->setParam('_boost', array('name' => '_boost', 'null_value' => 1.0));
             //Set mapping
             $mapping->setProperties($props);
             // Send mapping to type
             $mapping->send();
         }
     }
     //Return index
     return $index;
 }
 /**
  * Deletes and recreates a mapping type for the named index
  *
  * @param string $indexName
  * @param string $typeName
  * @throws \InvalidArgumentException if no index or type mapping exists for the given names
  * @throws ResponseException
  */
 public function resetIndexType($indexName, $typeName)
 {
     $typeConfig = $this->configManager->getTypeConfiguration($indexName, $typeName);
     $type = $this->indexManager->getIndex($indexName)->getType($typeName);
     try {
         $type->delete();
     } catch (ResponseException $e) {
         if (strpos($e->getMessage(), 'TypeMissingException') === false) {
             throw $e;
         }
     }
     $mapping = new Mapping();
     foreach ($this->mappingBuilder->buildTypeMapping($typeConfig) as $name => $field) {
         $mapping->setParam($name, $field);
     }
     $type->setMapping($mapping);
 }
 /**
  * @param Type $type
  * @param string $analyzer
  * @return Mapping
  */
 private function getTypeMapping(Type $type, $analyzer)
 {
     $mapping = new Mapping($type);
     $mapping->setParam('analyzer', $analyzer);
     $mapping->setProperties(['text' => ['type' => 'string', 'index' => 'analyzed', 'analyzer' => $analyzer], 'episode' => ['type' => 'object', 'properties' => ['id' => ['type' => 'integer'], 'number' => ['type' => 'integer'], 'name' => ['type' => 'string', 'index' => 'analyzed', 'analyzer' => $analyzer], 'slug' => ['type' => 'string', 'index' => 'not_analyzed']]], 'season' => ['type' => 'object', 'parameters' => ['id' => ['type' => 'integer'], 'number' => ['type' => 'integer']]], 'character' => ['type' => 'object', 'properties' => ['name' => ['type' => 'string', 'index' => 'not_analyzed'], 'slug' => ['type' => 'string', 'index' => 'not_analyzed']]], 'line' => ['type' => 'integer']]);
     return $mapping;
 }
Exemple #12
0
 /**
  * Deletes and recreates a mapping type for the named index.
  *
  * @param string $indexName
  * @param string $typeName
  *
  * @throws \InvalidArgumentException if no index or type mapping exists for the given names
  * @throws ResponseException
  */
 public function resetIndexType($indexName, $typeName)
 {
     $typeConfig = $this->configManager->getTypeConfiguration($indexName, $typeName);
     $index = $this->indexManager->getIndex($indexName);
     $type = $index->getType($typeName);
     $indexConfig = $this->configManager->getIndexConfiguration($indexName);
     $settings = $indexConfig->getSettings();
     $event = new TypeResetEvent($indexName, $typeName);
     $this->dispatcher->dispatch(TypeResetEvent::PRE_TYPE_RESET, $event);
     try {
         $type->delete();
     } catch (ResponseException $e) {
         if (strpos($e->getMessage(), 'TypeMissingException') === false) {
             throw $e;
         }
     }
     if (!empty($settings)) {
         $index->close();
         $index->setSettings($settings);
         $index->open();
     }
     $mapping = new Mapping();
     foreach ($this->mappingBuilder->buildTypeMapping($typeConfig) as $name => $field) {
         $mapping->setParam($name, $field);
     }
     $type->setMapping($mapping);
     $this->dispatcher->dispatch(TypeResetEvent::POST_TYPE_RESET, $event);
 }
 /**
  * Deletes and recreates a mapping type for the named index.
  *
  * @param string $indexName
  * @param string $typeName
  *
  * @throws \InvalidArgumentException if no index or type mapping exists for the given names
  * @throws ResponseException
  */
 public function resetIndexType($indexName, $typeName)
 {
     $typeConfig = $this->configManager->getTypeConfiguration($indexName, $typeName);
     $this->resetIndex($indexName, true);
     $index = $this->indexManager->getIndex($indexName);
     $type = $index->getType($typeName);
     $event = new TypeResetEvent($indexName, $typeName);
     $this->dispatcher->dispatch(TypeResetEvent::PRE_TYPE_RESET, $event);
     if (!empty($settings)) {
         unset($settings['number_of_shards']);
         $index->close();
         $index->setSettings($settings);
         $index->open();
     }
     $mapping = new Mapping();
     foreach ($this->mappingBuilder->buildTypeMapping($typeConfig) as $name => $field) {
         $mapping->setParam($name, $field);
     }
     $type->setMapping($mapping);
     $this->dispatcher->dispatch(TypeResetEvent::POST_TYPE_RESET, $event);
 }
Exemple #14
0
 /**
  * {@inheritdoc}
  */
 public function updateMapping(ClassMetadata $classMetadata)
 {
     try {
         $elasticaIndex = new Index($this->client, $classMetadata->getIndexForRead());
         $elasticaType = new Type($elasticaIndex, $classMetadata->type);
         $elasticaTypeMapping = new Mapping($elasticaType, $this->getMapping($classMetadata->fieldMappings));
         $elasticaTypeMapping->setParam('_id', array('path' => $classMetadata->getIdentifier()));
         if ($classMetadata->parent) {
             $elasticaTypeMapping->setParam('_parent', array('type' => $classMetadata->parent));
         }
         if ($classMetadata->dynamic) {
             $elasticaTypeMapping->setParam('dynamic', $classMetadata->dynamic);
         }
         $response = $elasticaType->setMapping($elasticaTypeMapping);
     } catch (\Exception $e) {
         return $e->getMessage();
     }
     return 200 == $response->getStatus() ? true : $response->getError();
 }
 /**
  * @dataProvider providerTransport
  */
 public function testGetMapping(array $config, $transport)
 {
     $client = new Client($config);
     $index = $client->getIndex('test');
     $index->create(array(), true);
     $type = $index->getType('mappingTest');
     // Define mapping
     $mapping = new Mapping();
     $mapping->setParam('_boost', array('name' => '_boost', 'null_value' => 1.0));
     $mapping->setProperties(array('id' => array('type' => 'integer', 'include_in_all' => FALSE), 'user' => array('type' => 'object', 'properties' => array('name' => array('type' => 'string', 'include_in_all' => TRUE), 'fullName' => array('type' => 'string', 'include_in_all' => TRUE))), 'msg' => array('type' => 'string', 'include_in_all' => TRUE), 'tstamp' => array('type' => 'date', 'include_in_all' => FALSE), 'location' => array('type' => 'geo_point', 'include_in_all' => FALSE), '_boost' => array('type' => 'float', 'include_in_all' => FALSE)));
     $type->setMapping($mapping);
     $index->refresh();
     $times = array();
     for ($i = 0; $i < $this->_max; $i++) {
         $response = $type->request('_mapping', Request::GET);
         $times[] = $response->getQueryTime();
     }
     self::logResults('get mapping', $transport, $times);
 }
 /**
  * Return default search fields mapping for node translations
  *
  * @param Index  $index
  * @param string $lang
  *
  * @return Mapping
  */
 protected function getMapping(Index $index, $lang = 'en')
 {
     $mapping = new Mapping();
     $mapping->setType($index->getType($this->indexType . '_' . $lang));
     $mapping->setParam('analyzer', 'index_analyzer_' . $lang);
     $mapping->setParam('_boost', array('name' => '_boost', 'null_value' => 1.0));
     $mapping->setProperties($this->properties);
     return $mapping;
 }
 /**
  * Define all known mappings
  */
 protected function createMappings(\Elastica\Index $index)
 {
     foreach ($this->getIndexedClasses() as $class) {
         /** @var $sng Searchable */
         $sng = singleton($class);
         $type = $sng->getElasticaType();
         if (isset($this->mappings[$type])) {
             // captured later
             continue;
         }
         $mapping = $sng->getElasticaMapping();
         $mapping->setType($index->getType($type));
         $mapping->send();
     }
     if ($this->mappings) {
         foreach ($this->mappings as $type => $fields) {
             $mapping = new Mapping();
             $mapping->setProperties($fields);
             $mapping->setParam('date_detection', false);
             $mapping->setType($index->getType($type));
             $mapping->send();
         }
     }
 }
Exemple #18
0
 /**
  * @group functional
  */
 public function testGetters()
 {
     $index = $this->_createIndex();
     $type = $index->getType('test');
     $properties = array('firstname' => array('type' => 'string', 'store' => true), 'lastname' => array('type' => 'string'));
     $mapping = new Mapping($type, $properties);
     $all = array('enabled' => true, 'store' => true);
     $mapping->setParam('_all', $all);
     $get_all = $mapping->getParam('_all');
     $this->assertEquals($get_all, $all);
     $this->assertNull($mapping->getParam('_boost', $all));
     $this->assertEquals($properties, $mapping->getProperties());
     $index->delete();
 }
 /**
  * @param Index $elasticaIndex
  */
 protected function setMapping(Index $elasticaIndex)
 {
     foreach ($this->configuration->getTypes() as $typeName) {
         $mapping = new Mapping();
         $type = $elasticaIndex->getType($typeName);
         $mapping->setType($type);
         // Set properties
         if ($properties = $this->configuration->getMappingProperties($type)) {
             $mapping->setProperties($properties);
         }
         // Set params if any
         if ($mappingParams = $this->configuration->getMappingParams($type)) {
             foreach ($mappingParams as $mappingParam => $mappingParamValue) {
                 $mapping->setParam($mappingParam, $mappingParamValue);
             }
         }
         if ($mappingParams || $properties) {
             $mapping->send();
         }
     }
 }