summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
diff options
context:
space:
mode:
authorMichael Trier <mtrier@gmail.com>2008-07-13 04:45:37 +0000
committerMichael Trier <mtrier@gmail.com>2008-07-13 04:45:37 +0000
commitf899157ca9f6f5104a358420eba8f1b9019ece6f (patch)
tree37baa09bec04f9c1f93fa4ea4a798158cc3c75e1 /lib/sqlalchemy/sql
parentbad78d9767fb9b076c7a6388286a0c37a81d8bc5 (diff)
downloadsqlalchemy-f899157ca9f6f5104a358420eba8f1b9019ece6f.tar.gz
Added new basic match() operator that performs a full-text search. Supported on PostgreSQL, SQLite, MySQL, MS-SQL, and Oracle backends.
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r--lib/sqlalchemy/sql/compiler.py1
-rw-r--r--lib/sqlalchemy/sql/expression.py11
-rw-r--r--lib/sqlalchemy/sql/operators.py4
3 files changed, 16 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index b6da29736..05b3f550d 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -81,6 +81,7 @@ OPERATORS = {
operators.ilike_op : lambda x, y, escape=None: "lower(%s) LIKE lower(%s)" % (x, y) + (escape and ' ESCAPE \'%s\'' % escape or ''),
operators.notilike_op : lambda x, y, escape=None: "lower(%s) NOT LIKE lower(%s)" % (x, y) + (escape and ' ESCAPE \'%s\'' % escape or ''),
operators.between_op : 'BETWEEN',
+ operators.match_op : 'MATCH',
operators.in_op : 'IN',
operators.notin_op : 'NOT IN',
operators.comma_op : ', ',
diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py
index bf848654c..308f4b202 100644
--- a/lib/sqlalchemy/sql/expression.py
+++ b/lib/sqlalchemy/sql/expression.py
@@ -1250,6 +1250,9 @@ class ColumnOperators(Operators):
def contains(self, other, **kwargs):
return self.operate(operators.contains_op, other, **kwargs)
+ def match(self, other, **kwargs):
+ return self.operate(operators.match_op, other, **kwargs)
+
def desc(self):
return self.operate(operators.desc_op)
@@ -1390,6 +1393,14 @@ class _CompareMixin(ColumnOperators):
return self.__compare(operators.like_op, literal_column("'%'", type_=sqltypes.String) + self._check_literal(other) + literal_column("'%'", type_=sqltypes.String), escape=escape)
+ def match(self, other):
+ """Produce a MATCH clause, i.e. ``MATCH '<other>'``
+
+ The allowed contents of ``other`` are database backend specific.
+ """
+
+ return self.__compare(operators.match_op, self._check_literal(other))
+
def label(self, name):
"""Produce a column label, i.e. ``<columnname> AS <name>``.
diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py
index 46dcaba66..37070a451 100644
--- a/lib/sqlalchemy/sql/operators.py
+++ b/lib/sqlalchemy/sql/operators.py
@@ -61,6 +61,9 @@ def endswith_op(a, b, escape=None):
def contains_op(a, b, escape=None):
return a.contains(b, escape=escape)
+def match_op(a, b):
+ return a.match(b)
+
def comma_op(a, b):
raise NotImplementedError()
@@ -88,6 +91,7 @@ _PRECEDENCE = {
add:6,
sub:6,
concat_op:6,
+ match_op:6,
ilike_op:5,
notilike_op:5,
like_op:5,