mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
More complete tests for search adapters.
This commit is contained in:
parent
a36175298e
commit
a31f3b7e73
@ -83,7 +83,7 @@ class BaseSearch(object):
|
|||||||
query `q`. This should return an iterable containing tuples of the
|
query `q`. This should return an iterable containing tuples of the
|
||||||
following format::
|
following format::
|
||||||
|
|
||||||
(<path>, <title> <context>)
|
(<path>, <title>, <context>)
|
||||||
|
|
||||||
`path` and `title` are the same values that were passed to
|
`path` and `title` are the same values that were passed to
|
||||||
:meth:`add_document`, and `context` should be a short text snippet
|
:meth:`add_document`, and `context` should be a short text snippet
|
||||||
|
@ -40,6 +40,8 @@ class WhooshSearch(BaseSearch):
|
|||||||
|
|
||||||
def finish_indexing(self):
|
def finish_indexing(self):
|
||||||
self.index_writer.commit()
|
self.index_writer.commit()
|
||||||
|
# Create a new searcher so changes can be seen immediately
|
||||||
|
self.searcher = self.index.searcher()
|
||||||
|
|
||||||
def add_document(self, pagename, title, text):
|
def add_document(self, pagename, title, text):
|
||||||
self.index_writer.add_document(path=unicode(pagename),
|
self.index_writer.add_document(path=unicode(pagename),
|
||||||
|
@ -78,9 +78,32 @@ def search_adapter_helper(adapter):
|
|||||||
settings.update({'srcdir': test_root,
|
settings.update({'srcdir': test_root,
|
||||||
'search': adapter})
|
'search': adapter})
|
||||||
support = WebSupport(**settings)
|
support = WebSupport(**settings)
|
||||||
|
|
||||||
support.build()
|
support.build()
|
||||||
|
|
||||||
|
s = support.search
|
||||||
|
|
||||||
|
# Test the adapters query method. A search for "Epigraph" should return
|
||||||
|
# one result.
|
||||||
|
results = s.query(u'Epigraph')
|
||||||
|
assert len(results) == 1, \
|
||||||
|
'%s search adapter returned %s search result(s), should have been 1'\
|
||||||
|
% (adapter, len(results))
|
||||||
|
|
||||||
|
# Make sure documents are properly updated by the search adapter.
|
||||||
|
s.init_indexing(changed=['markup'])
|
||||||
|
s.add_document(u'markup', u'title', u'SomeLongRandomWord')
|
||||||
|
s.finish_indexing()
|
||||||
|
# Now a search for "Epigraph" should return zero results.
|
||||||
|
results = s.query(u'Epigraph')
|
||||||
|
assert len(results) == 0, \
|
||||||
|
'%s search adapter returned %s search result(s), should have been 0'\
|
||||||
|
% (adapter, len(results))
|
||||||
|
# A search for "SomeLongRandomWord" should return one result.
|
||||||
|
results = s.query(u'SomeLongRandomWord')
|
||||||
|
assert len(results) == 1, \
|
||||||
|
'%s search adapter returned %s search result(s), should have been 1'\
|
||||||
|
% (adapter, len(results))
|
||||||
|
|
||||||
|
|
||||||
def test_xapian():
|
def test_xapian():
|
||||||
# Don't run tests if xapian is not installed.
|
# Don't run tests if xapian is not installed.
|
||||||
|
Loading…
Reference in New Issue
Block a user