Rev 51: Remove duplicate code. in http://people.ubuntu.com/~robertc/baz2.0/plugins/search/trunk

Robert Collins robertc at robertcollins.net
Fri Aug 1 02:42:31 BST 2008


At http://people.ubuntu.com/~robertc/baz2.0/plugins/search/trunk

------------------------------------------------------------
revno: 51
revision-id: robertc at robertcollins.net-20080801014230-m2h2dqwz4pel2aq2
parent: robertc at robertcollins.net-20080801013531-9mzodxpbhh9bucm2
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Fri 2008-08-01 11:42:30 +1000
message:
  Remove duplicate code.
modified:
  index.py                       index.py-20080608055509-hnimeek7q8tctkqf-2
=== modified file 'index.py'
--- a/index.py	2008-08-01 01:35:31 +0000
+++ b/index.py	2008-08-01 01:42:30 +0000
@@ -535,29 +535,15 @@
             # Now we whittle down the nodes we need - still going in sorted
             # order. (possibly doing concurrent reduction would be better).
             while common_doc_keys and term_info:
-                _, term_id, posting_start, posting_length = term_info.pop(0)
-                posting_stop = posting_start + posting_length
-                post_name = "term_list." + term_id
-                filemap = {post_name:(posting_start, posting_stop)}
-                view = FileView(self._indices_transport,
-                    component.name + '.pack', filemap)
-                post_index = GraphIndex(view, post_name, posting_length)
-                common_doc_keys = set([node[1] for node in
-                    post_index.iter_entries(common_doc_keys)])
+                common_doc_keys = self._select_doc_keys(common_doc_keys,
+                    term_info.pop(0), component)
             if common_doc_keys:
                 # exclude from largest-first, which should give us less
                 # exclusion steps.
                 exclude_info.sort(reverse=True)
                 while common_doc_keys and exclude_info:
-                    _, term_id, posting_start, posting_length = exclude_info.pop(0)
-                    posting_stop = posting_start + posting_length
-                    post_name = "term_list." + term_id
-                    filemap = {post_name:(posting_start, posting_stop)}
-                    view = FileView(self._indices_transport,
-                        component.name + '.pack', filemap)
-                    post_index = GraphIndex(view, post_name, posting_length)
-                    common_doc_keys.difference_update(set([node[1] for node in
-                        post_index.iter_entries(common_doc_keys)]))
+                    common_doc_keys.difference_update(self._select_doc_keys(
+                        common_doc_keys, exclude_info.pop(0), component))
             yield component, termlist, common_doc_keys
 
     def search(self, termlist):
@@ -588,6 +574,23 @@
                 else:
                     raise Exception("unknown doc type %r" % (doc_key,))
 
+    def _select_doc_keys(self, key_filter, term_info, component):
+        """Select some document keys from a term.
+
+        :param key_filter: An iterable of document keys to constrain the
+            search.
+        :param term_info: The index metadata about the terms posting list.
+        :param component: The component being searched within.
+        """
+        _, term_id, posting_start, posting_length = term_info
+        posting_stop = posting_start + posting_length
+        post_name = "term_list." + term_id
+        filemap = {post_name:(posting_start, posting_stop)}
+        view = FileView(self._indices_transport,
+            component.name + '.pack', filemap)
+        post_index = GraphIndex(view, post_name, posting_length)
+        return set([node[1] for node in post_index.iter_entries(key_filter)])
+
     def suggest(self, termlist):
         """Generate suggestions for extending a search.
 




More information about the bazaar-commits mailing list