3
a                 @   sx   d dl mZ d dl mZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dlm
Z
 G d	d
 d
e
ejZdS )   )exc)util)	coercions)elements)	operators)roles)_generative)
Generativec                   sL   e Zd ZdZdZdZ fddZedd Zedd	 Z	ed
d Z
  ZS )matcha[  Produce a ``MATCH (X, Y) AGAINST ('TEXT')`` clause.

    E.g.::

        from sqlalchemy import desc
        from sqlalchemy.dialects.mysql import match

        match_expr = match(
            users_table.c.firstname,
            users_table.c.lastname,
            against="Firstname Lastname",
        )

        stmt = (
            select(users_table)
            .where(match_expr.in_boolean_mode())
            .order_by(desc(match_expr))
        )

    Would produce SQL resembling::

        SELECT id, firstname, lastname
        FROM user
        WHERE MATCH(firstname, lastname) AGAINST (:param_1 IN BOOLEAN MODE)
        ORDER BY MATCH(firstname, lastname) AGAINST (:param_2) DESC

    The :func:`_mysql.match` function is a standalone version of the
    :meth:`_sql.ColumnElement.match` method available on all
    SQL expressions, as when :meth:`_expression.ColumnElement.match` is
    used, but allows to pass multiple columns

    :param cols: column expressions to match against

    :param against: expression to be compared towards

    :param in_boolean_mode: boolean, set "boolean mode" to true

    :param in_natural_language_mode: boolean , set "natural language" to true

    :param with_query_expansion: boolean, set "query expansion" to true

    .. versionadded:: 1.4.19

    .. seealso::

        :meth:`_expression.ColumnElement.match`

    Zmysql_matchTc                s   |st jd|jdd }|s(t jdtjtj|}tjj	t
j|d}d|_tj|jdd|jdd|jddd	}|rt jd
dj| tt| j||t
j|d d S )Nzcolumns are requiredagainstzagainst is required)ZclausesFin_boolean_modein_natural_language_modewith_query_expansion)mysql_boolean_modemysql_natural_languagemysql_query_expansionzunknown arguments: %sz, )	modifiers)r   ArgumentErrorpopr   expectr   ZExpressionElementRoler   ZBooleanClauseListZ_construct_rawr   Zcomma_opgroupr   Zimmutabledictjoinsuperr
   __init__Zmatch_op)selfcolskwr   leftflags)	__class__ J/tmp/pip-build-6_cqtusv/SQLAlchemy/sqlalchemy/dialects/mysql/expression.pyr   A   s*    



zmatch.__init__c             C   s   | j jddi| _ dS )zApply the "IN BOOLEAN MODE" modifier to the MATCH expression.

        :return: a new :class:`_mysql.match` instance with modifications
         applied.
        r   TN)r   union)r   r    r    r!   r   e   s    zmatch.in_boolean_modec             C   s   | j jddi| _ dS )zApply the "IN NATURAL LANGUAGE MODE" modifier to the MATCH
        expression.

        :return: a new :class:`_mysql.match` instance with modifications
         applied.
        r   TN)r   r"   )r   r    r    r!   r   o   s    	zmatch.in_natural_language_modec             C   s   | j jddi| _ dS )zApply the "WITH QUERY EXPANSION" modifier to the MATCH expression.

        :return: a new :class:`_mysql.match` instance with modifications
         applied.
        r   TN)r   r"   )r   r    r    r!   r   z   s    zmatch.with_query_expansion)__name__
__module____qualname____doc__Z__visit_name__Zinherit_cacher   r   r   r   r   __classcell__r    r    )r   r!   r
      s   0$
r
   N) r   r   Zsqlr   r   r   r   Zsql.baser   r	   ZBinaryExpressionr
   r    r    r    r!   <module>   s   