Show
Ignore:
Timestamp:
27/11/07 01:09:26 (3 years ago)
Author:
athomas
Message:

pyndexter: Documents are now referenced by a user-defined key rather than a
URI. It was a needless restriction. Fixed hyperestraier unit tests up a bit.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pyndexter/branches/simplification/pyndexter/indexers/_hyperestraier.py

    r465 r466  
    7878 
    7979    def index(self, document): 
    80         uri = unicode(document.uri) 
     80        key = unicode(document.key) 
    8181        hdoc = hyperestraier.Document() 
    8282        for k, v in document.iteritems(): 
    8383            hdoc.add_attr(u'@' + k, v) 
    84         hdoc.add_attr(u'@uri', uri) 
     84        hdoc.add_attr(u'@uri', key) 
    8585        for line in document.texts: 
    8686            hdoc.add_text(line) 
    8787        if not self.db.put_doc(hdoc): 
    88             raise errors.IndexerError('Failed to index %s' % document.uri) 
     88            raise errors.IndexerError('Failed to index %s' % document.key) 
    8989 
    90     def discard(self, uri): 
    91         uri = unicode(uri) 
    92         if not self.db.out_doc_by_uri(uri): 
    93             raise errors.DocumentNotFound(uri) 
     90    def discard(self, key): 
     91        key = unicode(key) 
     92        try: 
     93            self.db.out_doc_by_uri(key) 
     94        except hyperestraier.HyperestraierError, e: 
     95            raise errors.DocumentNotFound(key) 
    9496 
    95     def fetch(self, uri): 
    96         uri = unicode(uri) 
    97         doc = self.db.get_doc_by_uri(uri) 
     97    def fetch(self, key): 
     98        key = unicode(key) 
     99        doc = self.db.get_doc_by_uri(key) 
    98100        if not doc: 
    99             raise errors.DocumentNotFound(uri) 
     101            raise errors.DocumentNotFound(key) 
    100102        attributes = self._translate_attributes(doc) 
    101         return Document(uri, texts=doc.dtexts, quality=0.99, 
     103        return Document(key, texts=doc.dtexts, quality=0.99, 
    102104                        attributes=attributes) 
    103105 
     
    152154    # Internal methods 
    153155    def _translate(self, doc): 
    154         return Hit(uri=doc.uri, document=self.indexer.fetch, 
     156        return Hit(key=doc.uri, document=self.indexer.fetch, 
    155157                   attributes=self.indexer._translate_attributes(doc))