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


PHP Elastica\Index类代码示例

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


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

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

示例2: write

 /**
  * @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();
 }
开发者ID:spryker,项目名称:Collector,代码行数:12,代码来源:ElasticsearchUpdateWriter.php

示例3: tearDown

 protected function tearDown()
 {
     parent::tearDown();
     if ($this->_index instanceof Index) {
         $this->_index->delete();
     }
 }
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:7,代码来源:BaseAggregationTest.php

示例4: testSearch

 /**
  * @group functional
  */
 public function testSearch()
 {
     $client = $this->_getClient();
     $index = new Index($client, 'test');
     $index->create(array(), true);
     $type = new Type($index, 'helloworld');
     $doc = new Document(1, array('id' => 1, 'email' => 'hans@test.com', 'username' => 'hans', 'test' => array('2', '3', '5')));
     $type->addDocument($doc);
     $doc = new Document(2, array('id' => 2, 'email' => 'emil@test.com', 'username' => 'emil', 'test' => array('1', '3', '6')));
     $type->addDocument($doc);
     $doc = new Document(3, array('id' => 3, 'email' => 'ruth@test.com', 'username' => 'ruth', 'test' => array('2', '3', '7')));
     $type->addDocument($doc);
     // Refresh index
     $index->refresh();
     $boolQuery = new BoolQuery();
     $termQuery1 = new Term(array('test' => '2'));
     $boolQuery->addMust($termQuery1);
     $resultSet = $type->search($boolQuery);
     $this->assertEquals(2, $resultSet->count());
     $termQuery2 = new Term(array('test' => '5'));
     $boolQuery->addMust($termQuery2);
     $resultSet = $type->search($boolQuery);
     $this->assertEquals(1, $resultSet->count());
     $termQuery3 = new Term(array('username' => 'hans'));
     $boolQuery->addMust($termQuery3);
     $resultSet = $type->search($boolQuery);
     $this->assertEquals(1, $resultSet->count());
     $termQuery4 = new Term(array('username' => 'emil'));
     $boolQuery->addMust($termQuery4);
     $resultSet = $type->search($boolQuery);
     $this->assertEquals(0, $resultSet->count());
 }
开发者ID:MediaWiki-stable,项目名称:1.26.0,代码行数:35,代码来源:BoolQueryTest.php

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

示例6: matchDoc

 /**
  * Match a document to percolator queries
  *
  * @param  \Elastica\Document                                  $doc
  * @param  string|\Elastica\Query|\Elastica\Query\AbstractQuery $query Not implemented yet
  * @return \Elastica\Response
  */
 public function matchDoc(Document $doc, $query = null)
 {
     $path = $this->_index->getName() . '/type/_percolate';
     $data = array('doc' => $doc->getData());
     $response = $this->getIndex()->getClient()->request($path, Request::GET, $data);
     $data = $response->getData();
     return $data['matches'];
 }
开发者ID:kskod,项目名称:Elastica,代码行数:15,代码来源:Percolator.php

示例7: createMapping

 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();
 }
开发者ID:slaparra,项目名称:Training-Elastic-Search-Symfony,代码行数:10,代码来源:CreateElasticSearchTrackIndexCommand.php

示例8: getIndex

 /**
  * @return Index
  */
 private function getIndex()
 {
     if (null === $this->index) {
         $this->index = $this->client->getIndex($this->indexName);
         if (!$this->index->exists()) {
             $this->index->create();
         }
     }
     return $this->index;
 }
开发者ID:basster,项目名称:doctrine-elastica-cache,代码行数:13,代码来源:Cache.php

示例9: sendMapping

 /**
  * @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();
 }
开发者ID:spryker,项目名称:Search,代码行数:17,代码来源:IndexInstaller.php

示例10: testInvalidElasticRequest

 /**
  * @expectedException \Elastica\Exception\ResponseException
  */
 public function testInvalidElasticRequest()
 {
     $connection = new Connection();
     $connection->setHost('localhost');
     $connection->setPort(9500);
     $connection->setTransport('Thrift');
     $client = new Client();
     $client->addConnection($connection);
     $index = new Index($client, 'missing_index');
     $index->getStatus();
 }
开发者ID:kskod,项目名称:Elastica,代码行数:14,代码来源:ThriftTest.php

示例11: testInvalidElasticRequest

 /**
  * @group functional
  * @expectedException \Elastica\Exception\ResponseException
  */
 public function testInvalidElasticRequest()
 {
     $this->_checkPlugin();
     $connection = new Connection();
     $connection->setHost($this->_getHost());
     $connection->setPort(9500);
     $connection->setTransport('Thrift');
     $client = $this->_getClient();
     $client->addConnection($connection);
     $index = new Index($client, 'missing_index');
     $index->getStatus();
 }
开发者ID:MediaWiki-stable,项目名称:1.26.0,代码行数:16,代码来源:ThriftTest.php

示例12: _waitForAllocation

 protected function _waitForAllocation(Index $index)
 {
     do {
         $settings = $index->getStatus()->get();
         $allocated = true;
         foreach ($settings['shards'] as $shard) {
             if ($shard[0]['routing']['state'] != 'STARTED') {
                 $allocated = false;
             }
         }
     } while (!$allocated);
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:12,代码来源:Base.php

示例13: testSetType

 /**
  * @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());
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:16,代码来源:DocumentTest.php

示例14: matchDoc

 /**
  * Match a document to percolator queries
  *
  * @param  \Elastica\Document                                  $doc
  * @param  string|\Elastica\Query|\Elastica\Query\AbstractQuery $query Query to filter the data
  * @return \Elastica\Response
  */
 public function matchDoc(Document $doc, $query = null)
 {
     $path = $this->_index->getName() . '/type/_percolate';
     $data = array('doc' => $doc->getData());
     // Add query to filter results after percolation
     if ($query) {
         $query = Query::create($query);
         $data['query'] = $query->getQuery();
     }
     $response = $this->getIndex()->getClient()->request($path, Request::GET, $data);
     $data = $response->getData();
     return $data['matches'];
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:20,代码来源:Percolator.php

示例15: testGetDocument

 public function testGetDocument()
 {
     $type = self::$index->getType('message');
     $document = $type->getDocument(1);
     $message = $this->marshaler->unmarshal($document);
     $this->assertTrue($this->message->equals($message));
 }
开发者ID:gdbots,项目名称:pbj-php,代码行数:7,代码来源:ElasticaTest.php


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