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()); }
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()); }
/** * @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)); }