Commit 829b4405 authored by Andreas Jung's avatar Andreas Jung

- added "query_options" parameter to all index types

- made parseIndexRequest much more smarter in parsing the request parameter
parent b3d43e84
############################################################################## #############################################################################
# #
# Zope Public License (ZPL) Version 1.0 # Zope Public License (ZPL) Version 1.0
# ------------------------------------- # -------------------------------------
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
"""Simple column indices""" """Simple column indices"""
__version__='$Revision: 1.3 $'[11:-2] __version__='$Revision: 1.4 $'[11:-2]
from Globals import Persistent from Globals import Persistent
from Acquisition import Implicit from Acquisition import Implicit
...@@ -109,8 +109,6 @@ from OFS.History import Historical ...@@ -109,8 +109,6 @@ from OFS.History import Historical
from OFS.SimpleItem import SimpleItem from OFS.SimpleItem import SimpleItem
import sys
_marker = [] _marker = []
class FieldIndex(UnIndex,PluggableIndex.PluggableIndex, Persistent, class FieldIndex(UnIndex,PluggableIndex.PluggableIndex, Persistent,
...@@ -127,6 +125,7 @@ class FieldIndex(UnIndex,PluggableIndex.PluggableIndex, Persistent, ...@@ -127,6 +125,7 @@ class FieldIndex(UnIndex,PluggableIndex.PluggableIndex, Persistent,
'help': ('FieldIndex','FieldIndex_Settings.stx')}, 'help': ('FieldIndex','FieldIndex_Settings.stx')},
) )
query_options = ["query","range"]
index_html = DTMLFile('dtml/index', globals()) index_html = DTMLFile('dtml/index', globals())
......
...@@ -111,6 +111,8 @@ class KeywordIndex(UnIndex,PluggableIndex.PluggableIndex,Persistent, ...@@ -111,6 +111,8 @@ class KeywordIndex(UnIndex,PluggableIndex.PluggableIndex,Persistent,
'help': ('KeywordIndex','KeywordIndex_Settings.stx')}, 'help': ('KeywordIndex','KeywordIndex_Settings.stx')},
) )
query_options = ["query","operator"]
"""Like an UnIndex only it indexes sequences of items """Like an UnIndex only it indexes sequences of items
......
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
# #
############################################################################## ##############################################################################
__version__ = '$Id: PathIndex.py,v 1.3 2001/05/31 12:22:52 andreas Exp $' __version__ = '$Id: PathIndex.py,v 1.4 2001/06/01 18:53:39 andreas Exp $'
from Products.PluginIndexes import PluggableIndex from Products.PluginIndexes import PluggableIndex
from Products.PluginIndexes.common.util import parseIndexRequest from Products.PluginIndexes.common.util import parseIndexRequest
...@@ -126,6 +126,9 @@ class PathIndex(PluggableIndex.PluggableIndex, Persistent, ...@@ -126,6 +126,9 @@ class PathIndex(PluggableIndex.PluggableIndex, Persistent,
'help': ('PathIndex','PathIndex_Settings.stx')}, 'help': ('PathIndex','PathIndex_Settings.stx')},
) )
query_options = ["query","level"]
def __init__(self,id,caller=None): def __init__(self,id,caller=None):
self.id = id self.id = id
...@@ -329,7 +332,7 @@ class PathIndex(PluggableIndex.PluggableIndex, Persistent, ...@@ -329,7 +332,7 @@ class PathIndex(PluggableIndex.PluggableIndex, Persistent,
cid ??? cid ???
""" """
record = parseIndexRequest(request,self.id) record = parseIndexRequest(request,self.id,self.query_options)
if record.keys==None: return None if record.keys==None: return None
# get the level parameter # get the level parameter
......
from Splitter import Splitter from Splitter import Splitter
class ZopeSplitter:
meta_type="Splitter"
description="Zope Default Splitter"
Splitter = Splitter
def __init__(self):
print "__init__"
def a(self):
"""a"""
print "initialize",self.meta_type
pass
def b(self):
"""b"""
print "binitialize",self.meta_type
pass
...@@ -91,7 +91,7 @@ undo information so that objects can be unindexed when the old value ...@@ -91,7 +91,7 @@ undo information so that objects can be unindexed when the old value
is no longer known. is no longer known.
""" """
__version__ = '$Revision: 1.4 $'[11:-2] __version__ = '$Revision: 1.5 $'[11:-2]
import string, re import string, re
...@@ -150,6 +150,8 @@ class TextIndex(PluggableIndex.PluggableIndex, Persistent, ...@@ -150,6 +150,8 @@ class TextIndex(PluggableIndex.PluggableIndex, Persistent,
'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,extra=None): def __init__(self, id, ignore_ex=None, call_methods=None, lexicon=None,extra=None):
"""Create an index """Create an index
...@@ -501,7 +503,7 @@ class TextIndex(PluggableIndex.PluggableIndex, Persistent, ...@@ -501,7 +503,7 @@ class TextIndex(PluggableIndex.PluggableIndex, Persistent,
all data fields used. all data fields used.
""" """
record = parseIndexRequest(request,self.id) record = parseIndexRequest(request,self.id,self.query_options)
if record.keys==None: return None if record.keys==None: return None
# Changed for 2.4 # Changed for 2.4
......
...@@ -67,4 +67,7 @@ ...@@ -67,4 +67,7 @@
</table> </table>
</form> </form>
<dtml-var "objectItems("splitter")>
<dtml-var "objectItems()">
<dtml-var manage_page_footer> <dtml-var manage_page_footer>
...@@ -96,6 +96,8 @@ import KeywordIndex.KeywordIndex ...@@ -96,6 +96,8 @@ import KeywordIndex.KeywordIndex
_indexes = ['TextIndex','KeywordIndex','FieldIndex','PathIndex'] _indexes = ['TextIndex','KeywordIndex','FieldIndex','PathIndex']
from TextIndex.Splitter import ZopeSplitter as ZS
def initialize(context): def initialize(context):
for idx in _indexes: for idx in _indexes:
...@@ -114,9 +116,13 @@ def initialize(context): ...@@ -114,9 +116,13 @@ def initialize(context):
context.registerHelp() context.registerHelp()
context.registerHelpTitle('Indexes (Pluggable)') context.registerHelpTitle('Indexes (Pluggable)')
context.registerClass(ZS.ZopeSplitter,permission="Splitter",constructors=(ZS.ZopeSplitter.a,ZS.ZopeSplitter.b))
for idx in _indexes: for idx in _indexes:
exec("manage_add%sForm = %s.%s.manage_add%sForm" % (idx,idx,idx,idx)) exec("manage_add%sForm = %s.%s.manage_add%sForm" % (idx,idx,idx,idx))
exec("manage_add%s = %s.%s.manage_add%s" % (idx,idx,idx,idx)) exec("manage_add%s = %s.%s.manage_add%s" % (idx,idx,idx,idx))
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
"""Simple column indices""" """Simple column indices"""
__version__='$Revision: 1.2 $'[11:-2] __version__='$Revision: 1.3 $'[11:-2]
from Globals import Persistent from Globals import Persistent
from Acquisition import Implicit from Acquisition import Implicit
...@@ -108,7 +108,6 @@ _marker = [] ...@@ -108,7 +108,6 @@ _marker = []
class UnIndex(Persistent, Implicit): class UnIndex(Persistent, Implicit):
"""UnIndex object interface""" """UnIndex object interface"""
meta_type = 'Field Index'
def __init__(self, id, ignore_ex=None, call_methods=None): def __init__(self, id, ignore_ex=None, call_methods=None):
"""Create an unindex """Create an unindex
...@@ -378,7 +377,8 @@ class UnIndex(Persistent, Implicit): ...@@ -378,7 +377,8 @@ class UnIndex(Persistent, Implicit):
""" """
record = parseIndexRequest(request,self.id)
record = parseIndexRequest(request, self.id, self.query_options)
if record.keys==None: return None if record.keys==None: return None
index = self._index index = self._index
......
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
# #
############################################################################# #############################################################################
__version__ = '$Id: util.py,v 1.3 2001/06/01 16:50:06 shane Exp $' __version__ = '$Id: util.py,v 1.4 2001/06/01 18:53:40 andreas Exp $'
import re import re
...@@ -124,12 +124,13 @@ class parseIndexRequest: ...@@ -124,12 +124,13 @@ class parseIndexRequest:
ParserException = 'IndexRequestParseError' ParserException = 'IndexRequestParseError'
def __init__(self,request,iid): def __init__(self,request,iid,options=[]):
""" parse a request from the ZPublisher and return a uniform """ parse a request from the ZPublisher and return a uniform
datastructure back to the _apply_index() method of the index datastructure back to the _apply_index() method of the index
request -- the request dictionary send from the ZPublisher request -- the request dictionary send from the ZPublisher
iid -- Id of index iid -- Id of index
options -- a list of options the index is interested in
""" """
self.id = iid self.id = iid
...@@ -137,18 +138,12 @@ class parseIndexRequest: ...@@ -137,18 +138,12 @@ class parseIndexRequest:
if not request.has_key(iid): return if not request.has_key(iid): return
# We keep this for backward compatility
if request.has_key(iid+'_usage'): if request.has_key(iid+'_usage'):
self.usage = request[iid+'_usage'] self.usage = request[iid+'_usage']
if request.has_key(iid+'_operator'):
self.operator = request[iid+'_operator']
keys = request[iid] keys = request[iid]
# This check checks if the object is an instance of
# Record - This check is lame and should be fixed !
if type(keys) == InstanceType: if type(keys) == InstanceType:
""" query is of type record """ """ query is of type record """
record = keys record = keys
...@@ -164,10 +159,13 @@ class parseIndexRequest: ...@@ -164,10 +159,13 @@ class parseIndexRequest:
elif type(keys) == ListType: elif type(keys) == ListType:
self.keys = keys self.keys = keys
for k in dir(record): for op in options:
if not k in ['query','operator']: if op in ["query"]: continue
if hasattr(record,op):
setattr(self,k,getattr(record,k)) setattr(self,k,getattr(record,k))
elif type(keys)==DictType: elif type(keys)==DictType:
""" query is a dictionary containing all parameters """ """ query is a dictionary containing all parameters """
...@@ -177,9 +175,11 @@ class parseIndexRequest: ...@@ -177,9 +175,11 @@ class parseIndexRequest:
else: else:
self.keys = [ query ] self.keys = [ query ]
for k,v in keys.items(): for op in options:
if k in ["query"]: continue if op in ["query"]: continue
setattr(self,k,v)
if keys.has_key(op):
setattr(self,op,keys[op])
else: else:
...@@ -190,16 +190,10 @@ class parseIndexRequest: ...@@ -190,16 +190,10 @@ class parseIndexRequest:
else: else:
self.keys = [keys] self.keys = [keys]
if hasattr(request, 'keys'): for op in options:
# Look through the entire request for extra parameters. if request.has_key(iid+"_"+op):
# This is expensive! setattr(self,op,request[iid+"_"+op])
params = filter(lambda x,id=self.id: x.startswith(id+'_'),
request.keys())
params = map(lambda x,id=self.id: x[len(id)+1:],params)
for p in params:
setattr(self,p,request[self.id+'_'+p])
if self.keys != None: if self.keys != None:
self.keys = filter(lambda x: len(str(x))>0 , self.keys) self.keys = filter(lambda x: len(str(x))>0 , self.keys)
...@@ -219,7 +213,7 @@ class parseIndexRequest: ...@@ -219,7 +213,7 @@ class parseIndexRequest:
def test(): def test():
r = parseIndexRequest({'path':{'query':"xxxx","level":2,"operator":'and'}},'path') r = parseIndexRequest({'path':{'query':"xxxx","level":2,"operator":'and'}},'path',['query',"level","operator"])
for k in dir(r): for k in dir(r):
print k,getattr(r,k) print k,getattr(r,k)
......
...@@ -93,7 +93,7 @@ except ImportError: ...@@ -93,7 +93,7 @@ except ImportError:
import ZODB import ZODB
import unittest import unittest
from Products.PluginIndexes.common.UnIndex import UnIndex from Products.PluginIndexes.FieldIndex.FieldIndex import FieldIndex
class Dummy: class Dummy:
...@@ -116,7 +116,7 @@ class TestCase( unittest.TestCase ): ...@@ -116,7 +116,7 @@ class TestCase( unittest.TestCase ):
def setUp( self ): def setUp( self ):
""" """
""" """
self._index = UnIndex( 'foo' ) self._index = FieldIndex( 'foo' )
self._marker = [] self._marker = []
self._values = [ ( 0, Dummy( 'a' ) ) self._values = [ ( 0, Dummy( 'a' ) )
, ( 1, Dummy( 'ab' ) ) , ( 1, Dummy( 'ab' ) )
...@@ -229,7 +229,7 @@ class TestCase( unittest.TestCase ): ...@@ -229,7 +229,7 @@ class TestCase( unittest.TestCase ):
def testRange(self): def testRange(self):
"""Test a range search""" """Test a range search"""
index = UnIndex( 'foo' ) index = FieldIndex( 'foo' )
for i in range(100): for i in range(100):
index.index_object(i, Dummy(i%10)) index.index_object(i, Dummy(i%10))
......
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