_binary From c97ee6561fdba9c415fd883032595fb53ddcb372 Mon Sep 17 00:00:00 2001
From: Sandhya Vissapragada <sandyvissa@gmail.com>
Date: Thu, 4 Oct 2012 14:19:52 -0700
Subject: [PATCH 1/2] git add lib/trie.php git add
 locale/fr-FR/resources/suggest_trie.txt.gz git add
 scripts/suggest.js git add
 views/elements/language_element.php git add
 locale/ru/resources/suggest_trie.txt.gz

---
 lib/trie.php                               |   29 +++++++++-------
 locale/fr-FR/resources/suggest_trie.txt.gz |  Bin 28000 -> 27864 bytes
 scripts/suggest.js                         |   52 ++++++++++++++++------------
 views/elements/language_element.php        |    2 +-
 4 files changed, 47 insertions(+), 36 deletions(-)
 mode change 100755 => 100644 locale/fr-FR/resources/suggest_trie.txt.gz

diff --git a/lib/trie.php b/lib/trie.php
index 78ba6d9..178a0df 100644
--- a/lib/trie.php
+++ b/lib/trie.php
@@ -53,7 +53,6 @@ class Trie
      * @var string
      */
     var $end_marker;
-
     /**
      * Creates and returnes an empty trie. Sets the end of term character
      * 
@@ -74,18 +73,24 @@ class Trie
     function add($term) 
     {
         $trie_array = & $this->trie_array;
-        for($i = 0; $i < mb_strlen($term); $i++) {
-            $character = mb_substr($term, $i, 1);
-            // If letter doesnt exist then create one by
-            // assigning new array
-            $enc_char = urlencode($character);
-            if(!isset($trie_array[$enc_char])) {
+        for($i = 0; $i < mb_strlen($term,"utf-8"); $i++) {
+            $character = mb_substr($term, $i, 1, "utf-8");
+            $enc_char = rawurlencode($character);
+            // To avoid encoding the linefeed
+            if ($enc_char == "%0A"){
+                continue;
+            }
+            else {
+                // If letter doesnt exist then create one by
+                // assigning new array
+                if(!isset($trie_array[$enc_char])) {
                 $trie_array[$enc_char] = array();
+                }
+                $trie_array = & $trie_array[$enc_char];
             }
-            $trie_array = & $trie_array[$enc_char];
         }
         // Set end of term marker
-        $trie_array[$this->end_marker] = $this->end_marker; 
+        $trie_array[$this->end_marker] = $this->end_marker;
         return $trie_array;
     }
 
@@ -100,14 +105,14 @@ class Trie
     function exists($term)
     {
         $trie_array = & $this->trie_array;
-        $len = mb_strlen($term);
+        $len = mb_strlen($term,"utf-8");
         for($i = 0; $i < $len; $i++) {
             if($trie_array == null){
                 return false;
             }
             if ($trie_array != $this->end_marker) {
-                $character = mb_substr($term, $i, 1);
-                $enc_char = urlencode($character);
+                $character = mb_substr($term, $i, 1, "utf-8");
+                $enc_char = rawurlencode($character);
                 if(!isset($trie_array[$enc_char])) {
                     return false;
                 }
diff --git a/locale/fr-FR/resources/suggest_trie.txt.gz b/locale/fr-FR/resources/suggest_trie.txt.gz
old mode 100755
new mode 100644
index 1010962340f9228b808d6ea4f346921e33e2ede7..e73f959e9f6fcb92df13e589ced8070442fc4a43
GIT binary patch
diff --git a/scripts/suggest.js b/scripts/suggest.js
index 5033b53..e61e720 100644
--- a/scripts/suggest.js
+++ b/scripts/suggest.js
@@ -64,7 +64,7 @@ function onTypeTerm(event, text_field)
 {
     var key_code_pressed;
     var term_array;
-    var input_term = text_field.value;
+    var input_term = text_field.value.trim();
     var suggest_results = elt("suggest-results");
     var suggest_dropdown = elt("suggest-dropdown");
     var scroll_pos = 0;
@@ -84,14 +84,14 @@ function onTypeTerm(event, text_field)
         }
         concat_term = concat_term.trim();
     }    
-    input_term = term_array[term_array.length - 1];
+    input_term = term_array[term_array.length - 1].trim(" ");
 
     // behavior if typing keys other than up or down (notice call termSuggest)
     if (key_code_pressed != KeyCodes.DOWN_ARROW && 
-        key_code_pressed != KeyCodes.UP_ARROW) {
+            key_code_pressed != KeyCodes.UP_ARROW) {
         search_list = "";
         termSuggest(dictionary, input_term);
-        if(count <= 1) {
+        if(count < 1) {
             search_list = "";
         }
         suggest_dropdown.scrollTop =  0;
@@ -166,7 +166,7 @@ function setSelectedTerm(pos, class_value)
  *
  * @param String term what was clicked on
  */
