getType() 공개 메소드

Returns a type object for the current index with the given name.
public getType ( string $type ) : Type
$type string Type name
리턴 Type Type object
 /**
  * До любых других действий
  */
 public function initialize()
 {
     $currentActionName = $this->dispatcher->getActiveMethod();
     $annotations = $this->annotations->getMethod(self::class, $currentActionName);
     if ($annotations->has('actionInfo')) {
         $annotation = $annotations->get('actionInfo');
         $actionTitle = $annotation->getNamedArgument('name');
         $this->log->info('Запустили: {actionTitle}', ['actionTitle' => $actionTitle]);
     } else {
         $currentTaskName = $this->dispatcher->getTaskName();
         $this->log->info('Запустили: {currentTaskName}::{currentActionName}', ['currentTaskName' => $currentTaskName, 'currentActionName' => $currentActionName]);
     }
     $this->indexName = $this->dispatcher->getParam('index', 'string', false);
     $this->typeName = $this->dispatcher->getParam('type', 'string', false);
     if (!$this->indexName) {
         $this->log->error('Указание индекса является обязательным параметром');
         die;
     }
     $this->sizePerShard = $this->dispatcher->getParam('sizePerShard', 'int', false) ?: $this->sizePerShard;
     $this->elasticsearchHost = $this->dispatcher->getParam('host', 'string', false) ?: $this->elasticsearchHost;
     $this->elasticsearchPort = $this->dispatcher->getParam('port', 'int', false) ?: $this->elasticsearchPort;
     $connectParams = ['host' => $this->elasticsearchHost, 'port' => $this->elasticsearchPort];
     $this->client = new Client($connectParams);
     try {
         $this->client->getStatus();
     } catch (\Elastica\Exception\Connection\HttpException $e) {
         $context = ['host' => $this->elasticsearchHost, 'port' => $this->elasticsearchPort];
         $this->log->error('Подключение к серверу elasticsearch отсутствует: http://{host}:{port}', $context);
         die;
     }
     $this->elasticaIndex = $this->client->getIndex($this->indexName);
     $this->elasticaType = $this->elasticaIndex->getType($this->typeName);
 }
 /**
  * @param array $dataSet
  *
  * @return bool
  */
 public function write(array $dataSet)
 {
     $type = $this->index->getType($this->type);
     $type->updateDocuments($this->createDocuments($dataSet));
     $response = $type->getIndex()->refresh();
     return $response->isOk();
 }
예제 #3
0
 public function testGetDocument()
 {
     $type = self::$index->getType('message');
     $document = $type->getDocument(1);
     $message = $this->marshaler->unmarshal($document);
     $this->assertTrue($this->message->equals($message));
 }
 protected function setUp()
 {
     parent::setUp();
     $this->_index = $this->_createIndex("simple_query_string_test");
     $docs = array(new Document(1, array('make' => 'Gibson', 'model' => 'Les Paul')), new Document(2, array('make' => 'Gibson', 'model' => 'SG Standard')), new Document(3, array('make' => 'Gibson', 'model' => 'SG Supreme')), new Document(4, array('make' => 'Gibson', 'model' => 'SG Faded')), new Document(5, array('make' => 'Fender', 'model' => 'Stratocaster')));
     $this->_index->getType("guitars")->addDocuments($docs);
     $this->_index->refresh();
 }
