o
    Š¨Êh­  ã                   @   s,  d d„ Z d5dd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Zd6dd„ZG dd„ dƒZG dd„ deƒZ	G dd„ deƒZ
G dd„ deƒZG dd„ deƒZG dd„ dƒZG dd„ deƒZG d d!„ d!eƒZG d"d#„ d#eƒZG d$d%„ d%eƒZG d&d'„ d'eƒZG d(d)„ d)eƒZd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4S )7c                  G   s   | st dƒ‚t| Ž S )zx
    Indicate that the values should be matched to a tag field

    ### Parameters

    - **t**: Tags to search for
    z"At least one tag must be specified)Ú
ValueErrorÚTagValue)Út© r   úS/var/www/html/env/lib/python3.10/site-packages/redis/commands/search/querystring.pyÚtags   s   r   Tc                 C   s   t | |||d�S )z0
    Indicate that value is a numeric range
    )Úinclusive_minÚinclusive_max)Ú
RangeValue)ÚaÚbr   r   r   r   r   Úbetween   s   r   c                 C   s
   t | | ƒS )z
    Match a numeric value
    ©r   ©Únr   r   r   Úequal   s   
r   c                 C   ó   t d| dd�S )z%
    Match any value less than n
    NF©r   r   r   r   r   r   Últ   ó   r   c                 C   r   )z,
    Match any value less or equal to n
    NTr   r   r   r   r   r   Úle#   r   r   c                 C   ó   t | ddd�S )z(
    Match any value greater than n
    NF©r   r   r   r   r   r   Úgt*   r   r   c                 C   r   )z/
    Match any value greater or equal to n
    NTr   r   r   r   r   r   Úge1   r   r   Úkmc                 C   s   t | |||ƒS )z-
    Indicate that value is a geo region
    )ÚGeoValue)ÚlatÚlonÚradiusÚunitr   r   r   Úgeo8   r   r    c                   @   s4   e Zd Zedd„ ƒZedd„ ƒZdd„ Zdd„ Zd	S )
ÚValuec                 C   s   dS )z›
        Whether this type of value may be combined with other values
        for the same field. This makes the filter potentially more efficient
        Fr   ©Úselfr   r   r   Ú
combinable@   s   zValue.combinablec                 C   s   t | tƒr| S t| ƒS )zL
        Convert an object to a value, if it is not a value already
        )Ú
isinstancer!   ÚScalarValue©Úvr   r   r   Ú
make_valueH   s   
zValue.make_valuec                 C   ó   t ƒ ‚©N©ÚNotImplementedErrorr"   r   r   r   Ú	to_stringQ   ó   zValue.to_stringc                 C   ó   |   ¡ S r+   ©r.   r"   r   r   r   Ú__str__T   ó   zValue.__str__N)	Ú__name__Ú
__module__Ú__qualname__Úpropertyr$   Ústaticmethodr)   r.   r2   r   r   r   r   r!   ?   s    

r!   c                   @   s"   e Zd ZdZddd„Zdd„ ZdS )r	   Fc                 C   s:   |d u rd}|d u rd}t |ƒt |ƒg| _|| _|| _d S )Nz-infÚinf)ÚstrÚranger   r   )r#   r
   r   r   r   r   r   r   Ú__init__[   s   
zRangeValue.__init__c                 C   s&   d  | j| js	dnd| jsd¡S d¡S )Nz[{1}{0[0]} {2}{0[1]}]ú(Ú )Úformatr;   r   r   r"   r   r   r   r.   d   s   ýýzRangeValue.to_stringN)FF©r4   r5   r6   r$   r<   r.   r   r   r   r   r	   X   s    
	r	   c                   @   ó    e Zd ZdZdd„ Zdd„ ZdS )r&   Tc                 C   s   t |ƒ| _d S r+   )r:   r(   )r#   r(   r   r   r   r<   o   ó   zScalarValue.__init__c                 C   ó   | j S r+   r'   r"   r   r   r   r.   r   r/   zScalarValue.to_stringNr@   r   r   r   r   r&   l   ó    r&   c                   @   rA   )r   Fc                 G   s
   || _ d S r+   )r   )r#   r   r   r   r   r<   y   s   
