prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Search shows products with no category
  It should not, of course
  
  ![image](https://user-images.githubusercontent.com/3526796/67692684-9a9cb680-f9b1-11e9-8038-99534e063e03.png)
  
  Search link: https://www.shopelectro.ru/search/?term=MK1215NC
  Link to the product: https://www.shopelectro.ru/catalog/products/7608/
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `shopelectro/views/search.py`
  Content:
  ```
  1 from django.conf import settings
  2 
  3 from search import views as search_views, search as search_engine
  4 
  5 from pages.models import Page
  6 
  7 from shopelectro.models import Category, Product
  8 
  9 
  10 class Search(search_views.SearchView):
  11     def get_redirect_search_entity(self):
  12         return next(s for s in self.search_entities if s.name == 'product')
  13 
  14     # ignore CPDBear
  15     search_entities = [
  16         search_engine.Search(
  17             name='category',
  18             qs=Category.objects.active(),
  19             fields=['name'],  # Ignore CPDBear
  20             min_similarity=settings.TRIGRAM_MIN_SIMILARITY,
  21         ),
  22         search_engine.Search(
  23             name='product',
  24             qs=Product.objects.active(),
  25             fields=['name'],
  26             redirect_field='vendor_code',
  27             min_similarity=settings.TRIGRAM_MIN_SIMILARITY,
  28         ),
  29         search_engine.Search(
  30             name='page',  # Ignore CPDBear
  31             qs=Page.objects.filter(is_active=True).exclude(type=Page.MODEL_TYPE),
  32             fields=['name'],
  33             min_similarity=settings.TRIGRAM_MIN_SIMILARITY,
  34         )
  35     ]
  36 
  37     redirect_field = 'vendor_code'
  38 
  39 
  40 class Autocomplete(search_views.AutocompleteView):
  41 
  42     # ignore CPDBear
  43     search_entities = [
  44         search_engine.Search(
  45             name='category',
  46             qs=Category.objects.filter(page__is_active=True),
  47             fields=['name', 'id'],
  48             template_fields=['name', 'url'],
  49             min_similarity=settings.TRIGRAM_MIN_SIMILARITY,
  50         ),
  51         search_engine.Search(
  52             name='product',
  53             qs=Product.objects.active(),
  54             fields=['name', 'id', 'vendor_code'],
  55             template_fields=['name', 'price', 'url'],  # Ignore CPDBear
  56             min_similarity=settings.TRIGRAM_MIN_SIMILARITY,
  57         ),
  58         search_engine.Search(
  59             name='pages',
  60             qs=Page.objects.filter(is_active=True).exclude(type=Page.MODEL_TYPE),
  61             fields=['name'],
  62             template_fields=['name', 'url'],
  63             min_similarity=settings.TRIGRAM_MIN_SIMILARITY,
  64         )
  65     ]
  66 
  67     see_all_label = settings.SEARCH_SEE_ALL_LABEL
  68 
  69 
  70 class AdminAutocomplete(search_views.AdminAutocompleteView):
  71 
  72     # ignore CPDBear
  73     search_entities = [
  74         search_engine.Search(
  75             name='category',
  76             qs=Category.objects.filter(page__is_active=True),
  77             fields=['name'],
  78             min_similarity=settings.TRIGRAM_MIN_SIMILARITY,
  79         ),
  80         search_engine.Search(
  81             name='product',
  82             qs=Product.objects.active(),
  83             fields=['name'],
  84             min_similarity=settings.TRIGRAM_MIN_SIMILARITY,
  85         ),
  86         search_engine.Search(
  87             name='pages',
  88             qs=Page.objects.filter(is_active=True).exclude(type=Page.MODEL_TYPE),
  89             fields=['name'],
  90             min_similarity=settings.TRIGRAM_MIN_SIMILARITY,
  91         )
  92     ]
  93
  ```
  --- 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/shopelectro/views/search.py b/shopelectro/views/search.py
  --- a/shopelectro/views/search.py
  +++ b/shopelectro/views/search.py
  @@ -1,9 +1,7 @@
   from django.conf import settings
   
  -from search import views as search_views, search as search_engine
  -
   from pages.models import Page
  -
  +from search import views as search_views, search as search_engine
   from shopelectro.models import Category, Product
   
   
  @@ -21,14 +19,14 @@
           ),
           search_engine.Search(
               name='product',
  -            qs=Product.objects.active(),
  +            qs=Product.objects.active().exclude(category__isnull=True),
               fields=['name'],
               redirect_field='vendor_code',
               min_similarity=settings.TRIGRAM_MIN_SIMILARITY,
           ),
           search_engine.Search(
               name='page',  # Ignore CPDBear
  -            qs=Page.objects.filter(is_active=True).exclude(type=Page.MODEL_TYPE),
  +            qs=Page.objects.active().exclude(type=Page.MODEL_TYPE),
               fields=['name'],
               min_similarity=settings.TRIGRAM_MIN_SIMILARITY,
           )
  
