
    phI0                         S SK JrJrJrJr  S SKJ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                   X   \ rS rSrSrS\SS4S jrS\4S jrS3S jrS3S	 jr	   S4S
\S\
\   S\
\   S\
\   SS 4
S jjrS\
\\\   \4      S\4S jr    S5S\
\   S\
\   S\
\   S\
\   SS 4
S jjr S6S\
\\      S\
\\      SS 4S jjrS\SS 4S jrS\SS 4S jrS\SS 4S jrS3S jrS\SS 4S jrS\\\\\4      4S  jrS\\\\\4      4S! jrS"\S#\SS 4S$ jrS3S% jrS3S& jrS3S' jrS3S( jrS3S) jr S\SS 4S* jr!S7S+ jr"S8S
\S,\SS 4S- jjr#S.\SS 4S/ jr$S0\SS 4S1 jr%S2r&g)9Query   a)  
Query is used to build complex queries that have more parameters than just
the query string. The query string is set in the constructor, and other
options have setter functions.

The setter functions return the query object so they can be chained.
i.e. `Query("foo").verbatim().filter(...)` etc.
query_stringreturnNc                 \   Xl         SU l        SU l        SU l        SU l        SU l        SU l        SU l        SU l        SU l	        [        5       U l        SU l        SU l        SU l        SU l        SU l        / U l        0 U l        / U l        / U l        SU l        SU l        [.        U l        g)zq
Create a new query object.
The query string is set in the constructor, and other options have
setter functions.
r   
   FN)_query_string_offset_num_no_content_no_stopwords_fields	_verbatim_with_payloads_with_scores_scorerlist_filters_ids_slop_timeout	_in_order_sortby_return_fields_return_fields_decode_as_summarize_fields_highlight_fields	_language	_expanderr   _dialect)selfr   s     U/home/james-whalen/.local/lib/python3.13/site-packages/redis/commands/search/query.py__init__Query.__init__   s     #/	!&#(,0$$)"'&*"f/3	
)-$.2$&.0%')')(,(,,    c                     U R                   $ )z+Return the query string of this query only.)r   r(   s    r)   r   Query.query_string/   s    !!!r,   c                     Xl         U $ )zLLimit the results to a specific set of pre-known document
ids of any length.)r   )r(   idss     r)   	limit_idsQuery.limit_ids3   s     	r,   c                 :    U H  nU R                  U5        M     U $ )zAdd fields to return fields.)return_field)r(   fieldsfields      r)   return_fieldsQuery.return_fields9   s    Ee$ r,   r7   as_fielddecode_fieldencodingc                     U R                   R                  U5        U(       a  UOSU R                  U'   Ub  U =R                   SU4-  sl         U $ )a  
Add a field to the list of fields to return.

- **field**: The field to include in query results
- **as_field**: The alias for the field
- **decode_field**: Whether to decode the field from bytes to string
- **encoding**: The encoding to use when decoding the field
NAS)r!   appendr"   )r(   r7   r:   r;   r<   s        r)   r5   Query.return_field?   sM     	""5);GxT%%e,D(#33r,   r6   c                 Z    U(       d  / $ [        U[        5      (       a  U/$ [        U5      $ N)
isinstancestrr   r(   r6   s     r)   _mk_field_listQuery._mk_field_listT   s'    I%fc22xDVDr,   context_len	num_fragssepc                     S/nU R                  U5      nU(       a  US[        [        U5      5      /U-   -  nUb  US[        U5      /-  nUb  US[        U5      /-  nUb  USU/-  nXPl        U $ )a3  
Return an abridged format of the field, containing only the segments of
the field that contain the matching term(s).

If `fields` is specified, then only the mentioned fields are
summarized; otherwise, all results are summarized.

Server-side defaults are used for each option (except `fields`)
if not specified

- **fields** List of fields to summarize. All fields are summarized
if not specified
- **context_len** Amount of context to include with each fragment
- **num_frags** Number of fragments per document
- **sep** Separator string to separate fragments
	SUMMARIZEFIELDSLENFRAGS	SEPARATOR)rF   rD   lenr#   )r(   r6   rH   rI   rJ   argss         r)   	summarizeQuery.summarizeY   s    . }$$V,Xs3v;/0699D"UC,--D Wc)n--D?[#&&D!%r,   tagsc                     S/nU R                  U5      nU(       a  US[        [        U5      5      /U-   -  nU(       a  US/[        U5      -   -  nX0l        U $ )z
Apply specified markup to matched term(s) within the returned field(s).

