o
    <‘ði&¬  ã                   @   sÊ  d dl Z d dlZd dlmZmZmZmZmZ d dlm	Z	 d dl
mZmZ d dlmZmZmZmZ d dlmZmZ d dlmZmZ dd	lmZ d
dlmZ d
dlmZmZmZ d
dl m!Z! d
dl"m#Z# d
dl$m%Z% d
dl&m'Z' d
dl(m)Z) d
dl*m+Z+ d
dl,m-Z- dZ.dZ/dZ0dZ1dZ2dZ3dZ4dZ5dZ6dZ7dZ8dZ9d Z:d!Z;d"Z<d#Z=d$Z>d%Z?d&Z@d'ZAd(ZBd)ZCd*ZDd+ZEd,ZFd-ZGd.ZHd/ZId0ZJd1ZKd2ZLd3ZMd4ZNd5ZOd6ZPd7ZQd8ZRd9ZSd:ZTd;ZUd<ZVd=ZWG d>d?„ d?ƒZXG d@dA„ dAeXƒZYdS )Bé    N)ÚAnyÚDictÚListÚOptionalÚUnion)Úpairs_to_dict)ÚNEVER_DECODEÚPipeline)ÚCombineResultsMethodÚHybridCursorQueryÚHybridPostProcessingConfigÚHybridQuery)ÚHybridCursorResultÚHybridResult)Údeprecated_functionÚexperimental_methodé   )Úget_protocol_versioné   ©Ú	to_string)ÚAggregateRequestÚAggregateResultÚCursor)ÚDocument)ÚField)ÚIndexDefinition)ÚProfileInformation)ÚQuery)ÚResult)ÚSuggestionParserÚNUMERICz	FT.CREATEzFT.ALTERz	FT.SEARCHzFT.ADDz
FT.ADDHASHzFT.DROPINDEXz
FT.EXPLAINzFT.EXPLAINCLIzFT.DELzFT.AGGREGATEú
FT.PROFILEz	FT.CURSORzFT.SPELLCHECKz
FT.DICTADDz
FT.DICTDELzFT.DICTDUMPzFT.MGETz	FT.CONFIGz
FT.TAGVALSzFT.ALIASADDzFT.ALIASUPDATEzFT.ALIASDELzFT.INFOz	FT.SUGADDz	FT.SUGDELz	FT.SUGLENz	FT.SUGGETzFT.SYNUPDATEz
FT.SYNDUMPz	FT.HYBRIDÚ	NOOFFSETSÚNOFIELDSÚNOHLÚNOFREQSÚMAXTEXTFIELDSÚ	TEMPORARYÚ	STOPWORDSÚSKIPINITIALSCANÚ
WITHSCORESÚFUZZYÚWITHPAYLOADSc                   @   s¶  e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zd•dd„Z									d–dee dededeee  dee deded efd!d"„Zdeeee f fd#d$„Zd—d%efd&d'„Z			(					d˜d)d*„Z	d™d+d,„Zed-d.d/�		(					dšd0ed1ed2ed3ee d4ed5ed6ee d7edee fd8d9„ƒZed-d.d/�d›d:d;„ƒZed-d<d/�dœd=d>„ƒZd?d@„ Zed-d<d/�dAdB„ ƒZ dCdD„ Z!dEee"eeee#ee$f f  fdFdG„Z%dEee"eeee#ee$f f  fdHdI„Z&	d�dJeee'f dEee"eeee#ee$f f df fdKdL„Z(e)ƒ 					dždJe*dMee+ dNee, dOee"eeee#ee$f f  dPee# dQee- dRee.e/e0f fdSdT„ƒZ1	d�dJeee'f dEee"eeee#ee$f f  fdUdV„Z2dJeee'f fdWdX„Z3	d�dJee4e5f dEee"eeee#ee$f f  fdYdZ„Z6d[edJee4e5f d\efd]d^„Z7		dŸdJee'e4f d_edEee"eeee#ee$f f  fd`da„Z8d dbdc„Z9ddedeee fdfdg„Z:ddedeee fdhdi„Z;ddefdjdk„Z<edldmd/�dnedoedRefdpdq„ƒZ=edldrd/�dnedRefdsdt„ƒZ>duefdvdw„Z?dxefdydz„Z@dxefd{d|„ZAdxefd}d~„ZBdd€„ ZCd�edRe#fd‚dƒ„ZDd�ed„edRe#fd…d†„ZE		‡		d¡d�edˆed‰edŠe#d‹edŒedReeF fd�dŽ„ZGd—d�ed�edeee fd‘d’„ZHd“d”„ ZIdS )¢ÚSearchCommandszSearch commands.c                 K   s8   t | jƒdv r|dkrt|ƒS |S | j| |fi |¤ŽS )N©Ú3é   r"   )r   Úclientr   Ú_RESP2_MODULE_CALLBACKS)ÚselfÚcmdÚresÚkwargs© r8   ú]/root/parts/websockify/install/lib/python3.10/site-packages/redis/commands/search/commands.pyÚ_parse_resultsP   s   zSearchCommands._parse_resultsc                 K   s   t t|ƒ}tt||ƒƒS ©N)Úmapr   ÚdictÚzip)r4   r6   r7   Úitr8   r8   r9   Ú_parse_infoV   s   
zSearchCommands._parse_infoc                 K   s2   t ||d j |d |d j|d j|d jd�S )NÚqueryÚduration)rB   Úhas_payloadÚwith_scoresÚfield_encodings)r   Ú_no_contentÚ_with_payloadsÚ_with_scoresÚ_return_fields_decode_as©r4   r6   r7   r8   r8   r9   Ú_parse_searchZ   s   
úzSearchCommands._parse_searchc                 K   s|   t |dd�}d|v rtt|d ƒt|d ƒd�S g }|d D ]}t |dd�}| |¡ qtt|d ƒ||d	 t|d
 ƒd�S )NT)Údecode_keysÚcursorÚSEARCHÚVSIM)Úsearch_cursor_idÚvsim_cursor_idÚresultsÚtotal_resultsÚwarningsÚexecution_time)rS   rR   rT   rU   )r   r   ÚintÚappendr   Úfloat)r4   r6   r7   Úres_dictrR   Úres_itemÚ	item_dictr8   r8   r9   Ú_parse_hybrid_searchd   s    

