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


PHP Elastica\Type类代码示例

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


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

示例1: testSearchByDocument

 /**
  * @group functional
  */
 public function testSearchByDocument()
 {
     $client = $this->_getClient(array('persistent' => false));
     $index = $client->getIndex('elastica_test');
     $index->create(array('index' => array('number_of_shards' => 1, 'number_of_replicas' => 0)), true);
     $type = new Type($index, 'mlt_test');
     $type->addDocuments(array(new Document(1, array('visible' => true, 'name' => 'bruce wayne batman')), new Document(2, array('visible' => true, 'name' => 'bruce wayne')), new Document(3, array('visible' => false, 'name' => 'bruce wayne')), new Document(4, array('visible' => true, 'name' => 'batman')), new Document(5, array('visible' => false, 'name' => 'batman')), new Document(6, array('visible' => true, 'name' => 'superman')), new Document(7, array('visible' => true, 'name' => 'spiderman'))));
     $index->refresh();
     $doc = $type->getDocument(1);
     // Return all similar from id
     $mltQuery = new MoreLikeThis();
     $mltQuery->setMinTermFrequency(1);
     $mltQuery->setMinDocFrequency(1);
     $mltQuery->setLike($doc);
     $query = new Query($mltQuery);
     $resultSet = $type->search($query);
     $this->assertEquals(4, $resultSet->count());
     $mltQuery = new MoreLikeThis();
     $mltQuery->setMinTermFrequency(1);
     $mltQuery->setMinDocFrequency(1);
     $mltQuery->setLike($doc);
     $query = new Query\BoolQuery();
     $query->addMust($mltQuery);
     $this->hideDeprecated();
     // Return just the visible similar from id
     $filter = new Query\BoolQuery();
     $filterTerm = new Query\Term();
     $filterTerm->setTerm('visible', true);
     $filter->addMust($filterTerm);
     $query->addFilter($filter);
     $this->showDeprecated();
     $resultSet = $type->search($query);
     $this->assertEquals(2, $resultSet->count());
     // Return all similar from source
     $mltQuery = new MoreLikeThis();
     $mltQuery->setMinTermFrequency(1);
     $mltQuery->setMinDocFrequency(1);
     $mltQuery->setMinimumShouldMatch(90);
     $mltQuery->setLike($type->getDocument(1)->setId(''));
     $query = new Query($mltQuery);
     $resultSet = $type->search($query);
     $this->assertEquals(1, $resultSet->count());
     // Legacy test with filter
     $mltQuery = new MoreLikeThis();
     $mltQuery->setMinTermFrequency(1);
     $mltQuery->setMinDocFrequency(1);
     $mltQuery->setLike($doc);
     $query = new Query\BoolQuery();
     $query->addMust($mltQuery);
     $this->hideDeprecated();
     // Return just the visible similar
     $filter = new BoolFilter();
     $filterTerm = new Term();
     $filterTerm->setTerm('visible', true);
     $filter->addMust($filterTerm);
     $query->addFilter($filter);
     $this->showDeprecated();
     $resultSet = $type->search($query);
     $this->assertEquals(2, $resultSet->count());
 }
开发者ID:makeandship,项目名称:wordpress-fantastic-elasticsearch,代码行数:63,代码来源:MoreLikeThisTest.php

示例2: updateMappings

 /**
  * Create new mappings or update existing mappings
  */
 public function updateMappings()
 {
     /** @var ClassMetadata[] $metadatas */
     $metadatas = $this->sm->getMetadataFactory()->getAllMetadata();
     // Refresh all the mappings
     foreach ($metadatas as $metadata) {
         // if we're in the dev env, set the number of replicas to be 0
         if ($this->env == 'dev' || $this->env == 'test_local') {
             $metadata->numberOfReplicas = 0;
         }
         // create the index if it doesn't exist yet
         $indexName = $metadata->timeSeriesScale ? $metadata->getCurrentTimeSeriesIndex() : $metadata->index;
         /** @var Index $index */
         $index = $this->client->getIndex($indexName);
         if (!$index->exists()) {
             $this->client->createIndex($indexName, $metadata->getSettings());
         }
         // create the type if it doesn't exist yet
         if ($metadata->type) {
             $type = new Type($index, $metadata->type);
             if (!$type->exists()) {
                 $this->client->createType($metadata);
             }
             // update the mapping
             $result = $this->client->updateMapping($metadata);
             if (true !== $result) {
                 echo "Warning: Failed to update mapping for index '{$indexName}', type '{$metadata->type}'. Reason: {$result}\n";
             }
         }
     }
 }
