| @@ 34-66 (lines=33) @@ | ||
| 31 | /** |
|
| 32 | * @group functional |
|
| 33 | */ |
|
| 34 | public function testDotExpanderField(): void |
|
| 35 | { |
|
| 36 | $dotExpander = new DotExpanderProcessor('foo.bar'); |
|
| 37 | ||
| 38 | $pipeline = $this->_createPipeline('my_custom_pipeline', 'pipeline for DotExpander'); |
|
| 39 | $pipeline->addProcessor($dotExpander)->create(); |
|
| 40 | ||
| 41 | $index = $this->_createIndex(); |
|
| 42 | ||
| 43 | // Add document to normal index |
|
| 44 | $doc1 = new Document(null, ['foo.bar' => 'value']); |
|
| 45 | ||
| 46 | $bulk = new Bulk($index->getClient()); |
|
| 47 | $bulk->setIndex($index); |
|
| 48 | ||
| 49 | $bulk->addDocument($doc1); |
|
| 50 | $bulk->setRequestParam('pipeline', 'my_custom_pipeline'); |
|
| 51 | ||
| 52 | $bulk->send(); |
|
| 53 | $index->refresh(); |
|
| 54 | ||
| 55 | $result = $index->search('*'); |
|
| 56 | ||
| 57 | $this->assertCount(1, $result->getResults()); |
|
| 58 | ||
| 59 | $expect = [ |
|
| 60 | 'foo' => [ |
|
| 61 | 'bar' => 'value', |
|
| 62 | ], |
|
| 63 | ]; |
|
| 64 | $results = $result->getResults(); |
|
| 65 | $this->assertEquals($expect, ($results[0]->getHit())['_source']); |
|
| 66 | } |
|
| 67 | } |
|
| 68 | ||
| @@ 54-84 (lines=31) @@ | ||
| 51 | /** |
|
| 52 | * @group functional |
|
| 53 | */ |
|
| 54 | public function testJsonField(): void |
|
| 55 | { |
|
| 56 | $json = new JsonProcessor('name'); |
|
| 57 | $json->setTargetField('realname'); |
|
| 58 | ||
| 59 | $pipeline = $this->_createPipeline('my_custom_pipeline', 'pipeline for Json'); |
|
| 60 | $pipeline->addProcessor($json)->create(); |
|
| 61 | ||
| 62 | $index = $this->_createIndex(); |
|
| 63 | $bulk = new Bulk($index->getClient()); |
|
| 64 | $bulk->setIndex($index); |
|
| 65 | ||
| 66 | $bulk->addDocument(new Document(null, ['name' => \json_encode(['foo' => 2000])])); |
|
| 67 | $bulk->setRequestParam('pipeline', 'my_custom_pipeline'); |
|
| 68 | ||
| 69 | $bulk->send(); |
|
| 70 | $index->refresh(); |
|
| 71 | ||
| 72 | $result = $index->search('*'); |
|
| 73 | ||
| 74 | $this->assertCount(1, $result->getResults()); |
|
| 75 | ||
| 76 | $resultExpected = [ |
|
| 77 | 'foo' => 2000, |
|
| 78 | ]; |
|
| 79 | ||
| 80 | foreach ($result->getResults() as $rx) { |
|
| 81 | $value = $rx->getData(); |
|
| 82 | $this->assertEquals($resultExpected, $value['realname']); |
|
| 83 | } |
|
| 84 | } |
|
| 85 | } |
|
| 86 | ||