prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <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 
  
  
  </issue>
  <code>
  [start of ckanext-hdx_search/ckanext/hdx_search/plugin.py]
  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 of ckanext-hdx_search/ckanext/hdx_search/plugin.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
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"}]}