예제 #5
0
 protected function setUp()
 {
     parent::setUp();
     $this->_index = $this->_createIndex("query");
     $docs = array(new Document("1", array("color" => "green", "make" => "ford")), new Document("2", array("color" => "blue", "make" => "volvo")), new Document("3", array("color" => "red", "make" => "ford")), new Document("4", array("color" => "green", "make" => "renault")));
     $this->_index->getType("test")->addDocuments($docs);
     $this->_index->refresh();
 }
 public function createMapping()
 {
     // Define mapping
     $mapping = new \Elastica\Type\Mapping();
     $mapping->setType($this->trackIndex->getType('track'));
     // Set mapping
     $mapping->setProperties(['id' => ['type' => 'integer', 'include_in_all' => false], 'album' => ['type' => 'object', 'properties' => ['id' => ['type' => 'integer', 'include_in_all' => true], 'title' => ['type' => 'string', 'include_in_all' => true]]], 'name' => ['type' => 'string', 'include_in_all' => true], 'name_not_analyzed' => ['type' => 'string', "index" => "not_analyzed"], 'playList' => ['type' => 'nested', 'properties' => ['id' => ['type' => 'integer', 'include_in_all' => true], 'name' => ['type' => 'string', 'include_in_all' => true]]], 'genre' => ['type' => 'object', 'properties' => ['id' => ['type' => 'integer', 'include_in_all' => true], 'name' => ['type' => 'string', 'include_in_all' => true]]], 'mediaType' => ['type' => 'object', 'properties' => ['id' => ['type' => 'integer', 'include_in_all' => true], 'name' => ['type' => 'string', 'include_in_all' => true]]], 'composer' => ['type' => 'string', 'include_in_all' => true]]);
     // Send mapping to type
     $mapping->send();
 }
 protected function setUp()
 {
     parent::setUp();
     $this->index = $this->_createIndex('test_functionscore');
     $this->type = $this->index->getType('test');
     $this->type->setMapping(array('name' => array('type' => 'string', 'index' => 'not_analyzed'), 'location' => array('type' => 'geo_point'), 'price' => array('type' => 'float')));
     $this->type->addDocument(new Document(1, array('name' => "Mr. Frostie's", 'location' => array('lat' => 32.799605, 'lon' => -117.243027), 'price' => 4.5)));
     $this->type->addDocument(new Document(2, array('name' => "Miller's Field", 'location' => array('lat' => 32.795964, 'lon' => -117.255028), 'price' => 9.5)));
     $this->index->refresh();
 }
 protected function setUp()
 {
     parent::setUp();
     $this->index = $this->_createIndex('test_boostingquery');
     $this->type = $this->index->getType('test');
     $this->type->setMapping(array('name' => array('type' => 'string', 'index' => 'analyzed'), 'price' => array('type' => 'float')));
     $this->sampleData = array(array("name" => "Vital Lama", "price" => 5.2), array("name" => "Vital Match", "price" => 2.1), array("name" => "Mercury Vital", "price" => 7.5), array("name" => "Fist Mercury", "price" => 3.8), array("name" => "Lama Vital 2nd", "price" => 3.2));
     foreach ($this->sampleData as $key => $value) {
         $this->type->addDocument(new Document($key, $value));
     }
     $this->index->refresh();
 }
예제 #9
0
 protected function setUp()
 {
     parent::setUp();
     $this->_index1 = $this->_createIndex('indices_filter_1');
     $this->_index2 = $this->_createIndex('indices_filter_2');
     $this->_index1->addAlias("indices_filter");
     $this->_index2->addAlias("indices_filter");
     $docs = array(new Document("1", array("color" => "blue")), new Document("2", array("color" => "green")), new Document("3", array("color" => "blue")), new Document("4", array("color" => "yellow")));
     $this->_index1->getType("test")->addDocuments($docs);
     $this->_index2->getType("test")->addDocuments($docs);
     $this->_index1->refresh();
     $this->_index2->refresh();
 }
 protected function setUp()
 {
     parent::setUp();
     $this->_index = $this->_createIndex('test_suggest_phrase');
     $docs = array();
     $docs[] = new Document(1, array('text' => 'Github is pretty cool'));
     $docs[] = new Document(2, array('text' => 'Elasticsearch is bonsai cool'));
     $docs[] = new Document(3, array('text' => 'This is a test phrase'));
     $docs[] = new Document(4, array('text' => 'Another sentence for testing'));
     $docs[] = new Document(5, array('text' => 'Some more words here'));
     $type = $this->_index->getType(self::TEST_TYPE);
     $type->addDocuments($docs);
     $this->_index->refresh();
 }
 protected function setUp()
 {
     parent::setUp();
     $this->_index = $this->_createIndex('test_suggest');
     $docs = array();
     $docs[] = new Document(1, array('id' => 1, 'text' => 'GitHub'));
     $docs[] = new Document(2, array('id' => 1, 'text' => 'Elastic'));
     $docs[] = new Document(3, array('id' => 1, 'text' => 'Search'));
     $docs[] = new Document(4, array('id' => 1, 'text' => 'Food'));
     $docs[] = new Document(5, array('id' => 1, 'text' => 'Flood'));
     $docs[] = new Document(6, array('id' => 1, 'text' => 'Folks'));
     $type = $this->_index->getType(self::TEST_TYPE);
     $type->addDocuments($docs);
     $this->_index->refresh();
 }
