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


PHP Document::setRouting方法代码示例

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


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

示例1: testDeleteIdsIdxStringTypeString

 /**
  * Test deleteIds method using string parameters.
  *
  * This test ensures that the deleteIds method of
  * the \Elastica\Client can properly accept and use
  * an $index parameter and $type parameter that are
  * strings
  *
  * This test is a bit more verbose than just sending the
  * values to deleteIds and checking for exceptions or
  * warnings.
  *
  * It will add a document, search for it, then delete it
  * using the parameter types we are interested in, and then
  * re-search to verify that they have been deleted
  *
  * @group functional
  */
 public function testDeleteIdsIdxStringTypeString()
 {
     $data = array('username' => 'hans');
     $userSearch = 'username:hans';
     $index = $this->_createIndex(null, true, 2);
     // Create the index, deleting it first if it already exists
     $index->create(array(), true);
     $type = $index->getType('user');
     // Adds 1 document to the index
     $doc = new Document(null, $data);
     $doc->setRouting('first_routing');
     $result = $type->addDocument($doc);
     // Refresh index
     $index->refresh();
     $resultData = $result->getData();
     $ids = array($resultData['_id']);
     // Check to make sure the document is in the index
     $resultSet = $type->search($userSearch);
     $totalHits = $resultSet->getTotalHits();
     $this->assertEquals(1, $totalHits);
     // And verify that the variables we are doing to send to
     // deleteIds are the type we are testing for
     $idxString = $index->getName();
     $typeString = $type->getName();
     $this->assertTrue(is_string($idxString));
     $this->assertTrue(is_string($typeString));
     // Try to delete doc with a routing value which hashes to
     // a different shard then the id.
     $resp = $index->getClient()->deleteIds($ids, $index, $type, 'second_routing');
     // Refresh the index
     $index->refresh();
     // Research the index to verify that the items are still there
     $resultSet = $type->search($userSearch);
     $totalHits = $resultSet->getTotalHits();
     $this->assertEquals(1, $totalHits);
     // Using the existing $index and $type variables which
     // are \Elastica\Index and \Elastica\Type objects respectively
     $resp = $index->getClient()->deleteIds($ids, $index, $type, 'first_routing');
     // Refresh the index to clear out deleted ID information
     $index->refresh();
     // Research the index to verify that the items have been deleted
     $resultSet = $type->search($userSearch);
     $totalHits = $resultSet->getTotalHits();
     $this->assertEquals(0, $totalHits);
 }
开发者ID:bungkoko,项目名称:Elastica,代码行数:63,代码来源:ClientTest.php

示例2: testDeleteByQueryWithQueryAndOptions

 /**
  * @group functional
  */
 public function testDeleteByQueryWithQueryAndOptions()
 {
     $this->_checkPlugin('delete-by-query');
     $index = $this->_createIndex(null, true, 2);
     $type = new Type($index, 'test');
     $doc = new Document(1, array('name' => 'ruflin nicolas'));
     $doc->setRouting('first_routing');
     $type->addDocument($doc);
     $doc = new Document(2, array('name' => 'ruflin'));
     $doc->setRouting('second_routing');
     $type->addDocument($doc);
     $index->refresh();
     $response = $index->search('ruflin*');
     $this->assertEquals(2, $response->count());
     $response = $index->search('ruflin*', array('routing' => 'first_routing'));
     $this->assertEquals(1, $response->count());
     $response = $index->search('nicolas');
     $this->assertEquals(1, $response->count());
     // Route to the wrong document id; should not delete
     $response = $type->deleteByQuery(new SimpleQueryString('nicolas'), array('routing' => 'second_routing'));
     $this->assertTrue($response->isOk());
     $index->refresh();
     $response = $index->search('ruflin*');
     $this->assertEquals(2, $response->count());
     $response = $index->search('nicolas');
     $this->assertEquals(1, $response->count());
     // Delete first document
     $response = $type->deleteByQuery(new SimpleQueryString('nicolas'), array('routing' => 'first_routing'));
     $this->assertTrue($response->isOk());
     $index->refresh();
     // Makes sure, document is deleted
     $response = $index->search('ruflin*');
     $this->assertEquals(1, $response->count());
     $response = $index->search('nicolas');
     $this->assertEquals(0, $response->count());
 }
开发者ID:bungkoko,项目名称:Elastica,代码行数:39,代码来源:TypeTest.php


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