þ

üz#SearchCommands._parse_hybrid_searchc                 K   s   |   ||d |d ¡S )NrA   Ú
has_cursor)Ú_get_aggregate_resultrJ   r8   r8   r9   Ú_parse_aggregatez   ó   zSearchCommands._parse_aggregatec                 K   sZ   |d }t |tƒr|  |d ||j¡}nt|d |j |d |j|jd�}|t|d ƒfS )NrA   r   rB   )rB   rC   rD   r   )	Ú
isinstancer   r^   Ú_cursorr   rF   rG   rH   r   )r4   r6   r7   rA   Úresultr8   r8   r9   Ú_parse_profile}   s   
ûzSearchCommands._parse_profilec                 K   sr   i }|dkr|S |D ],}t |tƒr|dkrq
t|ƒdkrq
|d s"q
|d d s)q
dd„ |d D ƒ||d < q
|S )Nr   r1   r   c                 S   s   g | ]}|d  |d dœ‘qS )r   r   )ÚscoreÚ
suggestionr8   )Ú.0Ú_itemr8   r8   r9   Ú
<listcomp>«   s    ÿz4SearchCommands._parse_spellcheck.<locals>.<listcomp>r   )ra   rV   Úlen)r4   r6   r7   ÚcorrectionsÚ_correctionr8   r8   r9   Ú_parse_spellcheckŒ   s    ÿz SearchCommands._parse_spellcheckc                 K   s   |r	dd„ |D ƒS i S )Nc                 S   s   i | ]	}|d  |d “qS )r   r   r8   )rg   Úkvsr8   r8   r9   Ú
<dictcomp>²   s    z4SearchCommands._parse_config_get.<locals>.<dictcomp>r8   rJ   r8   r8   r9   Ú_parse_config_get±   r`   z SearchCommands._parse_config_getc                    s   ‡ fdd„t dtˆ ƒdƒD ƒS )Nc                    s   i | ]}ˆ | ˆ |d   “qS )r   r8   )rg   Úi©r6   r8   r9   ro   µ   ó    z1SearchCommands._parse_syndump.<locals>.<dictcomp>r   r   )Úrangerj   rJ   r8   rr   r9   Ú_parse_syndump´   s   zSearchCommands._parse_syndumpéd   c                 C   s   | j | |d�S )zT
        Create a new batch indexer from the client with a given chunk size
        )Ú
chunk_size)ÚBatchIndexer)r4   rw   r8   r8   r9   Úbatch_indexer·   s   zSearchCommands.batch_indexerFNÚfieldsÚno_term_offsetsÚno_field_flagsÚ	stopwordsÚ
definitionÚno_highlightÚno_term_frequenciesÚskip_initial_scanc                 C   s*  t | jg}|dur||j7 }|r| t¡ |dur(t|tƒr(| t¡ | |¡ |r/| t¡ |r6| t	¡ |r=| t
¡ |	rD| t¡ |
rK| t¡ |durkt|tttfƒrk|tt|ƒg7 }t|ƒdkrk|t|ƒ7 }| d¡ z|ttjdd„ |D ƒŽ ƒ7 }W n ty�   || ¡ 7 }Y nw | j|Ž S )a«  
        Creates the search index. The index must not already exist.

        For more information, see https://redis.io/commands/ft.create/

        Args:
            fields: A list of Field objects.
            no_term_offsets: If `true`, term offsets will not be saved in the index.
            no_field_flags: If true, field flags that allow searching in specific fields
                            will not be saved.
            stopwords: If provided, the index will be created with this custom stopword
                       list. The list can be empty.
            definition: If provided, the index will be created with this custom index
                        definition.
            max_text_fields: If true, indexes will be encoded as if there were more than
                             32 text fields, allowing for additional fields beyond 32.
            temporary: Creates a lightweight temporary index which will expire after the
                       specified period of inactivity. The internal idle timer is reset
                       whenever the index is searched or added to.
            no_highlight: If true, disables highlighting support. Also implied by
                          `no_term_offsets`.
            no_term_frequencies: If true, term frequencies will not be saved in the
                                 index.
            skip_initial_scan: If true, the initial scan and indexing will be skipped.

        Nr   ÚSCHEMAc                 s   ó   � | ]}|  ¡ V  qd S r;   ©Ú
redis_args©rg   Úfr8   r8   r9   Ú	<genexpr>ý   ó   € z.SearchCommands.create_index.<locals>.<genexpr>)Ú
CREATE_CMDÚ
index_nameÚargsrW   r'   ra   rV   r(   r#   r%   r$   r&   r*   ÚlistÚtupleÚsetr)   rj   Ú	itertoolsÚchainÚ	TypeErrorr…   Úexecute_command)r4   rz   r{   r|   r}   r~   Úmax_text_fieldsÚ	temporaryr   r€   r�   rŒ   r8   r8   r9   Úcreate_index½   s:   
'









 ÿ
zSearchCommands.create_indexc                 C   sX   t | jddg}z|ttjdd„ |D ƒŽ ƒ7 }W n ty&   || ¡ 7 }Y nw | j|Ž S )a  
        Alter the existing search index by adding new fields. The index
        must already exist.

        ### Parameters:

        - **fields**: a list of Field objects to add for the index

        For more information see `FT.ALTER <https://redis.io/commands/ft.alter>`_.
        r‚   ÚADDc                 s   rƒ   r;   r„   r†   r8   r8   r9   rˆ     r‰   z2SearchCommands.alter_schema_add.<locals>.<genexpr>)Ú	ALTER_CMDr‹   r�   r�   r‘   r’   r…   r“   )r4   rz   rŒ   r8   r8   r9   Úalter_schema_add  s    ÿ
