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

processing date ranges supplied like "created:3months", "created:1yr"

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11589 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9f75f698
...@@ -19,6 +19,20 @@ Everything else is treated as SearchableText ...@@ -19,6 +19,20 @@ Everything else is treated as SearchableText
import re import re
import sys
sys.path.append('/usr/lib/zope/lib/python/')
from DateTime import DateTime
def dateRangeProc(s):
m=re.match('(\d)([my]).*',s)
try:
dif=0
gr=m.groups()
if gr[1]=='m':dif=int(gr[0])*30
if gr[1]=='y':dif=int(gr[0])*365
return ('creation_from',DateTime()-dif)
except AttributeError, IndexError:
return ()
# parsing defined here # parsing defined here
simulation_states=() simulation_states=()
...@@ -29,7 +43,7 @@ filestripper=lambda s: ('source_reference',s.replace('"','')) ...@@ -29,7 +43,7 @@ filestripper=lambda s: ('source_reference',s.replace('"',''))
state=lambda s:('simulation_state',parsestates(s)) state=lambda s:('simulation_state',parsestates(s))
type=lambda s:('portal_type',parsestates(s)) type=lambda s:('portal_type',parsestates(s))
paramsmap=dict(file=filestripper,type=type,reference='reference',filetype=filetyper,state=state,\ paramsmap=dict(file=filestripper,type=type,reference='reference',filetype=filetyper,state=state,\
language='language',version='version') language='language',version='version',created=dateRangeProc)
def parsestates(s): def parsestates(s):
print s print s
...@@ -55,6 +69,8 @@ def analyze(params): ...@@ -55,6 +69,8 @@ def analyze(params):
params[paramsmap.get(ss[0])]=ss[1] params[paramsmap.get(ss[0])]=ss[1]
else: else:
params[ss[0]]=ss[1] params[ss[0]]=ss[1]
except IndexError:
return
return cutter return cutter
def parseSearchString(searchstring): def parseSearchString(searchstring):
...@@ -67,5 +83,6 @@ def parseSearchString(searchstring): ...@@ -67,5 +83,6 @@ 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" state:draft file:"ble ble.doc" type:("Site","Text") poza tym reference:abc-def dupa:kwas/zbita' #searchstring='byle "cisnie zego" state:draft file:"ble ble.doc" type:("Site","Text") poza tym reference:abc-def dupa:kwas/zbita'
searchstring='byleco created:3mth'
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