Browse Source

[search] Removed autocomplete and prevented django error for search on non-existing collection

Enrico Berti 12 years ago
parent
commit
9cd72d1e77

+ 18 - 10
apps/search/src/search/templates/search.mako

@@ -28,6 +28,17 @@ ${ commonheader(_('Search'), "search", user, "40px") | n,unicode }
 <script src="/static/ext/js/moment.min.js" type="text/javascript" charset="utf-8"></script>
 <script src="/search/static/js/search.utils.js" type="text/javascript" charset="utf-8"></script>
 
+<%
+  if "q" not in solr_query:
+    solr_query["q"] = ""
+  if "fq" not in solr_query:
+    solr_query["fq"] = ""
+  if "rows" not in solr_query:
+    solr_query["rows"] = ""
+  if "start" not in solr_query:
+    solr_query["start"] = ""
+%>
+
 <div class="search-bar">
   % if user.is_superuser:
     <div class="pull-right" style="margin-top: 4px">
@@ -70,7 +81,7 @@ ${ commonheader(_('Search'), "search", user, "40px") | n,unicode }
       </div>
     </div>
     %else:
-    % if response and response['response']['docs'] and len(response['response']['docs']) > 0 and response['normalized_facets']:
+    % if response and 'response' in response and 'docs' in response['response'] and len(response['response']['docs']) > 0 and 'normalized_facets' in response:
     <div class="span2 results">
       <ul class="facet-list">
         % for fld in response['normalized_facets']:
@@ -117,7 +128,7 @@ ${ commonheader(_('Search'), "search", user, "40px") | n,unicode }
     </div>
     % endif
 
-    % if response and response['response']['docs'] and len(response['response']['docs']) > 0:
+    % if response and 'response' in response and 'docs' in response['response'] and len(response['response']['docs']) > 0:
       % if response['normalized_facets']:
       <div class="span10 results">
       % else:
@@ -213,6 +224,11 @@ ${ commonheader(_('Search'), "search", user, "40px") | n,unicode }
 
 <script>
   $(document).ready(function () {
+    if ($(".errorlist").length > 0) {
+      $(".errorlist li").each(function () {
+        $.jHueNotify.error($(this).text());
+      });
+    }
 
     $("#loader").hide();
     $("#mainContent").removeClass("hide");
@@ -333,14 +349,6 @@ ${ commonheader(_('Search'), "search", user, "40px") | n,unicode }
       var query = $("#id_query").val();
       if ($.trim(query) != "") {
         $("#id_query").addClass("deletable");
-        $.ajax("${ url('search:query_suggest', collection_id=hue_collection.id) }" + query, {
-          type: 'GET',
-          success: function (data) {
-            if (data.message.spellcheck && ! jQuery.isEmptyObject(data.message.spellcheck.suggestions)) {
-              $('#id_query').typeahead({source: data.message.spellcheck.suggestions[1].suggestion});
-            }
-          }
-        });
       }
       else {
         $("#id_query").removeClass("deletable");

+ 2 - 1
apps/search/src/search/views.py

@@ -75,10 +75,11 @@ def index(request):
       error['message'] = unicode(str(e), "utf8")
   else:
     hue_collection = hue_collections[0]
-    collection = hue_collections.id
+    collection_id = hue_collection.id
 
   if hue_collection is not None:
     response = augment_solr_response(response, hue_collection.facets.get_data())
+    print response
 
   if request.GET.get('format') == 'json':
     return HttpResponse(json.dumps(response), mimetype="application/json")

+ 4 - 0
apps/search/static/css/search.css

@@ -95,4 +95,8 @@
 
 .results.span12 {
   width: 1180px;
+}
+
+.errorlist {
+  display: none;
 }