zSearchCommands.alter_schema_addÚdelete_documentsc                 C   s<   t | jg}t|tƒr|du rdnd}|r| |¡ | j|Ž S )ai  
        Drop the index if it exists.
        Replaced `drop_index` in RediSearch 2.0.
        Default behavior was changed to not delete the indexed documents.

        ### Parameters:

        - **delete_documents**: If `True`, all documents will be deleted.

        For more information see `FT.DROPINDEX <https://redis.io/commands/ft.dropindex>`_.
        TÚDDÚ )ÚDROPINDEX_CMDr‹   ra   ÚboolrW   r“   )r4   rš   rŒ   Ú
delete_strr8   r8   r9   Ú	dropindex  s   
ÿÿý

zSearchCommands.dropindexç      ð?c
                 K   sº   |s|	rd}t | j||g}|r| d¡ |dur"| d¡ | |¡ |r7| d¡ |r0| d¡ |	r7| d¡ |r?|d|g7 }| d	¡ |ttj|
 ¡ Ž ƒ7 }|durX|j|Ž S | j|Ž S )
zS
        Internal add_document used for both batch and single doc indexing
        TÚNOSAVENÚPAYLOADÚREPLACEÚPARTIALÚNOCREATEÚLANGUAGEÚFIELDS)ÚADD_CMDr‹   rW   r�   r�   r‘   Úitemsr“   )r4   Údoc_idÚconnÚnosavere   ÚpayloadÚreplaceÚpartialÚlanguageÚ	no_createrz   rŒ   r8   r8   r9   Ú_add_document0  s*   








zSearchCommands._add_documentc                 C   sH   t | j||g}|r| d¡ |r|d|g7 }|dur|j|Ž S | j|Ž S )zX
        Internal add_document_hash used for both batch and single doc indexing
        r¤   r§   N)ÚADDHASH_CMDr‹   rW   r“   )r4   r«   r¬   re   r±   r¯   rŒ   r8   r8   r9   Ú_add_document_hashZ  s   


z!SearchCommands._add_document_hashz2.0.0z2deprecated since redisearch 2.0, call hset instead©ÚversionÚreasonr«   r­   re   r®   r¯   r°   r±   r²   c	           
      K   s$   | j |fd|||||||dœ|	¤ŽS )aš  
        Add a single document to the index.

        Args:

            doc_id: the id of the saved document.
            nosave: if set to true, we just index the document, and don't
                      save a copy of it. This means that searches will just
                      return ids.
            score: the document ranking, between 0.0 and 1.0
            payload: optional inner-index payload we can save for fast
                     access in scoring functions
            replace: if True, and the document already is in the index,
                     we perform an update and reindex the document
            partial: if True, the fields specified will be added to the
                       existing document.
                       This has the added benefit that any fields specified
                       with `no_index`
                       will not be reindexed again. Implies `replace`
            language: Specify the language used for document tokenization.
            no_create: if True, the document is only updated and reindexed
                         if it already exists.
                         If the document does not exist, an error will be
                         returned. Implies `replace`
            fields: kwargs dictionary of the document fields to be saved
                    and/or indexed.
                    NOTE: Geo points shoule be encoded as strings of "lon,lat"
        N)r¬   r­   re   r®   r¯   r°   r±   r²   )r³   )
