_binary From 6da72d6079dba39b3c443d8bc42efe4f614419ad Mon Sep 17 00:00:00 2001
From: Sandhya Vissapragada <sandyvissa@gmail.com>
Date: Mon, 3 Dec 2012 11:15:32 -0800
Subject: [PATCH 1/2] git add controllers/resource_controller.php git add
 controllers/search_controller.php git add
 css/search.css git add lib/trie.php git add
 scripts/suggest.js git add views/search_view.php

---
 controllers/resource_controller.php |   23 +-
 controllers/search_controller.php   |    1 +
 css/search.css                      |   17 +-
 lib/trie.php                        |    9 +-
 scripts/suggest.js                  |  417 ++++++++++++++++++++++++++---------
 views/search_view.php               |   11 +-
 6 files changed, 360 insertions(+), 118 deletions(-)

diff --git a/controllers/resource_controller.php b/controllers/resource_controller.php
index 876cc4e..e2e3305 100644
--- a/controllers/resource_controller.php
+++ b/controllers/resource_controller.php
@@ -63,7 +63,7 @@ class ResourceController extends Controller implements CrawlConstants
      * These are the activities supported by this controller
      * @var array
      */
-    var $activities = array("get", "syncList", "syncNotify", "suggest");
+    var $activities = array("get", "syncList", "syncNotify", "suggest", "alpha");
 
 
     /**
@@ -75,7 +75,7 @@ class ResourceController extends Controller implements CrawlConstants
     function processRequest() 
     {
         if(!isset($_REQUEST['a']) ||
-            (!in_array($_REQUEST['a'], array("get", "suggest"))
+            (!in_array($_REQUEST['a'], array("get", "suggest", "alpha"))
             && !$this->checkRequest())) {return; }
         $activity = $_REQUEST['a'];
 
@@ -149,6 +149,25 @@ class ResourceController extends Controller implements CrawlConstants
             readfile($path);
         }
     }
+    
+    /**
+     * Get the alphabet for a give locale
+     */
+    function alpha()
+    {
+        if(!isset($_REQUEST["locale"])){return;}
+        $locale = $_REQUEST["locale"];
+        $count = preg_match("/^[a-zA-z]{2}(-[a-zA-z]{2})?$/", $locale);
+        if($count != 1) {return;}
+        $path = LOCALE_DIR."/$locale/resources/alpha.txt.gz";
+        if(file_exists($path)) {
+            header("Content-Type: application/json");
+            header("Content-Encoding: gzip");
+            header("Content-Length: ".filesize($path));
+            readfile($path);
+        }
+    }
+
 
     /**
      *  Used to notify a machine that another machine acting as a mirror
diff --git a/controllers/search_controller.php b/controllers/search_controller.php
index 38fae0b..8acb846 100755
--- a/controllers/search_controller.php
+++ b/controllers/search_controller.php
@@ -382,6 +382,7 @@ class SearchController extends Controller implements CrawlConstants
             $data['PAGES'] = $this->makeMediaGroups($data['PAGES']);
         }
         $data['INCLUDE_SCRIPTS'] = array("suggest");
+        $data['SCRIPT'] .= "\nlocal_strings = {'spell':'".tl('Search')."'}";
         if($no_query || isset($_REQUEST['no_query'])) {
             $data['NO_QUERY'] = true;
             $data['PAGING_QUERY'] .= "&no_query=true";
diff --git a/css/search.css b/css/search.css
index 0e44976..514bbe7 100755
--- a/css/search.css
+++ b/css/search.css
@@ -500,7 +500,7 @@ li.outer div
     display: block;
     background-color: gray;
     padding:2px;
-    width:1.5in;
+    width:1.25in;
     z-index:3;
 }
 
@@ -912,6 +912,9 @@ ul.in-list li
     padding:0;
     color:#666;
     font-size:14pt;
+    position:relative;
+    top:-12px;
+    left:608px;
 }
 
 .serp-links-score
@@ -939,6 +942,16 @@ ul.in-list li
     font-size:10pt;
 }
 
+.spell
+{
+    position:relative;
+    top:-47px;
+    left:49px;
+    color:#666666;
+    font-size:14pt;
+    z-index:1;
+}
+
 .searchbox
 {
     position: relative;
@@ -1053,7 +1066,7 @@ ul.in-list li
 
 .suggest-list li
 {
-    width:6.10in;
+    width:30.10in;
     background:#DDF;
     font-size:16pt;
     margin-right:0in;
diff --git a/lib/trie.php b/lib/trie.php
index 178a0df..2704e3d 100644
--- a/lib/trie.php
+++ b/lib/trie.php
@@ -73,8 +73,9 @@ class Trie
     function add($term) 
     {
         $trie_array = & $this->trie_array;
-        for($i = 0; $i < mb_strlen($term,"utf-8"); $i++) {
-            $character = mb_substr($term, $i, 1, "utf-8");
+        $term_arr = explode(" ",$term);
+        for($i = 0; $i < mb_strlen($term_arr[0],"utf-8"); $i++) {
+            $character = mb_substr($term_arr[0], $i, 1, "utf-8");
             $enc_char = rawurlencode($character);
             // To avoid encoding the linefeed
             if ($enc_char == "%0A"){
@@ -90,7 +91,9 @@ class Trie
             }
         }
         // Set end of term marker
-        $trie_array[$this->end_marker] = $this->end_marker;
+        //$trie_array[$this->end_marker] = $term_arr[1];
+        $trie_array[$this->end_marker] = '1';
+
         return $trie_array;
     }
 
diff --git a/scripts/suggest.js b/scripts/suggest.js
index d37af61..509386f 100644
--- a/scripts/suggest.js
+++ b/scripts/suggest.js
@@ -30,6 +30,12 @@
  * @filesource
  */
 
