本文整理汇总了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);
}
示例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());
}