diff options
author | Marco Pesenti Gritti <mpg@redhat.com> | 2007-10-04 16:15:19 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <mpg@redhat.com> | 2007-10-04 16:15:19 (GMT) |
commit | 23f5b3439e87aab2f6b0873942b3a07ddb05b3e8 (patch) | |
tree | 8c5263e724cd73667f4444e2829dea41f7dac065 | |
parent | ec0afe51537e9d00c8daa75f8dfbde4cc7f53690 (diff) |
Cache the id instead of fetching terms everytime from the db.
-rw-r--r-- | secore/datastructures.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/secore/datastructures.py b/secore/datastructures.py index 414625d..6006739 100644 --- a/secore/datastructures.py +++ b/secore/datastructures.py @@ -74,7 +74,7 @@ class ProcessedDocument(object): """ - __slots__ = '_doc', '_fieldmappings', '_data', + __slots__ = '_doc', '_fieldmappings', '_data', '_id' def __init__(self, fieldmappings, xapdoc=None): """Create a ProcessedDocument. @@ -91,6 +91,7 @@ class ProcessedDocument(object): self._doc = xapdoc self._fieldmappings = fieldmappings self._data = None + self._id = None def add_term(self, field, term, wdfinc=1, positions=None): """Add a term to the document. @@ -185,14 +186,16 @@ class ProcessedDocument(object): """) def _get_id(self): - tl = self._doc.termlist() - try: - term = tl.skip_to('Q').term - if len(term) == 0 or term[0] != 'Q': + if self._id is None: + tl = self._doc.termlist() + try: + term = tl.skip_to('Q').term + if len(term) == 0 or term[0] != 'Q': + return None + except StopIteration: return None - except StopIteration: - return None - return term[1:] + self._id = term[1:] + return self._id def _set_id(self, id): tl = self._doc.termlist() try: |