mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-08-09 10:22:51 +03:00
Search: Added structure for search term inputs
Sets things up to allow more complex terms ready to handle negation.
This commit is contained in:
56
app/Search/SearchOptionSet.php
Normal file
56
app/Search/SearchOptionSet.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace BookStack\Search;
|
||||
|
||||
class SearchOptionSet
|
||||
{
|
||||
/**
|
||||
* @var SearchOption[]
|
||||
*/
|
||||
public array $options = [];
|
||||
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
public function toValueArray(): array
|
||||
{
|
||||
return array_map(fn(SearchOption $option) => $option->value, $this->options);
|
||||
}
|
||||
|
||||
public function toValueMap(): array
|
||||
{
|
||||
$map = [];
|
||||
foreach ($this->options as $key => $option) {
|
||||
$map[$key] = $option->value;
|
||||
}
|
||||
return $map;
|
||||
}
|
||||
|
||||
public function merge(SearchOptionSet $set): self
|
||||
{
|
||||
return new self(array_merge($this->options, $set->options));
|
||||
}
|
||||
|
||||
public function filterEmpty(): self
|
||||
{
|
||||
$filteredOptions = array_filter($this->options, fn (SearchOption $option) => !empty($option->value));
|
||||
return new self($filteredOptions);
|
||||
}
|
||||
|
||||
public static function fromValueArray(array $values): self
|
||||
{
|
||||
$options = array_map(fn($val) => new SearchOption($val), $values);
|
||||
return new self($options);
|
||||
}
|
||||
|
||||
public static function fromMapArray(array $values): self
|
||||
{
|
||||
$options = [];
|
||||
foreach ($values as $key => $value) {
|
||||
$options[$key] = new SearchOption($value);
|
||||
}
|
||||
return new self($options);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user