prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Search Page (Amok): search controller - datasets displayed
  1. After merging the last changes, there are displayed a lower number of datasets (<10). This is basically due to the fact that search module searches in extras after "indicator" value 0. The database contains right now indicator value 1 for indicators and only for some datasets value 0.
     What will be the resolution for this bug?
  2. I noticed in search controller that we are basically performed 3 searches (in search_controller.py) line 280 and in count_types (line 283). Is it possible to optimize this?
     Assigning it to @mbellotti 
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `ckanext-hdx_search/ckanext/hdx_search/plugin.py`
  Content:
  ```
  1 import logging
  2 import ckan.plugins as plugins
  3 import ckan.plugins.toolkit as tk
  4 import ckan.lib.plugins as lib_plugins
  5 
  6 class HDXSearchPlugin(plugins.SingletonPlugin):
  7     plugins.implements(plugins.IConfigurer, inherit=False)
  8     plugins.implements(plugins.IRoutes, inherit=True)
  9     plugins.implements(plugins.ITemplateHelpers, inherit=False)
  10     plugins.implements(plugins.IPackageController, inherit=True)
  11 
  12     def update_config(self, config):
  13         tk.add_template_directory(config, 'templates')
  14 
  15     def get_helpers(self):
  16         return {}
  17 
  18     def before_map(self, map):
  19         map.connect('search','/search', controller='ckanext.hdx_search.controllers.search_controller:HDXSearchController', action='search')
  20         map.connect('/dataset', controller='ckanext.hdx_search.controllers.search_controller:HDXSearchController', action='package_search')
  21         return map
  22     
  23     def after_map(self, map):
  24         map.connect('search','/search', controller='ckanext.hdx_search.controllers.search_controller:HDXSearchController', action='search')
  25         map.connect('/dataset', controller='ckanext.hdx_search.controllers.search_controller:HDXSearchController', action='package_search')
  26         return map
  27 
  28     def before_search(self, search_params):
  29         #If indicator flag is set, search only that type
  30         if 'ext_indicator' in search_params['extras']:
  31             if int(search_params['extras']['ext_indicator']) == 1:
  32                 search_params['q'] = search_params['q']+'+extras_indicator:1'
  33             elif int(search_params['extras']['ext_indicator']) == 0:
  34                 search_params['q'] = search_params['q']+'+extras_indicator:0'
  35         return search_params
  36 
  37     def after_search(self, search_results, search_params):
  38         return search_results
  39 
  40     def before_view(self, pkg_dict):
  41         return pkg_dict
  42 
  43 
  44
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: 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
  @@ -26,7 +26,7 @@
               if int(search_params['extras']['ext_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']+'+extras_indicator:0'
  +                search_params['q'] = search_params['q']+'+!extras_indicator:1'
           return search_params
   
       def after_search(self, search_results, search_params):
  
verification_info: {"golden_diff": "diff --git a/ckanext-hdx_search/ckanext/hdx_search/plugin.py b/ckanext-hdx_search/ckanext/hdx_search/plugin.py\n--- a/ckanext-hdx_search/ckanext/hdx_search/plugin.py\n+++ b/ckanext-hdx_search/ckanext/hdx_search/plugin.py\n@@ -26,7 +26,7 @@\n             if int(search_params['extras']['ext_indicator']) == 1:\n                 search_params['q'] = search_params['q']+'+extras_indicator:1'\n             elif int(search_params['extras']['ext_indicator']) == 0:\n-                search_params['q'] = search_params['q']+'+extras_indicator:0'\n+                search_params['q'] = search_params['q']+'+!extras_indicator:1'\n         return search_params\n \n     def after_search(self, search_results, search_params):\n", "issue": "Search Page (Amok): search controller - datasets displayed\n1. After merging the last changes, there are displayed a lower number of datasets (<10). This is basically due to the fact that search module searches in extras after \"indicator\" value 0. The database contains right now indicator value 1 for indicators and only for some datasets value 0.\n   What will be the resolution for this bug?\n2. I noticed in search controller that we are basically performed 3 searches (in search_controller.py) line 280 and in count_types (line 283). Is it possible to optimize this?\n   Assigning it to @mbellotti \n\n", "before_files": [{"content": "import logging\nimport ckan.plugins as plugins\nimport ckan.plugins.toolkit as tk\nimport ckan.lib.plugins as lib_plugins\n\nclass HDXSearchPlugin(plugins.SingletonPlugin):\n    plugins.implements(plugins.IConfigurer, inherit=False)\n    plugins.implements(plugins.IRoutes, inherit=True)\n    plugins.implements(plugins.ITemplateHelpers, inherit=False)\n    plugins.implements(plugins.IPackageController, inherit=True)\n\n    def update_config(self, config):\n        tk.add_template_directory(config, 'templates')\n\n    def get_helpers(self):\n        return {}\n\n    def before_map(self, map):\n        map.connect('search','/search', controller='ckanext.hdx_search.controllers.search_controller:HDXSearchController', action='search')\n        map.connect('/dataset', controller='ckanext.hdx_search.controllers.search_controller:HDXSearchController', action='package_search')\n        return map\n    \n    def after_map(self, map):\n        map.connect('search','/search', controller='ckanext.hdx_search.controllers.search_controller:HDXSearchController', action='search')\n        map.connect('/dataset', controller='ckanext.hdx_search.controllers.search_controller:HDXSearchController', action='package_search')\n        return map\n\n    def before_search(self, search_params):\n        #If indicator flag is set, search only that type\n        if 'ext_indicator' in search_params['extras']:\n            if int(search_params['extras']['ext_indicator']) == 1:\n                search_params['q'] = search_params['q']+'+extras_indicator:1'\n            elif int(search_params['extras']['ext_indicator']) == 0:\n                search_params['q'] = search_params['q']+'+extras_indicator:0'\n        return search_params\n\n    def after_search(self, search_results, search_params):\n        return search_results\n\n    def before_view(self, pkg_dict):\n        return pkg_dict\n\n\n", "path": "ckanext-hdx_search/ckanext/hdx_search/plugin.py"}], "after_files": [{"content": "import logging\nimport ckan.plugins as plugins\nimport ckan.plugins.toolkit as tk\nimport ckan.lib.plugins as lib_plugins\n\nclass HDXSearchPlugin(plugins.SingletonPlugin):\n    plugins.implements(plugins.IConfigurer, inherit=False)\n    plugins.implements(plugins.IRoutes, inherit=True)\n    plugins.implements(plugins.ITemplateHelpers, inherit=False)\n    plugins.implements(plugins.IPackageController, inherit=True)\n\n    def update_config(self, config):\n        tk.add_template_directory(config, 'templates')\n\n    def get_helpers(self):\n        return {}\n\n    def before_map(self, map):\n        map.connect('/search', controller='ckanext.hdx_search.controllers.search_controller:HDXSearchController', action='search')\n        map.connect('/dataset', controller='ckanext.hdx_search.controllers.search_controller:HDXSearchController', action='package_search')\n        return map\n\n    def before_search(self, search_params):\n        #If indicator flag is set, search only that type\n        if 'ext_indicator' in search_params['extras']:\n            if int(search_params['extras']['ext_indicator']) == 1:\n                search_params['q'] = search_params['q']+'+extras_indicator:1'\n            elif int(search_params['extras']['ext_indicator']) == 0:\n                search_params['q'] = search_params['q']+'+!extras_indicator:1'\n        return search_params\n\n    def after_search(self, search_results, search_params):\n        return search_results\n\n    def before_view(self, pkg_dict):\n        return pkg_dict\n\n\n", "path": "ckanext-hdx_search/ckanext/hdx_search/plugin.py"}]}