More complete tests for search adapters.

This commit is contained in:
Jacob Mason 2010-07-31 12:23:26 -05:00
parent a36175298e
commit a31f3b7e73
3 changed files with 27 additions and 2 deletions

View File

@ -83,7 +83,7 @@ class BaseSearch(object):
query `q`. This should return an iterable containing tuples of the
following format::
(<path>, <title> <context>)
(<path>, <title>, <context>)
`path` and `title` are the same values that were passed to
:meth:`add_document`, and `context` should be a short text snippet

View File

@ -40,6 +40,8 @@ class WhooshSearch(BaseSearch):
def finish_indexing(self):
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):
self.index_writer.add_document(path=unicode(pagename),

View File

@ -78,9 +78,32 @@ def search_adapter_helper(adapter):
settings.update({'srcdir': test_root,
'search': adapter})
support = WebSupport(**settings)
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():
# Don't run tests if xapian is not installed.