Browse Source

[search] URL escape links to range facets

When clicking on a range facet, then a normal facet, removing or adding
a new facet would fail.
Romain Rigaux 12 năm trước cách đây
mục cha
commit
7141807901

+ 3 - 6
apps/search/src/search/api.py

@@ -16,16 +16,13 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-try:
-  import json
-except ImportError:
-  import simplejson as json
+import json
 
 import logging
 
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.rest.http_client import HttpClient, RestException
-from desktop.lib.rest.resource import Resource
+from desktop.lib.rest import resource
 from search.conf import EMPTY_QUERY, SECURITY_ENABLED
 from django.utils.translation import ugettext as _
 
@@ -46,7 +43,7 @@ class SolrApi(object):
     self.security_enabled = SECURITY_ENABLED.get()
     if self.security_enabled:
       self._client.set_kerberos_auth()
-    self._root = Resource(self._client)
+    self._root = resource.Resource(self._client)
 
   def _get_params(self):
     if self.security_enabled:

+ 7 - 7
apps/search/src/search/templates/search.mako

@@ -120,7 +120,7 @@ ${ commonheader(_('Search'), "search", user, "90px") | n,unicode }
             %if found_value != "":
               <% shown_facets += 1 %>
               <li class="nav-header">${fld['label']}</li>
-              <li><strong>${ found_value }</strong> <a href="?collection=${ current_collection }&query=${ solr_query['q'] }&fq=${'|'.join(remove_list)}${solr_query.get("sort") and '&sort=' + solr_query.get("sort") or ''}"><i class="fa fa-times"></i></a></li>
+              <li><strong>${ found_value }</strong> <a href="?collection=${ current_collection }&query=${ solr_query['q'] }&fq=${urllib.quote_plus('|'.join(remove_list))}${solr_query.get("sort") and '&sort=' + solr_query.get("sort") or ''}"><i class="fa fa-times"></i></a></li>
             %endif
           % endif
         % endfor
@@ -144,24 +144,24 @@ ${ commonheader(_('Search'), "search", user, "90px") | n,unicode }
             % for group, count in macros.pairwise(fld['counts']):
               % if count > 0 and group != "" and found_value == "" and loop.index < 100:
                 % if fld['type'] == 'field':
-                  <li class="facetItem"><a href='?collection=${ current_collection }&query=${ solr_query['q'] }&fq=${ solr_query['fq'] }|${ fld['field'] }:"${ urllib.quote_plus(group.encode('ascii', 'xmlcharrefreplace')) }"${solr_query.get("sort") and '&sort=' + solr_query.get("sort") or ''}'>${group}</a> <span class="counter">(${ count })</span></li>
+                  <li class="facetItem"><a href='?collection=${ current_collection }&query=${ solr_query['q'] }&fq=${ urllib.quote_plus(solr_query['fq']) }|${ fld['field'] }:"${ urllib.quote_plus(group.encode('ascii', 'xmlcharrefreplace')) }"${solr_query.get("sort") and '&sort=' + solr_query.get("sort") or ''}'>${group}</a> <span class="counter">(${ count })</span></li>
                 % endif
                 % if fld['type'] == 'range':
-                  <li class="facetItem"><a href='?collection=${ current_collection }&query=${ solr_query['q'] }&fq=${ solr_query['fq'] }|${ fld['field'] }:["${ group }" TO "${ str(int(group) + int(fld['gap']) - 1) }"]${solr_query.get("sort") and '&sort=' + solr_query.get("sort") or ''}'>${ group } - ${ str(int(group) + int(fld['gap']) - 1) }</a> <span class="counter">(${ count })</span></li>
+                  <li class="facetItem"><a href='?collection=${ current_collection }&query=${ solr_query['q'] }&fq=${ urllib.quote_plus(solr_query['fq']) }|${ fld['field'] }:["${ group }" TO "${ str(int(group) + int(fld['gap']) - 1) }"]${solr_query.get("sort") and '&sort=' + solr_query.get("sort") or ''}'>${ group } - ${ str(int(group) + int(fld['gap']) - 1) }</a> <span class="counter">(${ count })</span></li>
                 % endif
                 % if fld['type'] == 'date':
