]> _ Git - cubist_cms-back.git/commitdiff
wip #3305 @0.75
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 3 Jan 2020 18:14:32 +0000 (19:14 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 3 Jan 2020 18:14:32 +0000 (19:14 +0100)
src/app/Console/Commands/SearchIndexCommand.php
src/app/Magic/Menu/Menu.php
src/app/Magic/Search.php

index a794f6b633417dfc11c853509c256ed9582f5580..27c1928a2f6acb5baf60ac9e02bda47c5eb9f998 100644 (file)
@@ -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'));
     }
 
 
index fa85585838d2648c2a9b3a18c1a804a4975f05e5..c2a1b800dc59448f64d32a9f6f630d3025f92e07 100644 (file)
@@ -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;
             }
index aa0f32054359b2ce532cf94f819395d227b0106f..d4d3f6426a818ca3e622a74e70039f72c2b1b912 100644 (file)
@@ -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) {