r4   r«   r­   re   r®   r¯   r°   r±   r²   rz   r8   r8   r9   Úadd_documentn  s   +ÿ÷
özSearchCommands.add_documentc                 C   s   | j |d|||d�S )aþ  
        Add a hash document to the index.

        ### Parameters

        - **doc_id**: the document's id. This has to be an existing HASH key
                      in Redis that will hold the fields the index needs.
        - **score**:  the document ranking, between 0.0 and 1.0
        - **replace**: if True, and the document already is in the index, we
                      perform an update and reindex the document
        - **language**: Specify the language used for document tokenization.
        N)r¬   re   r±   r¯   )rµ   )r4   r«   re   r±   r¯   r8   r8   r9   Úadd_document_hash¦  s   
ÿz SearchCommands.add_document_hashzdeprecated since redisearch 2.0c                 C   s6   t | j|g}|r| d¡ |dur|j|Ž S | j|Ž S )a  
        Delete a document from index
        Returns 1 if the document was deleted, 0 if not

        ### Parameters

        - **delete_actual_document**: if set to True, RediSearch also delete
                                      the actual document if it is in the index
        r›   N)ÚDEL_CMDr‹   rW   r“   )r4   r«   r¬   Údelete_actual_documentrŒ   r8   r8   r9   Údelete_documentº  s   


zSearchCommands.delete_documentc                 C   sR   | j  |¡}dd„ | ¡ D ƒ}|}z|d= W n	 ty   Y nw tdd|i|¤ŽS )ú.
        Load a single document by id
        c                 S   ó   i | ]\}}t |ƒt |ƒ“qS r8   r   ©rg   ÚkÚvr8   r8   r9   ro   Ó  rs   z0SearchCommands.load_document.<locals>.<dictcomp>ÚidNr8   ©r2   Úhgetallrª   ÚKeyErrorr   ©r4   rÃ   rz   Úf2r8   r8   r9   Úload_documentÎ  s   
ÿzSearchCommands.load_documentc                 G   s   | j t| jg|¢R Ž S )z�
        Returns the full contents of multiple documents.

        ### Parameters

        - **ids**: the ids of the saved documents.

        )r“   ÚMGET_CMDr‹   )r4   Úidsr8   r8   r9   ÚgetÝ  s   zSearchCommands.getc                 C   ó   |   t| j¡}|  t|¡S )úÕ
        Get info an stats about the the current index, including the number of
        documents, memory consumption, etc

        For more information see `FT.INFO <https://redis.io/commands/ft.info>`_.
        ©r“   ÚINFO_CMDr‹   r:   ©r4   r6   r8   r8   r9   Úinfoê  s   zSearchCommands.infoÚquery_paramsc                 C   sb   |d u rg S g }t |ƒdkr/| d¡ | t |ƒd ¡ | ¡ D ]\}}| |¡ | |¡ q |S )Nr   ÚPARAMSr   )rj   rW   rª   )r4   rÓ   rŒ   ÚkeyÚvaluer8   r8   r9   Úget_params_argsõ  s   

zSearchCommands.get_params_argsc                 C   sX   | j g}t|tƒrt|ƒ}t|tƒstdt|ƒ› �ƒ‚|| ¡ 7 }||  |¡7 }||fS )NzBad query type )r‹   ra   Ústrr   Ú
ValueErrorÚtypeÚget_argsr×   )r4   rA   rÓ   rŒ   r8   r8   r9   Ú_mk_query_args  s   

zSearchCommands._mk_query_argsrA   c                 C   sx   | j ||d�\}}t ¡ }i }t| jƒdvrd|t< | jtg|¢R i |¤Ž}t|t	ƒr-|S | j
t||t ¡ | d d�S )á¦  
        Search the index for a given query, and return a result of documents

        ### Parameters

        - **query**: the search query. Either a text for simple queries with
                     default parameters, or a Query object for complex queries.
                     See RediSearch's documentation on query format

        For more information see `FT.SEARCH <https://redis.io/commands/ft.search>`_.
        ©rÓ   r/   Tç     @�@©rA   rB   ©rÜ   ÚtimeÚ	monotonicr   r2   r   r“   Ú
SEARCH_CMDra   r	   r:   ©r4   rA   rÓ   rŒ   ÚstÚoptionsr6   r8   r8   r9   Úsearch  s   
ÿzSearchCommands.searchÚcombine_methodÚpost_processingÚparams_substitutionÚtimeoutrM   Úreturnc                 C   sÌ   | j }i }t|g}	|	 | ¡ ¡ |r|	 | ¡ ¡ |r"|	 | ¡ ¡ |r,|	 |  |¡¡ |r5|	 d|f¡ |rBd|d< |	 | ¡ ¡ t| jƒdvrMd|t< | j	|	i |¤Ž}
t
|
tƒr\|
S | jt|
fi |¤ŽS )áM  
        Execute a hybrid search using both text and vector queries

        Args:
            - **query**: HybridQuery object
                        Contains the text and vector queries
            - **combine_method**: CombineResultsMethod object
                        Contains the combine method and parameters
            - **post_processing**: HybridPostProcessingConfig object
                        Contains the post processing configuration
            - **params_substitution**: Dict[str, Union[str, int, float, bytes]]
                        Contains the parameters substitution
            - **timeout**: int - contains the timeout in milliseconds
            - **cursor**: HybridCursorQuery object - contains the cursor configuration


        For more information see `FT.SEARCH <https://redis.io/commands/ft.hybrid>`.
        ÚTIMEOUTTrM   r/   ©r‹   Ú