+/*
+ * Update the version number manually when ever
+ * suggest.js undergoes changes
+ */
+VERSION_NO = 0;
+
 /**
  *  Constants for key codes will handle
  */
@@ -51,6 +57,19 @@ FONT_HEIGHT = 24;
  * what the trie object loaded says in loadTrie
  */
 END_OF_TERM_MARKER = " ";
+
+/**
+ * Process to follow once onsubmit event is fired
+ *
+ * @param None
+ * @return None
+ */
+corrected_query="";
+function processSubmit()
+{
+    updateLocalStorage();
+}
+
 /**
  * Steps to follow every time a key is up from the user end
  * Handles up/dowm arrow keys
@@ -60,7 +79,6 @@ END_OF_TERM_MARKER = " ";
  *
  */
 
-
 function onTypeTerm(event, text_field)
 {
     var key_code_pressed;
@@ -70,18 +88,20 @@ function onTypeTerm(event, text_field)
     var suggest_dropdown = elt("suggest-dropdown");
     var scroll_pos = 0;
     var tmp_pos = 0;
+    var local_count = 0;
     locale_terms = new Object();
     local_terms_present = false;
     local_suggest = true;
     search_list_array = new Object();
+    scroll_horz = false;
 
     //To find the length of an associative array
     Object.size = function(obj) {
-    var size = 0, key;
-    for (key in obj) {
-        if (obj.hasOwnProperty(key)) size++;
-    }
-    return size;
+        var size = 0, key;
+        for (key in obj) {
+            if (obj.hasOwnProperty(key)) size++;
+        }
+        return size;
     };
     concat_term = "";
     if(window.event) { // IE8 and earlier
@@ -104,39 +124,53 @@ function onTypeTerm(event, text_field)
             key_code_pressed != KeyCodes.UP_ARROW) {
         search_list = "";
 
-    // First search the local storage to fetch the suggestions
-    if (localStorage) {
-         if (localStorage[locale] != null) {
-            split_str = localStorage[locale].split("@@");
-            locale_terms = JSON.parse(split_str[1]);
-            local_dict = JSON.parse(split_str[0]);
-            if (local_dict != null) {
-                termSuggest(local_dict, input_term);
-                local_terms_present = true;
+        // First search the local storage to fetch the suggestions
+        if (localStorage) {
+            var locale_ver = locale+'_'+VERSION_NO;
+            if (localStorage[locale_ver] == null) {
+                localStorage.clear();
+                count=0;
             }
-         }
-         else  count =0;
-    }
-    var sorted_local = SortLocalTerms();
-    if (Object.size(search_list_array) > 0) {
-        search_list = "";
-         for(var i = 0; i < sorted_local.length ; i++) {
-            var split_array = sorted_local[i].split('*');
-
-            if(search_list_array[split_array[1]] != null)
-            search_list += search_list_array[split_array[1]];
-         }
-     }
-
-     // Now search the actual dictionary trie
-     local_suggest = false;
-     termSuggest(dictionary, input_term);
-
-     // insert nbsp of the number of suggestions are less than MAX_DISPLAY
-     short_max = MAX_DISPLAY - count;
-     for(var i = 0; i < short_max; i++) {
-        search_list += "<li><span class='unselected'>&nbsp;</span></li>";
-    }
+            else if (localStorage[locale_ver] != null) {
+                split_str = localStorage[locale_ver].split("@@");
+                locale_terms = JSON.parse(split_str[1]);
+                local_dict = JSON.parse(localStorage[locale_ver].split("@@", 1));
+                if (local_dict != null) {
+                    local_terms_present = true;
+                    termSuggest(local_dict, input_term);
+                    local_terms_present = false;
+                }
+                var sorted_local = SortLocalTerms();
+                if (Object.size(search_list_array) > 0) {
+                    search_list = "";
+                    for(var i = 0; i < sorted_local.length ; i++) {
+                        var split_array = sorted_local[i].split('*');
+
+                        if(search_list_array[split_array[1]] != null) {
+                            search_split = search_list_array[split_array[1]].split("_");
+                            search_list +=  "<li><span id='term" +local_count+
+                                "' class='unselected' onclick = 'void(0)' " +
+                                "title='"+search_split[0]+"' " +
+                                "onmouseover='setSelectedTerm(\""+local_count+"\",\"selected\")'" +
+                                "onmouseout='setSelectedTerm(\""+local_count+"\",\"unselected\")'" +
+                                "onmouseup='termClick(\""+search_split[0]+"\",this.id)'"+
+                                ">" + search_split[1] + "</span></li>";
+                            local_count++;
+                        }
+
+                    }
+                }
+                local_suggest = false;
+            }
+        }
+        count = local_count;
+        // Now search the actual dictionary trie
+        termSuggest(dictionary, input_term);
+        // insert nbsp of the number of suggestions are less than MAX_DISPLAY
+        short_max = MAX_DISPLAY - count;
+        for(var i = 0; i < short_max; i++) {
+            search_list += "<li><span class='unselected'>&nbsp;</span></li>";
+        }
         if(count < 1) {
             search_list = "";
         }
@@ -154,6 +188,10 @@ function onTypeTerm(event, text_field)
             suggest_results.style.visibility = "visible";
             suggest_dropdown.style.visibility = "visible";
             suggest_dropdown.style.height = (FONT_HEIGHT * MAX_DISPLAY) + "px";
+            if (scroll_horz)
+                suggest_dropdown.style.overflowX = "scroll";
+            else
+                suggest_dropdown.style.overflowX = "hidden";
         }
     }
     // behavior on up down arrows
@@ -170,8 +208,8 @@ function onTypeTerm(event, text_field)
                 setSelectedTerm(cursor_pos, "selected");
             }
             scroll_count = 1;
