mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-29 13:10:06 +02:00
Added possibility to apply filters to search results.
This commit is contained in:
parent
c3f144447f
commit
e96db21ceb
6 changed files with 61 additions and 30 deletions
|
@ -9,7 +9,7 @@ class PartSearchFilter implements FilterInterface
|
|||
{
|
||||
|
||||
/** @var string The string to query for */
|
||||
protected $query;
|
||||
protected $keyword;
|
||||
|
||||
/** @var boolean Whether to use regex for searching */
|
||||
protected $regex = false;
|
||||
|
@ -49,7 +49,7 @@ class PartSearchFilter implements FilterInterface
|
|||
|
||||
public function __construct(string $query)
|
||||
{
|
||||
$this->query = $query;
|
||||
$this->keyword = $query;
|
||||
}
|
||||
|
||||
protected function getFieldsToSearch(): array
|
||||
|
@ -95,7 +95,7 @@ class PartSearchFilter implements FilterInterface
|
|||
$fields_to_search = $this->getFieldsToSearch();
|
||||
|
||||
//If we have nothing to search for, do nothing
|
||||
if (empty($fields_to_search) || empty($this->query)) {
|
||||
if (empty($fields_to_search) || empty($this->keyword)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -115,27 +115,27 @@ class PartSearchFilter implements FilterInterface
|
|||
|
||||
//For regex we pass the query as is, for like we add % to the start and end as wildcards
|
||||
if ($this->regex) {
|
||||
$queryBuilder->setParameter('search_query', $this->query);
|
||||
$queryBuilder->setParameter('search_query', $this->keyword);
|
||||
} else {
|
||||
$queryBuilder->setParameter('search_query', '%' . $this->query . '%');
|
||||
$queryBuilder->setParameter('search_query', '%' . $this->keyword . '%');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getQuery(): string
|
||||
public function getKeyword(): string
|
||||
{
|
||||
return $this->query;
|
||||
return $this->keyword;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param string $keyword
|
||||
* @return PartSearchFilter
|
||||
*/
|
||||
public function setQuery(string $query): PartSearchFilter
|
||||
public function setKeyword(string $keyword): PartSearchFilter
|
||||
{
|
||||
$this->query = $query;
|
||||
$this->keyword = $keyword;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue