本文整理匯總了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());
}