
    keJi:-                        d dl mZmZmZmZ d dlmZ  e            Z G d d          Z	 G d d          Z
 G d d          Z G d	 d
e          Z G d de          Z G d d          Z G d d          Z G d d          ZdS )    )ListOptionalTupleUnion)DEFAULT_DIALECTc                   *    e Zd ZddededdfdZd ZdS )	Limitr   offsetcountreturnNc                 "    || _         || _        d S N)r
   r   )selfr
   r   s      g/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/redis/commands/search/aggregation.py__init__zLimit.__init__	   s    


    c                 f    | j         r)dt          | j                  t          | j                   gS g S )NLIMIT)r   strr
   r   s    r   
build_argszLimit.build_args   s0    : 	S--s4:??Ir   )r   r   __name__
__module____qualname__intr   r    r   r   r	   r	      sQ         s s 4        r   r	   c                   b    e Zd ZdZdZdeddfdZdedd fdZede	edf         fd	            Z
dS )
Reducerzr
    Base reducer object for all reducers.

    See the `redisearch.reducers` module for the actual reducers.
    Nargsr   c                 0    || _         d | _        d | _        d S r   )_args_field_aliasr   r    s     r   r   zReducer.__init__   s    &*
%)%)r   aliasc                 p    |t           u r%| j        st          d          | j        dd         }|| _        | S )a  
        Set the alias for this reducer.

        ### Parameters

        - **alias**: The value of the alias for this reducer. If this is the
            special value `aggregation.FIELDNAME` then this reducer will be
            aliased using the same name as the field upon which it operates.
            Note that using `FIELDNAME` is only possible on reducers which
            operate on a single field value.

        This method returns the `Reducer` object making it suitable for
        chaining.
        z(Cannot use FIELDNAME alias with no field   N)	FIELDNAMEr#   
ValueErrorr$   )r   r&   s     r   r&   zReducer.alias"   sE     I; ( !KLLL ABBr   .c                     | j         S r   )r"   r   s    r   r    zReducer.args:   s
    zr   )r   r   r   __doc__NAMEr   r   r&   propertyr   r    r   r   r   r   r      s          D*c *d * * * *
3 9    0 eCHo    X  r   r   c                   >    e Zd ZU dZdZee         ed<   deddfdZdS )SortDirectionz@
    This special class is used to indicate sort direction.
    N	DIRSTRINGfieldr   c                     || _         d S r   )r2   )r   r2   s     r   r   zSortDirection.__init__F   s    


r   )	r   r   r   r,   r1   r   r   __annotations__r   r   r   r   r0   r0   ?   sX            $Ix}###c d      r   r0   c                       e Zd ZdZdZdS )AsczK
    Indicate that the given field should be sorted in ascending order
    ASCNr   r   r   r,   r1   r   r   r   r6   r6   J   s          IIIr   r6   c                       e Zd ZdZdZdS )DesczL
    Indicate that the given field should be sorted in descending order
    DESCNr8   r   r   r   r:   r:   R   s          IIIr   r:   c                   "   e Zd ZdZddeddfdZdedd fdZdeeee         f         d	e	dd fd
Z
d dZdededd fdZdedd fdZdeeee         f         dd fdZd dZd dZdedd fdZd dZd!dededd fdZdee         fdZdedd fdZdS )"AggregateRequestzH
    Aggregation request which can be passed to `Client.aggregate`.
    *queryr   Nc                     || _         g | _        g | _        d| _        d| _        d| _        d| _        g | _        t          | _	        d| _
        d| _        dS )a}  
        Create an aggregation request. This request may then be passed to
        `client.aggregate()`.

        In order for the request to be usable, it must contain at least one
        group.

        - **query** Query string for filtering records.

        All member methods (except `build_args()`)
        return the object itself, making them useful for chaining.
        Fr   TFIDFN)_query_aggregateplan_loadfields_loadall_max_with_schema	_verbatim_cursorr   _dialect_add_scores_scorer)r   r?   s     r   r   zAggregateRequest.__init___   sY     !)+&(#	"'$"$,!&#r   fieldsc                 N    |r| j                             |           nd| _        | S )aC  
        Indicate the fields to be returned in the response. These fields are
        returned in addition to any others implicitly specified.

        ### Parameters

        - **fields**: If fields not specified, all the fields will be loaded.
        Otherwise, fields should be given in the format of `@field`.
        T)rD   extendrE   )r   rM   s     r   loadzAggregateRequest.loadx   s2      	!##F++++ DMr   reducersc           	      j   t          |t                    r|gn|}dt          t          |                    g|}|D ][}|d|j        t          t          |j                            gz  }|                    |j                   |j        |d|j        gz  }\| j                            |           | S )a|  
        Specify by which fields to group the aggregation.

        ### Parameters

        - **fields**: Fields to group by. This can either be a single string,
            or a list of strings. both cases, the field should be specified as
            `@field`.
        - **reducers**: One or more reducers. Reducers may be found in the
            `aggregation` module.
        GROUPBYREDUCENAS)
