-
Notifications
You must be signed in to change notification settings - Fork 736
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #914 from ruflin/nicolassing-master
FileScript implementaiton
- Loading branch information
Showing
13 changed files
with
340 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
ansible/roles/elasticsearch/templates/calculate-distance.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
doc['location'].arcDistanceInKm(lat,lon) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
doc['location'].arcDistanceInKm(lat,lon) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
namespace Elastica; | ||
|
||
/** | ||
* Base class for Script object. | ||
* | ||
* @author Nicolas Assing <[email protected]> | ||
* | ||
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html | ||
*/ | ||
abstract class AbstractScript extends AbstractUpdateAction | ||
{ | ||
/** | ||
* @param array|null $params | ||
* @param string $id | ||
*/ | ||
public function __construct(array $params = null, $id = null) | ||
{ | ||
if ($params) { | ||
$this->setParams($params); | ||
} | ||
|
||
if ($id) { | ||
$this->setId($id); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
namespace Elastica; | ||
|
||
use Elastica\Exception\InvalidException; | ||
|
||
/** | ||
* Script objects, containing script internals. | ||
* | ||
* @author avasilenko <[email protected]> | ||
* @author Nicolas Assing <[email protected]> | ||
* | ||
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html | ||
*/ | ||
class ScriptFile extends AbstractScript | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $_scriptFile; | ||
|
||
/** | ||
* @param string $scriptFile | ||
* @param array|null $params | ||
* @param null $id | ||
*/ | ||
public function __construct($scriptFile, array $params = null, $id = null) | ||
{ | ||
parent::__construct($params, $id); | ||
|
||
$this->setScriptFile($scriptFile); | ||
} | ||
|
||
/** | ||
* @param string $scriptFile | ||
* | ||
* @return $this | ||
*/ | ||
public function setScriptFile($scriptFile) | ||
{ | ||
$this->_scriptFile = $scriptFile; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getScriptFile() | ||
{ | ||
return $this->_scriptFile; | ||
} | ||
|
||
/** | ||
* @param string|array|\Elastica\Script $data | ||
* | ||
* @throws \Elastica\Exception\InvalidException | ||
* | ||
* @return self | ||
*/ | ||
public static function create($data) | ||
{ | ||
if ($data instanceof self) { | ||
$scriptFile = $data; | ||
} elseif (is_array($data)) { | ||
$scriptFile = self::_createFromArray($data); | ||
} elseif (is_string($data)) { | ||
$scriptFile = new self($data); | ||
} else { | ||
throw new InvalidException('Failed to create scriptFile. Invalid data passed.'); | ||
} | ||
|
||
return $scriptFile; | ||
} | ||
|
||
/** | ||
* @param array $data | ||
* | ||
* @throws \Elastica\Exception\InvalidException | ||
* | ||
* @return self | ||
*/ | ||
protected static function _createFromArray(array $data) | ||
{ | ||
if (!isset($data['script_file'])) { | ||
throw new InvalidException("\$data['script_file'] is required"); | ||
} | ||
|
||
$scriptFile = new self($data['script_file']); | ||
|
||
if (isset($data['params'])) { | ||
if (!is_array($data['params'])) { | ||
throw new InvalidException("\$data['params'] should be array"); | ||
} | ||
$scriptFile->setParams($data['params']); | ||
} | ||
|
||
return $scriptFile; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function toArray() | ||
{ | ||
$array = array( | ||
'script_file' => $this->_scriptFile, | ||
); | ||
|
||
if (!empty($this->_params)) { | ||
$array['params'] = $this->_params; | ||
} | ||
|
||
return $array; | ||
} | ||
} |
Oops, something went wrong.