• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Elastica\Index类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了Index类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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' => '[email protected]', 'username' => 'hans'));
     $type->addDocument($doc);
     $doc = new Document(2, array('id' => 2, 'email' => '[email protected]', 'username' => 'emil'));
     $type->addDocument($doc);
     $doc = new Document(3, array('id' => 3, 'email' => '[email protected]', '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' => '[email protected]', 'username' => 'hans', 'test' => array('2', '3', '5')));
     $type->addDocument($doc);
     $doc = new Document(2, array('id' => 2, 'email' => '[email protected]', 'username' => 'emil', 'test' => array('1', '3', '6')));
     $type->addDocument($doc);
     $doc = new Document(3, array('id' => 3, 'email' => '[email protected]', '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' => '[email protected]', 'content' => 'This is a sample post. Hello World Fuzzy Like This!'));
     $type->addDocument($doc);
     $doc = new Document(1001, array('email' => '[email protected]', '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: matchDoc

 /**
  * Match a document to percolator queries
  *
  * @param  \Elastica\Document                                   $doc
  * @param  string|\Elastica\Query|\Elastica\Query\AbstractQuery $query Query to filter the percolator queries which
  *                                                                     are executed.
  * @param  string                                               $type
  * @return array With matching registered queries.
  */
 public function matchDoc(Document $doc, $query = null, $type = 'type')
 {
     $path = $this->_index->getName() . '/' . $type . '/_percolate';
     $data = array('doc' => $doc->getData());
     // Add query to filter the percolator queries which are executed.
     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:raadhuis,项目名称:modx-basic,代码行数:22,代码来源:Percolator.php


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


示例17: backupAction

 /**
  * @actionInfo(name='Бэкап данных')
  */
 public function backupAction()
 {
     $this->folderName = __DIR__ . '/backup/';
     if (!$this->elasticaIndex->exists()) {
         $this->log->error('Индекс для бэкапа отсутствует: {indexName}', ['indexName' => $this->indexName]);
         return;
     }
     $this->checkFileName();
     $this->checkBackupFolder();
     $this->log->info('Всё ок, бекапим {indexName} в {fileName}', ['indexName' => $this->indexName, 'fileName' => $this->fileName]);
     $this->log->info('Параметры бэкапа: sizePerShard={sizePerShard}', ['sizePerShard' => $this->sizePerShard]);
     $scanAndScroll = $this->getScanAndScroll();
     foreach ($scanAndScroll as $resultSet) {
         $buffer = [];
         /* @var \Elastica\ResultSet $resultSet */
         $results = $resultSet->getResults();
         foreach ($results as $result) {
             $item = [];
             $item['_id'] = $result->getId();
             $item['_source'] = $result->getSource();
             $buffer[] = json_encode($item, JSON_UNESCAPED_UNICODE);
         }
         $fileBody = implode(PHP_EOL, $buffer);
         if (file_put_contents($this->fileName, $fileBody, FILE_APPEND)) {
             $countDocuments = count($results);
             $this->log->info('Сохранили {countDocuments} записей', ['countDocuments' => $countDocuments]);
         } else {
             $this->log->error('Ошибка записи данных');
             die;
         }
     }
 }
开发者ID:mzf,项目名称:phalcon-php-elasticsearch-backup,代码行数:35,代码来源:elasticsearch-dumper.php


示例18: 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, 'helloworld');
     $doc = new Document(1, array('email' => '[email protected]', 'username' => 'hanswurst', 'test' => array('2', '3', '5')));
     $type->addDocument($doc);
     // Refresh index
     $index->refresh();
     $queryString = new QueryString('test*');
     $resultSet = $type->search($queryString);
     $this->assertEquals(1, $resultSet->count());
 }
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:16,代码来源:QueryStringTest.php


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


示例20: testQuery

 public function testQuery()
 {
     $query = new SimpleQueryString("gibson +sg +-faded", array("make", "model"));
     $results = $this->_index->search($query);
     $this->assertEquals(2, $results->getTotalHits());
     $query->setFields(array("model"));
     $results = $this->_index->search($query);
     // We should not get any hits, since the "make" field was not included in the query.
     $this->assertEquals(0, $results->getTotalHits());
 }
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:10,代码来源:SimpleQueryStringTest.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Elastica\JSON类代码示例发布时间:2022-05-23
下一篇:
PHP Elastica\Document类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap