Changeset 458

Show
Ignore:
Timestamp:
08/23/07 23:26:25 (11 months ago)
Author:
athomas
Message:

pyndexter: More cleanup for new branch.

Files:

Legend:

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

    r457 r458  
    1919~~~~~ 
    2020 
    21 :: 
     21The URI form the Hyperestraier adapter is:: 
    2222 
    23     hyperestraier://<host>[:port]/<path> 
     23    hyperestraier://<host>[:<port>]/node/<node> 
     24 
     25Here's an example:: 
     26 
     27    import pyndexter 
     28    indexer = pyndexter.connect('hyperestraier://localhost/node/test') 
     29    for hit in indexer.search('search term'): 
     30        print hit 
    2431 
    2532Installation 
     
    2734 
    2835Install your distributions Hyperestraier package (typically the package 
    29 ``hyperestraier``). 
     36``hyperestraier``). Start and configure ``estmaster``. 
    3037 
    3138Next, install the Python bindings: 
     
    3441 
    3542    easy_install hyperestraier 
     43 
     44 
    3645""" 
    3746 
     
    4554 
    4655 
    47 def connect(uri): 
     56def factory(uri): 
    4857    """Indexer plugin entry point.""" 
    4958    # Copy and munge uri 
     
    102111        cond.set_phrase(phrase) 
    103112        search = self.db.search(cond, 0) 
    104         return HyperestraierResult(self, query, search) 
     113        return HyperestraierResultSet(self, query, search) 
    105114 
    106115    # Internal methods 
     
    117126 
    118127 
    119 class HyperestraierResult(Result): 
     128class HyperestraierResultSet(ResultSet): 
    120129    def __iter__(self): 
    121130        if self.context: 
  • pyndexter/branches/simplification/pyndexter/__init__.py

    r457 r458  
    2424 
    2525__docformat__ = 'restructuredtext en' 
     26__author__ = 'Alec Thomas <alec@swapoff.org>' 
     27__license__ = 'BSD' 
     28 
    2629try: 
    27     import pkg_resources 
    28     __version__ = pkg_resources.get_distribution('pyndexter').version 
     30    __version__ = __import__('pkg_resources').get_distribution('pyndexter').version 
    2931except (ImportError, pkg_resources.DistributionNotFound): 
    3032    pass 
    31 __author__ = 'Alec Thomas <alec@swapoff.org>' 
    32  
    33  
    34 debug = False 
     33 
     34 
     35__all__ = ['Document', 'Query', 'Hit', 'Indexer', 'ResultSet', 
     36           'Error', 'DocumentNotFound', 'InvalidURI', 'InvalidIndexer', 
     37           'connect'] 
     38 
     39 
     40class Error(Exception): 
     41    """Base of all pyndexter exceptions.""" 
     42 
     43class DocumentNotFound(Error): 
     44    """Raised when a document could not be found, usually by the fetch() 
     45    methods.""" 
     46 
     47class InvalidURI(Error): 
     48    """The URI provided was invalid in that context.""" 
     49 
     50class InvalidIndexer(Error): 
     51    """The provided indexer URI was invalid.""" 
    3552 
    3653 
     
    161178 
    162179 
    163 class Result(object): 
     180class ResultSet(object): 
    164181    """Represents the result of a search. Each hit is returned as a Hit 
    165182    object.""" 
     
    297314    def _format_error(item, e): 
    298315        if isinstance(e, pkg_resources.DistributionNotFound): 
    299             return '"%s" not found' % e 
     316            return 'required package "%s" not found' % e 
    300317        elif isinstance(e, pkg_resources.VersionConflict): 
    301318            return 'version conflict "%s"' % e 
     
    307324            return 'error "%s"' % e 
    308325 
    309     if debug
     326    if _debug.enabled
    310327        for dist, e in errors.iteritems(): 
    311             print >> sys.stderr, _format_error(dist, e
     328            _debug(_format_error(dist, e)
    312329 
    313330    for entry in pkg_resources.working_set.iter_entry_points('pyndexter.indexers'): 
    314331        if entry.name == uri.scheme: 
    315332            try: 
    316                 if debug: 
    317                     print >> sys.stderr, 'Loading', entry 
     333                _debug('Loading %s' % entry) 
    318334                connect = entry.load(require=True) 
    319335                return IndexerWrapper(connect(uri)) 
    320336            except (ImportError, pkg_resources.DistributionNotFound, 
    321337                    pkg_resources.VersionConflict, pkg_resources.UnknownExtra), e: 
    322                 if debug: 
    323                     print >> sys.stderr, 'Failed to load %s:' % uri.scheme, _format_error(entry, e) 
    324                 raise InvalidIndexerURI('%s (%s)' % (str(uri), _format_error(entry, e))) 
     338                _debug('Failed to load %s: %s' % (uri.scheme, _format_error(entry, e))) 
     339                raise InvalidIndexer('%s (%s)' % (str(uri), _format_error(entry, e))) 
     340 
     341 
     342def _debug(message): 
     343    """Print a debug message.""" 
     344    if _debug.enabled: 
     345        print >> sys.stderr, message 
     346# Set this to true to enable debug tracing 
     347_debug.enabled = False 
     348 
     349 
  • pyndexter/branches/simplification/pyndexter/query.py

    r457 r458  
    99 
    1010import re 
    11 from pyndexter import errors 
    12  
    13  
    14 class InvalidQuery(errors.Error): 
     11from pyndexter import Error 
     12 
     13 
     14__all__ = ['Query'] 
     15 
     16 
     17class InvalidQuery(Error): 
    1518    """Invalid query string.""" 
    16  
    17  
    18 __all__ = ['Query'] 
    1919 
    2020 
  • pyndexter/branches/simplification/pyndexter/reduce.py

    r457 r458  
     1# -*- coding: utf-8 -*- 
     2# 
     3# Copyright (C) 2006 Alec Thomas <alec@swapoff.org> 
     4# 
     5# This software is licensed as described in the file COPYING, which 
     6# you should have received as part of this distribution. 
     7# 
     8 
     9 
    110import re 
     11 
     12 
     13__all__ = ['Reducer'] 
    214 
    315 
  • pyndexter/branches/simplification/setup.py

    r457 r458  
    3030    entry_points=""" 
    3131        [pyndexter.indexers] 
    32         hyperestraier = pyndexter.indexers._hyperestraier:connect [hyperestraier] 
     32        hyperestraier = pyndexter.indexers._hyperestraier:factory[hyperestraier] 
     33 
     34        [pyndexter.stemmers] 
     35        builtin = pyndexter.stemmers.builtin 
    3336        """ 
    3437    )