From 1d2b2e33ed28ca932d1af3f47e3f658942b7be82 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 3 Jan 2020 19:14:32 +0100 Subject: [PATCH] wip #3305 @0.75 --- .../Console/Commands/SearchIndexCommand.php | 4 +- src/app/Magic/Menu/Menu.php | 6 +- src/app/Magic/Search.php | 65 ++++++++++++++++--- 3 files changed, 61 insertions(+), 14 deletions(-) diff --git a/src/app/Console/Commands/SearchIndexCommand.php b/src/app/Console/Commands/SearchIndexCommand.php index a794f6b..27c1928 100644 --- a/src/app/Console/Commands/SearchIndexCommand.php +++ b/src/app/Console/Commands/SearchIndexCommand.php @@ -16,12 +16,12 @@ use Cubist\Util\XML\DOMSelector; class SearchIndexCommand extends Command { - protected $signature = 'cubist:search:index'; + protected $signature = 'cubist:search:index {locale=all}'; protected $description = 'Index data for search engine'; public function handle() { - Search::index(); + Search::index($this->argument('locale')); } diff --git a/src/app/Magic/Menu/Menu.php b/src/app/Magic/Menu/Menu.php index fa85585..c2a1b80 100644 --- a/src/app/Magic/Menu/Menu.php +++ b/src/app/Magic/Menu/Menu.php @@ -72,9 +72,9 @@ class Menu extends BaseMenu /** * @return Cubist\Backpack\app\Magic\Menu\Item[] */ - public static function getAllNavigablePages() + public static function getAllNavigablePages($locale = null) { - $pages = self::getNavigation()->findAll(); + $pages = self::getNavigation($locale)->findAll(); $res = []; @@ -99,7 +99,7 @@ class Menu extends BaseMenu continue; } - $url = action('PageController@catchall', ['page' => $href]); + $url = $page->getURL(); if (isset($res[$url])) { continue; } diff --git a/src/app/Magic/Search.php b/src/app/Magic/Search.php index aa0f320..d4d3f64 100644 --- a/src/app/Magic/Search.php +++ b/src/app/Magic/Search.php @@ -22,7 +22,13 @@ class Search ], 'en' => [ 'type' => 'text', - 'analyser' => 'english', + 'analyzer' => 'english_light', + 'fields' => [ + 'stemmed' => [ + 'type' => 'text', + 'analyzer' => 'english_heavy' + ] + ] ], 'de' => [ 'type' => 'text', @@ -86,13 +92,51 @@ class Search ] ] ] + ], + 'en' => [ + "filter" => [ + "english_synonym" => [ + "type" => "synonym", + "ignore_case" => true, + "expand" => true, + "synonyms" => [ + 'pmi, pm instrumentation', + ] + ], + "english_stemmer" => [ + "type" => "stemmer", + "language" => "light_english" + ] + ], + "analyzer" => [ + "english_heavy" => [ + "tokenizer" => "icu_tokenizer", + "char_filter" => ["html_strip"], + "filter" => [ + "icu_folding", + "english_synonym", + "english_stemmer" + ] + ], + "english_light" => [ + "tokenizer" => "icu_tokenizer", + "char_filter" => ["html_strip"], + "filter" => [ + "icu_folding" + ] + ] + ] ] ]; - public static function index() + public static function index($locale = 'all') { - foreach (Locale::getLocales() as $locale) { + if ($locale !== 'all') { self::indexLocale($locale); + return; + } + foreach (Locale::getLocales() as $l) { + self::indexLocale($l->locale); } } @@ -112,18 +156,21 @@ class Search $settings['analysis'] = $analysis; } + $body = [ + 'mappings' => self::_typeMapping($locale, true), + ]; + if (count($settings) > 0) { + $body['settings'] = $settings; + } + Elasticsearch::indices()->create( [ 'index' => $index, - 'body' => [ - 'settings' => $settings, - 'mappings' => self::_typeMapping($locale, true), - ] + 'body' => $body ]); /** @var Cubist\Backpack\app\Magic\Menu\Item[] $pages */ - $pages = Menu::getAllNavigablePages(); - + $pages = Menu::getAllNavigablePages($locale); $indexed = []; foreach ($pages as $url => $page) { -- 2.39.5