diff options
author | Jacob Mason <jacoblmason@gmail.com> | 2010-07-31 12:23:26 -0500 |
---|---|---|
committer | Jacob Mason <jacoblmason@gmail.com> | 2010-07-31 12:23:26 -0500 |
commit | a31f3b7e73f2050efab07a9ed143c72e774af452 (patch) | |
tree | f6749c033ab94d56285b000d7fe9e866a429aea7 | |
parent | a36175298e252c4a92902e5c35a5f52ec35edaab (diff) | |
download | sphinx-git-a31f3b7e73f2050efab07a9ed143c72e774af452.tar.gz |
More complete tests for search adapters.
-rw-r--r-- | sphinx/websupport/search/__init__.py | 2 | ||||
-rw-r--r-- | sphinx/websupport/search/whooshsearch.py | 2 | ||||
-rw-r--r-- | tests/test_websupport.py | 25 |
3 files changed, 27 insertions, 2 deletions
diff --git a/sphinx/websupport/search/__init__.py b/sphinx/websupport/search/__init__.py index d41b560c3..0e613222e 100644 --- a/sphinx/websupport/search/__init__.py +++ b/sphinx/websupport/search/__init__.py @@ -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 diff --git a/sphinx/websupport/search/whooshsearch.py b/sphinx/websupport/search/whooshsearch.py index 658b764dd..257393a6a 100644 --- a/sphinx/websupport/search/whooshsearch.py +++ b/sphinx/websupport/search/whooshsearch.py @@ -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), diff --git a/tests/test_websupport.py b/tests/test_websupport.py index 3d61e55c2..3f352cd6c 100644 --- a/tests/test_websupport.py +++ b/tests/test_websupport.py @@ -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. |