prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Version to 0.17.0
  See discussion in #1166.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `mkdocs/contrib/legacy_search/__init__.py`
  Content:
  ```
  1 # coding: utf-8
  2 
  3 from __future__ import absolute_import, unicode_literals
  4 
  5 import os
  6 import logging
  7 from mkdocs import utils
  8 from mkdocs.plugins import BasePlugin
  9 from mkdocs.contrib.legacy_search.search_index import SearchIndex
  10 
  11 
  12 log = logging.getLogger(__name__)
  13 
  14 
  15 class SearchPlugin(BasePlugin):
  16     """ Add a search feature to MkDocs. """
  17 
  18     def on_config(self, config, **kwargs):
  19         "Add plugin templates and scripts to config."
  20         path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates')
  21         config['theme'].dirs.append(path)
  22         config['theme'].static_templates.add('search.html')
  23         config['extra_javascript'].append('search/require.js')
  24         config['extra_javascript'].append('search/search.js')
  25         return config
  26 
  27     def on_pre_build(self, config, **kwargs):
  28         "Create search index instance for later use."
  29         self.search_index = SearchIndex()
  30 
  31     def on_page_context(self, context, **kwargs):
  32         "Add page to search index."
  33         self.search_index.add_entry_from_context(context['page'])
  34 
  35     def on_post_build(self, config, **kwargs):
  36         "Build search index."
  37         search_index = self.search_index.generate_search_index()
  38         json_output_path = os.path.join(config['site_dir'], 'search', 'search_index.json')
  39         utils.write_file(search_index.encode('utf-8'), json_output_path)
  40
  ```
  --- 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/mkdocs/contrib/legacy_search/__init__.py b/mkdocs/contrib/legacy_search/__init__.py
  --- a/mkdocs/contrib/legacy_search/__init__.py
  +++ b/mkdocs/contrib/legacy_search/__init__.py
  @@ -17,11 +17,13 @@
   
       def on_config(self, config, **kwargs):
           "Add plugin templates and scripts to config."
  -        path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates')
  -        config['theme'].dirs.append(path)
  -        config['theme'].static_templates.add('search.html')
  -        config['extra_javascript'].append('search/require.js')
  -        config['extra_javascript'].append('search/search.js')
  +        if 'include_search_page' in config['theme'] and config['theme']['include_search_page']:
  +            config['theme'].static_templates.add('search.html')
  +        if not ('search_index_only' in config['theme'] and config['theme']['search_index_only']):
  +            path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates')
  +            config['theme'].dirs.append(path)
  +            config['extra_javascript'].append('search/require.js')
  +            config['extra_javascript'].append('search/search.js')
           return config
   
       def on_pre_build(self, config, **kwargs):
  
verification_info: {"golden_diff": "diff --git a/mkdocs/contrib/legacy_search/__init__.py b/mkdocs/contrib/legacy_search/__init__.py\n--- a/mkdocs/contrib/legacy_search/__init__.py\n+++ b/mkdocs/contrib/legacy_search/__init__.py\n@@ -17,11 +17,13 @@\n \n     def on_config(self, config, **kwargs):\n         \"Add plugin templates and scripts to config.\"\n-        path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates')\n-        config['theme'].dirs.append(path)\n-        config['theme'].static_templates.add('search.html')\n-        config['extra_javascript'].append('search/require.js')\n-        config['extra_javascript'].append('search/search.js')\n+        if 'include_search_page' in config['theme'] and config['theme']['include_search_page']:\n+            config['theme'].static_templates.add('search.html')\n+        if not ('search_index_only' in config['theme'] and config['theme']['search_index_only']):\n+            path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates')\n+            config['theme'].dirs.append(path)\n+            config['extra_javascript'].append('search/require.js')\n+            config['extra_javascript'].append('search/search.js')\n         return config\n \n     def on_pre_build(self, config, **kwargs):\n", "issue": "Version to 0.17.0\nSee discussion in #1166.\n", "before_files": [{"content": "# coding: utf-8\n\nfrom __future__ import absolute_import, unicode_literals\n\nimport os\nimport logging\nfrom mkdocs import utils\nfrom mkdocs.plugins import BasePlugin\nfrom mkdocs.contrib.legacy_search.search_index import SearchIndex\n\n\nlog = logging.getLogger(__name__)\n\n\nclass SearchPlugin(BasePlugin):\n    \"\"\" Add a search feature to MkDocs. \"\"\"\n\n    def on_config(self, config, **kwargs):\n        \"Add plugin templates and scripts to config.\"\n        path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates')\n        config['theme'].dirs.append(path)\n        config['theme'].static_templates.add('search.html')\n        config['extra_javascript'].append('search/require.js')\n        config['extra_javascript'].append('search/search.js')\n        return config\n\n    def on_pre_build(self, config, **kwargs):\n        \"Create search index instance for later use.\"\n        self.search_index = SearchIndex()\n\n    def on_page_context(self, context, **kwargs):\n        \"Add page to search index.\"\n        self.search_index.add_entry_from_context(context['page'])\n\n    def on_post_build(self, config, **kwargs):\n        \"Build search index.\"\n        search_index = self.search_index.generate_search_index()\n        json_output_path = os.path.join(config['site_dir'], 'search', 'search_index.json')\n        utils.write_file(search_index.encode('utf-8'), json_output_path)\n", "path": "mkdocs/contrib/legacy_search/__init__.py"}], "after_files": [{"content": "# coding: utf-8\n\nfrom __future__ import absolute_import, unicode_literals\n\nimport os\nimport logging\nfrom mkdocs import utils\nfrom mkdocs.plugins import BasePlugin\nfrom mkdocs.contrib.legacy_search.search_index import SearchIndex\n\n\nlog = logging.getLogger(__name__)\n\n\nclass SearchPlugin(BasePlugin):\n    \"\"\" Add a search feature to MkDocs. \"\"\"\n\n    def on_config(self, config, **kwargs):\n        \"Add plugin templates and scripts to config.\"\n        if 'include_search_page' in config['theme'] and config['theme']['include_search_page']:\n            config['theme'].static_templates.add('search.html')\n        if not ('search_index_only' in config['theme'] and config['theme']['search_index_only']):\n            path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates')\n            config['theme'].dirs.append(path)\n            config['extra_javascript'].append('search/require.js')\n            config['extra_javascript'].append('search/search.js')\n        return config\n\n    def on_pre_build(self, config, **kwargs):\n        \"Create search index instance for later use.\"\n        self.search_index = SearchIndex()\n\n    def on_page_context(self, context, **kwargs):\n        \"Add page to search index.\"\n        self.search_index.add_entry_from_context(context['page'])\n\n    def on_post_build(self, config, **kwargs):\n        \"Build search index.\"\n        search_index = self.search_index.generate_search_index()\n        json_output_path = os.path.join(config['site_dir'], 'search', 'search_index.json')\n        utils.write_file(search_index.encode('utf-8'), json_output_path)\n", "path": "mkdocs/contrib/legacy_search/__init__.py"}]}