
    ph:-                         S SK JrJrJrJr  S SKJr  \" 5       r " S S5      r	 " S S5      r
 " S S5      r " S	 S
\5      r " S S\5      r " S S5      r " S S5      r " S S5      rg)    )ListOptionalTupleUnion)DEFAULT_DIALECTc                   4    \ rS rSrS	S\S\SS4S jjrS rSrg)
Limit   offsetcountreturnNc                     Xl         X l        g N)r   r   )selfr   r   s      [/home/james-whalen/.local/lib/python3.13/site-packages/redis/commands/search/aggregation.py__init__Limit.__init__	   s    
    c                 ~    U R                   (       a+  S[        U R                  5      [        U R                   5      /$ / $ )NLIMIT)r   strr   r   s    r   
build_argsLimit.build_args   s,    ::S-s4::??Ir   )r   r   )r   r   __name__
__module____qualname____firstlineno__intr   r   __static_attributes__ r   r   r	   r	      s!    s s 4 r   r	   c                   b    \ rS rSrSrSrS\SS4S jrS\SS 4S jr\	S\
\S	4   4S
 j5       rSrg)Reducer   zf
Base reducer object for all reducers.

See the `redisearch.reducers` module for the actual reducers.
Nargsr   c                 ,    Xl         S U l        S U l        g r   )_args_field_aliasr   r&   s     r   r   Reducer.__init__   s    &*
%)%)r   aliasc                 z    U[         L a+  U R                  (       d  [        S5      eU R                  SS nXl        U $ )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-   Reducer.alias"   s:     I;; !KLL ABr   .c                     U R                   $ r   )r(   r   s    r   r&   Reducer.args:   s    zzr   )r*   r(   r)   )r   r   r   r   __doc__NAMEr   r   r-   propertyr   r&   r!   r"   r   r   r$   r$      sW     D*c *d *
3 9 0 eCHo  r   r$   c                   @    \ rS rSr% SrSr\\   \S'   S\SS4S jr	Sr
g)	SortDirection?   z8
This special class is used to indicate sort direction.
N	DIRSTRINGfieldr   c                     Xl         g r   r<   )r   r<   s     r   r   SortDirection.__init__F   s    
r   r>   )r   r   r   r   r5   r;   r   r   __annotations__r   r!   r"   r   r   r9   r9   ?   s*      $Ix}#c d r   r9   c                       \ rS rSrSrSrSrg)AscJ   zC
Indicate that the given field should be sorted in ascending order
ASCr"   Nr   r   r   r   r5   r;   r!   r"   r   r   rB   rB   J   s     Ir   rB   c                       \ rS rSrSrSrSrg)DescR   zD
Indicate that the given field should be sorted in descending order
DESCr"   NrE   r"   r   r   rG   rG   R   s     Ir   rG   c                   *   \ rS rSrSrSS\SS4S jjrS\SS 4S jrS\\\	\   4   S	\
SS 4S
 jrSS jrS\S\SS 4S jrS\SS 4S jrS\\\	\   4   SS 4S jrSS jrSS jrS\SS 4S jrSS jrS S\S\SS 4S jjrS\	\   4S jrS\SS 4S jrSrg)!AggregateRequestZ   z@
Aggregation request which can be passed to `Client.aggregate`.
queryr   Nc                     Xl         / U l        / U l        SU l        SU l        SU l        SU l        / U l        [        U l	        SU l
        SU l        g)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   rM   s     r   r   AggregateRequest.__init___   sS     !)+&(#	"'$"$,!&#r   fieldsc                 \    U(       a  U R                   R                  U5        U $ SU l        U $ )a  
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)rR   extendrS   )r   r\   s     r   loadAggregateRequest.loadx   s0     ##F+  !DMr   reducersc           	         [        U[        5      (       a  U/OUnS[        [        U5      5      /UQnU Hl  nUSUR                  [        [        UR                  5      5      /-  nUR                  UR                  5        UR                  c  M[  USUR                  /-  nMn     U R                  R                  U5        U $ )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REDUCEAS)
isinstancer   lenr6   r&   r^   r*   rQ   )r   r\   ra   retreducers        r   group_byAggregateRequest.group_by   s     (44&&#c&k*4V4GHgllCGLL0A,BCCCJJw||$~~)gnn--	   	""3'r   c                     UR                  5        H.  u  p#SU/nUb  USU/-  nU R                  R                  U5        M0     U $ )a!  
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)")`
APPLYre   )itemsrQ   r^   )r   kwexprr-   exprrh   s        r   applyAggregateRequest.apply   sN     "<<>KED/C e}$&&s+	 * r   r   numc                 n    [        X5      nU R                  R                  UR                  5       5        U $ )aX  
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	   rQ   r^   r   )r   r   rs   _limits       r   limitAggregateRequest.limit   s1    T v#""6#4#4#67r   c                 h   / nU H?  n[        U[        [        45      (       a  X4R                  UR                  /-  nM:  X4/-  nMA     S[        [        U5      5      /nUR                  U5        UR                  SS5      nUS:  a  US[        U5      /-  nU R                  R                  U5        U $ )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)
rf   rB   rG   r<   r;   r   rg   r^   getrQ   )r   r\   kwargsfields_argsfrh   rz   s          r   sort_byAggregateRequest.sort_by   s    : A!c4[))55s"	  S-./

