_binary From b14ccc8c356a8f230a7829ff3f38f9d5a4ce623b Mon Sep 17 00:00:00 2001
From: Sandhya Vissapragada <sandyvissa@gmail.com>
Date: Tue, 17 Apr 2012 14:07:56 -0700
Subject: [PATCH] commit

---
 css/search.css                     |   35 +++++++++-
 resources/en-hf-words/en-hf.txt.gz |  Bin 0 -> 124281 bytes
 scripts/autosuggest.js             |  135 ++++++++++++++++++++++++++++++++++++
 views/layouts/web_layout.php       |    3 +-
 views/search_view.php              |    6 +-
 5 files changed, 175 insertions(+), 4 deletions(-)
 create mode 100644 resources/en-hf-words/en-hf.txt.gz
 create mode 100644 scripts/autosuggest.js

diff --git a/css/search.css b/css/search.css
index 69df34f..0322201 100755
--- a/css/search.css
+++ b/css/search.css
@@ -280,7 +280,7 @@ body.html-tb-lr
     font-size:16pt;
 }
 
-.searchbox input
+.searchbox input, .autoresult, .dropdown
 {
     width: 6.5in;
     font-size:16pt;
@@ -288,9 +288,40 @@ body.html-tb-lr
     margin-left:0;
     border: 0;
     padding-top: 0;
-    padding-bottom:3pt;
+    padding-bottom:0.05in;
     padding-right:0;
     padding-left:0;
+    margin:0;    
+}
+
+#aslist li
+{
+    width: 6.5in;
+    font-size:16pt;
+    margin-right:0in;
+    margin-left:0in;
+    padding-top:0;
+    padding-right:0;
+    padding-left:0.1in;
+    cursor:pointer;
+    list-style:none;
+    border-color: #ddddff;
+    border-top-style:none;
+    border-right-style:solid;
+    border-bottom-style:none;
+    border-left-style:solid;
+}
+
+
+#aslist li:last-child
+{
+    border-bottom-style:solid;
+}
+
+#aslist li:hover 
+{
+    background:#ddddff;
+    color:black;
 }
 
 .html-ltr .buttonbox
