当前位置: 首页>>代码示例>>PHP>>正文


PHP Type::setMapping方法代码示例

本文整理汇总了PHP中Elastica\Type::setMapping方法的典型用法代码示例。如果您正苦于以下问题:PHP Type::setMapping方法的具体用法?PHP Type::setMapping怎么用?PHP Type::setMapping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Elastica\Type的用法示例。


在下文中一共展示了Type::setMapping方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUp

 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();
 }
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:10,代码来源:FunctionScoreTest.php

示例2: setUp

 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();
 }
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:12,代码来源:BoostingTest.php

示例3: testSearch

 /**
  * @group functional
  */
 public function testSearch()
 {
     $client = $this->_getClient();
     $index = new Index($client, 'test');
     $index->create(array(), true);
     $index->getSettings()->setNumberOfReplicas(0);
     //$index->getSettings()->setNumberOfShards(1);
     $type = new Type($index, 'helloworldmlt');
     $mapping = new Mapping($type, array('email' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed'), 'content' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed')));
     $mapping->setSource(array('enabled' => false));
     $type->setMapping($mapping);
     $doc = new Document(1000, array('email' => 'testemail@gmail.com', 'content' => 'This is a sample post. Hello World Fuzzy Like This!'));
     $type->addDocument($doc);
     $doc = new Document(1001, array('email' => 'nospam@gmail.com', 'content' => 'This is a fake nospam email address for gmail'));
     $type->addDocument($doc);
     // Refresh index
     $index->refresh();
     $mltQuery = new MoreLikeThis();
     $mltQuery->setLike('fake gmail sample');
     $mltQuery->setFields(array('email', 'content'));
     $mltQuery->setMaxQueryTerms(3);
     $mltQuery->setMinDocFrequency(1);
     $mltQuery->setMinTermFrequency(1);
     $query = new Query();
     $query->setQuery($mltQuery);
     $resultSet = $type->search($query);
     $resultSet->getResponse()->getData();
     $this->assertEquals(2, $resultSet->count());
 }
开发者ID:makeandship,项目名称:wordpress-fantastic-elasticsearch,代码行数:32,代码来源:MoreLikeThisTest.php

示例4: testNoSource

 public function testNoSource()
 {
     $index = $this->_createIndex();
     $type = new Type($index, 'user');
     $mapping = new Mapping($type, array('id' => array('type' => 'integer', 'store' => 'yes'), 'username' => array('type' => 'string', 'store' => 'no')));
     $mapping->setSource(array('enabled' => false));
     $type->setMapping($mapping);
     $mapping = $type->getMapping();
     $this->assertArrayHasKey('user', $mapping);
     $this->assertArrayHasKey('properties', $mapping['user']);
     $this->assertArrayHasKey('id', $mapping['user']['properties']);
     $this->assertArrayHasKey('type', $mapping['user']['properties']['id']);
     $this->assertEquals('integer', $mapping['user']['properties']['id']['type']);
     // Adds 1 document to the index
     $doc1 = new Document(1, array('username' => 'hans', 'test' => array('2', '3', '5')));
     $type->addDocument($doc1);
     // Adds a list of documents with _bulk upload to the index
     $docs = array();
     $docs[] = new Document(2, array('username' => 'john', 'test' => array('1', '3', '6')));
     $docs[] = new Document(3, array('username' => 'rolf', 'test' => array('2', '3', '7')));
     $type->addDocuments($docs);
     // To update index
     $index->refresh();
     $resultSet = $type->search('rolf');
     $this->assertEquals(1, $resultSet->count());
     // Tests if no source is in response except id
     $result = $resultSet->current();
     $this->assertEquals(3, $result->getId());
     $this->assertEmpty($result->getData());
 }
开发者ID:kskod,项目名称:Elastica,代码行数:30,代码来源:TypeTest.php

示例5: testParentMapping

 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);
 }
开发者ID:kskod,项目名称:Elastica,代码行数:11,代码来源:MappingTest.php

