Skip to content

Commit 874e7a9

Browse files
authored
Update SearchController.php
1 parent 45019b3 commit 874e7a9

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/SearchController.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,44 @@ private function buildSQL(){
216216
}
217217
return $sql;
218218
}
219+
220+
/**
221+
* Gets sql search query by apending AND clause.
222+
* @return string SQL query
223+
*/
224+
public function getAndQuery(){
225+
return $this->generateQuery("AND");
226+
}
227+
228+
/**
229+
* Gets sql search query by apending WHERE clause.
230+
* @return string SQL query
231+
*/
232+
public function getWhereQuery(){
233+
return $this->generateQuery("WHERE");
234+
}
235+
236+
/**
237+
* Gets sql search query by automatically detecting and apending start clause.
238+
* @return string SQL query
239+
*/
240+
public function getQuery(){
241+
return $this->generateQuery();
242+
}
219243

220244
/**
221245
* Execute search query.
246+
* @param string $checkOpt the search query start operator
222247
* @return string SQL query
223248
*/
224-
public function getQuery(){
249+
public function generateQuery($checkOpt = "AUTO"){
225250
if (!empty($this->searchQuery)){
226251
if (!empty($this->searchQuery)){
227-
$this->QueryCondition .= (!empty($this->QueryCondition) ? " AND (" : " WHERE (");
252+
if($checkOpt != "AUTO" && empty($this->QueryCondition)){
253+
$this->QueryCondition .= " {$checkOpt} (";
254+
}else{
255+
$this->QueryCondition .= (!empty($this->QueryCondition) ? " AND (" : " WHERE (");
256+
}
228257
switch ($this->searchAlgorithm){
229258
case self::OR:
230259
$this->setStart(self::LIKE);

0 commit comments

Comments
 (0)