
    Pf                        d  Z d(dZd Zd Zd Zd Zd Zd)d	Z G d
 d          Z G d de          Z	 G d de          Z
 G d de          Z G d de          Z G d d          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d  d!e          Zd" Zd# Zd$ Zd% Zd& Zd'S )*c                  6    | 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)ts    S/var/www/html/env/lib/python3.11/site-packages/redis/commands/search/querystring.pytagsr      s%      ?=>>>Q<    Tc                 (    t          | |||          S )z0
    Indicate that value is a numeric range
    )inclusive_mininclusive_max)
RangeValue)abr
   r   s       r   betweenr      s     a-}UUUUr   c                 "    t          | |           S )z
    Match a numeric value
    r   ns    r   equalr      s     1a==r   c                 &    t          d| d          S )z%
    Match any value less than n
    NFr   r   r   s    r   ltr      s     4%0000r   c                 &    t          d| d          S )z,
    Match any value less or equal to n
    NTr   r   r   s    r   ler   #   s     4$////r   c                 &    t          | dd          S )z(
    Match any value greater than n
    NFr
   r   r   s    r   gtr   *   s     1d%0000r   c                 &    t          | dd          S )z/
    Match any value greater or equal to n
    NTr   r   r   s    r   ger   1   s     1d$////r   kmc                 &    t          | |||          S )z-
    Indicate that value is a geo region
    )GeoValue)latlonradiusunits       r   geor&   8   s     Cfd+++r   c                   F    e Zd Zed             Zed             Zd Zd ZdS )Valuec                     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
        F selfs    r   
combinablezValue.combinable@   s	     ur   c                 N    t          | t                    r| S t          |           S )zL
        Convert an object to a value, if it is not a value already
        )
isinstancer(   ScalarValuevs    r   
make_valuezValue.make_valueH   s'    
 a 	H1~~r   c                     t                      NNotImplementedErrorr+   s    r   	to_stringzValue.to_stringQ   s    !###r   c                 *    |                                  S r5   r8   r+   s    r   __str__zValue.__str__T       ~~r   N)	__name__
__module____qualname__propertyr-   staticmethodr3   r8   r;   r*   r   r   r(   r(   ?   sf          X   \$ $ $         r   r(   c                        e Zd ZdZddZd ZdS )r   Fc                 x    |d}|d}t          |          t          |          g| _        || _        || _        d S )Nz-infinf)strranger
   r   )r,   r   r   r
   r   s        r   __init__zRangeValue.__init__[   sD    9A9A!ffc!ff%
**r   c                 ^    d                     | j        | j        sdnd| j        sdnd          S )Nz[{1}{0[0]} {2}{0[1]}]( )formatrF   r
   r   r+   s    r   r8   zRangeValue.to_stringd   s=    &--J)1CCr)1CCr
 
 	
r   N)FFr=   r>   r?   r-   rG   r8   r*   r   r   r   r   X   s<        J+ + + +
 
 
 
 
r   r   c                       e Zd ZdZd Zd ZdS )r0   Tc                 .    t          |          | _        d S r5   )rE   r2   )r,   r2   s     r   rG   zScalarValue.__init__o   s    Qr   c                     | j         S r5   r1   r+   s    r   r8   zScalarValue.to_stringr   	    vr   NrL   r*   r   r   r0   r0   l   s7        J      r   r0   c                       e Zd ZdZd Zd ZdS )r   Fc                     || _         d S r5   )r   )r,   r   s     r   rG   zTagValue.__init__y   s    			r   c                 V    dd                     d | j        D                       z   dz   S )N{z | c              3   4   K   | ]}t          |          V  d S r5   )rE   ).0r   s     r   	<genexpr>z%TagValue.to_string.<locals>.<genexpr>}   s(      ::1A::::::r   })joinr   r+   s    r   r8   zTagValue.to_string|   s/    UZZ::	::::::S@@r   NrL   r*   r   r   r   r   v   s<        J  A A A A Ar   r   c                       e Zd ZddZd ZdS )r!   r   c                 >    || _         || _        || _        || _        d S r5   r#   r"   r$   r%   )r,   r#   r"   r$   r%   s        r   rG   zGeoValue.__init__   s"    			r   c           	      H    d| j          d| j         d| j         d| j         d	S )N[ ]r\   r+   s    r   r8   zGeoValue.to_string   s3    C48CCdhCCCCtyCCCCr   Nr   )r=   r>   r?   rG   r8   r*   r   r   r!   r!      s<           D D D D Dr   r!   c                   Z    e Zd Zd Zd Zed             Zed             Zd	dZ	d Z
d ZdS )
Nodec                 p   g | _         i }|                                D ]\  }}|                    |g           }t          |t          t
          t          f          r.|                    t          	                    |                     kt          |t                    r|                    |           |
                    d |D                        | xj         d |D             z  c_         |                                D ]3\  }}| j         
                    |                     ||                     4d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              3   J   K   | ]}t                               |          V  d S r5   )r(   r3   )rV   subvs     r   rW   z Node.__init__.<locals>.<genexpr>   s0      DD$u//55DDDDDDr   c                 B    g | ]}t                               |          S r*   )rc   to_node)rV   ps     r   
<listcomp>z!Node.__init__.<locals>.<listcomp>   s"    :::AQ:::r   N)paramsitems
setdefaultr/   rE   intfloatappendr(   r3   extendjoin_fields)r,   childrenkwparamskvparamskr2   curvalss          r   rG   zNode.__init__   s=   V NN$$ 	E 	EDAq))!R00G!c3.// Eu//223333Au%% Eq!!!!DD!DDDDDDD::::::NN$$ 	7 	7DAqKt//1556666	7 	7r   c           	      2   t          |          dk    r.t          d d|d                                                    gS |d         j        sfd|D             S t          d d| j                            d |D                        d          }|gS )	N   @:    c           	      ^    g | ])}t          d  d|                                           *S )rz   r{   )BaseNoder8   )rV   r2   keys     r   rj   z$Node.join_fields.<locals>.<listcomp>   s:    FFFAH666q{{}}6677FFFr   z:(c              3   >   K   | ]}|                                 V  d S r5   r:   )rV   r2   s     r   rW   z#Node.join_fields.<locals>.<genexpr>   s*      1N1NA!++--1N1N1N1N1N1Nr   ))lenr~   r8   r-   JOINSTRrY   )r,   r   valsss    `  r   rr   zNode.join_fields   s    t99>><<<tAw'8'8':':<<==>>Aw! 	GFFFFFFFFQQQ 1 11N1N1N1N1N N NQQQRRs
r   c                 N    t          |t                    r|S t          |          S r5   )r/   rc   r~   )clsobjs     r   rh   zNode.to_node   s%    c4   	J}}r   c                     t                      r5   r6   r+   s    r   r   zNode.JOINSTR   s    !###r   Nc                     |                      |          }|rdnd\  }}| | j                            d | j        D                        | S )N)rI   r   )rJ   rJ   c              3   >   K   | ]}|                                 V  d S r5   r:   )rV   r   s     r   rW   z!Node.to_string.<locals>.<genexpr>   s*      (L(L1(L(L(L(L(L(Lr   )_should_use_parenr   rY   rk   )r,   with_parenspreposts       r   r8   zNode.to_string   s^    ,,[99"-;JJ8	TTt|(((L(L(L(L(LLLTdTTTr   c                 :    ||S t          | j                  dk    S )Nry   )r   rk   )r,   optvals     r   r   zNode._should_use_paren   s"    M4;!##r   c                 *    |                                  S r5   r:   r+   s    r   r;   zNode.__str__   r<   r   r5   )r=   r>   r?   rG   rr   classmethodrh   r@   r   r8   r   r;   r*   r   r   rc   rc      s        :7 :7 :7x     [
 $ $ X$U U U U
$ $ $
         r   rc   c                   &     e Zd Z fdZddZ xZS )r~   c                 p    t                                                       t          |          | _        d S r5   )superrG   rE   r   )r,   r   	__class__s     r   rG   zBaseNode.__init__   s*    Qr   Nc                     | j         S r5   )r   )r,   r   s     r   r8   zBaseNode.to_string   rP   r   r5   )r=   r>   r?   rG   r8   __classcell__r   s   @r   r~   r~      sL                   r   r~   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
    r_   Nr=   r>   r?   __doc__r   r*   r   r   r   r               
 GGGr   r   c                       e Zd ZdZdZdS )	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   r   c                   $     e Zd ZdZd fd	Z xZS )DisjunctNodezs
    Create a disjunct node. In order for this node to be true, all of its
    children must evaluate to false
    Nc                     |                      |          }t                                          d          }|rd|z   dz   S d|z   S )NFr   z(-r   -r   r   r8   r,   r   retr   s      r   r8   zDisjunctNode.to_string	  Q    ,,[99ggE22 	#:##9r   r5   r=   r>   r?   r   r8   r   r   s   @r   r   r     G         
         r   r   c                       e Zd ZdZdZdS )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          GGGr   r   c                   $     e Zd ZdZd fd	Z xZS )OptionalNodez}
    Create an optional node. If this nodes evaluates to true, then the document
    will be rated higher in score/rank.
    Nc                     |                      |          }t                                          d          }|rd|z   dz   S d|z   S )NFr   z(~r   ~r   r   s      r   r8   zOptionalNode.to_string#  r   r   r5   r   r   s   @r   r   r     r   r   r   c                      t          | i |S r5   )r   argskwargss     r   	intersectr   ,  s    $)&)))r   c                      t          | i |S r5   )r   r   s     r   unionr   0  s    d%f%%%r   c                      t          | i |S r5   )r   r   s     r   disjunctr   4  s    ((((r   c                      t          | i |S r5   )r   r   s     r   disjunct_unionr   8  s    4*6***r   c                  >    t          | i |                                S r5   )r   r8   r   s     r   querystringr   <  s!    d%f%%//111r   N)TTra   )r   r   r   r   r   r   r   r&   r(   r   r0   r   r!   rc   r~   r   r   r   r   r   r   r   r   r   r   r*   r   r   <module>r      s  
 
 
V V V V  1 1 10 0 01 1 10 0 0, , , ,               2
 
 
 
 
 
 
 
(    %   A A A A Au A A AD D D D Du D D DZ  Z  Z  Z  Z  Z  Z  Z z    t       D              =       \       =   * * *& & &) ) )+ + +2 2 2 2 2r   