HYBRID_CMDÚextendrÛ   Ú
build_argsr×   r   r2   r   r“   ra   r	   r:   ©r4   rA   ré   rê   rë   rì   rM   Úindexrç   Úpiecesr6   r8   r8   r9   Úhybrid_search3  s*   
zSearchCommands.hybrid_searchc                 C   s$   | j ||d�\}}| jtg|¢R Ž S )z�Returns the execution plan for a complex query.

        For more information see `FT.EXPLAIN <https://redis.io/commands/ft.explain>`_.
        rÞ   )rÜ   r“   ÚEXPLAIN_CMD)r4   rA   rÓ   rŒ   Ú
query_textr8   r8   r9   Úexplaini  s   	zSearchCommands.explainc                 C   s   t dƒ‚)Nz#EXPLAINCLI will not be implemented.)ÚNotImplementedError)r4   rA   r8   r8   r9   Úexplain_cliu  s   zSearchCommands.explain_clic                 C   s€   t |tƒrt|jƒ}t| jg| ¡  }nt |tƒr&d}td| jg| ¡  }nt	d|ƒ‚||  
|¡7 }| j|Ž }| jt|||d�S )á‰  
        Issue an aggregation query.

        ### Parameters

        **query**: This can be either an `AggregateRequest`, or a `Cursor`

        An `AggregateResult` object is returned. You can access the rows from
        its `rows` property, which will always yield the rows of the result.

        For more information see `FT.AGGREGATE <https://redis.io/commands/ft.aggregate>`_.
        TÚREADú	Bad query©rA   r]   ©ra   r   rž   rb   ÚAGGREGATE_CMDr‹   ró   r   Ú
CURSOR_CMDrÙ   r×   r“   r:   ©r4   rA   rÓ   r]   r5   Úrawr8   r8   r9   Ú	aggregatex  s   




ÿzSearchCommands.aggregater  r]   c                 C   sz   |rt |tƒr|d |_|}nt|d ƒ}|d }nd }t |tƒr/|jr/|d }|dd … }nd }|dd … }t|||ƒS )Nr   r   r   )ra   r   Úcidr   Ú_with_schemar   )r4   r  rA   r]   rM   ÚschemaÚrowsr8   r8   r9   r^   ˜  s   


z$SearchCommands._get_aggregate_resultÚlimitedc                 C   sª   t  ¡ }t| jdg}|r| d¡ | d¡ t|tƒr&d|d< || ¡ 7 }nt|tƒr=d|d< || 	¡ 7 }||  
|¡7 }ntdƒ‚| j|Ž }| jt||t  ¡ | d d	�S )
a  
        Performs a search or aggregate command and collects performance
        information.

        ### Parameters

        **query**: This can be either an `AggregateRequest` or `Query`.
        **limited**: If set to True, removes details of reader iterator.
        **query_params**: Define one or more value parameters.
        Each parameter has a name and a value.

        rœ   ÚLIMITEDÚQUERYÚ	AGGREGATEr   rN   z5Must provide AggregateRequest object or Query object.rß   rà   )râ   rã   ÚPROFILE_CMDr‹   rW   ra   r   ró   r   rÛ   r×   rÙ   r“   r:   )r4   rA   r  rÓ   ræ   r5   r6   r8   r8   r9   Úprofile®  s"   




ÿzSearchCommands.profilec                 C   s\   t | j|g}|r| d|g¡ |r| dd|g¡ |r#| dd|g¡ | j|Ž }|  t |¡S )a´  
        Issue a spellcheck query

        Args:

            query: search query.
            distance: the maximal Levenshtein distance for spelling
                       suggestions (default: 1, max: 4).
            include: specifies an inclusion custom dictionary.
            exclude: specifies an exclusion custom dictionary.

        For more information see `FT.SPELLCHECK <https://redis.io/commands/ft.spellcheck>`_.
        ÚDISTANCEÚTERMSÚINCLUDEÚEXCLUDE©ÚSPELLCHECK_CMDr‹   rò   r“   r:   ©r4   rA   ÚdistanceÚincludeÚexcluder5   r6   r8   r8   r9   Ú
spellcheckÖ  s   
zSearchCommands.spellcheckÚnameÚtermsc                 G   ó   t |g}| |¡ | j|Ž S )zûAdds terms to a dictionary.

        ### Parameters

        - **name**: Dictionary name.
        - **terms**: List of items for adding to the dictionary.

        For more information see `FT.DICTADD <https://redis.io/commands/ft.dictadd>`_.
        )ÚDICT_ADD_CMDrò   r“   ©r4   r  r  r5   r8   r8   r9   Údict_addò  ó   