isinstancer   lenr-   r    rO   r$   rC   )r   rM   rQ   retreducers        r   group_byzAggregateRequest.group_by   s     (44@&&#c&kk**4V4 	. 	.GHglCGL0A0A,B,BCCCJJw|$$$~)gn--""3'''r   c                     |                                 D ],\  }}d|g}||d|gz  }| j                            |           -| S )aQ  
        Specify one or more projection expressions to add to each result

        ### Parameters

        - **kwexpr**: One or more key-value pairs for a projection. The key is
            the alias for the projection, and the value is the projection
            expression itself, for example `apply(square_root="sqrt(@foo)")`
        APPLYNrU   )itemsrC   rO   )r   kwexprr&   exprrX   s        r   applyzAggregateRequest.apply   s[     "<<>> 	, 	,KE4D/C e}$&&s++++r   r
   numc                 ~    t          ||          }| j                            |                                           | S )a  
        Sets the limit for the most recent group or query.

        If no group has been defined yet (via `group_by()`) then this sets
        the limit for the initial pool of results from the query. Otherwise,
        this limits the number of items operated on from the previous group.

        Setting a limit on the initial search results may be useful when
        attempting to execute an aggregation on a sample of a large data set.

        ### Parameters

        - **offset**: Result offset from which to begin paging
        - **num**: Number of results to return


        Example of sorting the initial results:

        ```
        AggregateRequest("@sale_amount:[10000, inf]")            .limit(0, 10)            .group_by("@state", r.count())
        ```

        Will only group by the states found in the first 10 results of the
        query `@sale_amount:[10000, inf]`. On the other hand,

        ```
        AggregateRequest("@sale_amount:[10000, inf]")            .limit(0, 1000)            .group_by("@state", r.count()            .limit(0, 10)
        ```

        Will group all the results matching the query, but only return the
        first 10 groups.

        If you only wish to return a *top-N* style query, consider using
        `sort_by()` instead.

        )r	   rC   rO   r   )r   r
   ra   _limits       r   limitzAggregateRequest.limit   s<    T vs##""6#4#4#6#6777r   c                 v   g }|D ]6}t          |t          t          f          r||j        |j        gz  }0||gz  }7dt          t          |                    g}|                    |           |                    dd          }|dk    r|dt          |          gz  }| j	                            |           | S )a,  
        Indicate how the results should be sorted. This can also be used for
        *top-N* style queries

        ### Parameters

        - **fields**: The fields by which to sort. This can be either a single
            field or a list of fields. If you wish to specify order, you can
            use the `Asc` or `Desc` wrapper classes.
        - **max**: Maximum number of results to return. This can be
            used instead of `LIMIT` and is also faster.


        Example of sorting by `foo` ascending and `bar` descending:

        ```
        sort_by(Asc("@foo"), Desc("@bar"))
        ```

        Return the top 10 customers:

        ```
        AggregateRequest()            .group_by("@customer", r.sum("@paid").alias(FIELDNAME))            .sort_by(Desc("@paid"), max=10)
        ```
        SORTBYmaxr   MAX)
rV   r6   r:   r2   r1   r   rW   rO   getrC   )r   rM   kwargsfields_argsfrX   rg   s          r   sort_byzAggregateRequest.sort_by   s    :  	# 	#A!c4[)) #55s"S--../

