Rev 10: * Added ``Index.search`` to perform simple set based searches for terms. in http://people.ubuntu.com/~robertc/baz2.0/plugins/search/trunk
Robert Collins
robertc at robertcollins.net
Sun Jun 8 23:21:29 BST 2008
At http://people.ubuntu.com/~robertc/baz2.0/plugins/search/trunk
------------------------------------------------------------
revno: 10
revision-id: robertc at robertcollins.net-20080608221948-66c28r366alynula
parent: robertc at robertcollins.net-20080608143716-0eq1vm6b2zj8mx2t
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Mon 2008-06-09 08:19:48 +1000
message:
* Added ``Index.search`` to perform simple set based searches for terms.
(Robert Collins)
modified:
NEWS news-20080608052041-z5bahsl8kwl0uf4x-2
commands.py commands.py-20080608052041-z5bahsl8kwl0uf4x-5
errors.py errors.py-20080608055509-hnimeek7q8tctkqf-1
index.py index.py-20080608055509-hnimeek7q8tctkqf-2
tests/test_blackbox.py test_blackbox.py-20080608052041-z5bahsl8kwl0uf4x-9
tests/test_errors.py test_errors.py-20080608055509-hnimeek7q8tctkqf-3
tests/test_index.py test_index.py-20080608055509-hnimeek7q8tctkqf-4
=== modified file 'NEWS'
--- a/NEWS 2008-06-08 14:37:16 +0000
+++ b/NEWS 2008-06-08 22:19:48 +0000
@@ -41,6 +41,9 @@
* Added ``Index.indexed_revisions`` to report on indexed revisions.
(Robert Collins)
+ * Added ``Index.search`` to perform simple set based searches for terms.
+ (Robert Collins)
+
* New modules: ``commands``, ``errors``, ``index``. These contain the
console ui, exceptions, and the search index core respectively.
(Robert Collins)
=== modified file 'commands.py'
--- a/commands.py 2008-06-08 06:42:53 +0000
+++ b/commands.py 2008-06-08 22:19:48 +0000
@@ -18,6 +18,7 @@
"""The command console user interface for bzr search."""
import bzrlib.commands
+from bzrlib.plugins.search import errors
from bzrlib.plugins.search import index as _mod_index
from bzrlib.transport import get_transport
@@ -50,3 +51,8 @@
def run(self, query_list=[]):
trans = get_transport('.')
index = _mod_index.open_index_url(trans.base)
+ # XXX: Have a query translator etc.
+ for result in index.search(query_list):
+ pass
+ else:
+ raise errors.NoMatch(query_list)
=== modified file 'errors.py'
--- a/errors.py 2008-06-08 11:41:20 +0000
+++ b/errors.py 2008-06-08 22:19:48 +0000
@@ -38,3 +38,15 @@
def __init__(self, url):
self.url = url
+
+
+class NoMatch(BzrError):
+ """Raised by the ui when no searches are found.
+
+ The library functions are generators and raising exceptions there is ugly.
+ """
+
+ _fmt = "No matches were found for the search %(search)s."
+
+ def __init__(self, search):
+ self.search = search
=== modified file 'index.py'
--- a/index.py 2008-06-08 14:37:16 +0000
+++ b/index.py 2008-06-08 22:19:48 +0000
@@ -255,6 +255,15 @@
self._current_names = current_names
self._orig_names = new_names
+ def search(self, termlist):
+ """Trivial set-based search of the index.
+
+ :param termlist: A list of terms.
+ :return: An iterator of SearchResults for documents indexed by all
+ terms in the termlist.
+ """
+ return []
+
def _terms_for_revs(self, repository, revision_ids):
"""Generate the posting list for the revision texts of revision_ids.
=== modified file 'tests/test_blackbox.py'
--- a/tests/test_blackbox.py 2008-06-08 14:37:16 +0000
+++ b/tests/test_blackbox.py 2008-06-08 22:19:48 +0000
@@ -17,7 +17,7 @@
"""Tests for the commands supplied by search."""
-from bzrlib.plugins.search.index import open_index_url
+from bzrlib.plugins.search.index import init_index, open_index_url
from bzrlib.tests import TestCaseWithTransport
@@ -29,6 +29,11 @@
def test_no_index_error(self):
self.run_bzr_error(['No search index'], ['search', 'robert'])
+ def test_no_hits_error(self):
+ branch = self.make_branch('.')
+ init_index(branch)
+ self.run_bzr_error(['No matches'], ['search', 'robert'])
+
class TestIndex(TestCaseWithTransport):
=== modified file 'tests/test_errors.py'
--- a/tests/test_errors.py 2008-06-08 11:41:20 +0000
+++ b/tests/test_errors.py 2008-06-08 22:19:48 +0000
@@ -34,3 +34,9 @@
self.assertEqualDiff(
"No search index present for 'a url'. Please see 'bzr help index'.",
str(error))
+
+ def test_no_match(self):
+ error = errors.NoMatch(['a', 'search', 'here'])
+ self.assertEqualDiff(
+ "No matches were found for the search ['a', 'search', 'here'].",
+ str(error))
=== modified file 'tests/test_index.py'
--- a/tests/test_index.py 2008-06-08 14:37:16 +0000
+++ b/tests/test_index.py 2008-06-08 22:19:48 +0000
@@ -108,3 +108,11 @@
for term, posting_list in rev_index.all_terms():
all_terms[term] = set(posting_list)
self.assertEqual(expected_terms, all_terms)
+
+
+class TestSearching(TestCaseWithTransport):
+
+ def test_search_no_hits(self):
+ tree = self.make_branch_and_tree('')
+ rev_index = index.init_index(tree.branch)
+ self.assertEqual([], list(rev_index.search(['missing_term'])))
More information about the bazaar-commits
mailing list