- **fields** If specified, then only those mentioned fields are
highlighted, otherwise all fields are highlighted
- **tags** A list of two strings to surround the match.
	HIGHLIGHTrM   TAGS)rF   rD   rQ   r   r$   )r(   r6   rU   rR   s       r)   	highlightQuery.highlight   s^     }$$V,Xs3v;/0699DVHtDz))D!%r,   languagec                     Xl         U $ )zt
Analyze the query as being in the specified language.

:param language: The language (e.g. `chinese` or `english`)
)r%   )r(   r[   s     r)   r[   Query.language        "r,   slopc                     Xl         U $ )z`Allow a maximum of N intervening non-matched terms between
phrase terms (0 means exact phrase).
)r   )r(   r_   s     r)   r_   
Query.slop   s     
r,   timeoutc                     Xl         U $ )z-overrides the timeout parameter of the module)r   )r(   rb   s     r)   rb   Query.timeout   s    r,   c                     SU l         U $ )z
Match only documents where the query terms appear in
the same order in the document.
i.e., for the query "hello world", we do not match "world hello"
T)r   r.   s    r)   in_orderQuery.in_order   s     r,   scorerc                     Xl         U $ )z
Use a different scoring function to evaluate document relevance.
Default is `TFIDF`.

Since Redis 8.0 default was changed to BM25STD.

:param scorer: The scoring function to use
               (e.g. `TFIDF.DOCNORM` or `BM25`)
)r   )r(   rh   s     r)   rh   Query.scorer   s     r,   c                     U R                   /nXR                  5       -  nXR                  U R                  -   -  nUSU R                  U R
                  /-  nU$ )z:Format the redis arguments for this query and return them.LIMIT)r   _get_args_tagsr#   r$   r   r   )r(   rR   s     r)   get_argsQuery.get_args   sX    .2.@.@-A##%%&&)?)???$,,		22r,   c                    / nU R                   (       a  UR                  S5        U R                  (       aC  UR                  S5        UR                  [        U R                  5      5        XR                  -  nU R                  (       a  UR                  S5        U R
                  (       a  UR                  S5        U R                  (       aA  U R                   H1  n[        U[        5      (       d  [        S5      eXR                  -  nM3     U R                  (       a  UR                  S5        U R                  (       a  USU R                  /-  nU R                  (       a  UR                  S5        U R                  (       aC  UR                  S	5        UR                  [        U R                  5      5        XR                  -  nU R                  S
:  a  USU R                  /-  nU R                   b  USU R                   /-  nU R"                  (       a  UR                  S5        U R$                  (       aC  UR                  S5        UR                  [        U R$                  5      5        XR$                  -  nU R&                  (       aS  [        U R&                  [(        5      (       d  [        S5      eUR                  S5        XR&                  R                  -  nU R*                  (       a  USU R*                  /-  nU R,                  (       a  USU R,                  /-  nU R.                  (       a  USU R.                  /-  nU$ )N	NOCONTENTINFIELDSVERBATIMNOSTOPWORDSz Did not receive a Filter object.WITHPAYLOADSSCORER
WITHSCORESINKEYSr   SLOPTIMEOUTINORDERRETURNzDid not receive a SortByField.SORTBYLANGUAGEEXPANDERDIALECT)r   r?   r   rQ   r   r   r   rC   FilterAttributeErrorrR   r   r   r   r   r   r   r   r!   r    SortbyFieldr%   r&   r'   )r(   rR   flts      r)   rm   Query._get_args_tags   sH   -/KK$<<KK
#KKDLL)*LL D>>KK
#KK&==}}!#v..()KLL  % KK'<<Xt||,,DKK%99KK!KKDII'IID::?VTZZ((D==$Y..D>>KK	"KK!KKD//01'''D<<dllK88$%EFFKK!LL%%%D>>Z00D>>Z00D==Y..Dr,   offsetnumc                     Xl         X l        U $ )z
Set the paging for the query (defaults to 0..10).

- **offset**: Paging offset for the results. Defaults to 0
- **num**: How many results do we want
)r   r   )r(   r   r   s      r)   pagingQuery.paging   s     	r,   c                     SU l         U $ )zHSet the query to be verbatim, i.e., use no query expansion
or stemming.
T)r   r.   s    r)   verbatimQuery.verbatim  s     r,   c                     SU l         U $ )z>Set the query to only return ids and not the document content.T)r   r.   s    r)   
no_contentQuery.no_content  s    r,   c                     SU l         U $ )z
Prevent the query from being filtered for stopwords.
Only useful in very big queries that you are certain contain
no stopwords.
T)r   r.   s    r)   no_stopwordsQuery.no_stopwords  s     "r,   c                     SU l         U $ )z+Ask the engine to return document payloads.T)r   r.   s    r)   with_payloadsQuery.with_payloads  s    "r,   c                     SU l         U $ )z0Ask the engine to return document search scores.T)r   r.   s    r)   with_scoresQuery.with_scores  s     r,   c                 &    [        U5      U l        U $ )z
Limit the search to specific TEXT fields only.

