فهرست منبع

HUE-1728 [search] Error or disabled message when cannot connect to the Solr server

Improved error messages
Improved empty results message
Enrico Berti 12 سال پیش
والد
کامیت
1d39b50690
3فایلهای تغییر یافته به همراه39 افزوده شده و 20 حذف شده
  1. 8 7
      apps/search/src/search/api.py
  2. 28 12
      apps/search/src/search/templates/search.mako
  3. 3 1
      apps/search/src/search/views.py

+ 8 - 7
apps/search/src/search/api.py

@@ -27,6 +27,7 @@ from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.rest.http_client import HttpClient, RestException
 from desktop.lib.rest.resource import Resource
 from search.conf import EMPTY_QUERY, SECURITY_ENABLED
+from django.utils.translation import ugettext as _
 
 
 LOG = logging.getLogger(__name__)
@@ -80,7 +81,7 @@ class SolrApi(object):
           response = json.loads(response.replace('\x00', ''))
       return response
     except RestException, e:
-      raise PopupException('Error while accessing Solr: %s' % e)
+      raise PopupException(e, title=_('Error while accessing Solr'))
 
   def suggest(self, solr_query, hue_core):
     try:
@@ -93,7 +94,7 @@ class SolrApi(object):
         response = json.loads(response)
       return response
     except RestException, e:
-      raise PopupException('Error while accessing Solr: %s' % e)
+      raise PopupException(e, title=_('Error while accessing Solr'))
 
   def collections(self):
     try:
@@ -104,7 +105,7 @@ class SolrApi(object):
       response = self._root.get('zookeeper', params=params)
       return json.loads(response['znode']['data'])
     except RestException, e:
-      raise PopupException('Error while accessing Solr: %s' % e)
+      raise PopupException(e, title=_('Error while accessing Solr'))
 
   def collection_or_core(self, hue_collection):
     if hue_collection.is_core_only:
@@ -117,7 +118,7 @@ class SolrApi(object):
       collections = self.collections()
       return collections[name]
     except Exception, e:
-      raise PopupException('Error while accessing Solr: %s' % e)
+      raise PopupException(e, title=_('Error while accessing Solr'))
 
   def cores(self):
     try:
@@ -126,7 +127,7 @@ class SolrApi(object):
       )
       return self._root.get('admin/cores', params=params)['status']
     except RestException, e:
-      raise PopupException('Error while accessing Solr: %s' % e)
+      raise PopupException(e, title=_('Error while accessing Solr'))
 
   def core(self, core):
     try:
@@ -136,7 +137,7 @@ class SolrApi(object):
       )
       return self._root.get('admin/cores', params=params)
     except RestException, e:
-      raise PopupException('Error while accessing Solr: %s' % e)
+      raise PopupException(e, title=_('Error while accessing Solr'))
 
   def schema(self, core):
     try:
@@ -146,4 +147,4 @@ class SolrApi(object):
       )
       return self._root.get('%(core)s/admin/file' % {'core': core}, params=params)
     except RestException, e:
-      raise PopupException('Error while accessing Solr: %s' % e)
+      raise PopupException(e, title=_('Error while accessing Solr'))

+ 28 - 12
apps/search/src/search/templates/search.mako

@@ -86,16 +86,22 @@ ${ commonheader(_('Search'), "search", user, "90px") | n,unicode }
   <!-- <![endif]-->
 </div>
 
-
-<div class="container results">
-  <div id="mainContent" class="row hide">
-    % if error:
-    <div class="span12 results">
-      <div class="alert">
-        ${ error['message'] }
+% if error:
+<div class="container-fluid">
+  <div class="row-fluid">
+    <div class="span12">
+      <div class="alert alert-error">
+        % if error['title']:
+        <h4>${ error['title'] }</h4><br/>
+        % endif
+        <span class="decodeError" data-message="${ error['message'] }"></span>
       </div>
     </div>
-    %else:
+  </div>
+</div>
+% else:
+<div class="container results">
+  <div id="mainContent" class="row hide">
     % if response and 'response' in response and 'docs' in response['response'] and len(response['response']['docs']) > 0 and 'normalized_facets' in response:
       <% shown_facets = 0 %>
     <div class="span2 results">
@@ -275,15 +281,23 @@ ${ commonheader(_('Search'), "search", user, "90px") | n,unicode }
     </div>
     % else:
     <div class="span12">
-      <div class="alert">
-        ${_('Your search - %s - did not match any documents.') % (solr_query["q"])}
-      </div>
+      <h4>
+        ${_('Your search')} - <strong>${solr_query["q"]}</strong> - ${_('did not match any documents.')}
+      </h4>
+      ${_('Suggestions:')}
+      <ul>
+        <li>${_('Make sure all words are spelled correctly.')}</li>
+        <li>${_('Try different keywords.')}</li>
+        <li>${_('Try more general keywords.')}</li>
+        <li>${_('Try fewer keywords.')}</li>
+      </ul>
     </div>
     % endif
   </div>
-  % endif
 </div>
 
+% endif
+
 % if hue_collection:
   ${ hue_collection.result.get_extracode() | n,unicode }
 % endif
@@ -296,6 +310,8 @@ ${ commonheader(_('Search'), "search", user, "90px") | n,unicode }
       });
     }
 
+    $(".decodeError").text($("<span>").html($(".decodeError").data("message")).text());
+
     $("#loader").hide();
     $("#mainContent").removeClass("hide");
     window.onbeforeunload = function (e) {

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

@@ -38,6 +38,7 @@ from search.forms import QueryForm, CollectionForm, HighlightingForm
 from search.models import Collection, augment_solr_response
 from search.search_controller import SearchController
 
+from django.utils.encoding import force_unicode
 
 LOG = logging.getLogger(__name__)
 
@@ -83,7 +84,8 @@ def index(request):
       solr_query['total_pages'] = int(math.ceil((float(response['response']['numFound'])/float(solr_query['rows']))))
       solr_query['search_time'] = response['responseHeader']['QTime']
     except Exception, e:
-      error['message'] = unicode(str(e), "utf8")
+      error['title'] = force_unicode(e.title)
+      error['message'] = force_unicode(str(e))
   else:
     error['message'] = _('There is no collection to search.')