diff --git a/gertty/search/__init__.py b/gertty/search/__init__.py index 1e78bee..ae5f64c 100644 --- a/gertty/search/__init__.py +++ b/gertty/search/__init__.py @@ -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: diff --git a/gertty/search/parser.py b/gertty/search/parser.py index cd56e46..4a70d0e 100644 --- a/gertty/search/parser.py +++ b/gertty/search/parser.py @@ -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 diff --git a/gertty/search/tokenizer.py b/gertty/search/tokenizer.py index fe0b7b8..2c9b48c 100644 --- a/gertty/search/tokenizer.py +++ b/gertty/search/tokenizer.py @@ -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)