Changeset 458
- Timestamp:
- 08/23/07 23:26:25 (11 months ago)
- Files:
-
- pyndexter/branches/simplification/pyndexter/errors.py (deleted)
- pyndexter/branches/simplification/pyndexter/indexers/_hyperestraier.py (modified) (6 diffs)
- pyndexter/branches/simplification/pyndexter/__init__.py (modified) (4 diffs)
- pyndexter/branches/simplification/pyndexter/query.py (modified) (1 diff)
- pyndexter/branches/simplification/pyndexter/reduce.py (modified) (1 diff)
- pyndexter/branches/simplification/setup.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
pyndexter/branches/simplification/pyndexter/indexers/_hyperestraier.py
r457 r458 19 19 ~~~~~ 20 20 21 ::21 The URI form the Hyperestraier adapter is:: 22 22 23 hyperestraier://<host>[:port]/<path> 23 hyperestraier://<host>[:<port>]/node/<node> 24 25 Here'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 24 31 25 32 Installation … … 27 34 28 35 Install your distributions Hyperestraier package (typically the package 29 ``hyperestraier``). 36 ``hyperestraier``). Start and configure ``estmaster``. 30 37 31 38 Next, install the Python bindings: … … 34 41 35 42 easy_install hyperestraier 43 44 36 45 """ 37 46 … … 45 54 46 55 47 def connect(uri):56 def factory(uri): 48 57 """Indexer plugin entry point.""" 49 58 # Copy and munge uri … … 102 111 cond.set_phrase(phrase) 103 112 search = self.db.search(cond, 0) 104 return HyperestraierResult (self, query, search)113 return HyperestraierResultSet(self, query, search) 105 114 106 115 # Internal methods … … 117 126 118 127 119 class HyperestraierResult (Result):128 class HyperestraierResultSet(ResultSet): 120 129 def __iter__(self): 121 130 if self.context: pyndexter/branches/simplification/pyndexter/__init__.py
r457 r458 24 24 25 25 __docformat__ = 'restructuredtext en' 26 __author__ = 'Alec Thomas <alec@swapoff.org>' 27 __license__ = 'BSD' 28 26 29 try: 27 import pkg_resources 28 __version__ = pkg_resources.get_distribution('pyndexter').version 30 __version__ = __import__('pkg_resources').get_distribution('pyndexter').version 29 31 except (ImportError, pkg_resources.DistributionNotFound): 30 32 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 40 class Error(Exception): 41 """Base of all pyndexter exceptions.""" 42 43 class DocumentNotFound(Error): 44 """Raised when a document could not be found, usually by the fetch() 45 methods.""" 46 47 class InvalidURI(Error): 48 """The URI provided was invalid in that context.""" 49 50 class InvalidIndexer(Error): 51 """The provided indexer URI was invalid.""" 35 52 36 53 … … 161 178 162 179 163 class Result (object):180 class ResultSet(object): 164 181 """Represents the result of a search. Each hit is returned as a Hit 165 182 object.""" … … 297 314 def _format_error(item, e): 298 315 if isinstance(e, pkg_resources.DistributionNotFound): 299 return ' "%s" not found' % e316 return 'required package "%s" not found' % e 300 317 elif isinstance(e, pkg_resources.VersionConflict): 301 318 return 'version conflict "%s"' % e … … 307 324 return 'error "%s"' % e 308 325 309 if debug:326 if _debug.enabled: 310 327 for dist, e in errors.iteritems(): 311 print >> sys.stderr, _format_error(dist, e)328 _debug(_format_error(dist, e)) 312 329 313 330 for entry in pkg_resources.working_set.iter_entry_points('pyndexter.indexers'): 314 331 if entry.name == uri.scheme: 315 332 try: 316 if debug: 317 print >> sys.stderr, 'Loading', entry 333 _debug('Loading %s' % entry) 318 334 connect = entry.load(require=True) 319 335 return IndexerWrapper(connect(uri)) 320 336 except (ImportError, pkg_resources.DistributionNotFound, 321 337 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 342 def _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 9 9 10 10 import re 11 from pyndexter import errors 12 13 14 class InvalidQuery(errors.Error): 11 from pyndexter import Error 12 13 14 __all__ = ['Query'] 15 16 17 class InvalidQuery(Error): 15 18 """Invalid query string.""" 16 17 18 __all__ = ['Query']19 19 20 20 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 1 10 import re 11 12 13 __all__ = ['Reducer'] 2 14 3 15 pyndexter/branches/simplification/setup.py
r457 r458 30 30 entry_points=""" 31 31 [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 33 36 """ 34 37 )