开发者ID:revinate,项目名称:search-bundle,代码行数:34,代码来源:MappingManager.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->setLikeText('fake gmail sample');
     $mltQuery->setFields(array('email', 'content'));
     $mltQuery->setMaxQueryTerms(1);
     $mltQuery->setMinDocFrequency(1);
     $mltQuery->setMinTermFrequency(1);
     $query = new Query();
     $query->setFields(array('email', 'content'));
     $query->setQuery($mltQuery);
     $resultSet = $type->search($query);
     $resultSet->getResponse()->getData();
     $this->assertEquals(2, $resultSet->count());
 }
开发者ID:MediaWiki-stable,项目名称:1.26.0,代码行数:33,代码来源:MoreLikeThisTest.php

示例4: testQuery

 public function testQuery()
 {
     $client = $this->_getClient();
     $index = new Index($client, 'test');
     $index->create(array(), true);
     $type = new Type($index, 'constant_score');
     $doc = new Document(1, array('id' => 1, 'email' => 'hans@test.com', 'username' => 'hans'));
     $type->addDocument($doc);
     $doc = new Document(2, array('id' => 2, 'email' => 'emil@test.com', 'username' => 'emil'));
     $type->addDocument($doc);
     $doc = new Document(3, array('id' => 3, 'email' => 'ruth@test.com', 'username' => 'ruth'));
     $type->addDocument($doc);
     // Refresh index
     $index->refresh();
     $boost = 1.3;
     $query_match = new MatchAll();
     $query = new ConstantScore();
     $query->setQuery($query_match);
     $query->setBoost($boost);
     $expectedArray = array('constant_score' => array('query' => $query_match->toArray(), 'boost' => $boost));
     $this->assertEquals($expectedArray, $query->toArray());
     $resultSet = $type->search($query);
     $results = $resultSet->getResults();
     $this->assertEquals($resultSet->count(), 3);
     $this->assertEquals($results[1]->getScore(), 1);
 }
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:26,代码来源:ConstantScoreTest.php

示例5: setUp

 /**
  * @return void
  */
 protected function setUp()
 {
     $this->type = $this->getMockType();
     $this->index = $this->getMockIndex();
     $this->client = $this->getMockClient();
     // now that index is setup, we can use it for mocking the Type class method getIndex
     $this->type->method('getIndex')->willReturn($this->index);
 }
开发者ID:spryker,项目名称:Collector,代码行数:11,代码来源:ElasticsearchWriterTest.php

示例6: removeIndexById

 /**
  * @param integer $id
  * @param Type $type
  */
 public function removeIndexById($id, Type $type)
 {
     try {
         $type->deleteById($id);
     } catch (\InvalidArgumentException $e) {
     } catch (NotFoundException $e) {
     }
 }
开发者ID:leapt,项目名称:elastica-bundle,代码行数:12,代码来源:AbstractIndexer.php

示例7: setType

 /**
  * @param string|\Elastica\Type $type
  *
  * @return $this
  */
 public function setType($type)
 {
     if ($type instanceof Type) {
         $this->setIndex($type->getIndex()->getName());
         $type = $type->getName();
     }
     $this->_type = (string) $type;
     return $this;
 }
开发者ID:levijackson,项目名称:Elastica,代码行数:14,代码来源:Bulk.php

示例8: _addDocs

 /**
  * @param Type $type
  * @param int  $docs
  *
  * @return array
  */
 private function _addDocs(Type $type, $docs)
 {
     $insert = array();
     for ($i = 1; $i <= $docs; $i++) {
         $insert[] = new Document($i, array('_id' => $i, 'key' => 'value'));
     }
     $type->addDocuments($insert);
     $type->getIndex()->refresh();
     return $insert;
 }
开发者ID:MediaWiki-stable,项目名称:1.26.0,代码行数:16,代码来源:CrossIndexTest.php

示例9: 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