예제 #12
0
 /**
  * Get an elasticsearch type from its index.
  *
  * @param string $type
  * @return \Elastica\Type
  */
 protected function getType($type)
 {
     if (!isset($this->index)) {
         $this->index = $this->newIndex();
     }
     return $this->index->getType($type);
 }
예제 #13
0
 public function getType($type)
 {
     if (isset($this->typeCache[$type])) {
         return $this->typeCache[$type];
     }
     return $this->typeCache[$type] = parent::getType($type);
 }
예제 #14
0
 /**
  * @param array $dataSet
  *
  * @throws \Spryker\Zed\Collector\Business\Exporter\Exception\InvalidDataSetException
  *
  * @return bool
  */
 public function delete(array $dataSet)
 {
     if ($this->hasIntegerKeys($dataSet)) {
         throw new InvalidDataSetException();
     }
     try {
         $documents = [];
         foreach ($dataSet as $key => $value) {
             $documents[] = $this->index->getType($this->type)->getDocument($key);
         }
         $response = $this->index->deleteDocuments($documents);
         $this->index->flush(true);
         return $response->isOk();
     } catch (\Exception $exception) {
         return true;
     }
 }
예제 #15
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();
 }
예제 #16
0
 /**
  * @group unit
  */
 public function testSetType()
 {
     $document = new Document();
     $document->setType('type');
     $this->assertEquals('type', $document->getType());
     $index = new Index($this->_getClient(), 'index');
     $type = $index->getType('type');
     $document->setIndex('index2');
     $this->assertEquals('index2', $document->getIndex());
     $document->setType($type);
     $this->assertEquals('index', $document->getIndex());
     $this->assertEquals('type', $document->getType());
 }
 /**
  * @group functional
  */
 public function testSnapshotAndRestore()
 {
     $repositoryName = 'testrepo';
     $location = $this->_snapshotPath . 'backup2';
     // register the repository
     $response = $this->_snapshot->registerRepository($repositoryName, 'fs', array('location' => $location));
     $this->assertTrue($response->isOk());
     // create a snapshot of our test index
     $snapshotName = 'test_snapshot_1';
     $response = $this->_snapshot->createSnapshot($repositoryName, $snapshotName, array('indices' => $this->_index->getName()), true);
     // ensure that the snapshot was created properly
     $this->assertTrue($response->isOk());
     $this->assertArrayHasKey('snapshot', $response->getData());
     $data = $response->getData();
     $this->assertContains($this->_index->getName(), $data['snapshot']['indices']);
     $this->assertEquals(1, sizeof($data['snapshot']['indices']));
     // only the specified index should be present
     $this->assertEquals($snapshotName, $data['snapshot']['snapshot']);
     // retrieve data regarding the snapshot
     $response = $this->_snapshot->getSnapshot($repositoryName, $snapshotName);
     $this->assertContains($this->_index->getName(), $response['indices']);
     // delete our test index
     $this->_index->delete();
     // restore the index from our snapshot
     $response = $this->_snapshot->restoreSnapshot($repositoryName, $snapshotName, array(), true);
     $this->assertTrue($response->isOk());
     $this->_index->refresh();
     $this->_index->optimize();
     // ensure that the index has been restored
     $count = $this->_index->getType('test')->count();
     $this->assertEquals(sizeof($this->_docs), $count);
     // delete the snapshot
     $response = $this->_snapshot->deleteSnapshot($repositoryName, $snapshotName);
     $this->assertTrue($response->isOk());
     // ensure that the snapshot has been deleted
     $this->setExpectedException('Elastica\\Exception\\NotFoundException');
     $this->_snapshot->getSnapshot($repositoryName, $snapshotName);
 }
 public function testSnapshotAndRestore()
 {
     $repositoryName = "test_repository";
     $location = "/tmp/{$repositoryName}";
     // register the repository
     $response = $this->_snapshot->registerRepository($repositoryName, "fs", array("location" => $location));
     $this->assertTrue($response->isOk());
     // create a snapshot of our test index
     $snapshotName = "test_snapshot_1";
     $response = $this->_snapshot->createSnapshot($repositoryName, $snapshotName, array("indices" => $this->_index->getName()), true);
     // ensure that the snapshot was created properly
     $this->assertTrue($response->isOk());
     $this->assertArrayHasKey("snapshot", $response->getData());
     $data = $response->getData();
     $this->assertContains($this->_index->getName(), $data["snapshot"]["indices"]);
     $this->assertEquals(1, sizeof($data["snapshot"]["indices"]));
     // only the specified index should be present
     $this->assertEquals($snapshotName, $data["snapshot"]["snapshot"]);
     // retrieve data regarding the snapshot
     $response = $this->_snapshot->getSnapshot($repositoryName, $snapshotName);
     $this->assertContains($this->_index->getName(), $response["indices"]);
     // delete our test index
     $this->_index->delete();
     // restore the index from our snapshot
     $response = $this->_snapshot->restoreSnapshot($repositoryName, $snapshotName, array(), true);
     $this->assertTrue($response->isOk());
     $this->_index->refresh();
     $this->_index->optimize();
     // ensure that the index has been restored
     $count = $this->_index->getType("test")->count();
     $this->assertEquals(sizeof($this->_docs), $count);
     // delete the snapshot
     $response = $this->_snapshot->deleteSnapshot($repositoryName, $snapshotName);
     $this->assertTrue($response->isOk());
     // ensure that the snapshot has been deleted
     $this->setExpectedException('Elastica\\Exception\\NotFoundException');
     $this->_snapshot->getSnapshot($repositoryName, $snapshotName);
 }