zTagValue.__init__c                 C   s   dd  dd„ | jD ƒ¡ d S )NÚ{z | c                 s   s   � | ]}t |ƒV  qd S r+   )r:   )Ú.0r   r   r   r   Ú	<genexpr>}   ó   € z%TagValue.to_string.<locals>.<genexpr>Ú})Újoinr   r"   r   r   r   r.   |   s   zTagValue.to_stringNr@   r   r   r   r   r   v   rD   r   c                   @   s   e Zd Zddd„Zdd„ ZdS )r   r   c                 C   s   || _ || _|| _|| _d S r+   ©r   r   r   r   )r#   r   r   r   r   r   r   r   r<   �   s   
zGeoValue.__init__c              	   C   s&   d| j › d| j› d| j› d| j› d�	S )Nú[ú ú]rK   r"   r   r   r   r.   ‡   s   &zGeoValue.to_stringN©r   )r4   r5   r6   r<   r.   r   r   r   r   r   €   s    
r   c                   @   sN   e Zd Zdd„ Zdd„ Zedd„ ƒZedd„ ƒZdd
d„Z	dd„ Z
dd„ Zd	S )ÚNodec                 O   s¶   g | _ i }| ¡ D ]0\}}| |g ¡}t|tttfƒr$| t 	|¡¡ q	t|tƒr/| |¡ q	| 
dd„ |D ƒ¡ q	|  j dd„ |D ƒ7  _ | ¡ D ]\}}| j  
|  ||¡¡ qJdS )a†  
        Create a node

        ### Parameters

        - **children**: One or more sub-conditions. These can be additional
            `intersect`, `disjunct`, `union`, `optional`, or any other `Node`
            type.

            The semantics of multiple conditions are dependent on the type of
            query. For an `intersection` node, this amounts to a logical AND,
            for a `union` node, this amounts to a logical `OR`.

        - **kwparams**: key-value parameters. Each key is the name of a field,
            and the value should be a field value. This can be one of the
            following:

            - Simple string (for text field matches)
            - value returned by one of the helper functions
            - list of either a string or a value


        ### Examples

        Field `num` should be between 1 and 10
        ```
        intersect(num=between(1, 10)
        ```

        Name can either be `bob` or `john`

        ```
        union(name=("bob", "john"))
        ```

        Don't select countries in Israel, Japan, or US

        ```
        disjunct_union(country=("il", "jp", "us"))
        ```
        c                 s   s   � | ]}t  |¡V  qd S r+   )r!   r)   )rF   Úsubvr   r   r   rG   Á   s   € z Node.__init__.<locals>.<genexpr>c                 S   s   g | ]}t  |¡‘qS r   )rP   Úto_node)rF   Úpr   r   r   Ú
<listcomp>Ã   s    z!Node.__init__.<locals>.<listcomp>N)ÚparamsÚitemsÚ
setdefaultr%   r:   ÚintÚfloatÚappendr!   r)   ÚextendÚjoin_fields)r#   ÚchildrenÚkwparamsÚkvparamsÚkr(   Úcurvalsr   r   r   r<   Œ   s   +
ÿzNode.__init__c                    st   t |ƒdkrtdˆ › d|d  ¡ › �ƒgS |d js#‡ fdd„|D ƒS tdˆ › d| j dd	„ |D ƒ¡› d
�ƒ}|gS )Né   ú@ú:é    c                    s$   g | ]}t d ˆ › d| ¡ › �ƒ‘qS )rc   rd   )ÚBaseNoder.   ©rF   r(   ©Úkeyr   r   rT   Ì   s   $ z$Node.join_fields.<locals>.<listcomp>z:(c                 s   ó   � | ]}|  ¡ V  qd S r+   r1   rg   r   r   r   rG   Í   rH   z#Node.join_fields.<locals>.<genexpr>ú))Úlenrf   r.   r$   ÚJOINSTRrJ   )r#   ri   ÚvalsÚsr   rh   r   r\   È   s   
(zNode.join_fieldsc                 C   s   t |tƒr|S t|ƒS r+   )r%   rP   rf   )ÚclsÚobjr   r   r   rR   Ð   s   
zNode.to_nodec                 C   r*   r+   r,   r"   r   r   r   rm   Ö   s   zNode.JOINSTRNc                 C   s>   |   |¡}|r	dnd\}}|› | j dd„ | jD ƒ¡› |› �S )N)r=   rk   )r>   r>   c                 s   rj   r+   r1   )rF   r   r   r   r   rG   Ý   rH   z!Node.to_string.<locals>.<genexpr>)Ú_should_use_parenrm   rJ   rU   )r#   Úwith_parensÚpreÚpostr   r   r   r.   Ú   s   
$zNode.to_stringc                 C   s   |d ur|S t | jƒdkS )Nrb   )rl   rU   )r#   Úoptvalr   r   r   rr   ß   s   zNode._should_use_parenc                 C   r0   r+   r1   r"   r   r   r   r2   ä   r3   zNode.__str__r+   )r4   r5   r6   r<   r\   ÚclassmethodrR   r7   rm   r.   rr   r2   r   r   r   r   rP   ‹   s    <