示例6: testSearch

 public function testSearch()
 {
     $client = $this->_getClient();
     $index = new Index($client, 'test');
     $index->create(array(), true);
     $index->getSettings()->setNumberOfReplicas(0);
     //$index->getSettings()->setNumberOfShards(1);
     $type = new Type($index, 'helloworldfuzzy');
     $mapping = new Mapping($type, array('email' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed'), 'content' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed')));
     $mapping->setSource(array('enabled' => false));
     $type->setMapping($mapping);
     $doc = new Document(1000, array('email' => 'testemail@gmail.com', 'content' => 'This is a sample post. Hello World Fuzzy Like This!'));
     $type->addDocument($doc);
     // Refresh index
     $index->refresh();
     $fltQuery = new FuzzyLikeThis();
     $fltQuery->setLikeText("sample gmail");
     $fltQuery->addFields(array("email", "content"));
     $fltQuery->setMinSimilarity(0.3);
     $fltQuery->setMaxQueryTerms(3);
     $resultSet = $type->search($fltQuery);
     $this->assertEquals(1, $resultSet->count());
 }
开发者ID:kskod,项目名称:Elastica,代码行数:23,代码来源:FuzzyLikeThisTest.php

示例7: testParentMapping

 /**
  * @group functional
  */
 public function testParentMapping()
 {
     $index = $this->_createIndex();
     $childtype = new Type($index, 'childtype');
     $childmapping = new Mapping($childtype, array('name' => array('type' => 'string', 'store' => true)));
     $childmapping->setParent('parenttype');
     $childtype->setMapping($childmapping);
     $data = $childmapping->toArray();
     $this->assertEquals('parenttype', $data[$childtype->getName()]['_parent']['type']);
     $parenttype = new Type($index, 'parenttype');
     $parentmapping = new Mapping($parenttype, array('name' => array('type' => 'string', 'store' => true)));
     $parenttype->setMapping($parentmapping);
 }
开发者ID:zhangxiaoliu,项目名称:Elastica,代码行数:16,代码来源:MappingTest.php

示例8: testAddWordxFile

 public function testAddWordxFile()
 {
     $indexMapping = array('file' => array('type' => 'attachment'), 'text' => array('type' => 'string', 'store' => 'no'));
     $indexParams = array('index' => array('number_of_shards' => 1, 'number_of_replicas' => 0));
     $index = $this->_createIndex();
     $type = new Type($index, 'content');
     $index->create($indexParams, true);
     $type->setMapping($indexMapping);
     $doc1 = new Document(1);
     $doc1->addFile('file', BASE_PATH . '/data/test.docx');
     $doc1->set('text', 'basel world');
     $type->addDocument($doc1);
     $doc2 = new Document(2);
     $doc2->set('text', 'running in basel');
     $type->addDocument($doc2);
     $index->optimize();
     $resultSet = $type->search('xodoa');
     $this->assertEquals(1, $resultSet->count());
     $resultSet = $type->search('basel');
     $this->assertEquals(2, $resultSet->count());
     $resultSet = $type->search('ruflin');
     $this->assertEquals(0, $resultSet->count());
 }
开发者ID:kskod,项目名称:Elastica,代码行数:23,代码来源:IndexTest.php

