Skip to content

Commit e8a0860

Browse files
authored
Result: Add support for box filtering.
1 parent 35f8fcc commit e8a0860

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/Entity/EngineSingleResult.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,26 @@ class EngineSingleResult extends EngineResult
2525
*/
2626
private $sources;
2727

28+
/**
29+
* @var string[]
30+
*/
31+
private $filters;
32+
2833
/**
2934
* @param string $query
3035
* @param string $matchedRoute
3136
* @param Box|null $interpret
3237
* @param Box[] $boxes
3338
* @param Source[] $sources
39+
* @param string[] $filters
3440
*/
35-
public function __construct(string $query, string $matchedRoute, ?Box $interpret = null, array $boxes = [], array $sources = [])
41+
public function __construct(string $query, string $matchedRoute, ?Box $interpret = null, array $boxes = [], array $sources = [], array $filters = [])
3642
{
3743
parent::__construct($query, $matchedRoute);
3844
$this->interpret = $interpret;
3945
$this->boxes = $boxes;
4046
$this->sources = $sources;
47+
$this->filters = $filters;
4148
}
4249

4350
/**
@@ -55,6 +62,14 @@ public function getBoxes(): array
5562

5663
$return = $withoutNoResult === [] ? $this->boxes : $withoutNoResult;
5764

65+
if ($this->filters !== []) {
66+
foreach ($return as $boxKey => $box) {
67+
if (\in_array($box->getTag(), $this->filters, true) === false) {
68+
unset($return[$boxKey]);
69+
}
70+
}
71+
}
72+
5873
usort($return, static function (Box $a, Box $b): int {
5974
return $a->getRank() < $b->getRank() ? 1 : -1;
6075
});
@@ -100,4 +115,4 @@ public function addSource(Source $source): self
100115
return $this;
101116
}
102117

103-
}
118+
}

0 commit comments

Comments
 (0)