class_docstr: Search index is a collection of pages and sections (heading
  tags and their following content are sections).
docstr: Python to json conversion.
docstr_tok: ["Python","to","json","conversion","."]
code: def generate_search_index(self) -> str:
      """Python to json conversion."""
      page_dicts = {"docs": self._entries, "config": self.config}
      data = json.dumps(
          page_dicts, sort_keys=True, separators=(",", ":"), default=str
      )
  
      if self.config["prebuild_index"] in (True, "node"):
          try:
              script_path = os.path.join(
                  os.path.dirname(os.path.abspath(__file__)),
                  "prebuild-index.js",
              )
              p = subprocess.Popen(
                  ["node", script_path],
                  stdin=subprocess.PIPE,
                  stdout=subprocess.PIPE,
                  stderr=subprocess.PIPE,
                  encoding="utf-8",
              )
              idx, err = p.communicate(data)
              if not err:
                  page_dicts["index"] = json.loads(idx)
                  data = json.dumps(
                      page_dicts, sort_keys=True, separators=(",", ":")
                  )
                  log.debug(
                      "Pre-built search index created successfully."
                  )
              else:
                  log.warning(
                      f"Failed to pre-build search index. Error: {err}"
                  )
          except (OSError, ValueError) as e:
              log.warning(
                  f"Failed to pre-build search index. Error: {e}"
              )
      elif self.config["prebuild_index"] == "python":
          if haslunrpy:
              lunr_idx = lunr(
                  ref="location",
                  fields=("title", "text"),
                  documents=self._entries,
                  languages=self.config["lang"],
              )
              page_dicts["index"] = lunr_idx.serialize()
              data = json.dumps(
                  page_dicts, sort_keys=True, separators=(",", ":")
              )
          else:
              log.warning(
                  "Failed to pre-build search index. The 'python' method was specified; "
                  "however, the 'lunr.py' library does not appear to be installed. Try "
                  "installing it with 'pip install lunr'. If you are using any language "
                  "other than English you will also need to install 'lunr[languages]'."
              )
  
      return data
  
imports: from __future__ import annotations
  import json
  import logging
  import os
  import re
  import subprocess
  from html.parser import HTMLParser
  from typing import TYPE_CHECKING
label_desc: Use image node_id 6 for calling the SearchIndex obj's underlying member method code with example usage: obj.generate_search_index() and returns: data