-                  <li class="facetItem dateFacetItem"><a href='?collection=${ current_collection }&query=${ solr_query['q'] }&fq=${ solr_query['fq'] }|${ fld['field'] }:[${ group } TO ${ group }${ urllib.quote_plus(fld['gap']) }]${solr_query.get("sort") and '&sort=' + solr_query.get("sort") or ''}'><span class="dateFacet" data-format="${fld['format']}">${ group }<span class="dateFacetGap hide">${ fld['gap'] }</span></span></a> <span class="counter">(${ count })</span></li>
+                  <li class="facetItem dateFacetItem"><a href='?collection=${ current_collection }&query=${ solr_query['q'] }&fq=${ urllib.quote_plus(solr_query['fq']) }|${ fld['field'] }:[${ group } TO ${ group }${ urllib.quote_plus(fld['gap']) }]${solr_query.get("sort") and '&sort=' + solr_query.get("sort") or ''}'><span class="dateFacet" data-format="${fld['format']}">${ group }<span class="dateFacetGap hide">${ fld['gap'] }</span></span></a> <span class="counter">(${ count })</span></li>
                 % endif
               % endif
               % if found_value != "" and loop.index < 100:
                 % if fld['type'] == 'field' and '"' + group + '"' == found_value:
-                  <li class="facetItem"><strong>${ group }</strong> <a href="?collection=${ current_collection }&query=${ solr_query['q'] }&fq=${'|'.join(remove_list)}${solr_query.get("sort") and '&sort=' + solr_query.get("sort") or ''}"><i class="fa fa-times"></i></a></li>
+                  <li class="facetItem"><strong>${ group }</strong> <a href="?collection=${ current_collection }&query=${ solr_query['q'] }&fq=${urllib.quote_plus('|'.join(remove_list))}${solr_query.get("sort") and '&sort=' + solr_query.get("sort") or ''}"><i class="fa fa-times"></i></a></li>
                 % endif
                 % if fld['type'] == 'range' and '["' + group + '" TO "' + str(int(group) + int(fld['gap']) - 1) + '"]' == found_value:
-                  <li class="facetItem"><strong>${ group } - ${ str(int(group) + int(fld['gap']) - 1) }</strong> <a href="?collection=${ current_collection }&query=${ solr_query['q'] }&fq=${'|'.join(remove_list)}${solr_query.get("sort") and '&sort=' + solr_query.get("sort") or ''}"><i class="fa fa-times"></i></a></li>
+                  <li class="facetItem"><strong>${ group } - ${ str(int(group) + int(fld['gap']) - 1) }</strong> <a href="?collection=${ current_collection }&query=${ solr_query['q'] }&fq=${urllib.quote_plus('|'.join(remove_list))}${solr_query.get("sort") and '&sort=' + solr_query.get("sort") or ''}"><i class="fa fa-times"></i></a></li>
                 % endif
                 % if fld['type'] == 'date' and found_value.startswith('[' + group + ' TO'):
-                  <li class="facetItem"><strong><span class="dateFacet" data-format="${fld['format']}">${ group }<span class="dateFacetGap hide">${ fld['gap'] }</span></span></strong> <a href="?collection=${ current_collection }&query=${ solr_query['q'] }&fq=${'|'.join(remove_list)}${solr_query.get("sort") and '&sort=' + solr_query.get("sort") or ''}"><i class="fa fa-times"></i></a></li>
+                  <li class="facetItem"><strong><span class="dateFacet" data-format="${fld['format']}">${ group }<span class="dateFacetGap hide">${ fld['gap'] }</span></span></strong> <a href="?collection=${ current_collection }&query=${ solr_query['q'] }&fq=${urllib.quote_plus('|'.join(remove_list))}${solr_query.get("sort") and '&sort=' + solr_query.get("sort") or ''}"><i class="fa fa-times"></i></a></li>
                 % endif
               % endif
             % endfor

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 20 - 5
apps/search/src/search/tests.py


+ 4 - 8
apps/search/src/search/views.py

@@ -15,11 +15,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-try:
-  import json
-except ImportError:
-  import simplejson as json
-
+import json
 import logging
 import math
 
@@ -73,7 +69,7 @@ def index(request):
     solr_query['rows'] = search_form.cleaned_data['rows'] or 15
     solr_query['start'] = search_form.cleaned_data['start'] or 0
     solr_query['facets'] = search_form.cleaned_data['facets'] or 1
-    solr_query['current_page'] = int(math.ceil((float(solr_query['start'])+1)/float(solr_query['rows'])))
+    solr_query['current_page'] = int(math.ceil((float(solr_query['start']) + 1) / float(solr_query['rows'])))
     solr_query['total_pages'] = 0
     solr_query['search_time'] = 0
 
@@ -81,10 +77,10 @@ def index(request):
       hue_collection = Collection.objects.get(id=collection_id)
       solr_query['collection'] = hue_collection.name
       response = SolrApi(SOLR_URL.get(), request.user).query(solr_query, hue_collection)
-      solr_query['total_pages'] = int(math.ceil((float(response['response']['numFound'])/float(solr_query['rows']))))
+      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['title'] = force_unicode(e.title)
+      error['title'] = force_unicode(e.title) if hasattr(e, 'title') else ''
       error['message'] = force_unicode(str(e))
   else:
     error['message'] = _('There is no collection to search.')

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác