|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace Spameri\ElasticQuery\Mapping\Analyzer\Custom\Synonym; |
| 4 | + |
| 5 | +abstract class AbstractSynonym |
| 6 | + implements \Spameri\ElasticQuery\Mapping\CustomAnalyzerInterface, |
| 7 | + \Spameri\ElasticQuery\Collection\Item |
| 8 | +{ |
| 9 | + |
| 10 | + /** |
| 11 | + * @var \Spameri\ElasticQuery\Mapping\Settings\Analysis\FilterCollection |
| 12 | + */ |
| 13 | + protected $filter; |
| 14 | + |
| 15 | + /** |
| 16 | + * @var \Spameri\ElasticQuery\Mapping\Filter\Stop |
| 17 | + */ |
| 18 | + protected $stopFilter; |
| 19 | + |
| 20 | + /** |
| 21 | + * @var array |
| 22 | + */ |
| 23 | + protected $synonyms; |
| 24 | + |
| 25 | + |
| 26 | + public function __construct( |
| 27 | + ?\Spameri\ElasticQuery\Mapping\Filter\Stop $stopFilter = NULL, |
| 28 | + array $synonyms |
| 29 | + ) |
| 30 | + { |
| 31 | + $this->stopFilter = $stopFilter; |
| 32 | + $this->synonyms = $synonyms; |
| 33 | + } |
| 34 | + |
| 35 | + |
| 36 | + public function key() : string |
| 37 | + { |
| 38 | + return $this->name(); |
| 39 | + } |
| 40 | + |
| 41 | + |
| 42 | + public function getType() : string |
| 43 | + { |
| 44 | + return 'custom'; |
| 45 | + } |
| 46 | + |
| 47 | + |
| 48 | + public function tokenizer() : string |
| 49 | + { |
| 50 | + return 'standard'; |
| 51 | + } |
| 52 | + |
| 53 | + |
| 54 | + public function toArray() : array |
| 55 | + { |
| 56 | + $filterArray = []; |
| 57 | + /** @var \Spameri\ElasticQuery\Mapping\FilterInterface $filter */ |
| 58 | + foreach ($this->filter() as $filter) { |
| 59 | + if ($filter instanceof \Spameri\ElasticQuery\Mapping\Filter\Synonym) { |
| 60 | + $filterArray[] = $filter->getName(); |
| 61 | + |
| 62 | + } elseif ($filter instanceof \Spameri\ElasticQuery\Mapping\Filter\Stop) { |
| 63 | + $filterArray[] = $filter->getName(); |
| 64 | + |
| 65 | + } else { |
| 66 | + $filterArray[] = $filter->getType(); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + return [ |
| 71 | + $this->name() => [ |
| 72 | + 'type' => $this->getType(), |
| 73 | + 'tokenizer' => $this->tokenizer(), |
| 74 | + 'filter' => $filterArray, |
| 75 | + ], |
| 76 | + ]; |
| 77 | + } |
| 78 | + |
| 79 | + |
| 80 | +} |
0 commit comments