Fix age searching

This pretty much just didn't work at all.

Change-Id: I1ce40b6d89f6000149360649b54728d395329cae
This commit is contained in:
James E. Blair 2015-04-11 15:07:30 -04:00
parent b89ae385b7
commit 44dcc6a1d8
3 changed files with 17 additions and 60 deletions

View File

@ -62,7 +62,7 @@ class SearchCompiler(object):
if __name__ == '__main__':
class Dummy(object):
pass
query = 'message:"Blueprint"'
query = 'NOT label:Code-Review<=2 age:5d'
lexer = tokenizer.SearchTokenizer()
lexer.input(query)
while True:

View File

@ -85,34 +85,26 @@ def SearchParser():
| USTRING'''
p[0] = p[1]
def p_age_unit(p):
'''age_unit : SECONDS
| MINUTES
| HOURS
| DAYS
| WEEKS
| MONTHS
| YEARS'''
p[0] = p[1]
def p_age_term(p):
'''age_term : OP_AGE NUMBER age_unit'''
'''age_term : OP_AGE NUMBER string'''
now = datetime.datetime.utcnow()
delta = p[1]
unit = p[2]
if unit == 'minutes':
delta = p[2]
unit = p[3]
if unit in ['seconds', 'second', 'sec', 's']:
pass
elif unit in ['minutes', 'minute', 'min', 'm']:
delta = delta * 60
elif unit == 'hours':
elif unit in ['hours', 'hour', 'hr', 'h']:
delta = delta * 60 * 60
elif unit == 'days':
delta = delta * 60 * 60 * 60
elif unit == 'weeks':
delta = delta * 60 * 60 * 60 * 7
elif unit == 'months':
delta = delta * 60 * 60 * 60 * 30
elif unit == 'years':
delta = delta * 60 * 60 * 60 * 365
p[0] = gertty.db.change_table.c.updated < (now-delta)
elif unit in ['days', 'day', 'd']:
delta = delta * 60 * 60 * 24
elif unit in ['weeks', 'week', 'w']:
delta = delta * 60 * 60 * 24 * 7
elif unit in ['months', 'month', 'mon']:
delta = delta * 60 * 60 * 24 * 30
elif unit in ['years', 'year', 'y']:
delta = delta * 60 * 60 * 24 * 365
p[0] = gertty.db.change_table.c.updated < (now-datetime.timedelta(seconds=delta))
def p_change_term(p):
'''change_term : OP_CHANGE CHANGE_ID

View File

@ -51,13 +51,6 @@ tokens = [
'NEG',
'LPAREN',
'RPAREN',
'SECONDS',
'MINUTES',
'HOURS',
'DAYS',
'WEEKS',
'MONTHS',
'YEARS',
'NUMBER',
'CHANGE_ID',
'SSTRING',
@ -119,34 +112,6 @@ def SearchTokenizer():
t.value=t.value.decode("string-escape")
return t
def t_SECONDS(t):
r's|sec|second|seconds'
t.value = 'seconds'
def t_MINUTES(t):
r'm|min|minute|minutes'
t.value = 'minutes'
def t_HOURS(t):
r'h|hr|hour|hours'
t.value = 'hours'
def t_DAYS(t):
r'd|day|days'
t.value = 'days'
def t_WEEKS(t):
r'w|week|weeks'
t.value = 'weeks'
def t_MONTHS(t):
r'mon|month|months'
t.value = 'months'
def t_YEARS(t):
r'y|year|years'
t.value = 'years'
def t_newline(t):
r'\n+'
t.lexer.lineno += len(t.value)