search api phrase query instead of direct

This commit is contained in:
Bachir Soussi Chiadmi 2023-10-25 09:37:10 +02:00
parent 0a9b1291e7
commit 5df81ea019

View File

@ -17,7 +17,14 @@ use Drupal\search_api\Entity\Index;
*/ */
class Search extends ControllerBase { class Search extends ControllerBase {
private $content_type;
private $index;
private $results;
private $or_query;
private $phrase;
private $keys;
private $offset;
private $limit;
// private $limit = 15; // private $limit = 15;
// private $offset = 0; // private $offset = 0;
@ -48,7 +55,7 @@ class Search extends ControllerBase {
// - « phrase » => Single phrase // - « phrase » => Single phrase
// - " edismax " => ??? // - " edismax " => ???
$or_parse_mode = \Drupal::service('plugin.manager.search_api.parse_mode') $or_parse_mode = \Drupal::service('plugin.manager.search_api.parse_mode')
->createInstance('direct'); ->createInstance('phrase');
$or_parse_mode->setConjunction('OR'); $or_parse_mode->setConjunction('OR');
$this->or_query->setParseMode($or_parse_mode); $this->or_query->setParseMode($or_parse_mode);
@ -105,9 +112,9 @@ class Search extends ControllerBase {
*/ */
private function parseRequest(Request $request){ private function parseRequest(Request $request){
// Get the typed string from the URL, if it exists. // Get the typed string from the URL, if it exists.
$this->keys = $request->query->get('keys'); $this->phrase = $request->query->get('phrase');
if($this->keys){ if($this->phrase){
$this->keys = mb_strtolower($this->keys); $this->keys = mb_strtolower($this->phrase);
$this->keys = Tags::explode($this->keys); $this->keys = Tags::explode($this->keys);
// \Drupal::logger('ouatt_searchapi')->notice($this->keys); // \Drupal::logger('ouatt_searchapi')->notice($this->keys);
} }