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


PHP Type::addDocument方法代码示例

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


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

示例1: testSearch

 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 Bool();
     $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:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:32,代码来源:BoolTest.php

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

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

示例4: createStatusLog

 /**
  * @param $status
  * @param null $dateString
  * @return $this
  */
 public function createStatusLog($status, $dateString = null)
 {
     $date = $dateString ? new \DateTime($dateString) : new \DateTime('05/05/2016');
     $statusLog = new StatusLog();
     $statusLog->setId(uniqid());
     $statusLog->setStatus($status);
     $statusLog->setDate($date);
     $this->type->addDocument(new \Elastica\Document("", $statusLog->toArray()));
     return $this;
 }
开发者ID:revinate,项目名称:search-bundle,代码行数:15,代码来源:DocumentHelper.php

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

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

示例7: addHotel

 /**
  * @param Hotel $hotel
  *
  * @return $this
  */
 public function addHotel($hotel)
 {
     $data = array('id' => $hotel->getId());
     $document = $this->hotelType->createDocument($hotel->getId());
     $document->setData($data);
     $this->hotelType->addDocument($document);
     $this->updateHotel($hotel, $document);
     return $this;
 }
开发者ID:blab2015,项目名称:seh,代码行数:14,代码来源:AutocompleteManager.php

示例8: createNewDocumentOnSave

 /**
  * @test
  */
 public function createNewDocumentOnSave()
 {
     $id = 1;
     $data = 'foobar';
     $this->prophesizeGetDocumentThrowsException($id);
     $this->index->refresh()->shouldBeCalled();
     $doc = $this->getDocument($id, $data);
     $this->type->createDocument($this->getCacheId($id), [Cache::VALUE_FIELD => serialize($data)])->shouldBeCalled()->willReturn($doc);
     $this->type->addDocument($doc)->shouldBeCalled();
     self::assertTrue($this->cache->save($id, $data));
 }
开发者ID:basster,项目名称:doctrine-elastica-cache,代码行数:14,代码来源:CacheTest.php

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

示例10: 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' => 'test@test.com', '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

示例11: testQuery

 public function testQuery()
 {
     $client = $this->_getClient();
     $index = new Index($client, 'test');
     $index->create(array(), true);
     $type = new Type($index, 'multi_match');
     $doc = new Document(1, array('id' => 1, 'name' => 'Rodolfo', 'last_name' => 'Moraes'));
     $type->addDocument($doc);
     // Refresh index
     $index->refresh();
     $multiMatch = new MultiMatch();
     $query = new Query();
     $multiMatch->setQuery('Rodolfo');
     $multiMatch->setFields(array('name', 'last_name'));
     $query->setQuery($multiMatch);
     $resultSet = $index->search($query);
     $this->assertEquals(1, $resultSet->count());
     $multiMatch->setQuery('Moraes');
     $multiMatch->setFields(array('name', 'last_name'));
     $query->setQuery($multiMatch);
     $resultSet = $index->search($query);
     $this->assertEquals(1, $resultSet->count());
 }
开发者ID:kskod,项目名称:Elastica,代码行数:23,代码来源:MultiMatchTest.php

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

示例13: testAddDocumentVersion

 public function testAddDocumentVersion()
 {
     $client = $this->_getClient();
     $index = $client->getIndex('test');
     $index->create(array(), true);
     $type = new Type($index, 'test');
     $doc1 = new Document(1);
     $doc1->set('title', 'Hello world');
     $return = $type->addDocument($doc1);
     $data = $return->getData();
     $this->assertEquals(1, $data['_version']);
     $return = $type->addDocument($doc1);
     $data = $return->getData();
     $this->assertEquals(2, $data['_version']);
 }
开发者ID:kskod,项目名称:Elastica,代码行数:15,代码来源:IndexTest.php

示例14: addDocumentToElastic

 /**
  * @param array $document
  * @param string $type
  * @throws \Exception
  */
 protected function addDocumentToElastic(array $document, $type = 'issue')
 {
     switch ($type) {
         case 'issue':
             if (isset($document['custom_fields'])) {
                 foreach ($document['custom_fields'] as $customField) {
                     switch ($customField['id']) {
                         case 4:
                             $document['typo3_version'] = isset($customField['value']) ? $customField['value'] : '-';
                             break;
                         case 5:
                             $document['php_version'] = isset($customField['value']) ? $customField['value'] : '-';
                             break;
                         case 8:
                             $document['complexity'] = isset($customField['value']) ? $customField['value'] : '-';
                             break;
                         case 15:
                             $document['isregression'] = isset($customField['value']) ? true : false;
                             break;
                         case 18:
                             $document['focus']['name'] = isset($customField['value']) ? $customField['value'] : '-';
                             break;
                         default:
                     }
                 }
             }
             $document['updated_on'] = $this->fixDateFormat($document['updated_on']);
             $document['created_on'] = $this->fixDateFormat($document['created_on']);
             $type = new Elastica\Type($this->elasticIndex, 'issue');
             try {
                 $testIfDocExists = $type->getDocument($document['id']);
             } catch (\Exception $e) {
                 $message = new \WMDB\Forger\Utilities\Slack\Message();
                 $message->sendMessage($document);
             }
             break;
         case 'review':
             $type = new Elastica\Type($this->elasticIndex, 'review');
             break;
         case 'user':
             $type = new Elastica\Type($this->elasticIndex, 'user');
             break;
         default:
     }
     #\TYPO3\Flow\var_dump($type);
     $doc = new Elastica\Document($document['id'], $document);
     #\TYPO3\Flow\var_dump($doc);
     $type->addDocument($doc);
     #sleep(1);
 }
开发者ID:khuppenbauer,项目名称:WMDB.Forger,代码行数:55,代码来源:ForgeImportCommandController.php

示例15: testOldObject

 /**
  * @group functional
  */
 public function testOldObject()
 {
     if (version_compare(phpversion(), 7, '>=')) {
         self::markTestSkipped('These objects are not supported in PHP 7');
     }
     $index = $this->_createIndex();
     $type = new Type($index, 'test');
     $docNumber = 3;
     for ($i = 0; $i < $docNumber; ++$i) {
         $doc = new Document($i, array('email' => 'test@test.com'));
         $type->addDocument($doc);
     }
     $index->refresh();
     $this->hideDeprecated();
     $boolQuery = new \Elastica\Query\Bool();
     $this->showDeprecated();
     $resultSet = $type->search($boolQuery);
     $this->assertEquals($resultSet->count(), $docNumber);
 }
开发者ID:vinusebastian,项目名称:Elastica,代码行数:22,代码来源:BoolQueryTest.php


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