summaryrefslogtreecommitdiff
path: root/test/dialect/postgresql/test_compiler.py
diff options
context:
space:
mode:
authorjonathan vanasco <jonathan@2xlp.com>2014-06-10 18:56:27 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-07-08 18:18:04 -0400
commitc996b76d5b90476e0c0a253f8eb3db5cdbf73867 (patch)
tree4264d985c4b3ea6f019cb7ade49dfda663b5cab9 /test/dialect/postgresql/test_compiler.py
parent5eefdae113194d6aa029188f7200dd9aca54e2b7 (diff)
downloadsqlalchemy-c996b76d5b90476e0c0a253f8eb3db5cdbf73867.tar.gz
- add postgresql_regconfig argument to PG dialect for match() operator,
implements PG's to_tsquery('regconfig', 'arg') pattern. fixes #3078
Diffstat (limited to 'test/dialect/postgresql/test_compiler.py')
-rw-r--r--test/dialect/postgresql/test_compiler.py81
1 files changed, 81 insertions, 0 deletions
diff --git a/test/dialect/postgresql/test_compiler.py b/test/dialect/postgresql/test_compiler.py
index c81389385..76166b6dd 100644
--- a/test/dialect/postgresql/test_compiler.py
+++ b/test/dialect/postgresql/test_compiler.py
@@ -695,3 +695,84 @@ class DistinctOnTest(fixtures.TestBase, AssertsCompiledSQL):
"FROM t, (SELECT t.id AS id, t.a AS a, "
"t.b AS b FROM t) AS sq WHERE t.id = sq.id"
)
+
+class FullTextSearchTest(fixtures.TestBase, AssertsCompiledSQL):
+ """Tests for full text searching
+ """
+ __dialect__ = postgresql.dialect()
+
+ def setup(self):
+ self.table = Table('t', MetaData(),
+ Column('id', Integer, primary_key=True),
+ Column('title', String),
+ Column('body', String),
+ )
+ self.table_alt = table('mytable',
+ column('id', Integer),
+ column('title', String(128)),
+ column('body', String(128)))
+
+ def _raise_query(self, q):
+ """
+ useful for debugging. just do...
+ self._raise_query(q)
+ """
+ c = q.compile(dialect=postgresql.dialect())
+ raise ValueError(c)
+
+ def test_match_basic(self):
+ s = select([self.table_alt.c.id])\
+ .where(self.table_alt.c.title.match('somestring'))
+ self.assert_compile(s,
+ 'SELECT mytable.id '
+ 'FROM mytable '
+ 'WHERE mytable.title @@ to_tsquery(%(title_1)s)')
+
+ def test_match_regconfig(self):
+ s = select([self.table_alt.c.id])\
+ .where(
+ self.table_alt.c.title.match('somestring',
+ postgresql_regconfig='english')
+ )
+ self.assert_compile(s,
+ 'SELECT mytable.id '
+ 'FROM mytable '
+ """WHERE mytable.title @@ to_tsquery('english', %(title_1)s)""")
+
+ def test_match_tsvector(self):
+ s = select([self.table_alt.c.id])\
+ .where(
+ func.to_tsvector( self.table_alt.c.title )\
+ .match('somestring')
+ )
+ self.assert_compile(s,
+ 'SELECT mytable.id '
+ 'FROM mytable '
+ 'WHERE to_tsvector(mytable.title) @@ to_tsquery(%(to_tsvector_1)s)')
+
+ def test_match_tsvectorconfig(self):
+ s = select([self.table_alt.c.id])\
+ .where(
+ func.to_tsvector( 'english', self.table_alt.c.title )\
+ .match('somestring')
+ )
+ self.assert_compile(s,
+ 'SELECT mytable.id '
+ 'FROM mytable '
+ 'WHERE to_tsvector(%(to_tsvector_1)s, mytable.title) @@ '
+ 'to_tsquery(%(to_tsvector_2)s)'
+ )
+
+ def test_match_tsvectorconfig_regconfig(self):
+ s = select([self.table_alt.c.id])\
+ .where(\
+ func.to_tsvector( 'english', self.table_alt.c.title )\
+ .match('somestring', postgresql_regconfig='english')
+ )
+ self.assert_compile(s,
+ 'SELECT mytable.id '
+ 'FROM mytable '
+ 'WHERE to_tsvector(%(to_tsvector_1)s, mytable.title) @@ '
+ """to_tsquery('english', %(to_tsvector_2)s)"""
+ )
+