;jj"7E3s8$$C""3'r   expressionsc                     [        U[        5      (       a  U/nU H   nU R                  R                  SU/5        M"     U $ )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)rf   r   rQ   r^   )r   r   
expressions      r   filterAggregateRequest.filter  sB     k3''&-K%J&&*'=> & r   c                     SU l         U $ )zd
If set, the `schema` property will contain a list of `[field, type]`
entries in the result object.
T)rU   r   s    r   with_schemaAggregateRequest.with_schema!  s    
 !r   c                     SU l         U $ )z=
If set, includes the score as an ordinary field of the row.
T)rY   r   s    r   
add_scoresAggregateRequest.add_scores)  s      r   scorerc                     Xl         U $ )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`)
)rZ   )r   r   s     r   r   AggregateRequest.scorer0  s     r   c                     SU l         U $ )NT)rV   r   s    r   verbatimAggregateRequest.verbatim;  s    r   r   max_idlec                 z    S/nU(       a  US[        U5      /-  nU(       a  US[        US-  5      /-  nX0l        U $ )N
WITHCURSORCOUNTMAXIDLEi  )r   rW   )r   r   r   r&   s       r   cursorAggregateRequest.cursor?  sD    ~Wc%j))DYHtO 455Dr   c                 f   U R                   /nU R                  (       a  UR                  S5        U R                  (       a  UR                  S5        U R                  (       a  UR                  SU R                  /5        U R                  (       a  UR                  S5        U R                  (       a  XR                  -  nU R                  (       a#  UR                  S5        UR                  S5        OjU R                  (       aY  UR                  S5        UR                  [        [        U R                  5      5      5        UR                  U R                  5        U R                  (       a&  UR                  S[        U R                  5      /5        UR                  U R                  5        U$ )N
WITHSCHEMAVERBATIMSCORER	ADDSCORESLOAD*DIALECT)rP   rU   appendrV   rZ   r^   rY   rW   rS   rR   r   rg   rX   rQ   )r   rh   s     r   r   AggregateRequest.build_argsH  s   {{mJJ|$>>JJz"<<JJ$,,/0JJ{#<<<<C==JJvJJsOJJvJJs3t//012JJt''(==JJ	3t}}#567

4&&'
r   dialectc                     Xl         U $ )zk
Add a dialect field to the aggregate command.

- **dialect** - dialect version to execute the query under
)rX   )r   r   s     r   r   AggregateRequest.dialectk  s      r   )rY   rQ   rW   rX   rS   rR   rT   rP   rZ   rV   rU   )r   )r   rK   )r   g        )r   r   r   r   r5   r   r   r_   r   r   r$   rj   rq   r    rv   r   r   r   r   r   r   floatr   r   r   r!   r"   r   r   rK   rK   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   rK   c                   ,    \ rS rSrS\SS4S jrS rSrg)Cursoriu  cidr   Nc                 ,    Xl         SU l        SU l        g )Nr   )r   r   r   r   r   s     r   r   Cursor.__init__v  s    
r   c                     [        U R                  5      /nU R                  (       a  US[        U R                  5      /-  nU R                  (       a  US[        U R                  5      /-  nU$ )Nr   r   )r   r   r   r   r+   s     r   r   Cursor.build_args{  sS    DHH==YDMM 233D::Wc$**o..Dr   )r   r   r   r   r"   r   r   r   r   u  s    C D 
r   r   c                   4    \ rS rSrS\SS4S jrS\4S jrSrg)AggregateResulti  r   r   Nc                 (    Xl         X l        X0l        g r   )rowsr   schema)r   r   r   r   s       r   r   AggregateResult.__init__  s    	r   c           	          U R                   (       a  U R                   R                  OSnSU R                  R                   S[	        U 5      S S[        U R                  5       SU S3	$ )N<z at 0xxz Rows=z	, Cursor=>)r   r   	__class__r   idrg   r   r   s     r   __repr__AggregateResult.__repr__  sZ    !%dkkoo"''(r$xl ;		N#9SE4	
r   )r   r   r   )	r   r   r   r   r   r   r   r   r!   r"   r   r   r   r     s!    V  

# 
r   r   N)typingr   r   r   r   redis.commands.search.dialectr   objectr0   r	   r$   r9   rB   rG   rK   r   r   r"   r   r   <module>r      sm    / / 9H		 	( (V - = X Xv 
 
r   