Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
Implement new IQueryIndex interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
hannosch committed Aug 27, 2016
1 parent 8589095 commit 5f0c928
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -4,6 +4,8 @@ Changelog
4.0 (unreleased)
----------------

- Implement new `IQueryIndex` interface.

- Require at least Zope and ZCatalog 4.0.

3.0 (2016-07-18)
Expand Down
27 changes: 15 additions & 12 deletions src/Products/ZCTextIndex/ZCTextIndex.py
Expand Up @@ -31,10 +31,19 @@
from Persistence import Persistent
from zope.interface import implements

from Products.PluginIndexes.common.util import parseIndexRequest
from Products.PluginIndexes.common import safe_callable
from Products.PluginIndexes.interfaces import IPluggableIndex

# BBB New ZCatalog 4.0 release
try:
from Products.ZCatalog.query import IndexQuery
from Products.PluginIndexes.interfaces import IQueryIndex
except ImportError:
from zope.interface import Interface
from Products.PluginIndexes.common.util import \
parseIndexRequest as IndexQuery
IQueryIndex = Interface

from Products.ZCTextIndex.Lexicon import Lexicon
from Products.ZCTextIndex.NBest import NBest
from Products.ZCTextIndex.QueryParser import QueryParser
Expand All @@ -58,7 +67,7 @@ class ZCTextIndex(Persistent, Implicit, SimpleItem):

"""Persistent text index.
"""
implements(IZCTextIndex, IPluggableIndex)
implements(IZCTextIndex, IQueryIndex, IPluggableIndex)

meta_type = 'ZCTextIndex'
query_options = ('query',)
Expand Down Expand Up @@ -191,24 +200,18 @@ def unindex_object(self, docid):
self.index.unindex_doc(docid)

def _apply_index(self, request):
"""Apply query specified by request, a mapping containing the query.
Returns two object on success, the resultSet containing the
matching record numbers and a tuple containing the names of
the fields used
Returns None if request is not valid for this index.
"""
record = parseIndexRequest(request, self.id, self.query_options)
record = IndexQuery(request, self.id, self.query_options)
if record.keys is None:
return None
return (self.query_index(record), (self.id, ))

def query_index(self, record, resultset=None):
query_str = ' '.join(record.keys)
if not query_str:
return None
tree = QueryParser(self.getLexicon()).parseQuery(query_str)
results = tree.executeQuery(self.index)
return (results, (self.id, ))
return results

def getEntryForObject(self, documentId, default=None):
"""Return the list of words indexed for documentId"""
Expand Down

0 comments on commit 5f0c928

Please sign in to comment.