Commit fe6ee055 authored by Bartek Górny's avatar Bartek Górny

changed search syntax a bit (more reliance on security), added docstring

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10637 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 256221cd
'''
RULES
Single arguments:
- arg:value translates into arg='value' in query
- quotes are cleared
- if value contains spaces, punctuation or anything else it has to be put in quotes
- file is source_reference (original file name)
- language, version, reference
Multiple arguments:
- arg:xxx works the same way
- arg:(xxx,yyy) ORs both (do not put space after comma)
- arg:all translates into empty tuple, which implies all available values
- state (simulation_state), type (portal_type)
Everything else is treated as SearchableText
'''
import re import re
# parsing defined here # parsing defined here
simulation_states=('released','public','submitted') simulation_states=()
r=re.compile('(\w+:"[^"]+"|\w+:[\w/\-.]+)') r=re.compile('(\w+:"[^"]+"|\w+:[\(\),\w/\-.]+)')
filetyper=lambda s:('source_reference','%%.%s' % s) filetyper=lambda s:('source_reference','%%.%s' % s)
filestripper=lambda s: ('source_reference',s.replace('"','')) filestripper=lambda s: ('source_reference',s.replace('"',''))
addarchived=lambda s: ('simulation_state',simulation_states+('archived',)) #addarchived=lambda s: ('simulation_state',simulation_states+('archived',))
paramsmap=dict(file=filestripper,type='portal_type',reference='reference',filetype=filetyper,archived=addarchived,\ state=lambda s:('simulation_state',parsestates(s))
type=lambda s:('portal_type',parsestates(s))
paramsmap=dict(file=filestripper,type=type,reference='reference',filetype=filetyper,state=state,\
language='language',version='version') language='language',version='version')
def parsestates(s):
if s=='all':
return ()
if s[0]=='(' and s[-1]==')':
return [i for i in s[1:-1].split(',') if i!='']
return s.replace('"','').replace("'","")
def analyze(params): def analyze(params):
params['SearchableText']='' params['SearchableText']=''
params['simulation_state']=simulation_states params['simulation_state']=simulation_states
...@@ -38,5 +66,5 @@ def parseSearchString(searchstring): ...@@ -38,5 +66,5 @@ def parseSearchString(searchstring):
if __name__=='__main__': if __name__=='__main__':
#searchstring='byle cisnie zego file:"ble ble.doc" filetype:doc type:Text poza tym reference:abc-def' #searchstring='byle cisnie zego file:"ble ble.doc" filetype:doc type:Text poza tym reference:abc-def'
searchstring='byle "cisnie zego" file:"ble ble.doc" type:Text poza tym reference:abc-def dupa:kwas/zbita' searchstring='byle "cisnie zego" state:draft file:"ble ble.doc" type:"Web Site" poza tym reference:abc-def dupa:kwas/zbita'
print parseSearchString(searchstring) print parseSearchString(searchstring)
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