Добавление фильтра STARTS_WIDTH для регистронезависимого поиска
This commit is contained in:
parent
cbc26916ea
commit
b92e8792f0
|
@ -81,6 +81,18 @@ class Query extends Component implements QueryInterface
|
|||
*/
|
||||
public string $searchType = 'START';
|
||||
|
||||
/**
|
||||
* Поиск
|
||||
*
|
||||
* [свойство => его значение]
|
||||
*/
|
||||
public array $filter;
|
||||
|
||||
/**
|
||||
* Тип поиска
|
||||
*/
|
||||
public string $filterType = 'START';
|
||||
|
||||
public $orderBy;
|
||||
|
||||
public $indexBy;
|
||||
|
@ -229,13 +241,21 @@ class Query extends Component implements QueryInterface
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function filter(array $text, string $type = 'START'): self
|
||||
{
|
||||
$this->filter = $text;
|
||||
$this->filterType = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Обойти коллекцию вершин по направлению
|
||||
*
|
||||
* Генерация AQL выражения
|
||||
*
|
||||
* @see https://www.arangodb.com/docs/3.7/aql/operations-let.html
|
||||
*
|
||||
* @param mixed $vertex Коллекция вершин из которой требуется обход
|
||||
* @param string $direction Направление ('INBOUND', 'OUTBOUND', 'ANY')
|
||||
*/
|
||||
|
@ -851,6 +871,7 @@ class Query extends Component implements QueryInterface
|
|||
$query->genForeach($query->foreach),
|
||||
$query->genWhere($query->where, $params),
|
||||
isset($query->search) ? $query->genSearch($query->search, $query->searchType) : null,
|
||||
isset($query->filter) ? $query->genFilter($query->filter, $query->filterType) : null,
|
||||
$query->genOrderBy($query->orderBy, $params),
|
||||
$query->genLimit($query->limit, $query->offset, $params),
|
||||
$query->genSelect($query->select, $params),
|
||||
|
@ -1115,6 +1136,24 @@ class Query extends Component implements QueryInterface
|
|||
|
||||
return match (strtoupper($type)) {
|
||||
'START', 'STARTS', 'STARTS_WITH' => $query . $this->filterStartsWith($expression),
|
||||
'START_SENSETIVE' => $query . $this->filterStartsWith($expression, sensetive: true),
|
||||
'CONTAINS', 'LIKE' => $query . $this->filterContains($expression),
|
||||
default => $query . Serializer::encode($expression)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $collection
|
||||
* @param $columns
|
||||
* @return string
|
||||
*/
|
||||
protected function genFilter(array $expression, string $type = 'START'): string
|
||||
{
|
||||
$query = 'FILTER ';
|
||||
|
||||
return match (strtoupper($type)) {
|
||||
'START', 'STARTS', 'STARTS_WITH' => $query . $this->filterStartsWith($expression),
|
||||
'START_SENSETIVE' => $query . $this->filterStartsWith($expression, sensetive: true),
|
||||
'CONTAINS', 'LIKE' => $query . $this->filterContains($expression),
|
||||
default => $query . Serializer::encode($expression)
|
||||
};
|
||||
|
@ -1157,8 +1196,6 @@ class Query extends Component implements QueryInterface
|
|||
*
|
||||
* Генерация AQL выражения
|
||||
*
|
||||
* @see https://www.arangodb.com/docs/3.7/aql/operations-let.html
|
||||
*
|
||||
* @param string $direction Направление
|
||||
* @param mixed $vertex Коллекция вершин из которой требуется обход
|
||||
*/
|
||||
|
@ -1399,20 +1436,38 @@ class Query extends Component implements QueryInterface
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function filterStartsWith(array $expression): string
|
||||
public function filterStartsWith(array $expression, bool $sensetive = false): string
|
||||
{
|
||||
// Генерация
|
||||
foreach ($expression as $key => $value) {
|
||||
if ($sensetive) {
|
||||
if (isset($return)) {
|
||||
$return .= ' OR STARTS_WITH(' . $this->filterLower($this->quoteCollectionName($this->collection) . ".$key") . ", " . $this->filterLower("\"$value\"") . ")";
|
||||
} else {
|
||||
$return = 'STARTS_WITH(' . $this->filterLower($this->quoteCollectionName($this->collection) . ".$key") . ", " . $this->filterLower("\"$value\"") . ")";
|
||||
}
|
||||
} else {
|
||||
if (isset($return)) {
|
||||
$return .= ' OR STARTS_WITH(' . $this->quoteCollectionName($this->collection) . ".$key, \"$value\")";
|
||||
} else {
|
||||
$return = 'STARTS_WITH(' . $this->quoteCollectionName($this->collection) . ".$key, \"$value\")";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function filterUpper(string $target): string
|
||||
{
|
||||
return "UPPER($target)";
|
||||
}
|
||||
|
||||
public function filterLower(string $target): string
|
||||
{
|
||||
return "LOWER($target)";
|
||||
}
|
||||
|
||||
public function filterContains(array $expression): string
|
||||
{
|
||||
// Инициализация
|
||||
|
|
Loading…
Reference in New Issue