Author Topic: Multiple search terms with condition  (Read 1202 times)

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 341
    • View Profile
Multiple search terms with condition
« on: March 17, 2021, 03:35:40 pm »
Hi

For contain condition would it be possible to use keywords to split string to multiple search terms?
Ex:

term1+term2+term3 generates (PHP) query to DB:

Code: [Select]
...WHERE a LIKE '%term1%' AND a LIKE '%term2%' AND a LIKE '%term3%'
instead of

Code: [Select]
...WHERE a LIKE '%term1+term2+term3%'
« Last Edit: March 17, 2021, 05:16:57 pm by queensgambit9 »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6255
    • View Profile
Re: Multiple search terms with condition
« Reply #1 on: March 18, 2021, 10:03:26 am »
yes it's possible to do so by updating FilterHelper::_contain method in PHP code.

Code: [Select]
    public static function _contain($dataIndx, &$fcrule, &$param, $value){
        $_fcrule = array();
        $arr = explode("+", $value);
        foreach ($arr as $val) {
            $_fcrule[] = $dataIndx . " like CONCAT('%', ?, '%')";
            $param[] = $val;
        }
        $fcrule[] = implode(" AND ", $_fcrule);
    }