zSearchCommands.dict_addc                 G   r  )a  Deletes terms from a dictionary.

        ### Parameters

        - **name**: Dictionary name.
        - **terms**: List of items for removing from the dictionary.

        For more information see `FT.DICTDEL <https://redis.io/commands/ft.dictdel>`_.
        )ÚDICT_DEL_CMDrò   r“   r   r8   r8   r9   Údict_del   r"  zSearchCommands.dict_delc                 C   s   t |g}| j|Ž S )zÉDumps all terms in the given dictionary.

        ### Parameters

        - **name**: Dictionary name.

        For more information see `FT.DICTDUMP <https://redis.io/commands/ft.dictdump>`_.
        )ÚDICT_DUMP_CMDr“   )r4   r  r5   r8   r8   r9   Ú	dict_dump  s   	
zSearchCommands.dict_dumpú8.0.0úDdeprecated since Redis 8.0, call config_set from core module insteadÚoptionrÖ   c                 C   s   t d||g}| j|Ž }|dkS )á  Set runtime configuration option.

        ### Parameters

        - **option**: the name of the configuration option.
        - **value**: a value for the configuration option.

        For more information see `FT.CONFIG SET <https://redis.io/commands/ft.config-set>`_.
        ÚSETÚOK©Ú
CONFIG_CMDr“   ©r4   r)  rÖ   r5   r  r8   r8   r9   Ú
config_set  s   
zSearchCommands.config_setúDdeprecated since Redis 8.0, call config_get from core module insteadc                 C   s    t d|g}| j|Ž }|  t |¡S )úãGet runtime configuration option value.

        ### Parameters

        - **option**: the name of the configuration option.

        For more information see `FT.CONFIG GET <https://redis.io/commands/ft.config-get>`_.
        ÚGET©r.  r“   r:   ©r4   r)  r5   r6   r8   r8   r9   Ú
config_get,  s   

zSearchCommands.config_getÚtagfieldc                 C   s   |   t| j|¡S )zÒ
        Return a list of all possible tag values

        ### Parameters

        - **tagfield**: Tag field name

        For more information see `FT.TAGVALS <https://redis.io/commands/ft.tagvals>`_.
        )r“   ÚTAGVALS_CMDr‹   )r4   r7  r8   r8   r9   Útagvals=  ó   zSearchCommands.tagvalsÚaliasc                 C   ó   |   t|| j¡S )zî
        Alias a search index - will fail if alias already exists

        ### Parameters

        - **alias**: Name of the alias to create

        For more information see `FT.ALIASADD <https://redis.io/commands/ft.aliasadd>`_.
        )r“   ÚALIAS_ADD_CMDr‹   ©r4   r;  r8   r8   r9   ÚaliasaddJ  r:  zSearchCommands.aliasaddc                 C   r<  )zø
        Updates an alias - will fail if alias does not already exist

        ### Parameters

        - **alias**: Name of the alias to create

        For more information see `FT.ALIASUPDATE <https://redis.io/commands/ft.aliasupdate>`_.
        )r“   ÚALIAS_UPDATE_CMDr‹   r>  r8   r8   r9   ÚaliasupdateW  r:  zSearchCommands.aliasupdatec                 C   ó   |   t|¡S )zØ
        Removes an alias to a search index

        ### Parameters

        - **alias**: Name of the alias to delete

        For more information see `FT.ALIASDEL <https://redis.io/commands/ft.aliasdel>`_.
        )r“   ÚALIAS_DEL_CMDr>  r8   r8   r9   Úaliasdeld  s   
zSearchCommands.aliasdelc                 O   sl   | j dd�}|D ]'}t||j|jg}| d¡r| d¡ |jr*| d¡ | |j¡ |j|Ž  q| ¡ d S )aJ  
        Add suggestion terms to the AutoCompleter engine. Each suggestion has
        a score and string.
        If kwargs["increment"] is true and the terms are already in the
        server's dictionary, we increment their scores.

        For more information see `FT.SUGADD <https://redis.io/commands/ft.sugadd/>`_.
        F©ÚtransactionÚ	incrementÚINCRr£   éÿÿÿÿ©	ÚpipelineÚSUGADD_COMMANDÚstringre   rÌ   rW   r®   r“   Úexecute©r4   rÕ   Úsuggestionsr7   ÚpipeÚsugrŒ   r8   r8   r9   Úsugaddp  s   



zSearchCommands.sugaddrÕ   c                 C   rB  )z 
        Return the number of entries in the AutoCompleter index.

        For more information see `FT.SUGLEN <https://redis.io/commands/ft.suglen>`_.
        )r“   ÚSUGLEN_COMMAND)r4   rÕ   r8   r8   r9   Úsuglen‡  s   zSearchCommands.suglenrM  c                 C   s   |   t||¡S )zÙ
        Delete a string from the AutoCompleter index.
        Returns 1 if the string was found and deleted, 0 otherwise.

        For more information see `FT.SUGDEL <https://redis.io/commands/ft.sugdel>`_.
        )r“   ÚSUGDEL_COMMAND)r4   rÕ   rM  r8   r8   r9   Úsugdel�  s   zSearchCommands.sugdelé
   ÚprefixÚfuzzyÚnumrD   Úwith_payloadsc                 C   sh   t ||d|g}|r| t¡ |r| t¡ |r| t¡ | j|Ž }g }	|s'|	S t|||ƒ}
