diff options
-rw-r--r-- | lesana/collection.py | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/lesana/collection.py b/lesana/collection.py index 2a80072..92ffcbb 100644 --- a/lesana/collection.py +++ b/lesana/collection.py @@ -242,12 +242,15 @@ class Collection(object): offset += pagesize def _match_to_entry(self, match): - fname = match.document.get_value(0).decode('utf-8') + return self._doc_to_entry(match.document) + + def _doc_to_entry(self, doc): + fname = doc.get_value(0).decode('utf-8') if self.safe: - data = ruamel.yaml.safe_load(match.document.get_data()) + data = ruamel.yaml.safe_load(doc.get_data()) else: data = ruamel.yaml.load( - match.document.get_data(), + doc.get_data(), ruamel.yaml.RoundTripLoader ) entry = Entry( @@ -259,14 +262,10 @@ class Collection(object): def entry_from_uid(self, uid): cache = self._get_cache() - query = xapian.Query('Q'+uid) - enquire = xapian.Enquire(cache) - enquire.set_query(query) - # FIXME: if more items are returned, something is wrong? - try: - return self._match_to_entry(enquire.get_mset(0, 1)[0]) - except IndexError: - return None + postlist = cache.postlist('Q'+uid) + for pitem in postlist: + return self._doc_to_entry(cache.get_document(pitem.docid)) + return None def remove_entries(self, uids): cache = xapian.WritableDatabase( |