本文整理汇总了PHP中Elastica\Script::setLang方法的典型用法代码示例。如果您正苦于以下问题:PHP Script::setLang方法的具体用法?PHP Script::setLang怎么用?PHP Script::setLang使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Script
的用法示例。
在下文中一共展示了Script::setLang方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetScript
public function testSetScript()
{
$string = '_score * 2.0';
$lang = 'mvel';
$params = array('param1' => 'one', 'param2' => 1);
$script = new Script($string);
$script->setLang('mvel');
$script->setParams($params);
$customScoreQuery = new CustomScore();
$customScoreQuery->setScript($script);
$expected = array('custom_score' => array('query' => array('match_all' => new \stdClass()), 'script' => $string, 'params' => $params, 'lang' => $lang));
$this->assertEquals($expected, $customScoreQuery->toArray());
}
示例2: testAddFilterScript
public function testAddFilterScript()
{
$customFiltersScoreQuery = new CustomFiltersScore();
$rangeFilter = new Range('age', array('from' => 20, 'to' => 30));
$rangeScript = "doc['num1'].value > 1";
$customFiltersScoreQuery->addFilterScript($rangeFilter, $rangeScript);
$expected = array('custom_filters_score' => array('query' => array('match_all' => new \stdClass()), 'filters' => array(array('filter' => $rangeFilter->toArray(), 'script' => $rangeScript))));
$this->assertEquals($expected, $customFiltersScoreQuery->toArray());
$customFiltersScoreQuery = new CustomFiltersScore();
$script = "doc['num1'].value > 1";
$rangeScript = new Script($script);
$rangeScript->setParam('param1', 1);
$rangeScript->setLang(Script::LANG_GROOVY);
$customFiltersScoreQuery->addFilterScript($rangeFilter, $rangeScript);
$expected = array('custom_filters_score' => array('query' => array('match_all' => new \stdClass()), 'filters' => array(array('filter' => $rangeFilter->toArray(), 'script' => $script))));
$this->assertEquals($expected, $customFiltersScoreQuery->toArray());
$termFilter = new Term();
$termFilter->setTerm('name', 'ruflin');
$termScript = "doc['num2'].value > 1";
$customFiltersScoreQuery->addFilterScript($termFilter, $termScript);
$expected = array('custom_filters_score' => array('query' => array('match_all' => new \stdClass()), 'filters' => array(array('filter' => $rangeFilter->toArray(), 'script' => $script), array('filter' => $termFilter->toArray(), 'script' => $termScript))));
$this->assertEquals($expected, $customFiltersScoreQuery->toArray());
}
示例3: testSetLang
/**
* @group unit
*/
public function testSetLang()
{
$script = new Script('foo', array(), Script::LANG_GROOVY);
$this->assertEquals(Script::LANG_GROOVY, $script->getLang());
$script->setLang(Script::LANG_PYTHON);
$this->assertEquals(Script::LANG_PYTHON, $script->getLang());
$this->assertInstanceOf('Elastica\\Script', $script->setLang(Script::LANG_PYTHON));
}