Changeset 466

Show
Ignore:
Timestamp:
27/11/07 01:09:26 (2 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.

Location:
pyndexter/branches/simplification
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • pyndexter/branches/simplification/pyndexter/__init__.py

    r465 r466  
    5959    Defines three useful attributes: 
    6060 
    61     ``uri`` 
    62         The unique URI for this document. 
     61    ``key`` 
     62        The unique key for this document. 
    6363 
    6464    ``quality`` 
     
    6666    """ 
    6767 
    68     def __init__(self, uri, quality=1.0, attributes=None, text=None, 
     68    def __init__(self, key, quality=1.0, attributes=None, text=None, 
    6969                 texts=None): 
    70         self.uri = URI(uri) 
     70        self.key = key 
    7171        self.quality = quality 
    7272        self._attributes = {} 
     
    121121 
    122122    def __hash__(self): 
    123         return hash(self.uri) 
     123        return hash(self.key) 
    124124 
    125125 
     
    142142        raise NotImplementedError 
    143143 
    144     def discard(self, uri): 
     144    def discard(self, key): 
    145145        """ Discard a document. """ 
    146146        raise NotImplementedError 
     
    156156        raise NotImplementedError 
    157157 
    158     def fetch(self, uri): 
     158    def fetch(self, key): 
    159159        """Attempt to fetch indexer representation of the document. 
    160160 
     
    162162        and 1.0, representing the quality of the document in comparison to the 
    163163        original.""" 
    164         raise DocumentNotFound(uri) 
     164        raise DocumentNotFound(key) 
    165165 
    166166    def replace(self, document): 
    167167        """Replace a document in the index. Default is to `discard()` and 
    168168        `index()`.""" 
    169         self.discard(document.uri) 
     169        self.discard(document.key) 
    170170        self.index(document) 
    171171 
     
    227227        A Document object corresponding to the Hit. 
    228228 
    229     ``uri`` 
    230         The URI of the hit. 
     229    ``key`` 
     230        The key of the hit. 
    231231    """ 
    232232 
    233     def __init__(self, uri, document=None, score=0.0, attributes=None): 
    234         self.uri = uri 
     233    def __init__(self, key, document=None, score=0.0, attributes=None): 
     234        self.key = key 
    235235        if callable(document): 
    236             self.get_document = lambda: document(uri) 
     236            self.get_document = lambda: document(key) 
    237237        else: 
    238238            self._document = document 
     
    268268 
    269269    def __hash__(self): 
    270         return hash(self.uri) 
     270        return hash(self.key) 
    271271 
    272272 
     
    289289        return iter(self.indexer) 
    290290 
    291     def discard(self, uri): 
    292         if isinstance(uri, Document): 
    293             uri = uri.uri 
    294         return self.indexer.discard(uri) 
     291    def discard(self, key): 
     292        if isinstance(key, Document): 
     293            key = key.key 
     294        return self.indexer.discard(key) 
    295295 
    296296    def search(self, query): 
     
    299299        return self.indexer.search(query) 
    300300 
    301     def fetch(self, uri): 
    302         return self.indexer.fetch(URI(uri)) 
     301    def fetch(self, key): 
     302        return self.indexer.fetch(key) 
    303303 
    304304 
  • 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)) 
  • pyndexter/branches/simplification/setup.py

    r465 r466  
    2828    ], 
    2929    extras_require={ 
    30         'hyperestraier': ['hyperestraier>=0.9.3'], 
     30        'hyperestraier': ['hyperestraier>=0.10.4'], 
    3131        'snowball': ['PyStemmer>=1.0.1'], 
    3232        # TODO put more indexer requirements in here