Repository: OCHA-DAP/hdx-ckan

Issue:
Search Page (Amok): fix the count of the displayed items
There might be 2 problems:
1. when /search with no query the counters are zero even if there are items under datasets
2. gini_index is an indicator but it is displayed under datasets section

![screen shot 2014-09-22 at 11 37 37](https://cloud.githubusercontent.com/assets/3865844/4353502/e6efc3dc-4233-11e4-8133-e33fbd9945b1.png)
![screen shot 2014-09-22 at 11 37 26](https://cloud.githubusercontent.com/assets/3865844/4353503/e6f2f66a-4233-11e4-97a9-3f0fd64ba34e.png)



Discussion:

Resolving patch:
diff --git a/ckanext-hdx_search/ckanext/hdx_search/controllers/search_controller.py b/ckanext-hdx_search/ckanext/hdx_search/controllers/search_controller.py
--- a/ckanext-hdx_search/ckanext/hdx_search/controllers/search_controller.py
+++ b/ckanext-hdx_search/ckanext/hdx_search/controllers/search_controller.py
@@ -72,16 +72,17 @@ def search_url(params, package_type=None):
         url = h.url_for('{0}_search'.format(package_type))
     return url_with_params(url, params)
 
-def count_types(context, data_dict):
-	search = copy.copy(data_dict)
-	if search['q']:
-		search['extras']['ext_indicator'] = 1
-		indicators = get_action('package_search')(context, search)
-		search['extras']['ext_indicator'] = 0
-		datasets = get_action('package_search')(context, search)
-	else:
-		return (0,0)
-	return (datasets['count'],indicators['count'])
+def count_types(context, data_dict, tab):
+    search = copy.copy(data_dict)
+    search['extras']['ext_indicator'] = 1
+    indicators = get_action('package_search')(context, search)
+    search['extras']['ext_indicator'] = 0
+    datasets = get_action('package_search')(context, search)
+    if tab == 'all':
+        indicator = [indicators['results'][0]]
+    else:
+        indicator = None
+    return (datasets['count'],indicators['count'], indicator)
             
 
 class HDXSearchController(PackageController):
@@ -117,7 +118,6 @@ def search(self):
             page = int(request.params.get('page', 1))
         except ValueError, e:
             abort(400, ('"page" parameter must be an integer'))
-        limit = g.datasets_per_page
 
         # most search operations should reset the page counter:
         params_nopage = [(k, v) for k, v in request.params.items()
@@ -175,6 +175,12 @@ def pager_url(q=None, page=None):
             # a list of values eg {'tags':['tag1', 'tag2']}
             c.fields_grouped = {}
             search_extras = {}
+            #limit = g.datasets_per_page
+            if 'ext_indicator' in search_extras:
+                limit = 25
+            else:
+                limit = 7
+
             fq = ''
             for (param, value) in request.params.items():
                 if param not in ['q', 'page', 'sort'] \
@@ -240,9 +246,14 @@ def pager_url(q=None, page=None):
                     c.tab = "indicators"
                 elif int(data_dict['extras']['ext_indicator']) == 0:
                     c.tab = "datasets"
+            else:
+                #For all tab, only paginate datasets
+                data_dict['extras']['ext_indicator'] = 0
+                
+
 
             query = get_action('package_search')(context, data_dict)
-            c.dataset_counts, c.indicator_counts = count_types(context, data_dict)
+            c.dataset_counts, c.indicator_counts, c.indicator = count_types(context, data_dict, c.tab)
             c.sort_by_selected = query['sort']
 
             c.page = h.Page(
diff --git a/ckanext-hdx_search/ckanext/hdx_search/plugin.py b/ckanext-hdx_search/ckanext/hdx_search/plugin.py
--- a/ckanext-hdx_search/ckanext/hdx_search/plugin.py
+++ b/ckanext-hdx_search/ckanext/hdx_search/plugin.py
@@ -24,10 +24,9 @@ def before_search(self, search_params):
         #If indicator flag is set, search only that type
         if 'ext_indicator' in search_params['extras']:
             if int(search_params['extras']['ext_indicator']) == 1:
-                search_params['q'] = search_params['q']+' AND extras_indicator:1'
+                search_params['q'] = search_params['q']+'+extras_indicator:1'
             elif int(search_params['extras']['ext_indicator']) == 0:
-                search_params['q'] = search_params['q']+' AND extras_indicator:0'
-        print search_params
+                search_params['q'] = search_params['q']+'+extras_indicator:0'
         return search_params
 
     def after_search(self, search_results, search_params):


Test patch:
diff --git a/ckanext-hdx_search/ckanext/hdx_search/tests/test_search.py b/ckanext-hdx_search/ckanext/hdx_search/tests/test_search.py
--- a/ckanext-hdx_search/ckanext/hdx_search/tests/test_search.py
+++ b/ckanext-hdx_search/ckanext/hdx_search/tests/test_search.py
@@ -15,9 +15,7 @@
 class TestHDXSearch(hdx_test_base.HdxBaseTest):
 
     @classmethod
-    def _load_plugins(cls):
-        hdx_test_base.load_plugin('hdx_search')
-
+    
     def test_search(self):
         user = model.User.by_name('tester')
         offset = h.url_for(controller='ckanext.hdx_search.controllers.search_controller:HDXSearchController', action='search')