浏览代码

[search] Adding number of rows pagination

Romain Rigaux 11 年之前
父节点
当前提交
b24f682

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

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

+ 13 - 7
apps/search/src/search/models.py

@@ -286,7 +286,11 @@ class Collection(models.Model):
       props['collection']['label'] = self.label
     # fields updated
     # idField
-
+    
+    # tmp for dev    
+    if 'rows' not in props['collection']['template']:
+      props['collection']['template']['rows'] = 10
+      
     return json.dumps(props)
 
   def get_default(self, user):      
@@ -310,17 +314,16 @@ class Collection(models.Model):
       "showFieldList": True,
       "fieldsAttributes": [{'name': field['name'], 'sort': {'direction': None}} for field in fields], # sort priority, asc/desc/none
       "fieldsSelected": [],
+      "rows": 10,
     }
     
     FACETS = []
 
-    collection_properties = {
+    return {
       'id': self.id, 'name': self.name, 'label': self.label,
       'template': TEMPLATE, 'facets': FACETS, 
       'fields': fields, 'idField': id_field, 
-    }      
-    
-    return collection_properties
+    }          
 
   def get_absolute_url(self):
     return reverse('search:index') + '?collection=%s' % self.id
@@ -555,8 +558,11 @@ def augment_solr_response2(response, collection, query):
       response['warning'] = _("The Solr schema requires an id field for performing the result highlighting")
 
 
-  response['total_pages'] = 111 #int(math.ceil((float(response['response']['numFound']) / float(solr_query['rows']))))
-  response['search_time'] = response['responseHeader']['QTime']
+  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)

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

@@ -509,7 +509,12 @@ ${ commonheader(_('Search'), "search", user, "80px") | n,unicode }
 </script>
 
 <script type="text/html" id="resultset-pagination">
-  <span data-bind="text: $data.response.numFound"></span> ${ _(' results') } <i class="fa fa-arrow-right"></i>
+  <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>
+  ${ _('of') }
+  <span data-bind="text: $data.response.numFound"></span> ${ _(' results') }  
+  ## (<span data-bind="text: $data.responseHeader.QTime"></span> ${ _('ms') })
+  <i class="fa fa-arrow-right"></i>
   
   <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>

+ 1 - 1
apps/search/static/js/search.ko.js

@@ -354,7 +354,7 @@ var Collection = function (vm, collection) {
   self.fields = ko.mapping.fromJS(collection.fields);
   self.availableFacetFields = ko.computed(function() {
     var facetFieldNames = $.map(self.facets(), function(facet) {
-	  return facet.field();
+	  return facet.field(); //filter out text_general
     });
     return $.grep(self.fields(), function(field) {
       return facetFieldNames.indexOf(field.name()) == -1;