示例9: copy

 /**
  * Copies type mappings and documents from an old index to a new index.
  *
  * @see \Elastica\Tool\CrossIndex::reindex()
  *
  * @param \Elastica\Index $oldIndex
  * @param \Elastica\Index $newIndex
  * @param array           $options  keys: CrossIndex::OPTION_* constants
  *
  * @return \Elastica\Index The new index object
  */
 public static function copy(Index $oldIndex, Index $newIndex, array $options = array())
 {
     // normalize types to array of string
     $types = array();
     if (isset($options[self::OPTION_TYPE])) {
         $types = $options[self::OPTION_TYPE];
         $types = is_array($types) ? $types : array($types);
         $types = array_map(function ($type) {
             if ($type instanceof Type) {
                 $type = $type->getName();
             }
             return (string) $type;
         }, $types);
     }
     // copy mapping
     foreach ($oldIndex->getMapping() as $type => $mapping) {
         if (!empty($types) && !in_array($type, $types, true)) {
             continue;
         }
         $type = new Type($newIndex, $type);
         $type->setMapping($mapping['properties']);
     }
     // copy documents
     return self::reindex($oldIndex, $newIndex, $options);
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:36,代码来源:CrossIndex.php

示例10: testGetMappingAlias

 /**
  * @group functional
  */
 public function testGetMappingAlias()
 {
     $aliasName = 'test-alias';
     $typeName = 'test-alias-type';
     $index = $this->_createIndex();
     $index->addAlias($aliasName);
     $type = new Type($index, $typeName);
     $mapping = new Mapping($type, $expect = array('id' => array('type' => 'integer', 'store' => true)));
     $type->setMapping($mapping);
     $client = $index->getClient();
     $this->assertEquals(array('test-alias-type' => array('properties' => $expect)), $client->getIndex($aliasName)->getType($typeName)->getMapping());
 }
开发者ID:bungkoko,项目名称:Elastica,代码行数:15,代码来源:TypeTest.php

示例11: updateMapping

 /**
  * {@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();
 }
开发者ID:revinate,项目名称:search,代码行数:22,代码来源:Client.php

示例12: testSearchSetAnalyzer

 public function testSearchSetAnalyzer()
 {
     $client = $this->_getClient();
     $index = new Index($client, 'test');
     $index->create(array('analysis' => array('analyzer' => array('searchAnalyzer' => array('type' => 'custom', 'tokenizer' => 'standard', 'filter' => array('myStopWords'))), 'filter' => array('myStopWords' => array('type' => 'stop', 'stopwords' => array('The'))))), true);
     $index->getSettings()->setNumberOfReplicas(0);
     //$index->getSettings()->setNumberOfShards(1);
     $type = new Type($index, 'helloworldfuzzy');
     $mapping = new Mapping($type, array('email' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed'), 'content' => array('store' => 'yes', 'type' => 'string', 'index' => 'analyzed')));
     $mapping->setSource(array('enabled' => false));
     $type->setMapping($mapping);
     $doc = new Document(1000, array('email' => 'testemail@gmail.com', 'content' => 'The Fuzzy Test!'));
     $type->addDocument($doc);
     $doc = new Document(1001, array('email' => 'testemail@gmail.com', 'content' => 'Elastica Fuzzy Test'));
     $type->addDocument($doc);
     // Refresh index
     $index->refresh();
     $fltQuery = new FuzzyLikeThis();
     $fltQuery->addFields(array("email", "content"));
     $fltQuery->setLikeText("The");
     $fltQuery->setMinSimilarity(0.1);
     $fltQuery->setMaxQueryTerms(3);
     // Test before analyzer applied, should return 1 result
     $resultSet = $type->search($fltQuery);
     $this->assertEquals(1, $resultSet->count());
     $fltQuery->setParam('analyzer', 'searchAnalyzer');
     $resultSet = $type->search($fltQuery);
     $this->assertEquals(0, $resultSet->count());
 }
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:29,代码来源:FuzzyLikeThisTest.php

示例13: setUp

 protected function setUp()
 {
     /** @var ElasticaService elasticaService */
     $elasticaService = $this->getContainer()->get("revinate_search.elasticsearch_service");
     $this->elasticaClient = $elasticaService->getInstance();
     $this->index = new \Elastica\Index($this->elasticaClient, View::INDEX_NAME);
     if (!$this->index->exists()) {
         $this->index->create(array("index.number_of_replicas" => "0", "index.number_of_shards" => "1"));
         $this->type = new \Elastica\Type($this->index, View::INDEX_TYPE);
         $mappingJson = json_decode(file_get_contents(__DIR__ . "/../data/es/mapping.json"), true);
         $mapping = new \Elastica\Type\Mapping($this->type, $mappingJson['properties']);
         $this->type->setMapping($mapping);
     } else {
         $this->type = new \Elastica\Type($this->index, View::INDEX_TYPE);
     }
     $this->timeSeriesIndex = new \Elastica\Index($this->elasticaClient, StatusLog::INDEX_NAME . self::$timeSeriesTestDateSuffix);
     if (!$this->timeSeriesIndex->exists()) {
         $this->timeSeriesIndex->create(array("index.number_of_replicas" => "0", "index.number_of_shards" => "1"));
         $this->timeSeriesType = new \Elastica\Type($this->timeSeriesIndex, StatusLog::INDEX_TYPE);
         $mappingJson = json_decode(file_get_contents(__DIR__ . "/../data/es/statusLogMapping.json"), true);
         $mapping = new \Elastica\Type\Mapping($this->timeSeriesType, $mappingJson['properties']);
         $this->timeSeriesType->setMapping($mapping);
     } else {
         $this->timeSeriesType = new \Elastica\Type($this->timeSeriesIndex, StatusLog::INDEX_TYPE);
     }
 }
开发者ID:revinate,项目名称:search-bundle,代码行数:26,代码来源:BaseTestCase.php


注:本文中的Elastica\Type::setMapping方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。