dd„ |
D ƒS )át  
        Get a list of suggestions from the AutoCompleter, for a given prefix.

        Parameters:

        prefix : str
            The prefix we are searching. **Must be valid ascii or utf-8**
        fuzzy : bool
            If set to true, the prefix search is done in fuzzy mode.
            **NOTE**: Running fuzzy searches on short (<3 letters) prefixes
            can be very
            slow, and even scan the entire index.
        with_scores : bool
            If set to true, we also return the (refactored) score of
            each suggestion.
            This is normally not needed, and is NOT the original score
            inserted into the index.
        with_payloads : bool
            Return suggestion payloads
        num : int
            The maximum number of results we return. Note that we might
            return less. The algorithm trims irrelevant suggestions.

        Returns:

        list:
             A list of Suggestion objects. If with_scores was False, the
             score of all suggestions is 1.

        For more information see `FT.SUGGET <https://redis.io/commands/ft.sugget>`_.
        ÚMAXc                 S   ó   g | ]}|‘qS r8   r8   ©rg   Úsr8   r8   r9   ri   Î  ó    z)SearchCommands.sugget.<locals>.<listcomp>©ÚSUGGET_COMMANDrW   r,   r+   r-   r“   r    )r4   rÕ   rY  rZ  r[  rD   r\  rŒ   r6   rR   Úparserr8   r8   r9   Úsugget˜  s   (



zSearchCommands.suggetÚgroupidÚskipinitialc                 G   s0   t | j|g}|r| dg¡ | |¡ | j|Ž S )að  
        Updates a synonym group.
        The command is used to create or update a synonym group with
        additional terms.
        Only documents which were indexed after the update will be affected.

        Parameters:

        groupid :
            Synonym group id.
        skipinitial : bool
            If set to true, we do not scan and index.
        terms :
            The terms.

        For more information see `FT.SYNUPDATE <https://redis.io/commands/ft.synupdate>`_.
        r*   )ÚSYNUPDATE_CMDr‹   rò   r“   )r4   rg  rh  r  r5   r8   r8   r9   Ú	synupdateÐ  s
   

zSearchCommands.synupdatec                 C   rÍ   )a  
        Dumps the contents of a synonym group.

        The command is used to dump the synonyms data structure.
        Returns a list of synonym terms and their synonym group ids.

        For more information see `FT.SYNDUMP <https://redis.io/commands/ft.syndump>`_.
        )r“   ÚSYNDUMP_CMDr‹   r:   rÑ   r8   r8   r9   Úsyndumpè  s   	zSearchCommands.syndump)rv   )	FFNNFNFFF)F)NFr¡   NFFNF)Nr¡   NF)Fr¡   NFFNF)r¡   NF)NFr;   ©NNNNN)FN©NNN©FrX  FF)JÚ__name__Ú
__module__Ú__qualname__Ú__doc__r:   r@   rK   r\   r_   rd   rm   rp   ru   ry   r   r   rž   r   rØ   r   r–   r   r™   r    r³   rµ   r   rX   r¹   rº   r½   rÉ   rÌ   rÒ   r   rV   Úbytesr×   rÜ   r   rè   r   r   r
   r   r   r   r   r	   r÷   rú   rü   r   r   r  r^   r  r  r!  r$  r&  r0  r6  r9  r?  rA  rD  rS  rU  rW  r    rf  rj  rl  r8   r8   r8   r9   r.   M   s„   
%
	õþýü
ûú	÷
ö
õF
ö+
ÿÿ÷þýüûúùø	÷
ö5ÿ



