U
    ]g%i‘  ã                   @  s    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 dd
lmZ ddlmZ ddlmZ G dd„ dee	je ƒZdS )é    )Úannotations)ÚAnyé   )Úexc)Úutil)Ú	coercions)Úelements)Ú	operators)Úroles)Ú_generative)Ú
Generative)ÚSelfc                      sp   e Zd ZU dZdZdZded< dddœ‡ fd	d
„Zeddœdd„ƒZ	eddœdd„ƒZ
eddœdd„ƒZ‡  ZS )Úmatchas  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:

    .. sourcecode:: sql

        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_matchTzutil.immutabledict[str, Any]Ú	modifierszelements.ColumnElement[Any]r   )ÚcolsÚkwc                   s®   |st  d¡‚| dd ¡}|d kr,t  d¡‚t tj|¡}tjj	t
j|d}d|_t | dd¡| dd¡| dd¡d	œ¡}|r”t  d
d |¡ ¡‚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, )r   )r   ÚArgumentErrorÚpopr   Úexpectr
   ZExpressionElementRoler   ZBooleanClauseListZ_construct_rawr	   Zcomma_opÚgroupr   ZimmutabledictÚjoinÚsuperÚ__init__Zmatch_op)Úselfr   r   r   ÚleftÚflags©Ú	__class__© úc/var/www/html/api-medvista/venv/lib/python3.8/site-packages/sqlalchemy/dialects/mysql/expression.pyr   P   s4    

þþ
 ÿ
ûÿ
zmatch.__init__r   )Úreturnc                 C  s   | j  ddi¡| _ | S )z¢Apply the "IN BOOLEAN MODE" modifier to the MATCH expression.

        :return: a new :class:`_mysql.match` instance with modifications
         applied.
        r   T©r   Úunion©r    r%   r%   r&   r   r   s    zmatch.in_boolean_modec                 C  s   | j  ddi¡| _ | S )z³Apply the "IN NATURAL LANGUAGE MODE" modifier to the MATCH
        expression.

        :return: a new :class:`_mysql.match` instance with modifications
         applied.
        r   Tr(   r*   r%   r%   r&   r   }   s    	zmatch.in_natural_language_modec                 C  s   | j  ddi¡| _ | S )z§Apply the "WITH QUERY EXPANSION" modifier to the MATCH expression.

        :return: a new :class:`_mysql.match` instance with modifications
         applied.
        r   Tr(   r*   r%   r%   r&   r   ‰   s    zmatch.with_query_expansion)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Z__visit_name__Zinherit_cacheÚ__annotations__r   r   r   r   r   Ú__classcell__r%   r%   r#   r&   r      s   
3"
r   N)Ú
__future__r   Útypingr   Ú r   r   Úsqlr   r   r	   r
   Zsql.baser   r   Zutil.typingr   ZBinaryExpressionr   r%   r%   r%   r&   Ú<module>   s   