diff --git a/resources/en-hf-words/en-hf.txt.gz b/resources/en-hf-words/en-hf.txt.gz
new file mode 100644
index 0000000000000000000000000000000000000000..f7d145ed81c59d51d1fad7c6074bbfc74232fec9
GIT binary patch
diff --git a/scripts/autosuggest.js b/scripts/autosuggest.js
new file mode 100644
index 0000000..7ec0575
--- /dev/null
+++ b/scripts/autosuggest.js
@@ -0,0 +1,135 @@
+/** 
+ *  SeekQuarry/Yioop --
+ *  Open Source Pure PHP Search Engine, Crawler, and Indexer
+ *
+ *  Copyright (C) 2009 - 2012  Chris Pollett chris@pollett.org
+ *
+ *  LICENSE:
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *  END LICENSE
+ *
+ * @author Sandhya Vissapragada
+ * @package seek_quarry
+ * @subpackage javascript
+ * @license http://www.gnu.org/licenses/ GPL3
+ * @link http://www.seekquarry.com/
+ * @copyright 2009 - 2012s
+ * @filesource
+ */
+
+/**
+ * Steps to follow every time a key is up from the user end
+ */
+function askeyup(textobj) {
+    var inputTerm = textobj.value;
+    var res_obj = document.getElementById("aslist");
+    searchList="";
+    autosuggest(dictObj,inputTerm); 
+    res_obj.innerHTML = searchList; 
+    searchList="";        
+}
+
+/**
+ * To select a value from the dropdownlist and place in the search box 
+ */
+function aslitem_click(liObj) {
+    var res_obj = document.getElementById("aslist");
+   // var astobj = document.getElementById("astbox");
+    var astobj = document.getElementById("search-name"); 
+    astobj.value = liObj.innerHTML;
+    res_obj.innerHTML = ""; 
+}
+
+/**
+ * Fetch words from the Trie and add to seachList with <li> </li> tags
+ */
+function getValues(arrayLevel, parent_word) { 
+    if (arrayLevel != null && lastWord == 0 ) {
+        for (key in arrayLevel) { 
+            if (key != " " ) {
+                getValues(arrayLevel[key], parent_word+key);
+            } else {
+                searchList += "<li onclick='aslitem_click(this);'>" + parent_word + "</li>";
+                count++;
+                // Display only top 6 words
+                if(count == 6) {
+                    lastWord = 1;
+                }
+            }
+        }                                     
+    }
+}
+
+/**
+ * If more than one character is entered, get the level of array to fetch the
+ * words
+ */
+function exist(arrayLevel, searchTerm) {
+    var i;  
+    for(i=1;i<searchTerm.length;i++) {
+        if(arrayLevel == null){
+            return false;
+        }
+        if (arrayLevel != 'null') {
+            if(arrayLevel[searchTerm.charAt(i)] != 'null') { 
+                arrayLevel = arrayLevel[searchTerm.charAt(i)];
+            }
+        }
+        else {
+            return false;
+        }
+    } 
+    return arrayLevel;
+}
+
+/**
+ * Entry point to find words for autosuggestion.Find the level of the array based on
+ * the number of characters entered by the user
+ */
+function autosuggest(arrayLevel, searchTerm) {
+    lastWord=0, count=0;
+    if(arrayLevel == null || arrayLevel[" "] == " ") {
+        return false;
+    }
+    if((searchTerm.length) > 1) {  
+        arrayLevel = exist(arrayLevel[searchTerm.charAt(0)], searchTerm);
+
+    } else {
+        arrayLevel = arrayLevel[searchTerm];
+    }
+    getValues(arrayLevel, searchTerm);  
+}
+
+/**
+ * Load the Trie(compressed with .gz extension) during the launch of website
+ */
+function loadTrie() {
+    var xmlhttp;
+    if (window.XMLHttpRequest) {
+        // code for IE7i+, Firefox, Chrome, Opera, Safari
+        xmlhttp=new XMLHttpRequest();
+    } else {
+        // code for IE6, IE5
+        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
+    }
+    xmlhttp.onreadystatechange=function() {
+        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
+            dictObj = JSON.parse(xmlhttp.responseText);
+        }
+    }
+    xmlhttp.open("GET","./resources/en-hf-words/en-hf.txt.gz",true);
+    xmlhttp.send();   
+}
diff --git a/views/layouts/web_layout.php b/views/layouts/web_layout.php
index 11d97a5..77e1a58 100755
--- a/views/layouts/web_layout.php
+++ b/views/layouts/web_layout.php
@@ -89,7 +89,7 @@ class WebLayout extends Layout
 
         </head>
         <body class="html-<?php e($data['BLOCK_PROGRESSION']);?> html-<?php 
-            e($data['LOCALE_DIR']);?> html-<?php e($data['WRITING_MODE']);?>">
+            e($data['LOCALE_DIR']);?> html-<?php e($data['WRITING_MODE']);?>" onload="loadTrie()">
             <div id="message" ></div>
             <?php
                 $this->view->renderView($data);
@@ -114,6 +114,7 @@ class WebLayout extends Layout
                 <?php }
             ?>
             <script type="text/javascript" src="./scripts/basic.js" ></script>
+            <script type="text/javascript" src="./scripts/autosuggest.js" ></script>                        
             <?php
             if(isset($data['INCLUDE_SCRIPTS'])) {
                 foreach($data['INCLUDE_SCRIPTS'] as $script_name) {
diff --git a/views/search_view.php b/views/search_view.php
index c7c572d..5606aa8 100755
--- a/views/search_view.php
+++ b/views/search_view.php
@@ -89,7 +89,7 @@ class SearchView extends View implements CrawlConstants
         <input type="hidden" name="YIOOP_TOKEN" value="<?php 
             e($data['YIOOP_TOKEN']); ?>" />
         <input type="hidden" name="its" value="<?php e($data['its']); ?>" />
-        <input type="text" title="<?php e(tl('search_view_input_label')); ?>" 
+        <input type="text" autocomplete="off" onkeyup="askeyup(this)" title="<?php e(tl('search_view_input_label')); ?>" 
             id="search-name" name="q" value="<?php if(isset($data['QUERY'])) {
             e(urldecode($data['QUERY']));} ?>" 
             placeholder="<?php e(tl('search_view_input_placeholder')); ?>" />
@@ -97,6 +97,10 @@ class SearchView extends View implements CrawlConstants
             e(tl('search_view_search')); ?></button>
         </p>
         </form>
+            </div>
+        <div class="dropdown"> 
+            <ul id="aslist" class="autoresult">
+            </ul>
         </div>
         <?php
         if(isset($data['PAGES'])) {
-- 
1.7.9.4

