From 96359c6f3e81f55275666e94d9b9cadb7a1d923e Mon Sep 17 00:00:00 2001 From: Noufal Ibrahim Date: Thu, 5 Dec 2013 17:36:57 +0530 Subject: Implements TSVECTOR type for postgresql. Signed-off-by: Noufal Ibrahim --- lib/sqlalchemy/dialects/postgresql/base.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/sqlalchemy/dialects/postgresql/base.py') diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index b80f269c1..5ef16c412 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -368,6 +368,10 @@ class UUID(sqltypes.TypeEngine): PGUuid = UUID +class TSVECTOR(sqltypes.TypeEngine): + __visit_name__ = 'TSVECTOR' + + class _Slice(expression.ColumnElement): __visit_name__ = 'slice' @@ -1163,6 +1167,9 @@ class PGDDLCompiler(compiler.DDLCompiler): class PGTypeCompiler(compiler.GenericTypeCompiler): + def visit_TSVECTOR(self, type): + return "TSVECTOR" + def visit_INET(self, type_): return "INET" -- cgit v1.2.1 From 4eb8437f61139179a18f63168ff9987acfd0f3ca Mon Sep 17 00:00:00 2001 From: Noufal Ibrahim Date: Thu, 5 Dec 2013 18:21:49 +0530 Subject: Updates documentation for tsvector type. Signed-off-by: Noufal Ibrahim --- lib/sqlalchemy/dialects/postgresql/base.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/dialects/postgresql/base.py') diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 5ef16c412..ed8a8c90f 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -369,6 +369,31 @@ class UUID(sqltypes.TypeEngine): PGUuid = UUID class TSVECTOR(sqltypes.TypeEngine): + """The TSVECTOR type implements the Postgresql text search type + TSVECTOR. + + It can be used to do full text queries on natural language + *documents*. + + Search queries are performed using the ``@@`` operator in + postgresql. This is made available with the ``match`` method + available on the column. + + This means that if you have a table ``Example`` with a column + ``text`` of type ``TSVECTOR``, you can create a search clause like + so + + :: + + Example.text.match("search string") + + which will be compiled to + + :: + + text @@ to_tsquery('search string') + + """ __visit_name__ = 'TSVECTOR' @@ -1169,7 +1194,7 @@ class PGDDLCompiler(compiler.DDLCompiler): class PGTypeCompiler(compiler.GenericTypeCompiler): def visit_TSVECTOR(self, type): return "TSVECTOR" - + def visit_INET(self, type_): return "INET" -- cgit v1.2.1 From 892c8762e681502fa0c5f5740a619f17f7848ea7 Mon Sep 17 00:00:00 2001 From: Noufal Ibrahim Date: Tue, 10 Dec 2013 00:46:39 +0530 Subject: Adds tsvector to ischema_names for reflection to work. Signed-off-by: Noufal Ibrahim --- lib/sqlalchemy/dialects/postgresql/base.py | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/sqlalchemy/dialects/postgresql/base.py') diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index ed8a8c90f..7602304f8 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -942,6 +942,7 @@ ischema_names = { 'interval': INTERVAL, 'interval year to month': INTERVAL, 'interval day to second': INTERVAL, + 'tsvector' : TSVECTOR } -- cgit v1.2.1