From 5df81ea019b9e24cea1a3e2bb57e8f90419d027c Mon Sep 17 00:00:00 2001 From: bach Date: Wed, 25 Oct 2023 09:37:10 +0200 Subject: [PATCH] search api phrase query instead of direct --- .../ouatt_searchapi/src/Controller/Search.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/web/modules/custom/ouatt_searchapi/src/Controller/Search.php b/src/web/modules/custom/ouatt_searchapi/src/Controller/Search.php index 33664b4..99ee89b 100644 --- a/src/web/modules/custom/ouatt_searchapi/src/Controller/Search.php +++ b/src/web/modules/custom/ouatt_searchapi/src/Controller/Search.php @@ -17,7 +17,14 @@ use Drupal\search_api\Entity\Index; */ 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 $offset = 0; @@ -48,7 +55,7 @@ class Search extends ControllerBase { // - « phrase » => Single phrase // - " edismax " => ??? $or_parse_mode = \Drupal::service('plugin.manager.search_api.parse_mode') - ->createInstance('direct'); + ->createInstance('phrase'); $or_parse_mode->setConjunction('OR'); $this->or_query->setParseMode($or_parse_mode); @@ -105,9 +112,9 @@ class Search extends ControllerBase { */ private function parseRequest(Request $request){ // Get the typed string from the URL, if it exists. - $this->keys = $request->query->get('keys'); - if($this->keys){ - $this->keys = mb_strtolower($this->keys); + $this->phrase = $request->query->get('phrase'); + if($this->phrase){ + $this->keys = mb_strtolower($this->phrase); $this->keys = Tags::explode($this->keys); // \Drupal::logger('ouatt_searchapi')->notice($this->keys); }