ÿ
ÿý
þ
ý ùþýüûúùø8ý
þ
ýý
þ
ý ÿ
ÿ
ÿü
þý
ü
(þþùþýüûúù
ø8r.   c                   @   sx  e Zd Zdd„ Z	d,deeef deeeeee	e
ef f  fdd„Zeƒ 					d-dedee d	ee d
eeeeee	e
ef f  dee	 dee deeeef fdd„ƒZ	d,deeef deeeeee	e
ef f  fdd„Zd.dd„Zeddd�dededefdd„ƒZeddd�dedefdd„ƒZdd„ Zd d!„ Z	"	#	"	"d/d$ed%ed&ed'e	d(ed)ede e! fd*d+„Z"dS )0ÚAsyncSearchCommandsc                 Ã   s"   �|   t| j¡I dH }|  t|¡S )rÎ   NrÏ   rÑ   r8   r8   r9   rÒ   ö  s   €zAsyncSearchCommands.infoNrA   rÓ   c                 Ã   s€   �| j ||d�\}}t ¡ }i }t| jƒdvrd|t< | jtg|¢R i |¤ŽI dH }t|t	ƒr1|S | j
t||t ¡ | d d�S )rÝ   rÞ   r/   TNrß   rà   rá   rå   r8   r8   r9   rè     s   €
ÿzAsyncSearchCommands.searchré   rê   rë   rì   rM   rí   c                 Ã   sÔ   �| j }i }t|g}	|	 | ¡ ¡ |r|	 | ¡ ¡ |r#|	 | ¡ ¡ |r-|	 |  |¡¡ |r6|	 d|f¡ |rCd|d< |	 | ¡ ¡ t| jƒdvrNd|t< | j	|	i |¤ŽI dH }
t
|
tƒr`|
S | jt|
fi |¤ŽS )rî   rï   TrM   r/   Nrð   rô   r8   r8   r9   r÷   !  s,   €
z!AsyncSearchCommands.hybrid_searchc                 Ã   sˆ   �t |tƒrt|jƒ}t| jg| ¡  }nt |tƒr'd}td| jg| ¡  }nt	d|ƒ‚||  
|¡7 }| j|Ž I dH }| jt|||d�S )rý   Trþ   rÿ   Nr   r  r  r8   r8   r9   r  W  s   €



ÿzAsyncSearchCommands.aggregatec                 Ã   sd   �t | j|g}|r| d|g¡ |r| dd|g¡ |r$| dd|g¡ | j|Ž I dH }|  t |¡S )a¾  
        Issue a spellcheck query

        ### Parameters

        **query**: search query.
        **distance***: the maximal Levenshtein distance for spelling
                       suggestions (default: 1, max: 4).
        **include**: specifies an inclusion custom dictionary.
        **exclude**: specifies an exclusion custom dictionary.

        For more information see `FT.SPELLCHECK <https://redis.io/commands/ft.spellcheck>`_.
        r  r  r  r  Nr  r  r8   r8   r9   r  w  s   €zAsyncSearchCommands.spellcheckr'  r(  r¶   r)  rÖ   c                 Ã   s&   �t d||g}| j|Ž I dH }|dkS )r*  r+  Nr,  r-  r/  r8   r8   r9   r0  “  s   €zAsyncSearchCommands.config_setr1  c                 Ã   s,   �t d|g}i }| j|Ž I dH }|  t |¡S )r2  r3  Nr4  r5  r8   r8   r9   r6  ¥  s
   €
zAsyncSearchCommands.config_getc                 Ã   sZ   �| j  |¡I dH }dd„ | ¡ D ƒ}|}z|d= W n	 ty#   Y nw tdd|i|¤ŽS )r¾   Nc                 S   r¿   r8   r   rÀ   r8   r8   r9   ro   ¼  rs   z5AsyncSearchCommands.load_document.<locals>.<dictcomp>rÃ   r8   rÄ   rÇ   r8   r8   r9   rÉ   ·  s   €
ÿz!AsyncSearchCommands.load_documentc                 Ï   st   �| j dd�}|D ]'}t||j|jg}| d¡r| d¡ |jr+| d¡ | |j¡ |j|Ž  q	| ¡ I dH d S )aI  
        Add suggestion terms to the AutoCompleter engine. Each suggestion has
        a score and string.
        If kwargs["increment"] is true and the terms are already in the
        server's dictionary, we increment their scores.

        For more information see `FT.SUGADD <https://redis.io/commands/ft.sugadd>`_.
        FrE  rG  rH  r£   NrI  rJ  rO  r8   r8   r9   rS  Æ  s   €



zAsyncSearchCommands.sugaddFrX  rÕ   rY  rZ  r[  rD   r\  c                 Ã   sp   �t ||d|g}|r| t¡ |r| t¡ |r| t¡ | j|Ž I dH }g }	|s+|	S t|||ƒ}
dd„ |
D ƒS )r]  r^  Nc                 S   r_  r8   r8   r`  r8   r8   r9   ri     rb  z.AsyncSearchCommands.sugget.<locals>.<listcomp>rc  )r4   rÕ   rY  rZ  r[  rD   r\  rŒ   ÚretrR   re  r8   r8   r9   rf  Ý  s   €(


zAsyncSearchCommands.suggetr;   rm  rn  ro  )#rp  rq  rr  rÒ   r   rØ   r   r   r   rV   rX   rt  rè   r   r   r
   r   r   r   r   r	   r÷   r   r   r  r  r   rž   r0  r6  rÉ   rS  r   r    rf  r8   r8   r8   r9   ru  õ  s†    ý
þ
ý ùþýüûúùø8ý
þ
ý
 þþùþýüûúùøru  )Zr�   râ   Útypingr   r   r   r   r   Úredis._parsers.helpersr   Úredis.clientr   r	   Ú"redis.commands.search.hybrid_queryr
   r   r   r   Ú#redis.commands.search.hybrid_resultr   r   Úredis.utilsr   r   Úhelpersr   Ú_utilr   Úaggregationr   r   r   Údocumentr   Úfieldr   Úindex_definitionr   Úprofile_informationr   rA   r   rc   r   rf   r    r!   rŠ   r˜   rä   r©   r´   r�   rø   ÚEXPLAINCLI_CMDr»   r  r  r  r  r  r#  r%  rÊ   r.  r8  r=  r@  rC  rÐ   rL  rV  rT  rd  ri  rk  rñ   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   ru  r8   r8   r8   r9   Ú<module>   sŠ           /