FOC Search plugin: Search multiple values in multiple db fields


#1

I have one input field ‘q‘ where enter one or more keywords (q=frankfurt+de) to search in three db fields (name, city, country)., where frankfurt is city and de is country code.

$this->searchManager()
     ->value('q')
     ->add('q', 'Search.Like', [
         'before' => true,
         'after' => true,
         'multiValue' => true,
         'fieldMode' => 'OR',
         //'valueMode' =>OR',
         //'mode'=>'OR',
         'comparison' => 'LIKE',
         'wildcardAny' => '*',
         'wildcardOne' => '?',
         'field' => ['name', 'city','country']
     ]);

}

This produce sql query like:

FROM 
  `companies` `Companies` 
WHERE 
  (
    `Companies`.`name` like '%frankfurt de%' 
    OR `Companies`.`city` like '%frankfurt de%' 
    OR `Companies`.`country` like '%frankfurt de%'
  )  

How to setup this plugin to produce right sql query, to find multiple keywords in multiple db fields?


#2

Solved, by adding in beforeFilter:

    if(isset($this->request->query['q'])){
      $this->request->query['q'] = explode(" ", $this->request->query['q']);
    }