Skip to content

Commit 55dea3a

Browse files
committed
StopWords filter can accept extra stop words
1 parent 83e26eb commit 55dea3a

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/Mapping/Filter/Stop.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@
88
abstract class Stop implements \Spameri\ElasticQuery\Mapping\FilterInterface
99
{
1010

11+
12+
/**
13+
* @var array<string>
14+
*/
15+
private $extraWords;
16+
17+
18+
public function __construct(
19+
array $extraWords = []
20+
)
21+
{
22+
$this->extraWords = $extraWords;
23+
}
24+
25+
1126
public function getType() : string
1227
{
1328
return 'stop';
@@ -17,6 +32,9 @@ public function getType() : string
1732
abstract public function getStopWords() : array;
1833

1934

35+
abstract public function getName() : string;
36+
37+
2038
public function key() : string
2139
{
2240
return $this->getName();
@@ -25,10 +43,15 @@ public function key() : string
2543

2644
public function toArray() : array
2745
{
46+
$stopWords = $this->getStopWords();
47+
if ($this->extraWords) {
48+
$stopWords += $this->extraWords;
49+
}
50+
2851
return [
2952
$this->getName() => [
3053
'type' => $this->getType(),
31-
'stopwords' => $this->getStopWords(),
54+
'stopwords' => $stopWords,
3255
],
3356
];
3457
}

0 commit comments

Comments
 (0)