本文整理汇总了PHP中Elastica\Script类的典型用法代码示例。如果您正苦于以下问题:PHP Script类的具体用法?PHP Script怎么用?PHP Script使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Script类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: setScript
/**
* Set a script for this aggregation.
*
* @param string|Script $script
*
* @return $this
*/
public function setScript($script)
{
if ($script instanceof Script) {
$params = array_merge($this->getParams(), $script->toArray());
return $this->setParams($params);
}
return $this->setParam('script', $script);
}
开发者ID:MediaWiki-stable,项目名称:1.26.0,代码行数:15,代码来源:AbstractSimpleAggregation.php
示例2: setScript
/**
* Set a script for this aggregation
* @param string|Script $script
* @return AbstractSimpleAggregation
*/
public function setScript($script)
{
if ($script instanceof Script) {
$this->setParam('params', $script->getParams());
$script = $script->getScript();
}
return $this->setParam('script', $script);
}
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:13,代码来源:AbstractSimpleAggregation.php
示例3: addScript
/**
* @param string $name Name of the Script field
* @param \Elastica\Script $script
* @throws \Elastica\Exception\InvalidException
* @return \Elastica\ScriptFields
*/
public function addScript($name, Script $script)
{
if (!is_string($name) || !strlen($name)) {
throw new InvalidException('The name of a Script is required and must be a string');
}
$this->setParam($name, $script->toArray());
return $this;
}
开发者ID:raadhuis,项目名称:modx-basic,代码行数:14,代码来源:ScriptFields.php
示例4: 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());
}
开发者ID:kskod,项目名称:Elastica,代码行数:13,代码来源:CustomScoreTest.php
示例5: setScript
/**
* Set script
*
* @param string|\Elastica\Script $script
* @return \Elastica\Query\CustomScore
*/
public function setScript($script)
{
$script = Script::create($script);
foreach ($script->toArray() as $param => $value) {
$this->setParam($param, $value);
}
return $this;
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:14,代码来源:CustomScore.php
示例6: 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());
}
开发者ID:kskod,项目名称:Elastica,代码行数:23,代码来源:CustomFiltersScoreTest.php
示例7: create
/**
* @param \Elastica\Document|\Elastica\Script $data
* @param string $opType
* @return \Elastica\Bulk\Action\AbstractDocument
*/
public static function create($data, $opType = null)
{
//Check type
if (!$data instanceof Document && !$data instanceof Script) {
throw new \InvalidArgumentException("The data needs to be a Document or a Script.");
}
if (null === $opType && $data->hasOpType()) {
$opType = $data->getOpType();
}
//Check that scripts can only be used for updates
if ($data instanceof Script && isset($opType) && $opType != self::OP_TYPE_UPDATE) {
throw new \InvalidArgumentException("When performing an update action, the data needs to be a Document or a Script.");
}
switch ($opType) {
case self::OP_TYPE_DELETE:
$action = new DeleteDocument($data);
break;
case self::OP_TYPE_CREATE:
$action = new CreateDocument($data);
break;
case self::OP_TYPE_UPDATE:
$action = new UpdateDocument($data);
break;
case self::OP_TYPE_INDEX:
default:
$action = new IndexDocument($data);
break;
}
return $action;
}
开发者ID:raadhuis,项目名称:modx-basic,代码行数:35,代码来源:AbstractDocument.php
示例8: addScriptField
/**
* Adds a Script to the query
*
* @param string $name
* @param \Elastica\Script $script Script object
* @return \Elastica\Query Query object
*/
public function addScriptField($name, Script $script)
{
$this->_params['script_fields'][$name] = $script->toArray();
return $this;
}
开发者ID:tkaven,项目名称:Elastica,代码行数:12,代码来源:Query.php
示例9: setScript
/**
* Sets the script for the term.
*
* @param string $script The script for the term.
*
* @return $this
*/
public function setScript($script)
{
$this->setParam('script', Script::create($script));
return $this;
}
开发者ID:nadeem-khan,项目名称:Elastica,代码行数:12,代码来源:Terms.php
示例10: setScript
/**
* Sets script object
*
* @param \Elastica\Script|string|array $script
* @return \Elastica\Filter\Script
*/
public function setScript($script)
{
$script = Elastica\Script::create($script);
return $this->setParams($script->toArray());
}
开发者ID:raadhuis,项目名称:modx-basic,代码行数:11,代码来源:Script.php
示例11: updateDocument
/**
* Update document, using update script. Requires elasticsearch >= 0.19.0
*
* @param int $id document id
* @param array|\Elastica\Script|\Elastica\Document $data raw data for request body
* @param string $index index to update
* @param string $type type of index to update
* @param array $options array of query params to use for query. For possible options check es api
* @return \Elastica\Response
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html
*/
public function updateDocument($id, $data, $index, $type, array $options = array())
{
$path = $index . '/' . $type . '/' . $id . '/_update';
if ($data instanceof Script) {
$requestData = $data->toArray();
} elseif ($data instanceof Document) {
$requestData = array('doc' => $data->getData());
if ($data->getDocAsUpsert()) {
$requestData['doc_as_upsert'] = true;
}
$docOptions = $data->getOptions(array('version', 'version_type', 'routing', 'percolate', 'parent', 'fields', 'retry_on_conflict', 'consistency', 'replication', 'refresh', 'timeout'));
$options += $docOptions;
// set fields param to source only if options was not set before
if ($data instanceof Document && ($data->isAutoPopulate() || $this->getConfigValue(array('document', 'autoPopulate'), false)) && !isset($options['fields'])) {
$options['fields'] = '_source';
}
} else {
$requestData = $data;
}
//If an upsert document exists
if ($data instanceof Script || $data instanceof Document) {
if ($data->hasUpsert()) {
$requestData['upsert'] = $data->getUpsert()->getData();
}
}
if (!isset($options['retry_on_conflict'])) {
$retryOnConflict = $this->getConfig("retryOnConflict");
$options['retry_on_conflict'] = $retryOnConflict;
}
$response = $this->request($path, Request::POST, $requestData, $options);
if ($response->isOk() && $data instanceof Document && ($data->isAutoPopulate() || $this->getConfigValue(array('document', 'autoPopulate'), false))) {
$responseData = $response->getData();
if (isset($responseData['_version'])) {
$data->setVersion($responseData['_version']);
}
if (isset($options['fields'])) {
$this->_populateDocumentFieldsFromResponse($response, $data, $options['fields']);
}
}
return $response;
}
开发者ID:backplane,项目名称:elastica,代码行数:52,代码来源:Client.php
示例12: addScriptScoreFunction
/**
* Add a script_score function to the query.
*
* @param Script $script a Script object
* @param AbstractFilter $filter an optional filter to apply to the function
* @param float $weight the weight of the function
*
* @return $this
*/
public function addScriptScoreFunction(Script $script, AbstractFilter $filter = null, $weight = null)
{
return $this->addFunction('script_score', $script->toArray(), $filter, $weight);
}
开发者ID:MediaWiki-stable,项目名称:1.26.0,代码行数:13,代码来源:FunctionScore.php
示例13: setScript
/**
* Sets script object.
*
* @param \Elastica\Script|string|array $script
*
* @return $this
*/
public function setScript($script)
{
return $this->setParam('script', Elastica\Script::create($script));
}
开发者ID:zhangxiaoliu,项目名称:Elastica,代码行数:11,代码来源:Script.php
示例14: testUpdateDocumentWithoutSource
/**
* @group functional
*/
public function testUpdateDocumentWithoutSource()
{
$index = $this->_createIndex();
$type = $index->getType('elastica_type');
$mapping = new Mapping();
$mapping->setProperties(array('name' => array('type' => 'string', 'store' => 'yes'), 'counter' => array('type' => 'integer', 'store' => 'no')));
$mapping->disableSource();
$type->setMapping($mapping);
$newDocument = new Document();
$newDocument->setAutoPopulate();
$newDocument->set('name', 'Batman');
$newDocument->set('counter', 1);
$type->addDocument($newDocument);
$script = new Script('ctx._source.counter += count; ctx._source.name = name');
$script->setId($newDocument->getId());
$script->setParam('count', 2);
$script->setParam('name', 'robin');
$script->setUpsert($newDocument);
try {
$type->updateDocument($script);
$this->fail('Update request should fail because source is disabled. Fields param is not set');
} catch (ResponseException $e) {
$error = $e->getResponse()->getError();
$this->assertContains('document_source_missing_exception', $error['type']);
}
$newDocument->setFieldsSource();
try {
$type->updateDocument($newDocument);
$this->fail('Update request should fail because source is disabled. Fields param is set to _source');
} catch (ResponseException $e) {
$error = $e->getResponse()->getError();
$this->assertContains('document_source_missing_exception', $error['type']);
}
}
开发者ID:bungkoko,项目名称:Elastica,代码行数:37,代码来源:TypeTest.php
示例15: addFilterScript
/**
* Add a filter with a script to calculate the score
* Only script part of script object is used
*
* @param \Elastica\Filter\AbstractFilter $filter Filter object
* @param \Elastica\Script|string|array $script Script for calculating the score
* @return \Elastica\Query\CustomFiltersScore Current object
*/
public function addFilterScript(AbstractFilter $filter, $script)
{
$script = Script::create($script);
$filterParam = array('filter' => $filter->toArray(), 'script' => $script->getScript());
return $this->addParam('filters', $filterParam);
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:14,代码来源:CustomFiltersScore.php
示例16: updateDocument
/**
* Update document, using update script. Requires elasticsearch >= 0.19.0
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html
* @throws \Elastica\Exception\InvalidException
*
* @param \Elastica\Document|\Elastica\Script $data Document with update data
* @param array $options array of query params to use for query. For possible options check es api
* @return \Elastica\Response
*/
public function updateDocument($data, array $options = array())
{
if (!$data instanceof Document && !$data instanceof Script) {
throw new \InvalidArgumentException("Data should be a Document or Script");
}
if (!$data->hasId()) {
throw new InvalidException('Document or Script id is not set');
}
$id = urlencode($data->getId());
return $this->getIndex()->getClient()->updateDocument($id, $data, $this->getIndex()->getName(), $this->getName(), $options);
}
开发者ID:backplane,项目名称:elastica,代码行数:21,代码来源:Type.php
示例17: testUpdateDocumentPopulateFields
/**
* @group functional
*/
public function testUpdateDocumentPopulateFields()
{
$this->_checkScriptInlineSetting();
$index = $this->_createIndex();
$type = $index->getType('test');
$client = $index->getClient();
$newDocument = new Document(1, array('field1' => 'value1', 'field2' => 10, 'field3' => 'should be removed', 'field4' => 'value4'));
$newDocument->setAutoPopulate();
$type->addDocument($newDocument);
$script = new Script('ctx._source.field2 += count; ctx._source.remove("field3"); ctx._source.field4 = "changed"');
$script->setParam('count', 5);
$script->setUpsert($newDocument);
$client->updateDocument(1, $script, $index->getName(), $type->getName(), array('fields' => '_source'));
$data = $type->getDocument(1)->getData();
$this->assertArrayHasKey('field1', $data);
$this->assertEquals('value1', $data['field1']);
$this->assertArrayHasKey('field2', $data);
$this->assertEquals(15, $data['field2']);
$this->assertArrayHasKey('field4', $data);
$this->assertEquals('changed', $data['field4']);
$this->assertArrayNotHasKey('field3', $data);
$script = new Script('ctx._source.field2 += count; ctx._source.remove("field4"); ctx._source.field1 = field1;');
$script->setParam('count', 5);
$script->setParam('field1', 'updated');
$script->setUpsert($newDocument);
$client->updateDocument(1, $script, $index->getName(), $type->getName(), array('fields' => 'field2,field4'));
$document = $type->getDocument(1);
$data = $document->getData();
$this->assertArrayHasKey('field1', $data);
$this->assertEquals('updated', $data['field1']);
$this->assertArrayHasKey('field2', $data);
$this->assertEquals(20, $data['field2']);
$this->assertArrayNotHasKey('field3', $data);
$this->assertArrayNotHasKey('field4', $data);
}
开发者ID:bungkoko,项目名称:Elastica,代码行数:38,代码来源:ClientTest.php
示例18: setScript
/**
* @param \Elastica\Script|array|string $data
* @return \Elastica\Document
*/
public function setScript($data)
{
$script = Script::create($data);
$this->_script = $script;
return $this;
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:10,代码来源:Document.php
示例19: testSetScript
public function testSetScript()
{
$document = new Document();
$script = new Script('ctx._source.counter += count');
$script->setParam('count', 1);
$this->assertFalse($document->hasScript());
$document->setScript($script);
$this->assertTrue($document->hasScript());
$this->assertSame($script, $document->getScript());
}
开发者ID:kskod,项目名称:Elastica,代码行数:10,代码来源:DocumentTest.php
示例20: testCreateInvalid
/**
* @dataProvider dataProviderCreateInvalid
* @expectedException \Elastica\Exception\InvalidException
*/
public function testCreateInvalid($data)
{
Script::create($data);
}
开发者ID:viz,项目名称:wordpress-fantastic-elasticsearch,代码行数:8,代码来源:ScriptTest.php
注:本文中的Elastica\Script类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论