当前位置: 首页>>代码示例>>PHP>>正文


PHP Script::setParam方法代码示例

本文整理汇总了PHP中Elastica\Script::setParam方法的典型用法代码示例。如果您正苦于以下问题:PHP Script::setParam方法的具体用法?PHP Script::setParam怎么用?PHP Script::setParam使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Elastica\Script的用法示例。


在下文中一共展示了Script::setParam方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: testUpdateDocumentPopulateFields

 public function testUpdateDocumentPopulateFields()
 {
     $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);
     $newDocument->setScript($script);
     $client->updateDocument(1, $newDocument, $index->getName(), $type->getName(), array('fields' => '_source'));
     $data = $newDocument->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');
     $newDocument->setScript($script);
     $client->updateDocument(1, $newDocument, $index->getName(), $type->getName(), array('fields' => 'field2,field4'));
     $data = $newDocument->getData();
     $this->assertArrayHasKey('field1', $data);
     $this->assertEquals('value1', $data['field1'], 'Field1 should not be updated, because it is not in fields list');
     $this->assertArrayHasKey('field2', $data);
     $this->assertEquals(20, $data['field2'], 'Field2 should be 20 after incrementing by 5');
     $this->assertArrayNotHasKey('field3', $data, 'Field3 should be removed already');
     $this->assertArrayNotHasKey('field4', $data, 'Field3 should be removed');
     $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:kskod,项目名称:Elastica,代码行数:41,代码来源:ClientTest.php


注:本文中的Elastica\Script::setParam方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。