mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
More docs
This commit is contained in:
parent
dc2f45208f
commit
dc4000f4af
@ -1,47 +1,19 @@
|
|||||||
.. _searchadapters:
|
.. _storagebackends:
|
||||||
|
|
||||||
.. currentmodule:: sphinx.websupport.search
|
.. currentmodule:: sphinx.websupport.comments
|
||||||
|
|
||||||
Search Adapters
|
Storage Backends
|
||||||
===============
|
================
|
||||||
|
|
||||||
To create a custom search adapter you will need to subclass the
|
StorageBackend Methods
|
||||||
:class:`~BaseSearch` class. Then create an instance of the new class
|
~~~~~~~~~~~~~~~~~~~~~~
|
||||||
and pass that as the `search` keyword argument when you create the
|
|
||||||
:class:`~sphinx.websupport.WebSupport` object::
|
|
||||||
|
|
||||||
support = Websupport(srcdir=srcdir,
|
.. automethod:: sphinx.websupport.comments.StorageBackend.pre_build
|
||||||
outdir=outdir,
|
|
||||||
search=MySearch())
|
|
||||||
|
|
||||||
For more information about creating a custom search adapter, please see
|
.. automethod:: sphinx.websupport.comments.StorageBackend.add_node
|
||||||
the documentation of the :class:`BaseSearch` class below.
|
|
||||||
|
|
||||||
.. class:: BaseSearch
|
.. automethod:: sphinx.websupport.comments.StorageBackend.post_build
|
||||||
|
|
||||||
Defines an interface for search adapters.
|
.. automethod:: sphinx.websupport.comments.StorageBackend.add_comment
|
||||||
|
|
||||||
BaseSearch Methods
|
|
||||||
~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
The following methods are defined in the BaseSearch class. Some methods
|
|
||||||
do not need to be overridden, but some (
|
|
||||||
:meth:`~sphinx.websupport.search.BaseSearch.add_document` and
|
|
||||||
:meth:`~sphinx.websupport.search.BaseSearch.handle_query`) must be
|
|
||||||
overridden in your subclass. For a working example, look at the
|
|
||||||
built-in adapter for whoosh.
|
|
||||||
|
|
||||||
.. automethod:: sphinx.websupport.search.BaseSearch.init_indexing
|
|
||||||
|
|
||||||
.. automethod:: sphinx.websupport.search.BaseSearch.finish_indexing
|
|
||||||
|
|
||||||
.. automethod:: sphinx.websupport.search.BaseSearch.feed
|
|
||||||
|
|
||||||
.. automethod:: sphinx.websupport.search.BaseSearch.add_document
|
|
||||||
|
|
||||||
.. automethod:: sphinx.websupport.search.BaseSearch.query
|
|
||||||
|
|
||||||
.. automethod:: sphinx.websupport.search.BaseSearch.handle_query
|
|
||||||
|
|
||||||
.. automethod:: sphinx.websupport.search.BaseSearch.extract_context
|
|
||||||
|
|
||||||
|
.. automethod:: sphinx.websupport.comments.StorageBackend.get_comments
|
||||||
|
@ -1,17 +1,35 @@
|
|||||||
|
|
||||||
class StorageBackend(object):
|
class StorageBackend(object):
|
||||||
def pre_build(self):
|
def pre_build(self):
|
||||||
|
"""Called immediately before the build process begins. Use this
|
||||||
|
to prepare the StorageBackend for the addition of nodes.
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def add_node(self, document, line, source, treeloc):
|
def add_node(self, document, line, source, treeloc):
|
||||||
|
"""Add a node to the StorageBackend.
|
||||||
|
|
||||||
|
`document` is the name of the document the node belongs to.
|
||||||
|
|
||||||
|
`line` is the line in the source where the node begins.
|
||||||
|
|
||||||
|
`source` is the source files name.
|
||||||
|
|
||||||
|
`treeloc` is for future use.
|
||||||
|
"""
|
||||||
raise NotImplemented
|
raise NotImplemented
|
||||||
|
|
||||||
def post_build(self):
|
def post_build(self):
|
||||||
|
"""Called after a build has completed. Use this to finalize the
|
||||||
|
addition of nodes if needed.
|
||||||
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def add_comment(self, parent_id, text, displayed, username,
|
def add_comment(self, parent_id, text, displayed, username,
|
||||||
rating, time):
|
rating, time):
|
||||||
|
"""Called when a comment is being added."""
|
||||||
raise NotImplemented
|
raise NotImplemented
|
||||||
|
|
||||||
def get_comments(self, parent_id):
|
def get_comments(self, parent_id):
|
||||||
|
"""Called to retrieve all comments for a node."""
|
||||||
raise NotImplemented
|
raise NotImplemented
|
||||||
|
@ -33,6 +33,8 @@ class SQLAlchemyStorage(StorageBackend):
|
|||||||
|
|
||||||
session = Session()
|
session = Session()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
id = parent_id[1:]
|
id = parent_id[1:]
|
||||||
if parent_id[0] == 's':
|
if parent_id[0] == 's':
|
||||||
node = session.query(Node).filter(Node.id == id).first()
|
node = session.query(Node).filter(Node.id == id).first()
|
||||||
|
Loading…
Reference in New Issue
Block a user