verification_info: {"golden_diff": "diff --git a/shopelectro/views/search.py b/shopelectro/views/search.py\n--- a/shopelectro/views/search.py\n+++ b/shopelectro/views/search.py\n@@ -1,9 +1,7 @@\n from django.conf import settings\n \n-from search import views as search_views, search as search_engine\n-\n from pages.models import Page\n-\n+from search import views as search_views, search as search_engine\n from shopelectro.models import Category, Product\n \n \n@@ -21,14 +19,14 @@\n         ),\n         search_engine.Search(\n             name='product',\n-            qs=Product.objects.active(),\n+            qs=Product.objects.active().exclude(category__isnull=True),\n             fields=['name'],\n             redirect_field='vendor_code',\n             min_similarity=settings.TRIGRAM_MIN_SIMILARITY,\n         ),\n         search_engine.Search(\n             name='page',  # Ignore CPDBear\n-            qs=Page.objects.filter(is_active=True).exclude(type=Page.MODEL_TYPE),\n+            qs=Page.objects.active().exclude(type=Page.MODEL_TYPE),\n             fields=['name'],\n             min_similarity=settings.TRIGRAM_MIN_SIMILARITY,\n         )\n", "issue": "Search shows products with no category\nIt should not, of course\r\n\r\n![image](https://user-images.githubusercontent.com/3526796/67692684-9a9cb680-f9b1-11e9-8038-99534e063e03.png)\r\n\r\nSearch link: https://www.shopelectro.ru/search/?term=MK1215NC\r\nLink to the product: https://www.shopelectro.ru/catalog/products/7608/\r\n\n", "before_files": [{"content": "from django.conf import settings\n\nfrom search import views as search_views, search as search_engine\n\nfrom pages.models import Page\n\nfrom shopelectro.models import Category, Product\n\n\nclass Search(search_views.SearchView):\n    def get_redirect_search_entity(self):\n        return next(s for s in self.search_entities if s.name == 'product')\n\n    # ignore CPDBear\n    search_entities = [\n        search_engine.Search(\n            name='category',\n            qs=Category.objects.active(),\n            fields=['name'],  # Ignore CPDBear\n            min_similarity=settings.TRIGRAM_MIN_SIMILARITY,\n        ),\n        search_engine.Search(\n            name='product',\n            qs=Product.objects.active(),\n            fields=['name'],\n            redirect_field='vendor_code',\n            min_similarity=settings.TRIGRAM_MIN_SIMILARITY,\n        ),\n        search_engine.Search(\n            name='page',  # Ignore CPDBear\n            qs=Page.objects.filter(is_active=True).exclude(type=Page.MODEL_TYPE),\n            fields=['name'],\n            min_similarity=settings.TRIGRAM_MIN_SIMILARITY,\n        )\n    ]\n\n    redirect_field = 'vendor_code'\n\n\nclass Autocomplete(search_views.AutocompleteView):\n\n    # ignore CPDBear\n    search_entities = [\n        search_engine.Search(\n            name='category',\n            qs=Category.objects.filter(page__is_active=True),\n            fields=['name', 'id'],\n            template_fields=['name', 'url'],\n            min_similarity=settings.TRIGRAM_MIN_SIMILARITY,\n        ),\n        search_engine.Search(\n            name='product',\n            qs=Product.objects.active(),\n            fields=['name', 'id', 'vendor_code'],\n            template_fields=['name', 'price', 'url'],  # Ignore CPDBear\n            min_similarity=settings.TRIGRAM_MIN_SIMILARITY,\n        ),\n        search_engine.Search(\n            name='pages',\n            qs=Page.objects.filter(is_active=True).exclude(type=Page.MODEL_TYPE),\n            fields=['name'],\n            template_fields=['name', 'url'],\n            min_similarity=settings.TRIGRAM_MIN_SIMILARITY,\n        )\n    ]\n\n    see_all_label = settings.SEARCH_SEE_ALL_LABEL\n\n\nclass AdminAutocomplete(search_views.AdminAutocompleteView):\n\n    # ignore CPDBear\n    search_entities = [\n        search_engine.Search(\n            name='category',\n            qs=Category.objects.filter(page__is_active=True),\n            fields=['name'],\n            min_similarity=settings.TRIGRAM_MIN_SIMILARITY,\n        ),\n        search_engine.Search(\n            name='product',\n            qs=Product.objects.active(),\n            fields=['name'],\n            min_similarity=settings.TRIGRAM_MIN_SIMILARITY,\n        ),\n        search_engine.Search(\n            name='pages',\n            qs=Page.objects.filter(is_active=True).exclude(type=Page.MODEL_TYPE),\n            fields=['name'],\n            min_similarity=settings.TRIGRAM_MIN_SIMILARITY,\n        )\n    ]\n", "path": "shopelectro/views/search.py"}], "after_files": [{"content": "from django.conf import settings\n\nfrom pages.models import Page\nfrom search import views as search_views, search as search_engine\nfrom shopelectro.models import Category, Product\n\n\nclass Search(search_views.SearchView):\n    def get_redirect_search_entity(self):\n        return next(s for s in self.search_entities if s.name == 'product')\n\n    # ignore CPDBear\n    search_entities = [\n        search_engine.Search(\n            name='category',\n            qs=Category.objects.active(),\n            fields=['name'],  # Ignore CPDBear\n            min_similarity=settings.TRIGRAM_MIN_SIMILARITY,\n        ),\n        search_engine.Search(\n            name='product',\n            qs=Product.objects.active().exclude(category__isnull=True),\n            fields=['name'],\n            redirect_field='vendor_code',\n            min_similarity=settings.TRIGRAM_MIN_SIMILARITY,\n        ),\n        search_engine.Search(\n            name='page',  # Ignore CPDBear\n            qs=Page.objects.active().exclude(type=Page.MODEL_TYPE),\n            fields=['name'],\n            min_similarity=settings.TRIGRAM_MIN_SIMILARITY,\n        )\n    ]\n\n    redirect_field = 'vendor_code'\n\n\nclass Autocomplete(search_views.AutocompleteView):\n\n    # ignore CPDBear\n    search_entities = [\n        search_engine.Search(\n            name='category',\n            qs=Category.objects.filter(page__is_active=True),\n            fields=['name', 'id'],\n            template_fields=['name', 'url'],\n            min_similarity=settings.TRIGRAM_MIN_SIMILARITY,\n        ),\n        search_engine.Search(\n            name='product',\n            qs=Product.objects.active(),\n            fields=['name', 'id', 'vendor_code'],\n            template_fields=['name', 'price', 'url'],  # Ignore CPDBear\n            min_similarity=settings.TRIGRAM_MIN_SIMILARITY,\n        ),\n        search_engine.Search(\n            name='pages',\n            qs=Page.objects.filter(is_active=True).exclude(type=Page.MODEL_TYPE),\n            fields=['name'],\n            template_fields=['name', 'url'],\n            min_similarity=settings.TRIGRAM_MIN_SIMILARITY,\n        )\n    ]\n\n    see_all_label = settings.SEARCH_SEE_ALL_LABEL\n\n\nclass AdminAutocomplete(search_views.AdminAutocompleteView):\n\n    # ignore CPDBear\n    search_entities = [\n        search_engine.Search(\n            name='category',\n            qs=Category.objects.filter(page__is_active=True),\n            fields=['name'],\n            min_similarity=settings.TRIGRAM_MIN_SIMILARITY,\n        ),\n        search_engine.Search(\n            name='product',\n            qs=Product.objects.active(),\n            fields=['name'],\n            min_similarity=settings.TRIGRAM_MIN_SIMILARITY,\n        ),\n        search_engine.Search(\n            name='pages',\n            qs=Page.objects.filter(is_active=True).exclude(type=Page.MODEL_TYPE),\n            fields=['name'],\n            min_similarity=settings.TRIGRAM_MIN_SIMILARITY,\n        )\n    ]\n", "path": "shopelectro/views/search.py"}]}