[Zope-CVS] CVS: Products/ZCTextIndex - ZCTextIndex.py:1.1.2.1
Jeremy Hylton
jeremy@zope.com
Tue, 30 Apr 2002 20:28:39 -0400
Update of /cvs-repository/Products/ZCTextIndex
In directory cvs.zope.org:/tmp/cvs-serv20856
Added Files:
Tag: TextIndexDS9-branch
ZCTextIndex.py
Log Message:
Hook together the checked in components to create a simple text index.
=== Added File Products/ZCTextIndex/ZCTextIndex.py ===
from Products.ZCTextIndex.Index import Index
from Products.ZCTextIndex.QueryEngine import QueryEngine
from Products.ZCTextIndex.QueryParser import QueryParser
from Products.ZCTextIndex.tests.test_index import SimpleLexicon
from Products.PluginIndexes.common.PluggableIndex \
import PluggableIndexInterface
import ZODB
from Persistence import Persistent
class ZCTextIndex(Persistent):
__implements__ = PluggableIndexInterface
def __init__(self, doc_attr="text"):
self.engine = QueryEngine()
self.index = Index(SimpleLexicon(), doc_attr)
self.parser = QueryParser()
def index_object(self, docid, obj, thresh=None):
self.index.index_object(docid, obj, thresh)
self._p_changed = 1 # XXX
def unindex_object(self, docid):
self.index.unindex_object(docid)
self._p_changed = 1 # XXX
def _apply_index(self, req):
pass # XXX
def query(self, query):
# returns a mapping from docids to scores
tree = self.parser.parseQuery(query)
return self.engine.executeQuery(self.index, tree)