예제 #1
0
 public function testNewScriptFields()
 {
     $script = new Elastica_Script('1 + 2');
     // addScript
     $scriptFields = new Elastica_ScriptFields();
     $scriptFields->addScript('test', $script);
     $this->assertEquals($scriptFields->getParam('test'), $script->toArray());
     // setScripts
     $scriptFields = new Elastica_ScriptFields();
     $scriptFields->setScripts(array('test' => $script));
     $this->assertEquals($scriptFields->getParam('test'), $script->toArray());
     // Constructor
     $scriptFields = new Elastica_ScriptFields(array('test' => $script));
     $this->assertEquals($scriptFields->getParam('test'), $script->toArray());
 }
예제 #2
0
 /**
  * Set script fields
  *
  * @param  array|Elastica_ScriptFields $scriptFields Script fields
  * @return Elastica_Query              Current object
  * @link http://www.elasticsearch.org/guide/reference/api/search/script-fields.html
  */
 public function setScriptFields($scriptFields)
 {
     if (is_array($scriptFields)) {
         $scriptFields = new Elastica_ScriptFields($scriptFields);
     }
     return $this->setParam('script_fields', $scriptFields->toArray());
 }