Added catalog parameter support for match_tsquery operator
This commit is contained in:
@@ -4,6 +4,13 @@ Changelog
|
||||
Here you can see the full list of changes between each SQLAlchemy-Utils release.
|
||||
|
||||
|
||||
0.16.24 (2013-10-04)
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- Renamed match operator of TSVectorType to match_tsquery in order to avoid confusion with existing match operator
|
||||
- Added catalog parameter support for match_tsquery operator
|
||||
|
||||
|
||||
0.16.23 (2013-10-04)
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
2
setup.py
2
setup.py
@@ -56,7 +56,7 @@ for name, requirements in extras_require.items():
|
||||
|
||||
setup(
|
||||
name='SQLAlchemy-Utils',
|
||||
version='0.16.23',
|
||||
version='0.16.24',
|
||||
url='https://github.com/kvesteri/sqlalchemy-utils',
|
||||
license='BSD',
|
||||
author='Konsta Vesterinen, Ryan Leckey, Janne Vanhala, Vesa Uimonen',
|
||||
|
@@ -38,7 +38,7 @@ from .types import (
|
||||
)
|
||||
|
||||
|
||||
__version__ = '0.16.23'
|
||||
__version__ = '0.16.24'
|
||||
|
||||
|
||||
__all__ = (
|
||||
|
@@ -4,10 +4,20 @@ from sqlalchemy.dialects.postgresql.base import ischema_names
|
||||
|
||||
class TSVectorType(sa.types.UserDefinedType):
|
||||
class comparator_factory(sa.types.TypeEngine.Comparator):
|
||||
def match(self, other):
|
||||
from sqlalchemy_utils.expressions import tsvector_match
|
||||
def match_tsquery(self, other, catalog=None):
|
||||
from sqlalchemy_utils.expressions import tsvector_match, to_tsquery
|
||||
|
||||
return tsvector_match(self.expr, other)
|
||||
args = []
|
||||
if catalog:
|
||||
args.append(catalog)
|
||||
elif self.type.options.get('catalog'):
|
||||
args.append(self.type.options.get('catalog'))
|
||||
args.append(other)
|
||||
|
||||
return tsvector_match(
|
||||
self.expr,
|
||||
to_tsquery(*args)
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""
|
||||
|
@@ -38,6 +38,15 @@ class TestTSVector(TestCase):
|
||||
assert type_.options['catalog'] == 'pg_catalog.simple'
|
||||
|
||||
def test_match(self):
|
||||
assert six.text_type(self.User.search_index.match(u'something')) == (
|
||||
'("user".search_index) @@ :tsvector_match_1'
|
||||
expr = self.User.search_index.match_tsquery(u'something')
|
||||
assert six.text_type(expr) == (
|
||||
'("user".search_index) @@ to_tsquery(:to_tsquery_1)'
|
||||
)
|
||||
|
||||
def test_match_with_catalog(self):
|
||||
expr = self.User.search_index.match_tsquery(
|
||||
u'something', catalog='pg_catalog.simple'
|
||||
)
|
||||
assert six.text_type(expr) == (
|
||||
'("user".search_index) @@ to_tsquery(:to_tsquery_1, :to_tsquery_2)'
|
||||
)
|
||||
|
Reference in New Issue
Block a user