本文整理汇总了PHP中Elastica\Document::setIndex方法的典型用法代码示例。如果您正苦于以下问题:PHP Document::setIndex方法的具体用法?PHP Document::setIndex怎么用?PHP Document::setIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Document
的用法示例。
在下文中一共展示了Document::setIndex方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetOptions
public function testGetOptions()
{
$document = new Document();
$document->setIndex('index');
$document->setOpType('create');
$document->setParent('2');
$document->setId(1);
$options = $document->getOptions(array('index', 'type', 'id', 'parent'));
$this->assertInternalType('array', $options);
$this->assertEquals(3, count($options));
$this->assertArrayHasKey('index', $options);
$this->assertArrayHasKey('id', $options);
$this->assertArrayHasKey('parent', $options);
$this->assertEquals('index', $options['index']);
$this->assertEquals(1, $options['id']);
$this->assertEquals('2', $options['parent']);
$this->assertArrayNotHasKey('type', $options);
$this->assertArrayNotHasKey('op_type', $options);
$this->assertArrayNotHasKey('_index', $options);
$this->assertArrayNotHasKey('_id', $options);
$this->assertArrayNotHasKey('_parent', $options);
$options = $document->getOptions(array('parent', 'op_type', 'percolate'), true);
$this->assertInternalType('array', $options);
$this->assertEquals(2, count($options));
$this->assertArrayHasKey('_parent', $options);
$this->assertArrayHasKey('_op_type', $options);
$this->assertEquals('2', $options['_parent']);
$this->assertEquals('create', $options['_op_type']);
$this->assertArrayNotHasKey('percolate', $options);
$this->assertArrayNotHasKey('op_type', $options);
$this->assertArrayNotHasKey('parent', $options);
}
示例2: getDocument
/**
* Convert a log message into an Elastica Document
*
* @param array $record Log message
* @return Document
*/
protected function getDocument($record)
{
$document = new Document();
$document->setData($record);
$document->setType($this->type);
$document->setIndex($this->index);
return $document;
}
示例3: getDocument
public function getDocument($record)
{
$user = $this->token->getToken()->getUser();
$record['extra']['user'] = $user->getId();
$document = new Document();
$document->setData($record);
$document->setType($this->type);
$document->setIndex($this->index);
return $document;
}
示例4: __construct
/**
* ElasticaHelper constructor.
*
* @param string $gameVersion
* @param string $indexName
* @param int $magicNumber
*/
public function __construct($gameVersion, $indexName, $magicNumber = 500)
{
$docPrototype = new Document();
$docPrototype->setIndex($indexName)->setType('user:' . $gameVersion);
$this->documentFactory = new DocumentFactory($docPrototype);
$this->elastica = $this->makeElastica();
$this->magicNumber = $magicNumber;
$this->errorHandler = function (\Exception $exception) {
error_log(print_r($exception->getMessage(), true), 3, CONFIG_DIR . '/elastica.error');
};
}
示例5: deleteDocuments
protected function deleteDocuments()
{
dump(__METHOD__);
require_once __DIR__ . '/UserProvider.php';
$userList = (new \UserProvider())->listUser();
$documents = array_map(function (User $user) {
$document = new Document($user->snsid);
$document->setIndex($this->getIndexName())->setType($this->getTypeName());
return $document;
}, $userList);
$responseSet = $this->getClient()->getIndex($this->getIndexName())->deleteDocuments($documents);
foreach ($responseSet as $response) {
$data = $response->getData();
$this->assertEquals(3, $data['_version']);
$action = $response->getAction();
$this->assertEquals('delete', $action->getOpType());
}
}
示例6: testBulkIndex
/**
* Test bulk operations on Index.
*
* @group functional
*/
public function testBulkIndex()
{
$index = $this->_getClient()->getIndex('cryptocurrencies');
$anonCoin = new Document(1, array('name' => 'anoncoin'), 'altcoin');
$ixCoin = new Document(2, array('name' => 'ixcoin'), 'altcoin');
$index->addDocuments(array($anonCoin, $ixCoin));
$this->assertEquals('anoncoin', $index->getType('altcoin')->getDocument(1)->get('name'));
$this->assertEquals('ixcoin', $index->getType('altcoin')->getDocument(2)->get('name'));
$index->updateDocuments(array(new Document(1, array('name' => 'AnonCoin'), 'altcoin'), new Document(2, array('name' => 'iXcoin'), 'altcoin')));
$this->assertEquals('AnonCoin', $index->getType('altcoin')->getDocument(1)->get('name'));
$this->assertEquals('iXcoin', $index->getType('altcoin')->getDocument(2)->get('name'));
$ixCoin->setIndex(null);
// Make sure the index gets set properly if missing
$index->deleteDocuments(array($anonCoin, $ixCoin));
$this->setExpectedException('Elastica\\Exception\\NotFoundException');
$index->getType('altcoin')->getDocument(1);
$index->getType('altcoin')->getDocument(2);
}
示例7: __construct
/**
* Factory constructor.
*/
public function __construct()
{
$docPrototype = new Document();
$docPrototype->setIndex(ELASTIC_SEARCH_INDEX)->setType('user:unknown');
$this->documentFactory = new DocumentFactory($docPrototype);
}
示例8: setUpBeforeClass
/**
*
*/
public static function setUpBeforeClass()
{
require_once __DIR__ . '/../ES/UserProvider.php';
self::$documentPrototype = new Document();
self::$documentPrototype->setIndex('farm')->setType('user:tw');
}