Rev 19: More refactoring: make ComponentIndex responsible for accessing its own data files. in http://people.ubuntu.com/~robertc/baz2.0/plugins/search/trunk
Robert Collins
robertc at robertcollins.net
Wed Jun 11 05:07:07 BST 2008
At http://people.ubuntu.com/~robertc/baz2.0/plugins/search/trunk
------------------------------------------------------------
revno: 19
revision-id: robertc at robertcollins.net-20080611040706-n0orfqtmjah3k6d4
parent: robertc at robertcollins.net-20080611035938-hw90ua35seca1x1y
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Wed 2008-06-11 14:07:06 +1000
message:
More refactoring: make ComponentIndex responsible for accessing its own data files.
modified:
index.py index.py-20080608055509-hnimeek7q8tctkqf-2
=== modified file 'index.py'
--- a/index.py 2008-06-11 03:59:38 +0000
+++ b/index.py 2008-06-11 04:07:06 +0000
@@ -243,7 +243,8 @@
self._upload_transport.rename(element,
'../indices/' + element)
self._transport.put_file('names', new_names.finish())
- index = builder.get_index()
+ index = ComponentIndex(index_name, index_value,
+ self._indices_transport)
self._orig_names[index_name] = (index_value, index)
finally:
self._lock.unlock()
@@ -288,14 +289,7 @@
for name in added_names:
# TODO: byte length of the indices here.
value = new_names[name][0]
- lengths = value.split(' ')
- rev_index = GraphIndex(self._indices_transport, name + '.rix',
- int(lengths[0]))
- term_index = GraphIndex(self._indices_transport, name + '.tix',
- int(lengths[1]))
- doc_index = GraphIndex(self._indices_transport, name + '.dix',
- int(lengths[2]))
- component = ComponentIndex(rev_index, term_index, doc_index)
+ component = ComponentIndex(name, value, self._indices_transport)
self._add_index_to_memory(name, value, component)
for name in deleted_names:
self._remove_component_from_memory(name)
@@ -401,21 +395,28 @@
class ComponentIndex(object):
"""A single component in the aggregate search index.
- This has a revision index listing the indexed revisions, a term index
- with the indexed terms and there posting lists (as a list of document ids),
- and finally a document id index which maps document ids to document keys.
+ Components are a collection of files (later, they will become single packs).
+ The relevant files are:
+ - a GraphIndex listing indexed revisions (name.rix)
+ - a GraphIndex mapping terms to posting lists (name.tix)
+ - a GraphIndex mapping document ids to document keys (name.dix)
+ - A posting-list per term (name.N) listing the document ids the term
+ indexes.
"""
- def __init__(self, revision_index, term_index, document_index):
+ def __init__(self, name, value, transport):
"""Create a ComponentIndex.
- :param revision_index: The revision index for this component.
- :param term_index: The term index for this component.
- :param document_index: The document index for this component.
+ :param name: The name of the index.
+ :param value: The value string from the names list for this component.
"""
- self.revision_index = revision_index
+ lengths = value.split(' ')
+ rev_index = GraphIndex(transport, name + '.rix', int(lengths[0]))
+ term_index = GraphIndex(transport, name + '.tix', int(lengths[1]))
+ doc_index = GraphIndex(transport, name + '.dix', int(lengths[2]))
+ self.revision_index = rev_index
self.term_index = term_index
- self.document_index = document_index
+ self.document_index = doc_index
class ComponentIndexBuilder(object):
@@ -460,11 +461,6 @@
"""List a revision as having been indexed by this index."""
self.revision_index.add_node((revision_id,), '', ())
- def get_index(self):
- """Returns the created index."""
- return ComponentIndex(self.revision_index, self.term_index,
- self.document_index)
-
def upload_index(self, upload_transport):
"""Upload the index in preparation for insertion.
More information about the bazaar-commits
mailing list