本文整理汇总了PHP中Elastica\Query::setScriptFields方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::setScriptFields方法的具体用法?PHP Query::setScriptFields怎么用?PHP Query::setScriptFields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Query
的用法示例。
在下文中一共展示了Query::setScriptFields方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testQuery
public function testQuery()
{
$type = $this->index->getType('test');
$doc = new Document(1, array('firstname' => 'guschti', 'lastname' => 'ruflin'));
$type->addDocument($doc);
$this->index->refresh();
$query = new Query();
$script = new Script('1 + 2');
$scriptFields = new ScriptFields(array('test' => $script));
$query->setScriptFields($scriptFields);
$resultSet = $type->search($query);
$first = $resultSet->current()->getData();
// 1 + 2
$this->assertEquals(3, $first['test']);
}
示例2: testSetScriptFieldsToArrayCast
/**
* @group unit
*/
public function testSetScriptFieldsToArrayCast()
{
$query = new Query();
$scriptFields = new ScriptFields();
$scriptFields->addScript('script', new Script('script'));
$query->setScriptFields($scriptFields);
$scriptFields->addScript('another script', new Script('another script'));
$anotherQuery = new Query();
$anotherQuery->setScriptFields($scriptFields);
$this->assertEquals($query->toArray(), $anotherQuery->toArray());
}