diff --git a/configs/token_tool.php b/configs/token_tool.php
index 345321a91..088e01204 100644
--- a/configs/token_tool.php
+++ b/configs/token_tool.php
@@ -149,9 +149,12 @@ switch($argv[1])
{
case "dictionary":
if(!isset($argv[3])) {
- $argv[3] = " ";
+ $argv[3] = "en-US";
}
- makeSuggestTrie($argv[2], $argv[3]);
+ if(!isset($argv[4])) {
+ $argv[4] = " ";
+ }
+ makeSuggestTrie($argv[2], $argv[3], $argv[4]);
break;
case "filter":
@@ -237,7 +240,7 @@ function makeNWordGramsFiles($args)
function makeSuggestTrie($file_name, $locale, $end_marker)
{
$dict_file = trim($file_name);
- $out_file = LOCALE_DIR."/$locale/resource/suggest_trie.txt.gz";
+ $out_file = LOCALE_DIR."/$locale/resources/suggest_trie.txt.gz";
// Read and load dictionary and stop word files
$words = fileWithTrim($dict_file);
@@ -251,7 +254,7 @@ function makeSuggestTrie($file_name, $locale, $end_marker)
*/
foreach($words as $word) {
if(preg_match("/\p{P}/", $word) == 0 && mb_strlen($word) > 2) {
- $trie->add($word);
+ $trie->add(mb_strtolower($word));
}
}
$output = array();
diff --git a/lib/trie.php b/lib/trie.php
index 557b233a6..78ba6d9e2 100644
--- a/lib/trie.php
+++ b/lib/trie.php
@@ -78,10 +78,11 @@ class Trie
$character = mb_substr($term, $i, 1);
// If letter doesnt exist then create one by
// assigning new array
- if(!isset($trie_array[$character])) {
- $trie_array[$character] = array();
+ $enc_char = urlencode($character);
+ if(!isset($trie_array[$enc_char])) {
+ $trie_array[$enc_char] = array();
}
- $trie_array = & $trie_array[$character];
+ $trie_array = & $trie_array[$enc_char];
}
// Set end of term marker
$trie_array[$this->end_marker] = $this->end_marker;
@@ -106,11 +107,12 @@ class Trie
}
if ($trie_array != $this->end_marker) {
$character = mb_substr($term, $i, 1);
- if(!isset($trie_array[$character])) {
+ $enc_char = urlencode($character);
+ if(!isset($trie_array[$enc_char])) {
return false;
}
- if($trie_array[$character] != $this->end_marker) {
- $trie_array = & $trie_array[$character];
+ if($trie_array[$enc_char] != $this->end_marker) {
+ $trie_array = & $trie_array[$enc_char];
}
}
else {
@@ -157,7 +159,7 @@ class Trie
if ($character != $end_marker) {
$new_terms =
$this->getValuesTrieArray($subtrie,
- $prefix . $character,
+ $prefix . urldecode($character),
$max_results, $count, $find_more);
$terms = array_merge($terms, $new_terms);
} else {
diff --git a/locale/fr-FR/resources/suggest_trie.txt.gz b/locale/fr-FR/resources/suggest_trie.txt.gz
new file mode 100644
index 000000000..2e29e196e
Binary files /dev/null and b/locale/fr-FR/resources/suggest_trie.txt.gz differ
diff --git a/scripts/autosuggest.js b/scripts/autosuggest.js
index 71326df20..d1f18e41f 100644
--- a/scripts/autosuggest.js
+++ b/scripts/autosuggest.js
@@ -48,7 +48,7 @@ function aslitem_click(liObj)
{
var results_dropdown = document.getElementById("aslist");
var astobj = document.getElementById("search-name");
- astobj.value = liObj.innerHTML;
+ astobj.value = liObj.firstChild.innerHTML;
results_dropdown.innerHTML = "";
}
@@ -64,7 +64,7 @@ function getValues(trie_array, parent_word, max_display)
if (trie_array != null && last_word == false ) {
for (key in trie_array) {
if (key != end_marker ) {
- getValues(trie_array[key], parent_word + key);
+ getValues(trie_array[key], parent_word + urldecode(key));
} else {
search_list += "<li onclick='aslitem_click(this);'><span>"
+ parent_word + "</span></li>";
@@ -77,6 +77,7 @@ function getValues(trie_array, parent_word, max_display)
}
}
+
/**
* Returns the sub trie_array under term in
* trie_array. If term does not exist in the trie_array
@@ -95,8 +96,9 @@ function exist(trie_array, term)
tmp = getUnicodeCharAndNextOffset(term, i);
if(tmp == false) return false;
[next_char, i] = tmp;
- if(trie_array[next_char] != 'null') {
- trie_array = trie_array[next_char];
+ enc_char = urlencode(next_char);
+ if(trie_array[enc_char] != 'null') {
+ trie_array = trie_array[enc_char];
}
}
else {
@@ -123,6 +125,7 @@ function autosuggest(trie_array, term)
last_word = false;
count = 0;
search_list = "";
+ term = term.toLowerCase();
var tmp;
if(trie_array == null) {
return false;
@@ -131,7 +134,8 @@ function autosuggest(trie_array, term)
tmp = getUnicodeCharAndNextOffset(term, 0);
if(tmp == false) return false;
[start_char, ] = tmp;
- trie_array = exist(trie_array[start_char], term);
+ enc_chr = urlencode(start_char);
+ trie_array = exist(trie_array[enc_chr], term);
} else {
trie_array = trie_array[term];
@@ -139,6 +143,15 @@ function autosuggest(trie_array, term)
getValues(trie_array, term);
}
+function urldecode(str) {
+ return unescape(str);
+}
+
+function urlencode(str)
+{
+ return encodeURIComponent(str);
+}
+
/**
* Extract next Unicode Char beginning at offset i in str returns Array
* with this character and the next offset