From b10441866a858f47a414767915a6e2c61d874986 Mon Sep 17 00:00:00 2001
From: "James E. Blair" <jeblair@hp.com>
Date: Fri, 6 Mar 2015 16:50:00 -0800
Subject: [PATCH] Fix searching with uppercase booleans

AND and OR caused a syntax error while 'and' and 'or' worked.

The debugging method at the bottom of __init__.py is intentional,
at least until there's real testing for this.

Change-Id: Ib5a5d7b47d64204f6dda36513dea8249d3bbce4e
---
 gertty/search/__init__.py | 11 ++++++++++-
 gertty/search/parser.py   |  6 +++---
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/gertty/search/__init__.py b/gertty/search/__init__.py
index 7902970..2dbfc1a 100644
--- a/gertty/search/__init__.py
+++ b/gertty/search/__init__.py
@@ -62,9 +62,18 @@ class SearchCompiler(object):
 if __name__ == '__main__':
     class Dummy(object):
         pass
+    query = 'status:open AND topic:enable_swift'
+    lexer = tokenizer.SearchTokenizer()
+    lexer.input(query)
+    while True:
+        token = lexer.token()
+        if not token:
+            break
+        print token
+
     app = Dummy()
     app.config = Dummy()
     app.config.username = 'bob'
     search = SearchCompiler(app)
-    x = search.parse('owner:self')
+    x = search.parse(query)
     print x
diff --git a/gertty/search/parser.py b/gertty/search/parser.py
index b0ccfc0..0840305 100644
--- a/gertty/search/parser.py
+++ b/gertty/search/parser.py
@@ -47,12 +47,12 @@ def SearchParser():
     def p_boolean_expr(p):
         '''boolean_expr : expression AND expression
                         | expression OR expression'''
-        if p[2] == 'and':
+        if p[2].lower() == 'and':
             p[0] = and_(p[1], p[3])
-        elif p[2] == 'or':
+        elif p[2].lower() == 'or':
             p[0] = or_(p[1], p[3])
         else:
-            raise SyntaxError()
+            raise gertty.search.SearchSyntaxError("Boolean %s not recognized" % p[2])
 
     def p_negative_expr(p):
         '''negative_expr : NOT expression