예제 #19
0
 protected function setUp()
 {
     $typeName = Cache::TYPE_NAME;
     $this->type = $this->prophesize('\\Elastica\\Type');
     $this->type->request(Argument::any(), Argument::cetera())->willReturn(true);
     $this->type->getName()->willReturn($typeName);
     $this->index = $this->prophesize('\\Elastica\\Index');
     $this->index->getType($typeName)->willReturn($this->type->reveal());
     $this->index->exists()->willReturn(true);
     $nsDoc = new Document('DoctrineNamespaceCacheKey[]', [Cache::VALUE_FIELD => serialize($this->namespaceId)]);
     $this->type->getIndex()->willReturn($this->index->reveal());
     $this->type->getDocument("DoctrineNamespaceCacheKey[]")->willReturn($nsDoc);
     $this->client = $this->prophesize('\\Elastica\\Client');
     $this->client->getIndex($this->indexName)->willReturn($this->index->reveal());
     $this->cache = new Cache($this->client->reveal(), ['index' => $this->indexName]);
 }
 /**
  * Remove a Resource from the ElasticSearch index.
  *
  * @param string|int $id
  * @return boolean
  */
 public function removeIndex($id)
 {
     $this->modx->log(modX::LOG_LEVEL_DEBUG, '[SimpleSearch] Removing Resource From Index: ' . $id);
     /** @var modResource $resource */
     $resource = $this->modx->getObject('modResource', $id);
     if ($resource) {
         $typeName = $resource->context_key;
     } else {
         $typeName = 'web';
     }
     $type = $this->index->getType($typeName);
     try {
         $type->deleteById($id);
     } catch (Exception $e) {
     }
     $type->getIndex()->refresh();
 }
