Skip to content

Commit 33051a3

Browse files
authored
Update SearchController.php
1 parent 2eb342c commit 33051a3

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/SearchController.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ class SearchController{
7575
*/
7676
private $queryEnd;
7777

78+
/**
79+
* @var bool Search request query in lowercase
80+
*/
81+
private $lowerCaseQuery = false;
82+
7883
public function __construct($algorithm = self::OR) {
7984
$this->searchAlgorithm = $algorithm;
8085
$this->operators = self::END_WITH_QUERY;
@@ -131,6 +136,12 @@ public function setQuery($query){
131136
$this->searchQuery = htmlspecialchars($query, ENT_QUOTES, "UTF-8");
132137
return $this;
133138
}
139+
140+
public function toLower(){
141+
$this->lowerCaseQuery = true;
142+
$this->searchQuery = strtolower($this->searchQuery);
143+
return $this;
144+
}
134145

135146
/**
136147
* Set query prefix string.
@@ -174,7 +185,7 @@ private function format($value) {
174185
$queryString = "";
175186
foreach($this->paramArray as $col){
176187
$sqlQuery = str_replace("query", $value, $this->operators);
177-
$queryString .= $col . " {$this->queryStart} '{$sqlQuery}' {$this->queryEnd} ";
188+
$queryString .= ($this->lowerCaseQuery ? "LOWER(" . $col . ")" : $col ) . " {$this->queryStart} '{$sqlQuery}' {$this->queryEnd} ";
178189
}
179190
return $queryString;
180191
}

0 commit comments

Comments
 (0)