mirror of
https://github.com/YGGverse/YGGo.git
synced 2025-08-26 13:51:55 +00:00
add transliteration support in search requests #13
This commit is contained in:
parent
57332b1449
commit
ca92db8826
@ -282,6 +282,7 @@ See also: [SQLite tree](https://github.com/YGGverse/YGGo/tree/sqliteway)
|
|||||||
* Engine sources [MIT License](https://github.com/YGGverse/YGGo/blob/main/LICENSE)
|
* Engine sources [MIT License](https://github.com/YGGverse/YGGo/blob/main/LICENSE)
|
||||||
* Home page animation by [alvarotrigo](https://codepen.io/alvarotrigo/pen/GRvYNax)
|
* Home page animation by [alvarotrigo](https://codepen.io/alvarotrigo/pen/GRvYNax)
|
||||||
* CLI logo by [patorjk.com](https://patorjk.com/software/taag/#p=display&f=Slant&t=YGGo!)
|
* CLI logo by [patorjk.com](https://patorjk.com/software/taag/#p=display&f=Slant&t=YGGo!)
|
||||||
|
* Transliteration by [php-translit](https://github.com/ashtokalo/php-translit)
|
||||||
* Identicons by [jdenticon](https://github.com/dmester/jdenticon-php)
|
* Identicons by [jdenticon](https://github.com/dmester/jdenticon-php)
|
||||||
|
|
||||||
#### Feedback
|
#### Feedback
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
"yggverse/cache": ">=0.3.0",
|
"yggverse/cache": ">=0.3.0",
|
||||||
"symfony/dom-crawler": "^6.3",
|
"symfony/dom-crawler": "^6.3",
|
||||||
"symfony/css-selector": "^6.3",
|
"symfony/css-selector": "^6.3",
|
||||||
"jdenticon/jdenticon": "^1.0"
|
"jdenticon/jdenticon": "^1.0",
|
||||||
|
"ashtokalo/php-translit": "^0.2.0"
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
@ -113,7 +113,12 @@ class Filter {
|
|||||||
|
|
||||||
if (mb_strlen($word) > 1) {
|
if (mb_strlen($word) > 1) {
|
||||||
|
|
||||||
$words[] = sprintf('(%s*)', $word);
|
$words[] = sprintf('%s*', $word);
|
||||||
|
|
||||||
|
foreach (self::_generateWordForms($word) as $wordForm)
|
||||||
|
{
|
||||||
|
$words[] = sprintf('(*%s*)', $wordForm);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,4 +137,59 @@ class Filter {
|
|||||||
|
|
||||||
return $texts[(($number % 100) > 4 && ($number % 100) < 20) ? 2 : $cases[min($number % 10, 5)]];
|
return $texts[(($number % 100) > 4 && ($number % 100) < 20) ? 2 : $cases[min($number % 10, 5)]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Word forms generator to improve search results
|
||||||
|
// e.g. transliteration rules for latin filenames
|
||||||
|
private static function _generateWordForms(
|
||||||
|
string $keyword,
|
||||||
|
// #13 supported locales:
|
||||||
|
// https://github.com/ashtokalo/php-translit
|
||||||
|
array $transliteration = [
|
||||||
|
'be',
|
||||||
|
'bg',
|
||||||
|
'el',
|
||||||
|
'hy',
|
||||||
|
'kk',
|
||||||
|
'mk',
|
||||||
|
'ru',
|
||||||
|
'ka',
|
||||||
|
'uk'
|
||||||
|
],
|
||||||
|
// Additional char forms
|
||||||
|
array $charForms =
|
||||||
|
[
|
||||||
|
'c' => 'k',
|
||||||
|
'k' => 'c',
|
||||||
|
]
|
||||||
|
): array
|
||||||
|
{
|
||||||
|
$wordForms = [];
|
||||||
|
|
||||||
|
// Apply transliteration
|
||||||
|
foreach ($transliteration as $locale)
|
||||||
|
{
|
||||||
|
$wordForms[] = \ashtokalo\translit\Translit::object()->convert(
|
||||||
|
$keyword,
|
||||||
|
$locale
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply char forms
|
||||||
|
foreach ($wordForms as $wordForm)
|
||||||
|
{
|
||||||
|
foreach ($charForms as $from => $to)
|
||||||
|
{
|
||||||
|
$wordForms[] = str_replace(
|
||||||
|
$from,
|
||||||
|
$to,
|
||||||
|
$wordForm
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove duplicates
|
||||||
|
return array_unique(
|
||||||
|
$wordForms
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user