LanguageNameIndexer/Search: use unicode aware lowercasing

With this MEÄNKELI with typos=1 finds results.

Updated test case for lowercased result. Renamed variables in test
file for clarity. Updated the default value for MW_INSTALL_PATH to
work with the default layout.

Change-Id: Id93c84d308705f55b4d2378fc8c7b7f243e1b53f
This commit is contained in:
Niklas Laxström
2016-06-15 10:13:49 +02:00
parent 920155fb18
commit 9daeacf1c5
5 changed files with 11 additions and 8 deletions

View File

@@ -37,7 +37,7 @@ class LanguageNameIndexer extends Maintenance {
foreach ( $languages as $sourceLanguage => $autonym ) { foreach ( $languages as $sourceLanguage => $autonym ) {
$translations = LanguageNames::getNames( $sourceLanguage, 0, 2 ); $translations = LanguageNames::getNames( $sourceLanguage, 0, 2 );
foreach ( $translations as $targetLanguage => $translation ) { foreach ( $translations as $targetLanguage => $translation ) {
$translation = strtolower( $translation ); $translation = mb_strtolower( $translation );
$bucket = LanguageNameSearch::getIndex( $translation ); $bucket = LanguageNameSearch::getIndex( $translation );
$buckets[$bucket][$translation] = $targetLanguage; $buckets[$bucket][$translation] = $targetLanguage;
} }

View File

@@ -29,8 +29,11 @@ class LanguageNameSearch {
self::init(); self::init();
} }
// Use code's mb_strtolower compatibily code for MW < 1.27
$language = Language::factory( 'en' );
// @todo: Shouldn't this be unicode aware? // @todo: Shouldn't this be unicode aware?
$searchKey = strtolower( $searchKey ); $searchKey = $language->lc( $searchKey );
$index = self::getIndex( $searchKey ); $index = self::getIndex( $searchKey );
if ( !isset( self::$languagenames[$index] ) ) { if ( !isset( self::$languagenames[$index] ) ) {

File diff suppressed because one or more lines are too long

View File

@@ -19,12 +19,12 @@
*/ */
require_once __DIR__ . '/../../data/LanguageNameSearch.php'; require_once __DIR__ . '/../../data/LanguageNameSearch.php';
class LanguageSearchTest extends PHPUnit_Framework_TestCase { class LanguageSearchTest extends PHPUnit_Framework_TestCase {
/** /**
* @dataProvider searchDataProvider * @dataProvider searchDataProvider
*/ */
public function testSearch( $searchKey, $result ) { public function testSearch( $searchKey, $expected ) {
$this->assertEquals( $result, LanguageNameSearch::search( $searchKey, 1 ) ); $actual = LanguageNameSearch::search( $searchKey, 1 );
$this->assertEquals( $expected, $actual );
} }
public function searchDataProvider() { public function searchDataProvider() {
@@ -40,7 +40,7 @@ class LanguageSearchTest extends PHPUnit_Framework_TestCase {
] ]
], ],
[ 'Φινλαν', [ [ 'Φινλαν', [
'fi' => 'Φινλανδικά', 'fi' => 'φινλανδικά',
] ]
], ],
[ 'blah', [] [ 'blah', []

View File

@@ -1,5 +1,5 @@
ifndef MW_INSTALL_PATH ifndef MW_INSTALL_PATH
MW_INSTALL_PATH=../../.. MW_INSTALL_PATH=../../../..
endif endif
default: default: