Эх сурвалжийг харах

[search] Next and previous pagination

Romain Rigaux 11 жил өмнө
parent
commit
497ceb23c9

+ 2 - 2
apps/search/src/search/api.py

@@ -181,8 +181,8 @@ class SolrApi(object):
     solr_query = {}      
     
     solr_query['collection'] = collection['name']
-    solr_query['rows'] = min(collection['template']['rows'], 1000)
-    solr_query['start'] = 0
+    solr_query['rows'] = min(int(collection['template']['rows']), 1000)
+    solr_query['start'] = min(int(query['start']), 10000)
     
     q_template = '(%s)' if len(query['qs']) >= 2 else '%s'
           

+ 0 - 6
apps/search/src/search/models.py

@@ -558,12 +558,6 @@ def augment_solr_response2(response, collection, query):
       response['warning'] = _("The Solr schema requires an id field for performing the result highlighting")
 
 
-  augmented['pagination'] = {
-    'rows': collection['template']['rows'],
-  }
-#  response['total_pages'] = 111 #int(math.ceil((float(response['response']['numFound']) / float(solr_query['rows']))))
-#  response['search_time'] = response['responseHeader']['QTime']
-
   if normalized_facets:
     augmented['normalized_facets'].extend(normalized_facets)
 

+ 27 - 6
apps/search/src/search/templates/search2.mako

@@ -41,7 +41,7 @@ ${ commonheader(_('Search'), "search", user, "80px") | n,unicode }
     <!-- /ko -->
   </form>
   
-  <form class="form-search" style="margin: 0" data-bind="submit: search, visible: columns().length != 0"">
+  <form class="form-search" style="margin: 0" data-bind="submit: searchBtn, visible: columns().length != 0"">
     <strong>${_("Search")}</strong>
     <div class="input-append">
       <div class="selectMask">
@@ -509,12 +509,33 @@ ${ commonheader(_('Search'), "search", user, "80px") | n,unicode }
 </script>
 
 <script type="text/html" id="resultset-pagination">
-  <span data-bind="text: $root.collection.template.rows, visible: ! $root.isEditing()"></span>
-  <input type="text" data-bind="value: $root.collection.template.rows, visible: $root.isEditing()"></input>
+  <a href="javascript: void(0)" title="${ _('Previous') }">
+    <span data-bind="text: name, click: $root.collection.toggleSortColumnGridLayout"></span>
+    <i class="fa fa-arrow-left" data-bind="
+        visible: $data.response.start >= $root.collection.template.rows(),
+        click: function() { $root.query.paginate('prev') }">
+    </i>
+  </a>  
+
+  <span data-bind="text: $data.response.start"></span>
   ${ _('of') }
-  <span data-bind="text: $data.response.numFound"></span> ${ _(' results') }  
+  <span data-bind="text: $data.response.numFound"></span>
+  
+  <span data-bind="visible: $root.isEditing()">
+    ${ _('by') }
+    <input type="text" data-bind="value: $root.collection.template.rows, valueUpdate: 'afterkeydown'"></input>
+  </span>
+  
+  ${ _(' results') }  
   ## (<span data-bind="text: $data.responseHeader.QTime"></span> ${ _('ms') })
-  <i class="fa fa-arrow-right"></i>
+  
+  <a href="javascript: void(0)" title="${ _('Next') }">
+    <span data-bind="text: name, click: $root.collection.toggleSortColumnGridLayout"></span>
+    <i class="fa fa-arrow-right" data-bind="
+        visible: ($root.collection.template.rows() + $data.response.start) < $data.response.numFound,
+        click: function() { $root.query.paginate('next') }">
+    </i>
+  </a>  
   
   <span class="pull-right" data-bind="visible: $data.response.numFound > 0 && $data.response.numFound <= 1000">
     <a class="btn" href="javascript:void(0)" id="download-csv"><i class="hfo hfo-file-csv"></i></a>
@@ -525,7 +546,7 @@ ${ commonheader(_('Search'), "search", user, "80px") | n,unicode }
 <script type="text/html" id="histogram-widget">
   <!-- ko ifnot: $root.getFacetFromQuery(id()) -->
     <a data-bind="click: showAddFacetDemiModal" class="btn" href="javascript:void(0)"><i class="fa fa-plus"></i></a>
-  <!-- /ko -->
+  <!-- /ko -->text
 
   <div class="widget-spinner" data-bind="visible: isLoading()">
     <!--[if !IE]> --><i class="fa fa-spinner fa-spin"></i><!-- <![endif]-->

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

@@ -63,7 +63,7 @@ def index(request):
       return no_collections(request)
 
   collection = Collection.objects.get(id=collection_id) # TODO perms HUE-1987
-  query = {'qs': [{'q': ''}], 'fqs': []}
+  query = {'qs': [{'q': ''}], 'fqs': [], 'start': 0}
 
   return render('search2.mako', request, {
     'collection': collection,
@@ -78,7 +78,7 @@ def new_search(request):
     return no_collections(request)
 
   collection = Collection(name=collections[0], label=collections[0])
-  query = {'qs': [{'q': ''}], 'fqs': []}
+  query = {'qs': [{'q': ''}], 'fqs': [], 'start': 0}
 
   return render('search2.mako', request, {
     'collection': collection,

+ 20 - 2
apps/search/static/js/search.ko.js

@@ -199,6 +199,8 @@ var Query = function (vm, query) {
 
   self.qs = ko.mapping.fromJS(query.qs);
   self.fqs = ko.mapping.fromJS(query.fqs);
+  self.start = ko.mapping.fromJS(query.start);
+  
   var defaultMultiqGroup = {'id': 'query', 'label': 'query'};
   self.multiqs = ko.computed(function () { // List of widgets supporting multiqs
 	var histogram_id = vm.collection.getHistogramFacet();
@@ -321,7 +323,16 @@ var Query = function (vm, query) {
         return false;
       }
     });
-  };   
+  }; 
+  
+  self.paginate = function (direction) {
+	if (direction == 'next') {
+	  self.start(self.start() + vm.collection.template.rows());
+	} else {
+	  self.start(self.start() - vm.collection.template.rows());
+	}
+	vm.search();
+  };
 };
 
 
@@ -349,7 +360,9 @@ var Collection = function (vm, collection) {
       vm.search();
     });
   });
-
+  self.template.rows.subscribe(function(){
+	vm.search();
+  });
 
   self.fields = ko.mapping.fromJS(collection.fields);
   self.availableFacetFields = ko.computed(function() {
@@ -676,6 +689,11 @@ var SearchViewModel = function (collection_json, query_json, initial_json) {
     self.isEditing(true);
     self.search();
   }
+  
+  self.searchBtn = function () {
+    self.query.start(0);
+    self.search();
+  };
 
   self.search = function () {
     self.isRetrievingResults(true);