;jj""77E3s88$$C""3'''r   expressionsc                 x    t          |t                    r|g}|D ]}| j                            d|g           | S )z
        Specify filter for post-query results using predicates relating to
        values in the result set.

        ### Parameters

        - **fields**: Fields to group by. This can either be a single string,
            or a list of strings.
        FILTER)rV   r   rC   rO   )r   rn   
expressions      r   filterzAggregateRequest.filter  sP     k3'' 	(&-K% 	? 	?J&&*'=>>>>r   c                     d| _         | S )z|
        If set, the `schema` property will contain a list of `[field, type]`
        entries in the result object.
        T)rG   r   s    r   with_schemazAggregateRequest.with_schema!  s    
 !r   c                     d| _         | S )zM
        If set, includes the score as an ordinary field of the row.
        T)rK   r   s    r   
add_scoreszAggregateRequest.add_scores)  s      r   scorerc                     || _         | S )z
        Use a different scoring function to evaluate document relevance.
        Default is `TFIDF`.

        :param scorer: The scoring function to use
                       (e.g. `TFIDF.DOCNORM` or `BM25`)
        )rL   )r   rw   s     r   rw   zAggregateRequest.scorer0  s     r   c                     d| _         | S )NT)rH   r   s    r   verbatimzAggregateRequest.verbatim;  s    r   r           r   max_idlec                 x    dg}|r|dt          |          gz  }|r|dt          |dz            gz  }|| _        | S )N
WITHCURSORCOUNTMAXIDLEi  )r   rI   )r   r   r|   r    s       r   cursorzAggregateRequest.cursor?  sU    ~ 	*Wc%jj))D 	6YHtO 4 455Dr   c                    | j         g}| j        r|                    d           | j        r|                    d           | j        r|                    d| j        g           | j        r|                    d           | j        r
|| j        z  }| j        r+|                    d           |                    d           nj| j	        rc|                    d           |                    t          t          | j	                                       |                    | j	                   | j        r)|                    dt          | j                  g           |                    | j                   |S )N
WITHSCHEMAVERBATIMSCORER	ADDSCORESLOADr>   DIALECT)rB   rG   appendrH   rL   rO   rK   rI   rE   rD   r   rW   rJ   rC   )r   rX   s     r   r   zAggregateRequest.build_argsH  sc   {m 	%JJ|$$$> 	#JJz"""< 	1JJ$,/000 	$JJ{###< 	 4<C= 	)JJvJJsOOOO 	)JJvJJs3t/0011222JJt'(((= 	8JJ	3t}#5#56777

4&'''
r   dialectc                     || _         | S )z
        Add a dialect field to the aggregate command.

        - **dialect** - dialect version to execute the query under
        )rJ   )r   r   s     r   r   zAggregateRequest.dialectk  s      r   )r>   )r   r=   )r   r{   )r   r   r   r,   r   r   rP   r   r   r   rZ   r`   r   rd   rm   rr   rt   rv   rw   rz   floatr   r   r   r   r   r   r=   r=   Z   s        $ $c $D $ $ $ $2C $6     CcN+8?	   4   $,C ,c ,.@ , , , ,\+s +1C + + + +Z%T#Y"7 <N    $      	S 	%7 	 	 	 	    C u ?Q    !DI ! ! ! !Fs '9      r   r=   c                   $    e Zd ZdeddfdZd ZdS )Cursorcidr   Nc                 0    || _         d| _        d| _        d S )Nr   )r   r|   r   r   r   s     r   r   zCursor.__init__v  s    


r   c                     t          | j                  g}| j        r|dt          | j                  gz  }| j        r|dt          | j                  gz  }|S )Nr   r   )r   r   r|   r   r%   s     r   r   zCursor.build_args{  sZ    DH= 	4YDM 2 233D: 	/Wc$*oo..Dr   r   r   r   r   r   r   u  sE        C D    
    r   r   c                   *    e Zd ZdeddfdZdefdZdS )AggregateResultr   r   Nc                 0    || _         || _        || _        d S r   )rowsr   schema)r   r   r   r   s       r   r   zAggregateResult.__init__  s    	r   c           	          | j         r| j         j        nd}d| j        j         dt	          |           ddt          | j                   d| d	S )N<z at 0xxz Rows=z	, Cursor=>)r   r   	__class__r   idrW   r   r   s     r   __repr__zAggregateResult.__repr__  sm    !%4dkoo"4' 4 4r$xx< 4 4	NN4 4-04 4 4	
r   )r   r   r   r   r   r   r   r   r   r   r   r     sQ        V     

# 
 
 
 
 
 
r   r   N)typingr   r   r   r   redis.commands.search.dialectr   objectr)   r	   r   r0   r6   r:   r=   r   r   r   r   r   <module>r      s   / / / / / / / / / / / / 9 9 9 9 9 9FHH		 	 	 	 	 	 	 	( ( ( ( ( ( ( (V           -       =   X X X X X X X Xv       
 
 
 
 
 
 
 
 
 
r   