- **fields**: Each element should be a string, case sensitive field name
from the defined schema.
)r   r   rE   s     r)   limit_fieldsQuery.limit_fields#  s     F|r,   c                 <    U R                   R                  U5        U $ )z
Add a numeric or geo filter to the query.
**Currently, only one of each filter is supported by the engine**

- **flt**: A NumericFilter or GeoFilter object, used on a
corresponding field
)r   r?   )r(   r   s     r)   
add_filterQuery.add_filter-  s     	S!r,   ascc                 &    [        X5      U l        U $ )z
Add a sortby field to the query.

- **field** - the name of the field to sort by
- **asc** - when `True`, sorting will be done in ascending order
)r   r    r(   r7   r   s      r)   sort_byQuery.sort_by9  s     #5.r,   expanderc                     Xl         U $ )zP
Add an expander field to the query.

- **expander** - the name of the expander
)r&   )r(   r   s     r)   r   Query.expanderC  r^   r,   dialectc                     Xl         U $ )z_
Add a dialect field to the query.

- **dialect** - dialect version to execute the query under
)r'   )r(   r   s     r)   r   Query.dialectL  s      r,   )r'   r&   r   r   r$   r   r   r%   r   r   r   r   r   r!   r"   r   r   r    r#   r   r   r   r   )r   r	   )NTutf8)NNNN)NN)r   r   r   r	   T)'__name__
__module____qualname____firstlineno____doc__rD   r*   r   r2   r8   r   boolr5   r   r   rF   intrS   rY   r[   r_   floatrb   rf   rh   rn   rm   r   r   r   r   r   r   r   r   r   r   r   __static_attributes__ r,   r)   r	   r	      sC   -S -T ->"c " #''+"( 3- tn	
 3- 
*EXeDIsN.C%D E E "&%)#'!$$ c]$ C=	$
 c]$ 
$N OStCy)8@c8K	(    u  
S W $uS#u_56 1U3U?%; < 1f	S 	s 	w 	


C G 
S t w   s w r,   r	   c                   8    \ rS rSrS\S\S\\\4   SS4S jrSrg)	r   iV  keywordr7   rR   r   Nc                 ,    X/[        U5      -   U l        g rB   )r   rR   )r(   r   r7   rR   s       r)   r*   Filter.__init__W  s    $tDz1	r,   rR   )	r   r   r   r   rD   r   r   r*   r   r   r,   r)   r   r   V  s,    2 2C 2c5j8I 2d 2r,   r   c                   Z    \ rS rSrSrSr  SS\S\\\4   S\\\4   S\	S\	S	S
4S jjr
Srg
)NumericFilteri[  z+infz-infr7   minvalmaxvalminExclusivemaxExclusiver   Nc                 n    U(       d  UOSU 3U(       d  UOSU 3/n[         R                  " U SU/UQ76   g )N(FILTERr   r*   )r(   r7   r   r   r   r   rR   s          r)   r*   NumericFilter.__init___  s<     'FaxL&FaxL

 	h55r,   r   )FF)r   r   r   r   INFNEG_INFrD   r   r   r   r*   r   r   r,   r)   r   r   [  sh    
CG #"66 c3h6 c3h	6
 6 6 
6 6r,   r   c                   L    \ rS rSrSrSrSrSr\4S\S\	S\	S	\	S
\SS4S jjr
Srg)	GeoFilterio  mkmftmir7   lonlatradiusunitr   Nc           	      6    [         R                  U SXX4U5        g )N	GEOFILTERr   )r(   r7   r   r   r   r   s         r)   r*   GeoFilter.__init__u  s     	k5sDIr,   r   )r   r   r   r   METERS
KILOMETERSFEETMILESrD   r   r*   r   r   r,   r)   r   r   o  s_    FJDE NXJJ$J+0J:?JGJJ	J Jr,   r   c                   *    \ rS rSrSS\SS4S jjrSrg)r   i{  r7   r   Nc                 &    X(       a  SOS/U l         g )NASCDESCr   r   s      r)   r*   SortbyField.__init__|  s    SEf5	r,   r   r   )r   r   r   r   rD   r*   r   r   r,   r)   r   r   {  s    6c 6 6 6r,   r   N)typingr   r   r   r   redis.commands.search.dialectr   r	   r   r   r   r   r   r,   r)   <module>r      sI    / / 9M M`
2 2
6F 6(	J 	J6 6r,   