Skip to content

Commit

Permalink
avoid problems with unknown languages
Browse files Browse the repository at this point in the history
we fall back to the standard analyzer then
  • Loading branch information
splitbrain committed Jul 25, 2019
1 parent b38b23e commit 53ee83d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions helper/client.php
Expand Up @@ -110,7 +110,7 @@ public function createLanguageMapping() {
'fields' => [
$conf['lang'] => [
'type' => 'text',
'analyzer' => self::ANALYZERS[$conf['lang']]
'analyzer' => $this->getLanguageAnalyzer($conf['lang'])
],
]
]
Expand All @@ -124,7 +124,7 @@ public function createLanguageMapping() {
if ($translations) foreach ($translations as $lang) {
$props['content']['fields'][$lang] = [
'type' => 'text',
'analyzer' => self::ANALYZERS[$lang]
'analyzer' => $this->getLanguageAnalyzer($lang)
];
}
}
Expand All @@ -135,6 +135,20 @@ public function createLanguageMapping() {
$response = $mapping->send();
return $response;
}

/**
* Get the correct analyzer for the given language code
*
* Returns the standard analalyzer for unknown languages
*
* @param string $lang
* @return string
*/
protected function getLanguageAnalyzer($lang)
{
if (isset(self::ANALYZERS[$lang])) return self::ANALYZERS[$lang];
return 'standard';
}
}

// vim:ts=4:sw=4:et:

0 comments on commit 53ee83d

Please sign in to comment.