rP   c                       s&   e Zd Z‡ fdd„Zddd„Z‡  ZS )rf   c                    s   t ƒ  ¡  t|ƒ| _d S r+   )Úsuperr<   r:   ro   )r#   ro   ©Ú	__class__r   r   r<   é   s   
zBaseNode.__init__Nc                 C   rC   r+   )ro   )r#   rs   r   r   r   r.   í   r/   zBaseNode.to_stringr+   )r4   r5   r6   r<   r.   Ú__classcell__r   r   ry   r   rf   è   s    rf   c                   @   ó   e Zd ZdZdZdS )ÚIntersectNodezw
    Create an intersection node. All children need to be satisfied in order for
    this node to evaluate as true
    rM   N©r4   r5   r6   Ú__doc__rm   r   r   r   r   r}   ñ   ó    r}   c                   @   r|   )Ú	UnionNodezv
    Create a union node. Any of the children need to be satisfied in order for
    this node to evaluate as true
    ú|Nr~   r   r   r   r   r�   ú   r€   r�   c                       ó"   e Zd ZdZd‡ fdd„	Z‡  ZS )ÚDisjunctNodezs
    Create a disjunct node. In order for this node to be true, all of its
    children must evaluate to false
    Nc                    ó0   |   |¡}tƒ jdd�}|rd| d S d| S )NF©rs   z(-rk   ú-©rr   rx   r.   ©r#   rs   Úretry   r   r   r.   	  ó
   
zDisjunctNode.to_stringr+   ©r4   r5   r6   r   r.   r{   r   r   ry   r   r„     ó    r„   c                   @   r|   )ÚDistjunctUnionz~
    This node is true if *all* of its children are false. This is equivalent to
    ```
    disjunct(union(...))
    ```
    r‚   Nr~   r   r   r   r   rŽ     s    rŽ   c                       rƒ   )ÚOptionalNodez}
    Create an optional node. If this nodes evaluates to true, then the document
    will be rated higher in score/rank.
    Nc                    r…   )NFr†   z(~rk   ú~rˆ   r‰   ry   r   r   r.   #  r‹   zOptionalNode.to_stringr+   rŒ   r   r   ry   r   r�     r�   r�   c                  O   ó   t | i |¤ŽS r+   )r}   ©ÚargsÚkwargsr   r   r   Ú	intersect,  rB   r•   c                  O   r‘   r+   )r�   r’   r   r   r   Úunion0  rB   r–   c                  O   r‘   r+   )r„   r’   r   r   r   Údisjunct4  rB   r—   c                  O   r‘   r+   )rŽ   r’   r   r   r   Údisjunct_union8  rB   r˜   c                  O   s   t | i |¤Ž ¡ S r+   )r•   r.   r’   r   r   r   Úquerystring<  s   r™   N)TTrO   )r   r   r   r   r   r   r   r    r!   r	   r&   r   r   rP   rf   r}   r�   r„   rŽ   r�   r•   r–   r—   r˜   r™   r   r   r   r   Ú<module>   s2    



]			