示例10: populate

 /**
  * Insert the repository objects in the type index
  *
  * @param \Closure $loggerClosure A logging function
  * @param array    $options
  */
 public function populate(\Closure $loggerClosure = null, array $options = array())
 {
     if ($loggerClosure) {
         $loggerClosure('Indexing groups');
     }
     $groups = \Group::getQueryBuilder()->active()->getModels();
     $documents = array();
     foreach ($groups as $group) {
         $documents[] = $this->transformer->transform($group, array());
     }
     $this->groupType->addDocuments($documents);
 }
开发者ID:kleitz,项目名称:bzion,代码行数:18,代码来源:GroupProvider.php

示例11: populate

 /**
  * Insert the repository objects in the type index
  *
  * @param \Closure $loggerClosure A logging function
  * @param array    $options
  */
 public function populate(\Closure $loggerClosure = null, array $options = array())
 {
     if ($loggerClosure) {
         $loggerClosure('Indexing messages');
     }
     $messages = \Message::getQueryBuilder()->active()->getModels();
     $documents = array();
     foreach ($messages as $message) {
         $documents[] = $this->transformer->transform($message);
     }
     $this->messageType->addDocuments($documents);
 }
开发者ID:kleitz,项目名称:bzion,代码行数:18,代码来源:MessageProvider.php

示例12: getMappingProperties

 public function getMappingProperties(Type $type)
 {
     $array = array('name' => array('type' => 'multi_field', 'fields' => array('partial_name' => array('search_analyzer' => 'standard', 'index_analyzer' => 'shop', 'type' => 'string'), 'full_name' => array('type' => 'string'))), 'image' => array('type' => 'string', 'index' => 'no'));
     switch ($type->getName()) {
         case 'book':
             $array += array('author' => array('type' => 'string'));
             break;
         case 'dvd':
             $array += array('released' => array('type' => 'date'));
             break;
     }
     return $array;
 }
开发者ID:darklow,项目名称:ff-elastica-manager,代码行数:13,代码来源:TestConfiguration.php

示例13: testSearch

 /**
  * @group functional
  */
 public function testSearch()
 {
     $index = $this->_createIndex();
     $index->getSettings()->setNumberOfReplicas(0);
     $type = new Type($index, 'helloworld');
     $doc = new Document(1, array('email' => 'test@test.com', 'username' => 'test 7/6 123', 'test' => array('2', '3', '5')));
     $type->addDocument($doc);
     // Refresh index
     $index->refresh();
     $queryString = new QueryString(Util::escapeTerm('test 7/6'));
     $resultSet = $type->search($queryString);
     $this->assertEquals(1, $resultSet->count());
 }
开发者ID:makeandship,项目名称:wordpress-fantastic-elasticsearch,代码行数:16,代码来源:EscapeStringTest.php

示例14: deleteMapping

 /**
  * @param string $typeName
  * @return \Elastica\Type
  * @throws \Exception
  */
 protected function deleteMapping($typeName)
 {
     $type = new Elastica\Type($this->index, $typeName);
     if ($type->exists()) {
         try {
             $type->delete();
         } catch (\Exception $e) {
             throw new \Exception('Could not delete type ' . $type->getName() . '');
         }
     }
     $type = new Elastica\Type($this->index, $typeName);
     return $type;
 }
开发者ID:randomresult,项目名称:WMDB.Forger,代码行数:18,代码来源:SetupCommandController.php

示例15: testToArrayFromReference

 /**
  * @group unit
  */
 public function testToArrayFromReference()
 {
     $client = $this->_getClient();
     $index = new Index($client, 'test');
     $type = new Type($index, 'helloworld');
     $field = 'image';
     $query = new Image();
     $query->setFieldFeature($field, 'CEDD');
     $query->setFieldHash($field, 'BIT_SAMPLING');
     $query->setFieldBoost($field, 100);
     $query->setImageByReference($field, $index->getName(), $type->getName(), 10);
     $jsonString = '{"image":{"image":{"feature":"CEDD","hash":"BIT_SAMPLING","boost":100,"index":"test","type":"helloworld","id":10,"path":"image"}}}';
     $this->assertEquals($jsonString, json_encode($query->toArray()));
 }
开发者ID:JanJakes,项目名称:Elastica,代码行数:17,代码来源:ImageTest.php


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