'Prepare search index for tools loaded in toolbox.
Use `tool_cache` to determine which tools need indexing and which tools should be expired.'

def build_index(self, tool_cache, index_help=True):

    log.debug('Starting    to    build    toolbox    index.')
    self.index_count += 1
    execution_timer = ExecutionTimer()
    writer = self.index.writer()
    for tool_id in tool_cache._removed_tool_ids:
        writer.delete_by_term('id', tool_id)
    for tool_id in tool_cache._new_tool_ids:
        tool = tool_cache.get_tool_by_id(tool_id)
        if tool:
            add_doc_kwds = self._create_doc(tool_id=tool_id, tool=tool, index_help=index_help)
            writer.add_document(**add_doc_kwds)
    writer.commit()
    log.debug('Toolbox    index    finished    %s', execution_timer)
