|
Revision 452, 1.3 kB
(checked in by athomas, 1 year ago)
|
pyndexter: All modules are now prefixed with _ to avoid import collisions. Updated unit tests.
|
- Property svn:eol-style set to
native
|
| Line | |
|---|
| 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 |
import SwishE |
|---|
| 10 |
from pyndexter import * |
|---|
| 11 |
|
|---|
| 12 |
""" |
|---|
| 13 |
Swish-e |
|---|
| 14 |
------- |
|---|
| 15 |
|
|---|
| 16 |
`Siwsh-e <http://swish-e.org/>`_ is a popular indexer, typically used for internal web sites. |
|---|
| 17 |
|
|---|
| 18 |
This is a search-only adapter, implemented via the SwishE_ Python module (which |
|---|
| 19 |
doesn't appear to support indexing?). Indexing still has to be performed by |
|---|
| 20 |
Swish-e itself. |
|---|
| 21 |
|
|---|
| 22 |
Usage |
|---|
| 23 |
~~~ |
|---|
| 24 |
|
|---|
| 25 |
:: |
|---|
| 26 |
|
|---|
| 27 |
swishe://<path> |
|---|
| 28 |
|
|---|
| 29 |
Installation |
|---|
| 30 |
~~~~~~~~~~ |
|---|
| 31 |
|
|---|
| 32 |
:: |
|---|
| 33 |
|
|---|
| 34 |
easy_install SwishE |
|---|
| 35 |
|
|---|
| 36 |
.. _SwishE: http://jibe.freeshell.org/bits/SwishE/ |
|---|
| 37 |
""" |
|---|
| 38 |
|
|---|
| 39 |
class SwishEIndexer(Indexer): |
|---|
| 40 |
def __init__(self, framework, path): |
|---|
| 41 |
Indexer.__init__(self, framework) |
|---|
| 42 |
self.path = path |
|---|
| 43 |
self.db = SwishE.new(path) |
|---|
| 44 |
|
|---|
| 45 |
def search(self, query): |
|---|
| 46 |
results = self.db.query(query.phrase) |
|---|
| 47 |
return SwishEResult(self, query, results) |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
class SwishEResult(Result): |
|---|
| 51 |
def __iter__(self): |
|---|
| 52 |
for row in self.context: |
|---|
| 53 |
uri = row.getproperty('swishdocpath') |
|---|
| 54 |
yield Hit(current=self.indexer.framework.fetch, |
|---|
| 55 |
indexed=self.indexer.fetch, uri=uri) |
|---|
| 56 |
|
|---|
| 57 |
def len(self): |
|---|
| 58 |
return self.context.hits() |
|---|
| 59 |
|
|---|
| 60 |
indexer_factory = PluginFactory(SwishEIndexer) |
|---|