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
# -------------------------------------
......@@ -85,7 +85,7 @@
"""Simple column indices"""
__version__='$Revision: 1.3 $'[11:-2]
__version__='$Revision: 1.4 $'[11:-2]
from Globals import Persistent
from Acquisition import Implicit
......@@ -109,8 +109,6 @@ from OFS.History import Historical
from OFS.SimpleItem import SimpleItem
import sys
_marker = []
class FieldIndex(UnIndex,PluggableIndex.PluggableIndex, Persistent,
......@@ -127,6 +125,7 @@ class FieldIndex(UnIndex,PluggableIndex.PluggableIndex, Persistent,
'help': ('FieldIndex','FieldIndex_Settings.stx')},
)
query_options = ["query","range"]
index_html = DTMLFile('dtml/index', globals())
......
......@@ -111,6 +111,8 @@ class KeywordIndex(UnIndex,PluggableIndex.PluggableIndex,Persistent,
'help': ('KeywordIndex','KeywordIndex_Settings.stx')},
)
query_options = ["query","operator"]
"""Like an UnIndex only it indexes sequences of items
......
......@@ -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.common.util import parseIndexRequest
......@@ -119,13 +119,16 @@ class PathIndex(PluggableIndex.PluggableIndex, Persistent,
__implements__ = (PluggableIndex.PluggableIndexInterface,)
meta_type="PathIndex"
manage_options= (
{'label': 'Settings',
'action': 'manage_main',
'help': ('PathIndex','PathIndex_Settings.stx')},
)
query_options = ["query","level"]
def __init__(self,id,caller=None):
self.id = id
......@@ -329,7 +332,7 @@ class PathIndex(PluggableIndex.PluggableIndex, Persistent,
cid ???
"""
record = parseIndexRequest(request,self.id)
record = parseIndexRequest(request,self.id,self.query_options)
if record.keys==None: return None
# get the level parameter
......
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
is no longer known.
"""
__version__ = '$Revision: 1.4 $'[11:-2]
__version__ = '$Revision: 1.5 $'[11:-2]
import string, re
......@@ -149,6 +149,8 @@ class TextIndex(PluggableIndex.PluggableIndex, Persistent,
'action': 'manage_main',
'help': ('TextIndex','TextIndex_Settings.stx')},
)
query_options = ["query","operator"]
def __init__(self, id, ignore_ex=None, call_methods=None, lexicon=None,extra=None):
"""Create an index
......@@ -501,7 +503,7 @@ class TextIndex(PluggableIndex.PluggableIndex, Persistent,
all data fields used.
"""
record = parseIndexRequest(request,self.id)
record = parseIndexRequest(request,self.id,self.query_options)
if record.keys==None: return None
# Changed for 2.4
......
......@@ -67,4 +67,7 @@
</table>
</form>
<dtml-var "objectItems("splitter")>
<dtml-var "objectItems()">
<dtml-var manage_page_footer>
......@@ -96,6 +96,8 @@ import KeywordIndex.KeywordIndex
_indexes = ['TextIndex','KeywordIndex','FieldIndex','PathIndex']
from TextIndex.Splitter import ZopeSplitter as ZS
def initialize(context):
for idx in _indexes:
......@@ -114,9 +116,13 @@ def initialize(context):
context.registerHelp()
context.registerHelpTitle('Indexes (Pluggable)')
context.registerClass(ZS.ZopeSplitter,permission="Splitter",constructors=(ZS.ZopeSplitter.a,ZS.ZopeSplitter.b))
for idx in _indexes:
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))
......@@ -85,7 +85,7 @@
"""Simple column indices"""
__version__='$Revision: 1.2 $'[11:-2]
__version__='$Revision: 1.3 $'[11:-2]
from Globals import Persistent
from Acquisition import Implicit
......@@ -108,7 +108,6 @@ _marker = []
class UnIndex(Persistent, Implicit):
"""UnIndex object interface"""
meta_type = 'Field Index'
def __init__(self, id, ignore_ex=None, call_methods=None):
"""Create an unindex
......@@ -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
index = self._index
......
......@@ -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
......@@ -124,12 +124,13 @@ class parseIndexRequest:
ParserException = 'IndexRequestParseError'
def __init__(self,request,iid):
def __init__(self,request,iid,options=[]):
""" parse a request from the ZPublisher and return a uniform
datastructure back to the _apply_index() method of the index
request -- the request dictionary send from the ZPublisher
iid -- Id of index
options -- a list of options the index is interested in
"""
self.id = iid
......@@ -137,18 +138,12 @@ class parseIndexRequest:
if not request.has_key(iid): return
# We keep this for backward compatility
if request.has_key(iid+'_usage'):
self.usage = request[iid+'_usage']
if request.has_key(iid+'_operator'):
self.operator = request[iid+'_operator']
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:
""" query is of type record """
record = keys
......@@ -164,22 +159,27 @@ class parseIndexRequest:
elif type(keys) == ListType:
self.keys = keys
for k in dir(record):
if not k in ['query','operator']:
for op in options:
if op in ["query"]: continue
if hasattr(record,op):
setattr(self,k,getattr(record,k))
elif type(keys)==DictType:
""" query is a dictionary containing all parameters """
query = keys.get("query",[])
if type(query) in [TupleType,ListType]:
self.keys = query
else:
self.keys = [ query ]
for k,v in keys.items():
if k in ["query"]: continue
setattr(self,k,v)
for op in options:
if op in ["query"]: continue
if keys.has_key(op):
setattr(self,op,keys[op])
else:
......@@ -190,16 +190,10 @@ class parseIndexRequest:
else:
self.keys = [keys]
if hasattr(request, 'keys'):
# Look through the entire request for extra parameters.
# This is expensive!
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 op in options:
if request.has_key(iid+"_"+op):
setattr(self,op,request[iid+"_"+op])
for p in params:
setattr(self,p,request[self.id+'_'+p])
if self.keys != None:
self.keys = filter(lambda x: len(str(x))>0 , self.keys)
......@@ -219,7 +213,7 @@ class parseIndexRequest:
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):
print k,getattr(r,k)
......
......@@ -93,7 +93,7 @@ except ImportError:
import ZODB
import unittest
from Products.PluginIndexes.common.UnIndex import UnIndex
from Products.PluginIndexes.FieldIndex.FieldIndex import FieldIndex
class Dummy:
......@@ -116,7 +116,7 @@ class TestCase( unittest.TestCase ):
def setUp( self ):
"""
"""
self._index = UnIndex( 'foo' )
self._index = FieldIndex( 'foo' )
self._marker = []
self._values = [ ( 0, Dummy( 'a' ) )
, ( 1, Dummy( 'ab' ) )
......@@ -229,7 +229,7 @@ class TestCase( unittest.TestCase ):
def testRange(self):
"""Test a range search"""
index = UnIndex( 'foo' )
index = FieldIndex( 'foo' )
for i in range(100):
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