-function termClick(term)
+function termClick(term,termid)
 {
     var results_dropdown = elt("suggest-results");
     var query_field_object = elt("query-field");
@@ -194,7 +194,7 @@ function getTrieTerms(trie_array, parent_word, highlighted_word)
         for (key in trie_array) {
             if (key != END_OF_TERM_MARKER ) {
                 getTrieTerms(trie_array[key], parent_word + key, 
-                    highlighted_word + key);
+                        highlighted_word + key);
             } else {
                 search_terms = concat_term.trim() + " " + decode(parent_word);
                 search_terms = search_terms.trim();
@@ -203,7 +203,9 @@ function getTrieTerms(trie_array, parent_word, highlighted_word)
                 search_list += "<li><span id='term" +count+
                     "' class='unselected' onclick = 'void(0)' " +
                     "title='"+search_terms+"' " +
-                    "onmouseup='termClick(\""+search_terms+"\")'"+
+                    "onmouseover='setSelectedTerm(\""+count+"\",\"selected\")'" +
+                    "onmouseout='setSelectedTerm(\""+count+"\",\"unselected\")'" +
+                    "onmouseup='termClick(\""+search_terms+"\",this.id)'"+
                     ">" + highlighted_terms + "</span></li>";
                 count++;
             }
@@ -221,21 +223,17 @@ function getTrieTerms(trie_array, parent_word, highlighted_word)
  */
 function exist(trie_array, term)
 {
-    for(var i = 1; i< term.length; i++) {
-        if(trie_array == null){
-            return false;
-        }
-        if (trie_array != 'null') {
-            tmp = getUnicodeCharAndNextOffset(term, i);
-            if(tmp == false) return false;
-            next_char = tmp[0];
-            i = tmp[1];
-            enc_char = encode(next_char);
-            if(trie_array[enc_char] != 'null') {
-                trie_array = trie_array[enc_char];
-            }
-        }
-        else {
+    if(trie_array == null) {
+        return false;
+    }
+    for(var i = 1; i < term.length; i++) {
+        tmp = getUnicodeCharAndNextOffset(term, i);
+        if(tmp == false) return false;
+        next_char = tmp[0];
+        i = tmp[1]; 
+        enc_char = encode(next_char);
+        trie_array = trie_array[enc_char];
+        if(trie_array == null) {
             return false;
         }
     }
@@ -256,7 +254,10 @@ function termSuggest(trie_array, term)
     last_word = false;
     count = 0;
     search_list = "";
+    // For US english ignore the case
+    if(locale == 'en-US') {
     term = term.toLowerCase();
+    }
     var tmp;
     if(trie_array == null) {
         return false;
@@ -267,6 +268,9 @@ function termSuggest(trie_array, term)
         start_char = tmp[0];
         enc_chr = encode(start_char);
         trie_array = exist(trie_array[enc_chr], term);
+        if(trie_array == false) {
+            return false;
+        }
     } else {
         trie_array = trie_array[term];
     }
@@ -285,7 +289,9 @@ function decode(str) {
 /* wrappers to save typing */
 function encode(str)
 {
-    return encodeURIComponent(str);
+    str = encodeURIComponent(str);
+    str = str.replace(/\'/g, '%27'); // encodeURIComponent doesnt convert '
+    return str;    
 }
 
 /**
diff --git a/views/elements/language_element.php b/views/elements/language_element.php
index f18810f..a83dfb4 100755
--- a/views/elements/language_element.php
+++ b/views/elements/language_element.php
@@ -56,7 +56,7 @@ class LanguageElement extends Element
     {
     ?>
 
-        <select id="locale" name="lang" dir="ltr">
+        <select id="locale" name="lang" dir="ltr" size="4">
         <?php 
         foreach ($data['LANGUAGES'] as $locale_tag => $locale_name) {
             if($data['LOCALE_TAG'] == $locale_tag) {
-- 
1.7.9.4


From 7fc528250b14623e07e9d5fcebd74d7f47b02791 Mon Sep 17 00:00:00 2001
From: Sandhya Vissapragada <sandyvissa@gmail.com>
Date: Thu, 4 Oct 2012 14:21:30 -0700
Subject: [PATCH 2/2] git add locale/ru/resources/suggest_trie.txt.gz

---
 locale/ru/resources/suggest_trie.txt.gz |  Bin 0 -> 21540 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100755 locale/ru/resources/suggest_trie.txt.gz

diff --git a/locale/ru/resources/suggest_trie.txt.gz b/locale/ru/resources/suggest_trie.txt.gz
new file mode 100755
index 0000000000000000000000000000000000000000..2a39b9c30eeb2aabb262dfdd025aa77c6a1749a0
GIT binary patch
-- 
1.7.9.4