-            scroll_pos = (cursor_pos - MAX_DISPLAY > 0) ?
-                (cursor_pos - MAX_DISPLAY + 1) : 1;
+            scroll_pos = (cursor_pos - MAX_DISPLAY >= 0) ?
+                (cursor_pos - MAX_DISPLAY + 1) : 0;
             suggest_dropdown.scrollTop = scroll_pos * FONT_HEIGHT;
         } else if(key_code_pressed == KeyCodes.UP_ARROW) {
             if (cursor_pos < 0) {
@@ -184,8 +222,8 @@ function onTypeTerm(event, text_field)
                 }
                 setSelectedTerm(cursor_pos, "selected");
             }
-            scroll_pos = (cursor_pos - MAX_DISPLAY + scroll_count > 0) ?
-                (cursor_pos - MAX_DISPLAY + scroll_count) : 1;
+            scroll_pos = (cursor_pos - MAX_DISPLAY + scroll_count >= 0) ?
+                (cursor_pos - MAX_DISPLAY + scroll_count) : 0;
             scroll_count = (MAX_DISPLAY > scroll_count) ? scroll_count + 1 :
                 MAX_DISPLAY;
             suggest_dropdown.scrollTop = scroll_pos * FONT_HEIGHT;
@@ -194,6 +232,121 @@ function onTypeTerm(event, text_field)
 }
 
 /**
+ * To correct the spelling of the query words
+ *
+ * @param String word Input word
+ * @return String corrected_word Corrected word
+ */
+function correctSpelling(word)
+{
+    var prob=0,ret_array,curr_prob=0;
+    var candidates = known(edits1(word));
+    var corrected_word = "";
+    // Use the fequencies to get the best match
+    for(var i=0;i<candidates.length;i++) {
+        ret_array = exist(dictionary, candidates[i]);
+        if(ret_array != false) {
+            curr_prob = parseInt(ret_array[END_OF_TERM_MARKER]);
+        }
+        if (curr_prob > prob) {
+            prob = curr_prob;
+            corrected_word = candidates[i];
+        }
+    }
+    return corrected_word;
+}
+
+/**
+ * To get the candidates for the spell correction with edit
+ * distance 1
+ *
+ * @param String word Input word
+ * @return Array set Words with edit distance - 1
+ */
+
+function edits1(word)
+{
+    var splits = new Object();
+    var deletes = new Array();
+    var transposes =new Array();
+    var replaces = new Array();
+    var inserts = new Array();
+    var j=0;
+
+    splits[""] = word;
+    for(var i=0;i<word.length;i++) {
+        splits[word.substring(0,i+1)] = word.substring(i+1,word.length);
+    }
+    // Deletes
+    for (key in splits) {
+        if (splits[key] != "") {
+            deletes[j] = key + splits[key].substring(1);
+            j++;
+        }
+    }
+    // Transposes
+    j=0;
+    for (key in splits) {
+        if (splits[key].length > 1) {
+            transposes[j] = key + splits[key].substring(1,2) + splits[key].substring(0,1) + splits[key].substring(2);
+            j++;
+        }
+    }
+    // Replaces
+    j=0;
+    for (key in splits) {
+        if (splits[key] != "") {
+            for(var i=0;i<alpha.length;i++) {
+                replaces[j] = key + alpha.substring(i,i+1) + splits[key].substring(1);
+                j++;
+            }
+        }
+    }
+    // Inserts
+    j=0;
+    for (key in splits) {
+        for(var i=0;i<alpha.length;i++) {
+            inserts[j] = key + alpha.substring(i,i+1) + splits[key];
+            j++;
+        }
+    }
+    var set = deletes.concat(transposes).concat(replaces).concat(inserts).unique();
+    return set;
+}
+
+Array.prototype.unique = function() {
+    var a = this.concat();
+    for(var i=0; i<a.length; ++i) {
+        for(var j=i+1; j<a.length; ++j) {
+            if(a[i] === a[j])
+                a.splice(j, 1);
+        }
+    }
+    return a;
+}
+
+/**
+ * To get the set of words which are known from the dictionary
+ *
+ * @param Array words_ip array of words
+ * @return Array known_words array of known words
+ */
+
+function known(words_ip)
+{
+    var known_words = new Array(),j=0;
+    var ret_array;
+    for(var i=0;i<words_ip.length;i++) {
+        ret_array = exist(dictionary, words_ip[i]);
+        if(ret_array[END_OF_TERM_MARKER] != null) {
+            known_words[j] =  words_ip[i];
+            j++;
+        }
+    }
+    return known_words;
+}
+
+/**
  * To update the local storage with the previous query terms and
  * create a trie on those terms
  *
@@ -201,48 +354,48 @@ function onTypeTerm(event, text_field)
  */
 function updateLocalStorage()
 {
-     var trie_to_store;
-     trie_storage = {};
-     var store_term = elt("query-field").value;
-     var freq, k=0;
-     var sorted_locale_terms = new Array();
-     if(localStorage) {
-         if (locale_terms[store_term] == null) {
+    var trie_to_store;
+    trie_storage = {};
+    var store_term = elt("query-field").value;
+    var freq, k=0;
+    var sorted_locale_terms = new Array();
+    if(localStorage) {
+        if (locale_terms[store_term] == null) {
             locale_terms[store_term] = 1;
-         } else {
+        } else {
             freq = parseInt(locale_terms[store_term]);
             freq++;
             locale_terms[store_term] = freq;
-         }
-         for(var key in locale_terms) {
+        }
+        for(var key in locale_terms) {
             sorted_locale_terms[k] = key;
             k++;
-         }
+        }
         sorted_locale_terms.sort();
 
         // Build the trie
         for(var i=0; i<sorted_locale_terms.length; i++) {
-        var trie_word = sorted_locale_terms[i];
-        var letters = trie_word.split(""),cur = trie_storage;
-        for (var j=0;j<letters.length;j++) {
-        var letter = encode(letters[j]);
-            var pos = cur[ letter ];
-            if (pos == null) {
-                if (j === letters.length - 1) {
-                    cur = cur[ letter ] = {'$' : '$'};
+            var trie_word = sorted_locale_terms[i];
+            var letters = trie_word.split(""),cur = trie_storage;
+            for (var j=0;j<letters.length;j++) {
+                var letter = encode(letters[j]);
+                var pos = cur[ letter ];
+                if (pos == null) {
+                    if (j === letters.length - 1) {
+                        cur = cur[ letter ] = {'$' : '$'};
+                    } else {
+                        cur = cur[ letter ] = {};
+                    }
+                } else if (pos === 0) {
+                    cur = cur[ letter ] = { '$' : '$' };
                 } else {
-                    cur = cur[ letter ] = {};
+                    cur = cur[ letter ];
                 }
-            } else if (pos === 0) {
-                cur = cur[ letter ] = { '$' : '$' };
-            } else {
-                cur = cur[ letter ];
             }
         }
     }
-    }
     trie_to_store = JSON.stringify( trie_storage );
-    localStorage.setItem(locale,trie_to_store + "@@" + JSON.stringify(locale_terms));
+    localStorage.setItem(locale+'_'+VERSION_NO,trie_to_store + "@@" + JSON.stringify(locale_terms));
 }
 
 /**
@@ -326,24 +479,31 @@ function getTrieTerms(trie_array, parent_word, highlighted_word)
                 getTrieTerms(trie_array[key], parent_word + key,
                         highlighted_word + key);
             } else {
-                if (local_terms_present == false || (locale_terms[decode(parent_word)] == null && local_terms_present == true)) {
+                if( (locale_terms[decode(parent_word)] == null && local_terms_present == false)) {
                     search_terms = concat_term.trim() + " " + decode(parent_word);
                     search_terms = search_terms.trim();
                     highlighted_terms = concat_term.trim() + " " + decode(highlighted_word) + "</b>";
-                    search_string =  "<li><span id='term" +count+
-                    "' class='unselected' onclick = 'void(0)' " +
-                    "title='"+search_terms+"' " +
-                    "onmouseover='setSelectedTerm(\""+count+"\",\"selected\")'" +
-                    "onmouseout='setSelectedTerm(\""+count+"\",\"unselected\")'" +
-                    "onmouseup='termClick(\""+search_terms+"\",this.id)'"+
-                    ">" + highlighted_terms + "</span></li>";
-                    search_list += search_string;
-                    search_list_array[decode(parent_word)] = search_string;
+                    search_list +=  "<li><span id='term" +count+
+                        "' class='unselected' onclick = 'void(0)' " +
+                        "title='"+search_terms+"' " +
+                        "onmouseover='setSelectedTerm(\""+count+"\",\"selected\")'" +
+                        "onmouseout='setSelectedTerm(\""+count+"\",\"unselected\")'" +
+                        "onmouseup='termClick(\""+search_terms+"\",this.id)'"+
+                        ">" + highlighted_terms + "</span></li>";
                     count++;
-                }
+                    if (search_terms.length * 24 > 1200 &&  !scroll_horz)
+                        scroll_horz = true;
+                } else if (local_terms_present == true) {
+                    search_terms = concat_term.trim() + " " + decode(parent_word);
+                    search_terms = search_terms.trim();
+                    highlighted_terms = concat_term.trim() + " " + decode(highlighted_word) + "</b>";
+                    search_list_array[decode(parent_word)] = search_terms+ "_" +highlighted_terms;
+                    if (search_terms.length * 24 > 1200 &&  !scroll_horz)
+                        scroll_horz = true;
                 }
             }
         }
+    }
 }
 
 /**
@@ -359,7 +519,7 @@ function exist(trie_array, term)
     if(trie_array == null) {
         return false;
     }
-    for(var i = 1; i < term.length; i++) {
+    for(var i = 0; i < term.length; i++) {
         tmp = getUnicodeCharAndNextOffset(term, i);
         if(tmp == false) return false;
         next_char = tmp[0];
@@ -398,11 +558,7 @@ function termSuggest(trie_array, term)
         return false;
     }
     if((term.length) > 1) {
-        tmp = getUnicodeCharAndNextOffset(term, 0);
-        if(tmp == false) return false;
-        start_char = tmp[0];
-        enc_chr = encode(start_char);
-        trie_array = exist(trie_array[enc_chr], term);
+        trie_array = exist(trie_array, term);
         if(trie_array == false) {
             return false;
         }
@@ -467,40 +623,91 @@ function getUnicodeCharAndNextOffset(str, i)
 }
 
 /**
- * Load the Trie(compressed with .gz extension) during the launch of website
+ * Load the Trie,alphabet(compressed with .gz extension) during the launch of website
  * Trie's are represented using nested arrays.
  */
-function loadTrie()
+function loadFiles()
 {
-    var request = makeRequest();
-    if(request) {
-        request.onreadystatechange = function() {
-            if (request.readyState == 4 && request.status == 200) {
-                trie = JSON.parse(request.responseText);
-                dictionary = trie["trie_array"];
-                END_OF_TERM_MARKER = trie["end_marker"];
+    var request_a = makeRequest();
+    if(request_a) {
+        request_a.onreadystatechange = function() {
+            if (request_a.readyState == 4 && request_a.status == 200) {
+                alpha_obj = JSON.parse(request_a.responseText);
+                alpha = alpha_obj["alpha"];
+                var request = makeRequest();
+                if(request) {
+                    request.onreadystatechange = function() {
+                        if (request.readyState == 4 && request.status == 200) {
+                            trie = JSON.parse(request.responseText);
+                            dictionary = trie["trie_array"];
+                            END_OF_TERM_MARKER = trie["end_marker"];
+                            if(locale=='en-US')
+                                spellCheck();
+                        }
+                        END_OF_TERM_MARKER = (typeof END_OF_TERM_MARKER == 'undefined') ?
+                            ' ' : END_OF_TERM_MARKER;
+                    }
+                    if(locale) {
+                        trie_loc = "./?c=resource&a=suggest&locale=" + locale;
+                        request.open("GET", trie_loc, true);
+                        request.send();
+                    }
+                }
+
             }
-            END_OF_TERM_MARKER = (typeof END_OF_TERM_MARKER == 'undefined') ?
-                ' ' : END_OF_TERM_MARKER;
         }
-
         locale = document.documentElement.lang;
         if(locale) {
-            trie_loc = "./?c=resource&a=suggest&locale=" + locale;
-            request.open("GET", trie_loc, true);
-            request.send();
+            alpha_loc = "./?c=resource&a=alpha&locale=" + locale;
+            request_a.open("GET", alpha_loc, true);
+            request_a.send();
+        }
+    }
+}
+
+/**
+ * To process spell correction
+ */
+function spellCheck()
+{
+    var referenceNode;
+    if (document.getElementsByClassName) {
+        referenceNode = document.getElementsByClassName("serp")[0];
+    }
+    if (referenceNode) {
+        var correctedSpell = document.createElement("div");
+        correctedSpell.id = "spell-check";
+        correctedSpell.className='spell';
+        var csrf_token = elt("csrf-token").value;
+        var its_value = elt("its-value").value;
+
+        var query = elt("query-field").value;
+        var ret_array,ret_word;
+        var term_array = query.split(" ");
+        for(var i =0; i<term_array.length; i++) {
+            ret_word = "";
+            ret_word = correctSpelling(term_array[i].toLowerCase());
+            if(ret_word.trim(" ") == "") {
+                corrected_query += term_array[i] + " ";
+            } else
+                corrected_query += ret_word + " ";
+        }
+        if (corrected_query.trim() != query) {
+            var spell_link = "?YIOOP_TOKEN="+csrf_token+"&q="+corrected_query;
+            correctedSpell.innerHTML = "<b>" + local_strings.spell +": <a rel='nofollow' href="+spell_link+">"  + corrected_query + "</a></b>";
+            referenceNode.parentNode.insertBefore(correctedSpell, referenceNode.nextSibling);
         }
     }
 }
-document.getElementsByTagName("body")[0].onload = loadTrie;
+document.getElementsByTagName("body")[0].onload = loadFiles;
 var ip_field = elt("query-field");
 ip_field.onpaste = function(e) {
     setTimeout(function(){
-        onTypeTerm(e,ip_field);
-    }, 0);
+            onTypeTerm(e,ip_field);
+            }, 0);
 }
 ip_field.oncut = function(e) {
     setTimeout(function(){
-        onTypeTerm(e,ip_field);
-    }, 0);
+            onTypeTerm(e,ip_field);
+            }, 0);
 }
diff --git a/views/search_view.php b/views/search_view.php
index f6935f5..d8f68ff 100755
--- a/views/search_view.php
+++ b/views/search_view.php
@@ -112,18 +112,17 @@ class SearchView extends View implements CrawlConstants
         ?>
 
         <div class="searchbox">
-            <form id="search-form" method="get" action='?' onsubmit="updateLocalStorage()">
+            <form id="search-form" method="get" action='?' onsubmit="processSubmit()">
             <p>
             <?php if(isset($data["SUBSEARCH"]) && $data["SUBSEARCH"] != "") { ?>
             <input type="hidden" name="s" value="<?php 
                 e($data['SUBSEARCH']); ?>" />
             <?php } ?>
-            <input type="hidden" name="<?php e(CSRF_TOKEN); ?>" value="<?php 
+            <input id="csrf-token" type="hidden" name="<?php e(CSRF_TOKEN); ?>" value="<?php 
                 e($data[CSRF_TOKEN]); ?>" />
-            <input type="hidden" name="its" value="<?php e($data['its']); ?>" />
+            <input id="its-value" type="hidden" name="its" value="<?php e($data['its']); ?>" />
             <input type="text" <?php if(WORD_SUGGEST) { ?>
                 autocomplete="off"  onkeyup="onTypeTerm(event, this)"
-                onpaste="onTypeTerm(event, this)"
                 <?php } ?>
                 title="<?php e(tl('search_view_input_label')); ?>" 
                 id="query-field" name="q" value="<?php 
@@ -154,10 +153,10 @@ class SearchView extends View implements CrawlConstants
                 $num_results = min($data['TOTAL_ROWS'], 
                     $data['LIMIT'] + $data['RESULTS_PER_PAGE']);
                 $limit = min($data['LIMIT'] + 1, $num_results);
-                e(tl('search_view_query_results')); ?> (<?php 
+                 ?> <?php 
                 e(tl('search_view_calculated', $data['ELAPSED_TIME']));?> <?php
                 e(tl('search_view_results', $limit, $num_results,
-                    $data['TOTAL_ROWS'].")"));
+                    $data['TOTAL_ROWS']));
                 }
             ?></h2>
             <?php
-- 
1.7.9.4


From 64b707a03d8a6cbf43eb968869eb9dd171a8ea5e Mon Sep 17 00:00:00 2001
From: Sandhya Vissapragada <sandyvissa@gmail.com>
Date: Mon, 3 Dec 2012 11:17:03 -0800
Subject: [PATCH 2/2] git add locale/en-US/resources/alpha.txt.gz

---
 locale/en-US/resources/alpha.txt.gz |  Bin 0 -> 68 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100755 locale/en-US/resources/alpha.txt.gz

diff --git a/locale/en-US/resources/alpha.txt.gz b/locale/en-US/resources/alpha.txt.gz
new file mode 100755
index 0000000000000000000000000000000000000000..949ace51b431f7c23f345046fe676ac63770f41c
GIT binary patch
-- 
1.7.9.4

