From 91256b13840cc1e58859752e98f4bd020ec9327b Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Mon, 19 May 2014 13:02:54 -0400 Subject: [PATCH] Finish parameterize() for Text. --- bitshift/database/__init__.py | 2 +- bitshift/query/nodes.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/bitshift/database/__init__.py b/bitshift/database/__init__.py index 7a794f6..4e2d2e8 100644 --- a/bitshift/database/__init__.py +++ b/bitshift/database/__init__.py @@ -62,7 +62,7 @@ class Database(object): base = """SELECT codelet_id FROM codelets %s WHERE %s - ORDER BY codelet_rank LIMIT 10""" + GROUP BY codelet_id ORDER BY codelet_rank DESC LIMIT 10""" conditional, tables, args = query.parameterize() joins = " ".join(tables) qstring = base % (joins, conditional) diff --git a/bitshift/query/nodes.py b/bitshift/query/nodes.py index 2797012..9f01093 100644 --- a/bitshift/query/nodes.py +++ b/bitshift/query/nodes.py @@ -84,8 +84,15 @@ class Text(_Node): def parameterize(self, tables): tables |= {"code", "symbols"} - # (FTS: codelet_name, =: symbol_name, FTS: code_code) vs. node.text (_Literal) - pass + if isinstance(self.text, Regex): + cols = ["codelet_name", "symbol_name", "code_code"] + cond = "((" + " REGEXP ?) OR (".join(cols) + " REGEXP ?))" + return cond, [self.text.regex] * 3 + conds = ["MATCH(codelet_name) AGAINST (? IN BOOLEAN MODE)", + "MATCH(code_code) AGAINST (? IN BOOLEAN MODE)", + "symbol_name = ?"] + cond = "((" + ") OR (".join(conds) + "))" + return cond, tables, [self.text.string] * 3 class Language(_Node):