mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Updates related to new feed() signature
This commit is contained in:
@@ -719,7 +719,11 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
# only index pages with title
|
# only index pages with title
|
||||||
if self.indexer is not None and title:
|
if self.indexer is not None and title:
|
||||||
filename = self.env.doc2path(pagename, base=None)
|
filename = self.env.doc2path(pagename, base=None)
|
||||||
self.indexer.feed(pagename, filename, title, doctree)
|
try:
|
||||||
|
self.indexer.feed(pagename, filename, title, doctree)
|
||||||
|
except TypeError:
|
||||||
|
# fallback for old search-adapters
|
||||||
|
self.indexer.feed(pagename, title, doctree)
|
||||||
|
|
||||||
def _get_local_toctree(self, docname, collapse=True, **kwds):
|
def _get_local_toctree(self, docname, collapse=True, **kwds):
|
||||||
if 'includehidden' not in kwds:
|
if 'includehidden' not in kwds:
|
||||||
|
|||||||
@@ -34,19 +34,20 @@ class BaseSearch(object):
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def feed(self, pagename, title, doctree):
|
def feed(self, pagename, filename, title, doctree):
|
||||||
"""Called by the builder to add a doctree to the index. Converts the
|
"""Called by the builder to add a doctree to the index. Converts the
|
||||||
`doctree` to text and passes it to :meth:`add_document`. You probably
|
`doctree` to text and passes it to :meth:`add_document`. You probably
|
||||||
won't want to override this unless you need access to the `doctree`.
|
won't want to override this unless you need access to the `doctree`.
|
||||||
Override :meth:`add_document` instead.
|
Override :meth:`add_document` instead.
|
||||||
|
|
||||||
:param pagename: the name of the page to be indexed
|
:param pagename: the name of the page to be indexed
|
||||||
|
:param filename: the name of the original source file
|
||||||
:param title: the title of the page to be indexed
|
:param title: the title of the page to be indexed
|
||||||
:param doctree: is the docutils doctree representation of the page
|
:param doctree: is the docutils doctree representation of the page
|
||||||
"""
|
"""
|
||||||
self.add_document(pagename, title, doctree.astext())
|
self.add_document(pagename, filename, title, doctree.astext())
|
||||||
|
|
||||||
def add_document(self, pagename, title, text):
|
def add_document(self, pagename, filename, title, text):
|
||||||
"""Called by :meth:`feed` to add a document to the search index.
|
"""Called by :meth:`feed` to add a document to the search index.
|
||||||
This method should should do everything necessary to add a single
|
This method should should do everything necessary to add a single
|
||||||
document to the search index.
|
document to the search index.
|
||||||
@@ -59,6 +60,7 @@ class BaseSearch(object):
|
|||||||
query.
|
query.
|
||||||
|
|
||||||
:param pagename: the name of the page being indexed
|
:param pagename: the name of the page being indexed
|
||||||
|
:param filename: the name of the original source file
|
||||||
:param title: the page's title
|
:param title: the page's title
|
||||||
:param text: the full text of the page
|
:param text: the full text of the page
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class NullSearch(BaseSearch):
|
|||||||
"""A search adapter that does nothing. Used when no search adapter
|
"""A search adapter that does nothing. Used when no search adapter
|
||||||
is specified.
|
is specified.
|
||||||
"""
|
"""
|
||||||
def feed(self, pagename, title, doctree):
|
def feed(self, pagename, filename, title, doctree):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def query(self, q):
|
def query(self, q):
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class WhooshSearch(BaseSearch):
|
|||||||
def finish_indexing(self):
|
def finish_indexing(self):
|
||||||
self.index_writer.commit()
|
self.index_writer.commit()
|
||||||
|
|
||||||
def add_document(self, pagename, title, text):
|
def add_document(self, pagename, filename, title, text):
|
||||||
self.index_writer.add_document(path=text_type(pagename),
|
self.index_writer.add_document(path=text_type(pagename),
|
||||||
title=title,
|
title=title,
|
||||||
text=text)
|
text=text)
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ def search_adapter_helper(adapter):
|
|||||||
|
|
||||||
# Make sure documents are properly updated by the search adapter.
|
# Make sure documents are properly updated by the search adapter.
|
||||||
s.init_indexing(changed=['markup'])
|
s.init_indexing(changed=['markup'])
|
||||||
s.add_document(u'markup', u'title', u'SomeLongRandomWord')
|
s.add_document(u'markup', u'filename', u'title', u'SomeLongRandomWord')
|
||||||
s.finish_indexing()
|
s.finish_indexing()
|
||||||
# Now a search for "Epigraph" should return zero results.
|
# Now a search for "Epigraph" should return zero results.
|
||||||
results = s.query(u'Epigraph')
|
results = s.query(u'Epigraph')
|
||||||
|
|||||||
Reference in New Issue
Block a user