feat: implement wild card search
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -47,6 +47,20 @@ class Store {
|
||||
'tags' => 'data.tags',
|
||||
];
|
||||
|
||||
/**
|
||||
* Document paths searched by the wildcard "*" (search-all) entity filter
|
||||
* attribute (CAPABILITY_ENTITY_FILTER_ALL).
|
||||
*
|
||||
* Name fields only for now: emails and organizations are stored as keyed
|
||||
* objects, which a plain find() cannot regex-match without an aggregation
|
||||
* expression — deferred to a later pass.
|
||||
*/
|
||||
protected array $_EntityFilterWildcardFields = [
|
||||
'data.names.given',
|
||||
'data.names.family',
|
||||
'data.label',
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
protected readonly DataStore $_store
|
||||
) { }
|
||||
@@ -55,10 +69,26 @@ class Store {
|
||||
$mongoFilter = [];
|
||||
|
||||
foreach ($filter->conditions() as $entry) {
|
||||
// Wildcard "*" search-all: expand a LIKE/NLIKE into an $or regex
|
||||
// across the human-searchable name fields. Only meaningful for
|
||||
// entity queries; collection filters never carry the "*" attribute.
|
||||
if ($entry['attribute'] === '*' && $map === $this->_EntityFilterAttributeMap) {
|
||||
$value = $entry['value'];
|
||||
$comparator = $entry['comparator'] ?? FilterComparisonOperator::LIKE;
|
||||
$condition = match ($comparator) {
|
||||
FilterComparisonOperator::NLIKE => ['$not' => ['$regex' => $value, '$options' => 'i']],
|
||||
default => ['$regex' => $value, '$options' => 'i'],
|
||||
};
|
||||
foreach ($this->_EntityFilterWildcardFields as $field) {
|
||||
$mongoFilter['$or'][] = [$field => $condition];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($map[$entry['attribute']])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$attribute = $map[$entry['attribute']];
|
||||
$value = $entry['value'];
|
||||
$comparator = $entry['comparator'] ?? FilterComparisonOperator::EQ;
|
||||
|
||||
Reference in New Issue
Block a user