Commit d90bf5bb authored by 's avatar

- some minor plugin indexes cleanup

parent 09be733c
...@@ -8,6 +8,8 @@ Zope Changes ...@@ -8,6 +8,8 @@ Zope Changes
Restructuring Restructuring
- Indexes: Removed unused parameters from '_apply_index' methods.
- Fixed Collector #2190: Calls to - Fixed Collector #2190: Calls to
zope.security.management.checkPermission aren't rerouted to zope.security.management.checkPermission aren't rerouted to
Zope 2's security policy. Zope 2's security policy.
...@@ -78,6 +80,8 @@ Zope Changes ...@@ -78,6 +80,8 @@ Zope Changes
Bugs Fixed Bugs Fixed
- PluginIndexes: Fixed 'parseIndexRequest' for false values.
- Collector #2269: fixed broken ZPT FTP support - Collector #2269: fixed broken ZPT FTP support
- Collector #2261: Acquisition when creating objects via Webdav. - Collector #2261: Acquisition when creating objects via Webdav.
......
...@@ -19,7 +19,6 @@ import time ...@@ -19,7 +19,6 @@ import time
from logging import getLogger from logging import getLogger
from datetime import date, datetime from datetime import date, datetime
from datetime import tzinfo, timedelta from datetime import tzinfo, timedelta
from types import StringType, FloatType, IntType
import BTrees.Length import BTrees.Length
from BTrees.IIBTree import IISet, union, intersection, multiunion from BTrees.IIBTree import IISet, union, intersection, multiunion
...@@ -90,7 +89,7 @@ class DateIndex(UnIndex, PropertyManager): ...@@ -90,7 +89,7 @@ class DateIndex(UnIndex, PropertyManager):
implements(IDateIndex) implements(IDateIndex)
meta_type = 'DateIndex' meta_type = 'DateIndex'
query_options = ['query', 'range'] query_options = ('query', 'range')
index_naive_time_as_local = True # False means index as UTC index_naive_time_as_local = True # False means index as UTC
_properties=({'id':'index_naive_time_as_local', _properties=({'id':'index_naive_time_as_local',
...@@ -157,14 +156,14 @@ class DateIndex(UnIndex, PropertyManager): ...@@ -157,14 +156,14 @@ class DateIndex(UnIndex, PropertyManager):
return returnStatus return returnStatus
def _apply_index( self, request, cid='', type=type ): def _apply_index(self, request):
"""Apply the index to query parameters given in the argument """Apply the index to query parameters given in the argument
Normalize the 'query' arguments into integer values at minute Normalize the 'query' arguments into integer values at minute
precision before querying. precision before querying.
""" """
record = parseIndexRequest( request, self.id, self.query_options ) record = parseIndexRequest(request, self.id, self.query_options)
if record.keys == None: if record.keys is None:
return None return None
keys = map( self._convert, record.keys ) keys = map( self._convert, record.keys )
...@@ -215,22 +214,17 @@ class DateIndex(UnIndex, PropertyManager): ...@@ -215,22 +214,17 @@ class DateIndex(UnIndex, PropertyManager):
else: else:
setlist = index.values(lo) setlist = index.values(lo)
#for k, set in setlist:
#if type(set) is IntType:
#set = IISet((set,))
#r = set_func(r, set)
# XXX: Use multiunion!
r = multiunion(setlist) r = multiunion(setlist)
else: # not a range search else: # not a range search
for key in keys: for key in keys:
set = index.get(key, None) set = index.get(key, None)
if set is not None: if set is not None:
if type(set) is IntType: if isinstance(set, int):
set = IISet((set,)) set = IISet((set,))
r = set_func(r, set) r = set_func(r, set)
if type(r) is IntType: if isinstance(r, int):
r = IISet((r,)) r = IISet((r,))
if r is None: if r is None:
...@@ -242,20 +236,20 @@ class DateIndex(UnIndex, PropertyManager): ...@@ -242,20 +236,20 @@ class DateIndex(UnIndex, PropertyManager):
"""Convert Date/Time value to our internal representation""" """Convert Date/Time value to our internal representation"""
# XXX: Code patched 20/May/2003 by Kiran Jonnalagadda to # XXX: Code patched 20/May/2003 by Kiran Jonnalagadda to
# convert dates to UTC first. # convert dates to UTC first.
if isinstance( value, DateTime ): if isinstance(value, DateTime):
t_tup = value.toZone('UTC').parts() t_tup = value.toZone('UTC').parts()
elif type( value ) in (FloatType, IntType): elif isinstance(value, (float, int)):
t_tup = time.gmtime( value ) t_tup = time.gmtime( value )
elif type( value ) is StringType and value: elif isinstance(value, str) and value:
t_obj = DateTime( value ).toZone('UTC') t_obj = DateTime( value ).toZone('UTC')
t_tup = t_obj.parts() t_tup = t_obj.parts()
elif type( value ) is date: elif isinstance(value, datetime):
t_tup = value.timetuple()
elif type( value ) is datetime:
if self.index_naive_time_as_local and value.tzinfo is None: if self.index_naive_time_as_local and value.tzinfo is None:
value = value.replace(tzinfo=Local) value = value.replace(tzinfo=Local)
# else if tzinfo is None, naive time interpreted as UTC # else if tzinfo is None, naive time interpreted as UTC
t_tup = value.utctimetuple() t_tup = value.utctimetuple()
elif isinstance(value, date):
t_tup = value.timetuple()
else: else:
return default return default
......
...@@ -63,6 +63,7 @@ class DateRangeIndex(UnIndex): ...@@ -63,6 +63,7 @@ class DateRangeIndex(UnIndex):
security = ClassSecurityInfo() security = ClassSecurityInfo()
meta_type = "DateRangeIndex" meta_type = "DateRangeIndex"
query_options = ('query',)
manage_options= ( { 'label' : 'Properties' manage_options= ( { 'label' : 'Properties'
, 'action' : 'manage_indexProperties' , 'action' : 'manage_indexProperties'
...@@ -70,8 +71,6 @@ class DateRangeIndex(UnIndex): ...@@ -70,8 +71,6 @@ class DateRangeIndex(UnIndex):
, ,
) )
query_options = ['query']
since_field = until_field = None since_field = until_field = None
def __init__(self, id, since_field=None, until_field=None, def __init__(self, id, since_field=None, until_field=None,
...@@ -213,7 +212,6 @@ class DateRangeIndex(UnIndex): ...@@ -213,7 +212,6 @@ class DateRangeIndex(UnIndex):
t2 = self._until_only t2 = self._until_only
result = [] result = []
IntType = type( 0 )
if not withLengths: if not withLengths:
...@@ -224,7 +222,7 @@ class DateRangeIndex(UnIndex): ...@@ -224,7 +222,7 @@ class DateRangeIndex(UnIndex):
for key in t1.keys(): for key in t1.keys():
set = t1[ key ] set = t1[ key ]
if type( set ) is IntType: if isinstance(set, int):
length = 1 length = 1
else: else:
length = len( set ) length = len( set )
...@@ -232,7 +230,7 @@ class DateRangeIndex(UnIndex): ...@@ -232,7 +230,7 @@ class DateRangeIndex(UnIndex):
for key in t2.keys(): for key in t2.keys():
set = t2[ key ] set = t2[ key ]
if type( set ) is IntType: if isinstance(set, int):
length = 1 length = 1
else: else:
length = len( set ) length = len( set )
...@@ -240,12 +238,12 @@ class DateRangeIndex(UnIndex): ...@@ -240,12 +238,12 @@ class DateRangeIndex(UnIndex):
return tuple( result ) return tuple( result )
def _apply_index( self, request, cid='' ): def _apply_index(self, request):
""" """
Apply the index to query parameters given in 'request', which Apply the index to query parameters given in 'request', which
should be a mapping object. should be a mapping object.
If the request does not contain the needed parametrs, then If the request does not contain the needed parameters, then
return None. return None.
If the request contains a parameter with the name of the If the request contains a parameter with the name of the
...@@ -257,7 +255,7 @@ class DateRangeIndex(UnIndex): ...@@ -257,7 +255,7 @@ class DateRangeIndex(UnIndex):
second object is a tuple containing the names of all data fields second object is a tuple containing the names of all data fields
used. used.
""" """
record = parseIndexRequest( request, self.getId() ) record = parseIndexRequest(request, self.id, self.query_options)
if record.keys is None: if record.keys is None:
return None return None
...@@ -396,10 +394,10 @@ class DateRangeIndex(UnIndex): ...@@ -396,10 +394,10 @@ class DateRangeIndex(UnIndex):
def _convertDateTime( self, value ): def _convertDateTime( self, value ):
if value is None: if value is None:
return value return value
if type( value ) == type( '' ): if isinstance(value, str):
dt_obj = DateTime( value ) dt_obj = DateTime( value )
value = dt_obj.millis() / 1000 / 60 # flatten to minutes value = dt_obj.millis() / 1000 / 60 # flatten to minutes
if isinstance( value, DateTime ): if isinstance(value, DateTime):
value = value.millis() / 1000 / 60 # flatten to minutes value = value.millis() / 1000 / 60 # flatten to minutes
result = int( value ) result = int( value )
if isinstance(result, long): # this won't work (Python 2.3) if isinstance(result, long): # this won't work (Python 2.3)
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
$Id$ $Id$
""" """
from types import StringType, ListType, TupleType
from logging import getLogger from logging import getLogger
from Globals import Persistent, DTMLFile from Globals import Persistent, DTMLFile
...@@ -56,6 +55,7 @@ class PathIndex(Persistent, SimpleItem): ...@@ -56,6 +55,7 @@ class PathIndex(Persistent, SimpleItem):
implements(IPathIndex, IUniqueValueIndex) implements(IPathIndex, IUniqueValueIndex)
meta_type="PathIndex" meta_type="PathIndex"
query_options = ('query', 'level', 'operator')
manage_options= ( manage_options= (
{'label': 'Settings', {'label': 'Settings',
...@@ -63,8 +63,6 @@ class PathIndex(Persistent, SimpleItem): ...@@ -63,8 +63,6 @@ class PathIndex(Persistent, SimpleItem):
'help': ('PathIndex','PathIndex_Settings.stx')}, 'help': ('PathIndex','PathIndex_Settings.stx')},
) )
query_options = ("query", "level", "operator")
def __init__(self,id,caller=None): def __init__(self,id,caller=None):
self.id = id self.id = id
self.operators = ('or','and') self.operators = ('or','and')
...@@ -108,7 +106,7 @@ class PathIndex(Persistent, SimpleItem): ...@@ -108,7 +106,7 @@ class PathIndex(Persistent, SimpleItem):
else: else:
path = f path = f
if not isinstance(path, (StringType, TupleType)): if not isinstance(path, (str, tuple)):
raise TypeError('path value must be string or tuple of strings') raise TypeError('path value must be string or tuple of strings')
else: else:
try: try:
...@@ -116,7 +114,7 @@ class PathIndex(Persistent, SimpleItem): ...@@ -116,7 +114,7 @@ class PathIndex(Persistent, SimpleItem):
except AttributeError: except AttributeError:
return 0 return 0
if isinstance(path, (ListType, TupleType)): if isinstance(path, (list, tuple)):
path = '/'+ '/'.join(path[1:]) path = '/'+ '/'.join(path[1:])
comps = filter(None, path.split('/')) comps = filter(None, path.split('/'))
...@@ -165,8 +163,7 @@ class PathIndex(Persistent, SimpleItem): ...@@ -165,8 +163,7 @@ class PathIndex(Persistent, SimpleItem):
level >= 0 starts searching at the given level level >= 0 starts searching at the given level
level < 0 not implemented yet level < 0 not implemented yet
""" """
if isinstance(path, str):
if isinstance(path, StringType):
level = default_level level = default_level
else: else:
level = int(path[1]) level = int(path[1])
...@@ -207,17 +204,15 @@ class PathIndex(Persistent, SimpleItem): ...@@ -207,17 +204,15 @@ class PathIndex(Persistent, SimpleItem):
def __len__(self): def __len__(self):
return self._length() return self._length()
def _apply_index(self, request, cid=''): def _apply_index(self, request):
""" hook for (Z)Catalog """ hook for (Z)Catalog
'request' -- mapping type (usually {"path": "..." } 'request' -- mapping type (usually {"path": "..." }
additionaly a parameter "path_level" might be passed additionaly a parameter "path_level" might be passed
to specify the level (see search()) to specify the level (see search())
'cid' -- ???
""" """
record = parseIndexRequest(request, self.id, self.query_options)
record = parseIndexRequest(request,self.id,self.query_options) if record.keys is None:
if record.keys==None: return None return None
level = record.get("level",0) level = record.get("level",0)
operator = record.get('operator',self.useOperator).lower() operator = record.get('operator',self.useOperator).lower()
......
...@@ -82,6 +82,7 @@ class TextIndex(Persistent, Implicit, SimpleItem): ...@@ -82,6 +82,7 @@ class TextIndex(Persistent, Implicit, SimpleItem):
implements(ITextIndex, IPluggableIndex) implements(ITextIndex, IPluggableIndex)
meta_type='TextIndex' meta_type='TextIndex'
query_options = ('query', 'operator')
manage_options= ( manage_options= (
{'label': 'Settings', {'label': 'Settings',
...@@ -89,8 +90,6 @@ class TextIndex(Persistent, Implicit, SimpleItem): ...@@ -89,8 +90,6 @@ class TextIndex(Persistent, Implicit, SimpleItem):
'help': ('TextIndex','TextIndex_Settings.stx')}, 'help': ('TextIndex','TextIndex_Settings.stx')},
) )
query_options = ["query","operator"]
def __init__(self, id, ignore_ex=None, call_methods=None, lexicon=None, def __init__(self, id, ignore_ex=None, call_methods=None, lexicon=None,
caller=None, extra=None): caller=None, extra=None):
"""Create an index """Create an index
...@@ -440,7 +439,7 @@ class TextIndex(Persistent, Implicit, SimpleItem): ...@@ -440,7 +439,7 @@ class TextIndex(Persistent, Implicit, SimpleItem):
return r return r
def _apply_index(self, request, cid=''): def _apply_index(self, request):
""" Apply the index to query parameters given in the argument, """ Apply the index to query parameters given in the argument,
request request
...@@ -454,9 +453,9 @@ class TextIndex(Persistent, Implicit, SimpleItem): ...@@ -454,9 +453,9 @@ class TextIndex(Persistent, Implicit, SimpleItem):
records. The second object is a tuple containing the names of records. The second object is a tuple containing the names of
all data fields used. all data fields used.
""" """
record = parseIndexRequest(request, self.id, self.query_options)
record = parseIndexRequest(request,self.id,self.query_options) if record.keys is None:
if record.keys==None: return None return None
# Changed for 2.4 # Changed for 2.4
# We use the default operator that can me managed via the ZMI # We use the default operator that can me managed via the ZMI
......
...@@ -46,7 +46,7 @@ class TopicIndex(Persistent, SimpleItem): ...@@ -46,7 +46,7 @@ class TopicIndex(Persistent, SimpleItem):
implements(ITopicIndex, IPluggableIndex) implements(ITopicIndex, IPluggableIndex)
meta_type="TopicIndex" meta_type="TopicIndex"
query_options = ('query','operator') query_options = ('query', 'operator')
manage_options= ( manage_options= (
{'label': 'FilteredSets', {'label': 'FilteredSets',
...@@ -91,14 +91,13 @@ class TopicIndex(Persistent, SimpleItem): ...@@ -91,14 +91,13 @@ class TopicIndex(Persistent, SimpleItem):
if self.filteredSets.has_key(filter_id): if self.filteredSets.has_key(filter_id):
return self.filteredSets[filter_id].getIds() return self.filteredSets[filter_id].getIds()
def _apply_index(self, request, cid=''): def _apply_index(self, request):
""" hook for (Z)Catalog """ hook for (Z)Catalog
'request' -- mapping type (usually {"topic": "..." } 'request' -- mapping type (usually {"topic": "..." }
'cid' -- ???
""" """
record = parseIndexRequest(request, self.id, self.query_options)
record = parseIndexRequest(request,self.id,self.query_options) if record.keys is None:
if record.keys is None: return None return None
operator = record.get('operator', self.defaultOperator).lower() operator = record.get('operator', self.defaultOperator).lower()
if operator == 'or': set_func = union if operator == 'or': set_func = union
......
...@@ -304,7 +304,7 @@ class UnIndex(SimpleItem): ...@@ -304,7 +304,7 @@ class UnIndex(SimpleItem):
LOG.debug('Attempt to unindex nonexistent document' LOG.debug('Attempt to unindex nonexistent document'
' with id %s' % documentId,exc_info=True) ' with id %s' % documentId,exc_info=True)
def _apply_index(self, request, cid='', type=type): def _apply_index(self, request):
"""Apply the index to query parameters given in the request arg. """Apply the index to query parameters given in the request arg.
The request argument should be a mapping object. The request argument should be a mapping object.
...@@ -344,7 +344,8 @@ class UnIndex(SimpleItem): ...@@ -344,7 +344,8 @@ class UnIndex(SimpleItem):
up in a tuple ala: request = {'id':('',)} up in a tuple ala: request = {'id':('',)}
""" """
record = parseIndexRequest(request, self.id, self.query_options) record = parseIndexRequest(request, self.id, self.query_options)
if record.keys==None: return None if record.keys is None:
return None
index = self._index index = self._index
r = None r = None
......
##############################################################################
#
# Copyright (c) 2007 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Unit tests for util module.
$Id$
"""
import unittest
from ZPublisher.HTTPRequest import record as Record
class parseIndexRequestTests(unittest.TestCase):
def _getTargetClass(self):
from Products.PluginIndexes.common.util import parseIndexRequest
return parseIndexRequest
def _makeOne(self, *args, **kw):
return self._getTargetClass()(*args, **kw)
def test_get_record(self):
record = Record()
record.query = 'foo'
record.level = 0
record.operator = 'and'
request = {'path': record}
parser = self._makeOne(request, 'path', ('query','level','operator'))
self.assertEqual(parser.get('keys'), ['foo'])
self.assertEqual(parser.get('level'), 0)
self.assertEqual(parser.get('operator'), 'and')
def test_get_dict(self):
request = {'path': {'query': 'foo', 'level': 0, 'operator': 'and'}}
parser = self._makeOne(request, 'path', ('query','level','operator'))
self.assertEqual(parser.get('keys'), ['foo'])
self.assertEqual(parser.get('level'), 0)
self.assertEqual(parser.get('operator'), 'and')
def test_get_string(self):
request = {'path': 'foo', 'path_level': 0, 'path_operator': 'and'}
parser = self._makeOne(request, 'path', ('query','level','operator'))
self.assertEqual(parser.get('keys'), ['foo'])
self.assertEqual(parser.get('level'), 0)
self.assertEqual(parser.get('operator'), 'and')
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(parseIndexRequestTests))
return suite
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
...@@ -7,20 +7,21 @@ ...@@ -7,20 +7,21 @@
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE # FOR A PARTICULAR PURPOSE.
# #
############################################################################# ##############################################################################
"""PluginIndexes utils.
__version__ = '$Id$'
$Id$
"""
from warnings import warn from warnings import warn
from types import StringType,ListType,TupleType,DictType,InstanceType from types import InstanceType
from DateTime import DateTime from DateTime import DateTime
SequenceTypes = (TupleType, ListType)
class parseIndexRequest: class parseIndexRequest:
""" """
This class provides functionality to hide the internals of a request This class provides functionality to hide the internals of a request
send from the Catalog/ZCatalog to an index._apply_index() method. send from the Catalog/ZCatalog to an index._apply_index() method.
...@@ -31,7 +32,6 @@ class parseIndexRequest: ...@@ -31,7 +32,6 @@ class parseIndexRequest:
the request directory where the index name is the name of the key. the request directory where the index name is the name of the key.
Additional parameters for an index could be passed as index+"_usage" ... Additional parameters for an index could be passed as index+"_usage" ...
- dictionary-style parameters specify a query for an index as - dictionary-style parameters specify a query for an index as
an entry in the request dictionary where the key corresponds to the an entry in the request dictionary where the key corresponds to the
name of the index and the key is a dictionary with the parameters name of the index and the key is a dictionary with the parameters
...@@ -43,16 +43,13 @@ class parseIndexRequest: ...@@ -43,16 +43,13 @@ class parseIndexRequest:
other parameters depend on the the index other parameters depend on the the index
- record-style parameters specify a query for an index as instance of the - record-style parameters specify a query for an index as instance of the
Record class. This happens usually when parameters from a web form use Record class. This happens usually when parameters from a web form use
the "record" type e.g. <input type="text" name="path.query:record:string">. the "record" type e.g. <input type="text" name="path.query:record:string">.
All restrictions of the dictionary-style parameters apply to the record-style All restrictions of the dictionary-style parameters apply to the record-style
parameters parameters
""" """
ParserException = 'IndexRequestParseError' ParserException = 'IndexRequestParseError'
def __init__(self, request, iid, options=[]): def __init__(self, request, iid, options=[]):
...@@ -73,13 +70,16 @@ class parseIndexRequest: ...@@ -73,13 +70,16 @@ class parseIndexRequest:
usage_param = iid + '_usage' usage_param = iid + '_usage'
if request.has_key(usage_param): if request.has_key(usage_param):
self.usage = request[usage_param] self.usage = request[usage_param]
warn("\nZCatalog query using '%s' detected.\nUsing query parameters ending with '_usage' is deprecated.\nConsider using record-style parameters instead (see lib/python/Products/PluginIndexes/README.txt for details)" % usage_param, DeprecationWarning) warn("ZCatalog query using '%s' detected.\n"
"Using query parameters ending with '_usage' is deprecated.\n"
"Consider using record-style parameters instead "
"(see lib/python/Products/PluginIndexes/README.txt for "
"details)" % usage_param, DeprecationWarning)
param = request[iid] param = request[iid]
keys = None keys = None
t = type(param)
if t is InstanceType and not isinstance(param, DateTime): if isinstance(param, InstanceType) and not isinstance(param, DateTime):
""" query is of type record """ """ query is of type record """
record = param record = param
...@@ -90,7 +90,7 @@ class parseIndexRequest: ...@@ -90,7 +90,7 @@ class parseIndexRequest:
"'query' attribute" % self.id) "'query' attribute" % self.id)
keys = record.query keys = record.query
if type(keys) is StringType: if isinstance(keys, str):
keys = [keys.strip()] keys = [keys.strip()]
for op in options: for op in options:
...@@ -99,11 +99,11 @@ class parseIndexRequest: ...@@ -99,11 +99,11 @@ class parseIndexRequest:
if hasattr(record, op): if hasattr(record, op):
setattr(self, op, getattr(record, op)) setattr(self, op, getattr(record, op))
elif t is DictType: elif isinstance(param, dict):
""" query is a dictionary containing all parameters """ """ query is a dictionary containing all parameters """
query = param.get("query", ()) query = param.get("query", ())
if type(query) in SequenceTypes: if isinstance(query, (tuple, list)):
keys = query keys = query
else: else:
keys = [ query ] keys = [ query ]
...@@ -117,7 +117,7 @@ class parseIndexRequest: ...@@ -117,7 +117,7 @@ class parseIndexRequest:
else: else:
""" query is tuple, list, string, number, or something else """ """ query is tuple, list, string, number, or something else """
if t in SequenceTypes: if isinstance(param, (tuple, list)):
keys = param keys = param
else: else:
keys = [param] keys = [param]
...@@ -129,21 +129,9 @@ class parseIndexRequest: ...@@ -129,21 +129,9 @@ class parseIndexRequest:
self.keys = keys self.keys = keys
def get(self, k, default_v=None):
def get(self,k,default_v=None): if hasattr(self, k):
v = getattr(self, k)
if hasattr(self,k): if v != '':
v = getattr(self,k) return v
if v: return v return default_v
else: return default_v
else:
return default_v
def test():
r = parseIndexRequest({'path':{'query':"","level":2,"operator":'and'}},'path',['query',"level","operator"])
for k in dir(r):
print k,getattr(r,k)
if __name__=="__main__":
test()
...@@ -43,12 +43,12 @@ class IPluggableIndex(Interface): ...@@ -43,12 +43,12 @@ class IPluggableIndex(Interface):
def unindex_object(documentId): def unindex_object(documentId):
"""Remove the documentId from the index.""" """Remove the documentId from the index."""
def _apply_index(request, cid=''): def _apply_index(request):
"""Apply the index to query parameters given in 'request'. """Apply the index to query parameters given in 'request'.
The argument should be a mapping object. The argument should be a mapping object.
If the request does not contain the needed parametrs, then If the request does not contain the needed parameters, then
None is returned. None is returned.
If the request contains a parameter with the name of the column If the request contains a parameter with the name of the column
......
...@@ -61,13 +61,12 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem): ...@@ -61,13 +61,12 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
## Magic class attributes ## ## Magic class attributes ##
meta_type = 'ZCTextIndex' meta_type = 'ZCTextIndex'
query_options = ('query',)
manage_options = ( manage_options = (
{'label': 'Overview', 'action': 'manage_main'}, {'label': 'Overview', 'action': 'manage_main'},
) )
query_options = ['query']
security = ClassSecurityInfo() security = ClassSecurityInfo()
security.declareObjectProtected(manage_zcatalog_indexes) security.declareObjectProtected(manage_zcatalog_indexes)
...@@ -204,7 +203,7 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem): ...@@ -204,7 +203,7 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
if self.index.has_doc(docid): if self.index.has_doc(docid):
self.index.unindex_doc(docid) self.index.unindex_doc(docid)
def _apply_index(self, request, cid=''): def _apply_index(self, request):
"""Apply query specified by request, a mapping containing the query. """Apply query specified by request, a mapping containing the query.
Returns two object on success, the resultSet containing the Returns two object on success, the resultSet containing the
...@@ -216,6 +215,7 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem): ...@@ -216,6 +215,7 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
record = parseIndexRequest(request, self.id, self.query_options) record = parseIndexRequest(request, self.id, self.query_options)
if record.keys is None: if record.keys is None:
return None return None
query_str = ' '.join(record.keys) query_str = ' '.join(record.keys)
if not query_str: if not query_str:
return None return None
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment