
    +h                     Z   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y%)(c                  ,    | 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    T/var/www/html/venv/lib/python3.12/site-packages/redis/commands/search/querystring.pytagsr      s     =>>Q<    c                      t        | |||      S )z0
    Indicate that value is a numeric range
    )inclusive_mininclusive_max)
RangeValue)abr
   r   s       r   betweenr      s     a-}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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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   c                     t        | |||      S )z-
    Indicate that value is a geo region
    )GeoValue)latlonradiusunits       r   geor%   8   s     Cfd++r   c                   8    e Zd Zed        Zed        Zd Zd Zy)Valuec                      y)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     r   c                 <    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                 "    | j                         S r4   r7   r*   s    r   __str__zValue.__str__T       ~~r   N)	__name__
__module____qualname__propertyr,   staticmethodr2   r7   r:   r)   r   r   r'   r'   ?   s2       $ r   r'   c                       e Zd ZdZddZd Zy)r   Fc                 f    |d}|d}t        |      t        |      g| _        || _        || _        y )Nz-infinf)strranger
   r   )r+   r   r   r
   r   s        r   __init__zRangeValue.__init__[   s:    9A9A!fc!f%
**r   c                 |    dj                  | j                  | j                  sdnd| j                  sd      S d      S )Nz[{1}{0[0]} {2}{0[1]}]( )formatrE   r
   r   r*   s    r   r7   zRangeValue.to_stringd   sC    &--JJ))Cr))C
 	
 02
 	
r   N)FFr<   r=   r>   r,   rF   r7   r)   r   r   r   r   X   s    J+
r   r   c                       e Zd ZdZd Zd Zy)r/   Tc                 $    t        |      | _        y r4   )rD   r1   )r+   r1   s     r   rF   zScalarValue.__init__o   s    Qr   c                     | j                   S r4   r0   r*   s    r   r7   zScalarValue.to_stringr       vvr   NrK   r)   r   r   r/   r/   l   s    Jr   r/   c                       e Zd ZdZd Zd Zy)r   Fc                     || _         y r4   )r   )r+   r   s     r   rF   zTagValue.__init__y   s	    	r   c                 R    ddj                  d | j                  D              z   dz   S )N{z | c              3   2   K   | ]  }t        |        y wr4   )rD   ).0r   s     r   	<genexpr>z%TagValue.to_string.<locals>.<genexpr>}   s     :1A:s   })joinr   r*   s    r   r7   zTagValue.to_string|   s%    UZZ:		:::S@@r   NrK   r)   r   r   r   r   v   s    JAr   r   c                       e Zd ZddZd Zy)r    c                 <    || _         || _        || _        || _        y r4   r"   r!   r#   r$   )r+   r"   r!   r#   r$   s        r   rF   zGeoValue.__init__   s    	r   c           	      p    d| j                    d| j                   d| j                   d| j                   d	S )N[ ]r[   r*   s    r   r7   zGeoValue.to_string   s3    488*AdhhZqQtyykCCr   Nkm)r<   r=   r>   rF   r7   r)   r   r   r    r       s    Dr   r    c                   L    e Zd Zd Zd Zed        Zed        Zd	dZ	d Z
d Zy)
Nodec                 Z   g | _         i }|j                         D ]  \  }}|j                  |g       }t        |t        t
        t        f      r%|j                  t        j                  |             Xt        |t              r|j                  |       z|j                  d |D                | xj                   |D cg c]  }t        j                  |       c}z  c_         |j                         D ]0  \  }}| j                   j                  | j                  ||             2 yc c}w )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   F   K   | ]  }t         j                  |        y wr4   )r'   r2   )rU   subvs     r   rV   z Node.__init__.<locals>.<genexpr>   s     D$u//5Ds   !N)paramsitems
setdefaultr.   rD   intfloatappendr'   r2   extendrc   to_nodejoin_fields)r+   childrenkwparamskvparamskr1   curvalsps           r   rF   zNode.__init__   s    V NN$ 	EDAq))!R0G!c3./u//23Au%q!D!DD	E 	:AQ::NN$ 	7DAqKKt//156	7 ;s   >D(c           
      P   t        |      dk(  r#t        d| d|d   j                                gS |d   j                  s-|D cg c]!  }t        d| d|j                                # c}S t        d| d| j                  j                  d |D               d      }|gS c c}w )N   @:    z:(c              3   <   K   | ]  }|j                           y wr4   r9   )rU   r1   s     r   rV   z#Node.join_fields.<locals>.<genexpr>   s     1NA!++-1N   ))lenBaseNoder7   r,   JOINSTRrX   )r+   keyvalsr1   ss        r   ro   zNode.join_fields   s    t9>qQtAw'8'8':&;<=>>Aw!!AEFAHqQq{{}o67FFqR 1 11N1N NOqQRs
 Gs   &B#c                 <    t        |t              r|S t        |      S r4   )r.   rc   r   )clsobjs     r   rn   zNode.to_node   s    c4 J}r   c                     t               r4   r5   r*   s    r   r   zNode.JOINSTR   s    !##r   Nc                     | j                  |      }|rdnd\  }}| | j                  j                  d | j                  D               | S )N)rH   r}   )rI   rI   c              3   <   K   | ]  }|j                           y wr4   r9   )rU   r   s     r   rV   z!Node.to_string.<locals>.<genexpr>   s     (L1(Lr|   )_should_use_parenr   rX   rg   )r+   with_parenspreposts       r   r7   zNode.to_string   sL    ,,[9"-J8	Tt||(((L(LLMdVTTr   c                 :    ||S t        | j                        dkD  S )Nrw   )r~   rg   )r+   optvals     r   r   zNode._should_use_paren   s!    M4;;!##r   c                 "    | j                         S r4   r9   r*   s    r   r:   zNode.__str__   r;   r   r4   )r<   r=   r>   rF   ro   classmethodrn   r?   r   r7   r   r:   r)   r   r   rc   rc      sE    :7x  
 $ $U
$
 r   rc   c                   &     e Zd Z fdZddZ xZS )r   c                 B    t         |           t        |      | _        y r4   )superrF   rD   r   )r+   r   	__class__s     r   rF   zBaseNode.__init__   s    Qr   c                     | j                   S r4   )r   )r+   r   s     r   r7   zBaseNode.to_string   rO   r   r4   )r<   r=   r>   rF   r7   __classcell__r   s   @r   r   r      s    r   r   c                       e Zd ZdZdZy)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          
 Gr   r   c                       e Zd ZdZdZy)	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
    c                 d    | j                  |      }t        | 	  d      }|rd|z   dz   S d|z   S )NFr   z(-r}   -r   r   r7   r+   r   retr   s      r   r7   zDisjunctNode.to_string	  A    ,,[9gE2#:##9r   r4   r<   r=   r>   r   r7   r   r   s   @r   r   r         
 r   r   c                       e Zd ZdZdZy)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     Gr   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.
    c                 d    | j                  |      }t        | 	  d      }|rd|z   dz   S d|z   S )NFr   z(~r}   ~r   r   s      r   r7   zOptionalNode.to_string#  r   r   r4   r   r   s   @r   r   r     r   r   r   c                      t        | i |S r4   )r   argskwargss     r   	intersectr   ,  s    $)&))r   c                      t        | i |S r4   )r   r   s     r   unionr   0  s    d%f%%r   c                      t        | i |S r4   )r   r   s     r   disjunctr   4  s    (((r   c                      t        | i |S r4   )r   r   s     r   disjunct_unionr   8  s    4*6**r   c                  4    t        | i |j                         S r4   )r   r7   r   s     r   querystringr   <  s    d%f%//11r   N)TTr`   )r   r   r   r   r   r   r   r%   r'   r   r/   r   r    rc   r   r   r   r   r   r   r   r   r   r   r   r)   r   r   <module>r      s   
V1010,   2
 
(% Au ADu DZ  Z zt D  = \ = *&)+2r   