예제 #21
0
 /**
  * @param string $key
  * @param string $type
  *
  * @return \Elastica\Document
  */
 public function getDocument($key, $type)
 {
     return $this->index->getType($type)->getDocument($key);
 }
 /**
  * @param ReadNodeInterface $node
  * @param Index             $index
  */
 protected function indexDocument($node, Index $index)
 {
     $type = $index->getType(NodeSchemaGenerator::INDEX_TYPE);
     $document = $this->transformer->transform($node);
     $type->addDocument($document);
 }
예제 #23
0
 /**
  * @param Index $index
  * @param null $typeName
  * @return Type
  */
 protected function getType(Index $index, $typeName)
 {
     if (isset($this->types[$typeName])) {
         return $this->types[$typeName];
     }
     return $this->types[$typeName] = $index->getType($typeName);
 }
 /**
  * @param ContentInterface $content
  * @param Index            $index
  */
 protected function indexDocument($content, Index $index)
 {
     $type = $index->getType(ContentTypeSchemaGenerator::INDEX_TYPE . $content->getContentType());
     $document = $this->transformer->transform($content);
     $type->addDocument($document);
 }
예제 #25
0
 /**
  * @return \Elastica\Type
  */
 public function getType()
 {
     return $this->index->getType($this->typeName);
 }
 /**
  * Return default search fields mapping for node translations
  *
  * @param Index  $index
  * @param string $lang
  *
  * @return Mapping
  */
 protected function createDefaultSearchFieldsMapping(Index $index, $lang = 'en')
 {
     $mapping = new Mapping();
     $mapping->setType($index->getType($this->indexType));
     $mapping->setProperties($this->properties);
     return $mapping;
 }
 /**
  * Deletes all timestamps. Parameter $dataSet is ignored.
  * TODO Needs refactoring
  *
  * @param array $dataSet
  *
  * @return void
  */
 public function delete(array $dataSet)
 {
     $mapping = new Mapping($this->index->getType($this->type));
     $mapping->setMeta(['' => ''])->send();
     // Empty mapping causes ClassCastException[java.util.ArrayList cannot be cast to java.util.Map]
 }
 /**
  * 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();
         }
     }
 }
 /**
  * Return default search fields mapping for node translations
  *
  * @param \Elastica\Index $index
  * @param string          $lang
  *
  * @return \Elastica\Type\Mapping
  */
 protected function getMapping(\Elastica\Index $index, $lang = 'en')
 {
     $mapping = new \Elastica\Type\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(array('node_id' => array('type' => 'integer', 'include_in_all' => false, 'index' => 'not_analyzed'), 'nodetranslation_id' => array('type' => 'integer', 'include_in_all' => false, 'index' => 'not_analyzed'), 'nodeversion_id' => array('type' => 'integer', 'include_in_all' => false, 'index' => 'not_analyzed'), 'title' => array('type' => 'string', 'include_in_all' => true), 'lang' => array('type' => 'string', 'include_in_all' => true, 'index' => 'not_analyzed'), 'slug' => array('type' => 'string', 'include_in_all' => false, 'index' => 'not_analyzed'), 'type' => array('type' => 'string', 'include_in_all' => false, 'index' => 'not_analyzed'), 'page_class' => array('type' => 'string', 'include_in_all' => false, 'index' => 'not_analyzed'), 'contentanalyzer' => array('type' => 'string', 'include_in_all' => true, 'index' => 'not_analyzed'), 'content' => array('type' => 'string', 'include_in_all' => true), 'created' => array('type' => 'date', 'include_in_all' => false, 'index' => 'not_analyzed'), 'updated' => array('type' => 'date', 'include_in_all' => false, 'index' => 'not_analyzed'), 'view_roles' => array('type' => 'string', 'include_in_all' => true, 'index' => 'not_analyzed', 'index_name' => 'view_role'), '_boost' => array('type' => 'float', 'include_in_all' => false)));
     return $mapping;
 }