U
    d                     @   sf  d dl Z d dl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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ZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+d Z,d!Z-d"Z.d#Z/d$Z0d%Z1d&Z2d'Z3d(Z4d)Z5d*Z6d+Z7d,Z8d-Z9d.Z:d/Z;d0Z<d1Z=d2Z>d3Z?d4Z@d5ZAd6ZBd7ZCd8ZDG d9d: d:ZEG d;d< d<eEZFdS )=    N)DictOptionalUnion)Pipeline)deprecated_function   )parse_to_dict   	to_string)AggregateRequestAggregateResultCursor)Document)Query)Result)SuggestionParserNUMERICz	FT.CREATEzFT.ALTERz	FT.SEARCHzFT.ADDz
FT.ADDHASHzFT.DROPzFT.DROPINDEXz
FT.EXPLAINzFT.EXPLAINCLIzFT.DELzFT.AGGREGATEz
FT.PROFILEz	FT.CURSORzFT.SPELLCHECKz
FT.DICTADDz
FT.DICTDELzFT.DICTDUMPzFT.GETz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.SYNDUMP	NOOFFSETSNOFIELDSNOHLNOFREQSMAXTEXTFIELDS	TEMPORARY	STOPWORDSSKIPINITIALSCAN
WITHSCORESFUZZYWITHPAYLOADSc                
   @   s<  e Zd ZdZdVddZdWddZd	d
 ZdXddZdYddZdZddZ	e
dddd[ddZe
dddd\ddZd]ddZdd Zdd Zdd  Zeeeeeeef f df d!d"d#Zeeeeeef f d!d$d%Zd^eeef eeeeeef f d&d'd(Zd_eeef eeeeeef f d&d)d*Zeeef d+d,d-Zd`eeef eeeeeef f d&d.d/Zd0d1 Zdaeeeef ee eeeeeef f  d2d3d4Z!dbd5d6Z"d7d8 Z#d9d: Z$d;d< Z%d=d> Z&d?d@ Z'dAdB Z(dCdD Z)dEdF Z*dGdH Z+dIdJ Z,dKdL Z-dMdN Z.dcdPdQZ/dddRdSZ0dTdU Z1dS )eSearchCommandszSearch commands.d   c                 C   s   | j | |dS )zT
        Create a new batch indexer from the client with a given chunk size
        )
chunk_size)ZBatchIndexer)selfr!    r#   B/tmp/pip-unpacked-wheel-f5h5_hbx/redis/commands/search/commands.pybatch_indexerB   s    zSearchCommands.batch_indexerFNc                 C   s.  t | jg}|dk	r||j7 }|r*|t |dk	rPt|trP|t || |r^|t |rl|t	 |rz|t
 |	r|t |
r|t |dk	rt|tttfr|tt|g7 }t|dkr|t|7 }|d z |ttjdd |D  7 }W n" tk
r"   || 7 }Y nX | j| S )a  
        Create the search index. The index must not already exist.

        ### Parameters:

        - **fields**: a list of TextField or NumericField objects
        - **no_term_offsets**: If true, we will not save term offsets in
        the index
        - **no_field_flags**: If true, we will not save field flags that
        allow searching in specific fields
        - **stopwords**: If not None, we create the index with this custom
        stopword list. The list can be empty
        - **max_text_fields**: If true, we will encode indexes as if there
        were more than 32 text fields which allows you to add additional
        fields (beyond 32).
        - **temporary**: Create a lightweight temporary index which will
        expire after the specified period of inactivity (in seconds). The
        internal idle timer is reset whenever the index is searched or added to.
        - **no_highlight**: If true, disabling highlighting support.
        Also implied by no_term_offsets.
        - **no_term_frequencies**: If true, we avoid saving the term frequencies
        in the index.
        - **skip_initial_scan**: If true, we do not scan and index.

        For more information see `FT.CREATE <https://redis.io/commands/ft.create>`_.
        Nr   SCHEMAc                 s   s   | ]}|  V  qd S N
redis_args.0fr#   r#   r$   	<genexpr>   s     z.SearchCommands.create_index.<locals>.<genexpr>)
CREATE_CMD
index_nameargsappendr   
isinstanceintr   r   r   r   r   r   listtuplesetr   len	itertoolschain	TypeErrorr)   execute_command)r"   fieldsZno_term_offsetsZno_field_flagsZ	stopwordsZ
definitionZmax_text_fields	temporaryZno_highlightZno_term_frequenciesZskip_initial_scanr0   r#   r#   r$   create_indexH   s8    (










 zSearchCommands.create_indexc                 C   sZ   t | jddg}z |ttjdd |D  7 }W n  tk
rN   || 7 }Y nX | 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&   ZADDc                 s   s   | ]}|  V  qd S r'   r(   r*   r#   r#   r$   r-      s     z2SearchCommands.alter_schema_add.<locals>.<genexpr>)	ALTER_CMDr/   r4   r8   r9   r:   r)   r;   )r"   r<   r0   r#   r#   r$   alter_schema_add   s     zSearchCommands.alter_schema_addc                 C   s   |rdnd}|  t| 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>`_.
        DD )r;   DROPINDEX_CMDr/   )r"   Zdelete_documentsZ
delete_strr#   r#   r$   	dropindex   s    zSearchCommands.dropindex      ?c
                 K   s   |s|	rd}t | j||g}|r(|d |dk	rD|d || |rn|d |r`|d |	rn|d |r~|d|g7 }|d	 |ttj|
  7 }|dk	r|j| S | j| S )
zS
        Internal add_document used for both batch and single doc indexing
        TZNOSAVENPAYLOADREPLACEPARTIALZNOCREATELANGUAGEZFIELDS)ADD_CMDr/   r1   r4   r8   r9   itemsr;   )r"   doc_idconnnosavescorepayloadreplacepartiallanguage	no_creater<   r0   r#   r#   r$   _add_document   s*    







zSearchCommands._add_documentc                 C   sH   t | j||g}|r|d |r,|d|g7 }|dk	r>|j| S | j| S )zX
        Internal add_document_hash used for both batch and single doc indexing
        rG   rI   N)ADDHASH_CMDr/   r1   r;   )r"   rL   rM   rO   rS   rQ   r0   r#   r#   r$   _add_document_hash   s    

z!SearchCommands._add_document_hashz2.0.0z2deprecated since redisearch 2.0, call hset instead)versionreasonc	           
      K   s$   | j |fd|||||||d|	S )a  
        Add a single document to the index.

        ### Parameters

        - **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
        i              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)rM   rN   rO   rP   rQ   rR   rS   rT   )rU   )
r"   rL   rN   rO   rP   rQ   rR   rS   rT   r<   r#   r#   r$   add_document   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)rM   rO   rS   rQ   )rW   )r"   rL   rO   rS   rQ   r#   r#   r$   add_document_hash(  s        z SearchCommands.add_document_hashc                 C   s6   t | j|g}|r|d |dk	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
        rA   N)DEL_CMDr/   r1   r;   )r"   rL   rM   Zdelete_actual_documentr0   r#   r#   r$   delete_document<  s    


zSearchCommands.delete_documentc                 C   sT   | j |}dd | D }|}z
|d= W n tk
r@   Y nX tf d|i|S ).
        Load a single document by id
        c                 S   s   i | ]\}}t |t |qS r#   r
   r+   kvr#   r#   r$   
<dictcomp>T  s      z0SearchCommands.load_document.<locals>.<dictcomp>idclientZhgetallrK   KeyErrorr   r"   rc   r<   f2r#   r#   r$   load_documentO  s    
zSearchCommands.load_documentc                 G   s   | j t| jf| S )z
        Returns the full contents of multiple documents.

        ### Parameters

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

        )r;   MGET_CMDr/   )r"   idsr#   r#   r$   get^  s    
zSearchCommands.getc                 C   s&   |  t| j}tt|}t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/   mapr   dictzipr"   resitr#   r#   r$   infoj  s    
zSearchCommands.infoquery_paramsc                 C   sb   |d krg S g }t |dkr^|d |t |d  | D ]\}}|| || q@|S )Nr   paramsr   )r7   r1   rK   )r"   rx   r0   keyvaluer#   r#   r$   get_params_argsv  s    

zSearchCommands.get_params_argsc                 C   sX   | j g}t|trt|}t|ts6tdt| || 7 }|| |7 }||fS )NzBad query type )r/   r2   strr   
ValueErrortypeget_argsr|   )r"   queryrx   r0   r#   r#   r$   _mk_query_args  s    

zSearchCommands._mk_query_argsr   rx   c                 C   s^   | j ||d\}}t }| jtf| }t|tr8|S t||j t | d |j|j	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>`_.
        rw        @@durationZhas_payloadwith_scores
r   timer;   
SEARCH_CMDr2   r   r   _no_content_with_payloads_with_scoresr"   r   rx   r0   strt   r#   r#   r$   search  s    
zSearchCommands.searchc                 C   s"   | j ||d\}}| jtf| S )zReturns the execution plan for a complex query.

        For more information see `FT.EXPLAIN <https://redis.io/commands/ft.explain>`_.
        rw   )r   r;   EXPLAIN_CMD)r"   r   rx   r0   Z
query_textr#   r#   r$   explain  s    	zSearchCommands.explain)r   c                 C   s   t dd S )Nz#EXPLAINCLI will not be implemented.)NotImplementedError)r"   r   r#   r#   r$   explain_cli  s    zSearchCommands.explain_clic                 C   s|   t |tr(t|j}t| jg|  }n.t |trLd}td| jg|  }n
t	d||| 
|7 }| j| }| |||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r2   r   bool_cursorAGGREGATE_CMDr/   
build_argsr   
CURSOR_CMDr~   r|   r;   _get_aggregate_resultr"   r   rx   
has_cursorcmdrawr#   r#   r$   	aggregate  s    




zSearchCommands.aggregatec                 C   sz   |r4t |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   )r2   r   Zcidr   Z_with_schemar   )r"   r   r   r   cursorZschemaZrowsr#   r#   r$   r     s    


z$SearchCommands._get_aggregate_result)r   limitedrx   c                 C   s   t   }t| jdg}|r"|d |d t|trLd|d< || 7 }n6t|trzd|d< || 7 }|| 	|7 }nt
d| j| }t|tr| |d ||j}n*t|d |j t   | d	 |j|jd
}|t|d fS )a  
        Performs a search or aggregate command and collects performance
        information.

        ### Parameters

        **query**: This can be either an `AggregateRequest`, `Query` or string.
        **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.

        rB   ZLIMITEDZQUERYZ	AGGREGATEr   ZSEARCHz5Must provide AggregateRequest object or Query object.r   r   r   r	   )r   PROFILE_CMDr/   r1   r2   r   r   r   r   r|   r~   r;   r   r   r   r   r   r   r   )r"   r   r   rx   r   r   rt   resultr#   r#   r$   profile  s0    





zSearchCommands.profilec           	      C   s   t | j|g}|r|d|g |r2|dd|g |rF|dd|g | j| }i }|dkr`|S |D ]X}t|tr||dkr|qdt|dkrqd|d sqd|d d sqddd	 |d D ||d
 < qd|S )  
        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>`_.
        DISTANCETERMSINCLUDEEXCLUDEr      r   c                 S   s   g | ]}|d  |d dqS r   r	   )rO   
suggestionr#   r+   Z_itemr#   r#   r$   
<listcomp>[  s    z-SearchCommands.spellcheck.<locals>.<listcomp>r	   SPELLCHECK_CMDr/   extendr;   r2   r3   r7   	r"   r   Zdistanceincludeexcluder   r   ZcorrectionsZ_correctionr#   r#   r$   
spellcheck#  s0    
zSearchCommands.spellcheckc                 G   s   t |g}|| | j| S )zAdds 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;   r"   nametermsr   r#   r#   r$   dict_adda  s    

zSearchCommands.dict_addc                 G   s   t |g}|| | j| S )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   r#   r#   r$   dict_delo  s    

zSearchCommands.dict_delc                 C   s   t |g}| j| S )zDumps 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;   )r"   r   r   r#   r#   r$   	dict_dump}  s    	zSearchCommands.dict_dumpc                 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;   r"   optionr{   r   r   r#   r#   r$   
config_set  s    

zSearchCommands.config_setc                 C   s:   t d|g}i }| j| }|r6|D ]}|d ||d < q |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>`_.
        GETr	   r   r   r"   r   r   rt   r   Zkvsr#   r#   r$   
config_get  s    	

zSearchCommands.config_getc                 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/   )r"   Ztagfieldr#   r#   r$   tagvals  s    zSearchCommands.tagvalsc                 C   s   |  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/   r"   aliasr#   r#   r$   aliasadd  s    zSearchCommands.aliasaddc                 C   s   |  t|| jS )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   r#   r#   r$   aliasupdate  s    zSearchCommands.aliasupdatec                 C   s   |  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   r#   r#   r$   aliasdel  s    
zSearchCommands.aliasdelc                 O   sl   | j dd}|D ]N}t||j|jg}|dr8|d |jrT|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Ztransaction	incrementINCRrF   	ZpipelineSUGADD_COMMANDstringrO   rl   r1   rP   r;   executer"   rz   ZsuggestionskwargspipeZsugr0   r#   r#   r$   sugadd  s    



zSearchCommands.sugaddc                 C   s   |  t|S )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)r"   rz   r#   r#   r$   suglen  s    zSearchCommands.suglenc                 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)r"   rz   r   r#   r#   r$   sugdel  s    zSearchCommands.sugdel
   c                 C   sh   t ||d|g}|r|t |r*|t |r8|t | j| }g }	|sN|	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   s   g | ]}|qS r#   r#   r+   sr#   r#   r$   r   3  s     z)SearchCommands.sugget.<locals>.<listcomp>SUGGET_COMMANDr1   r   r   r   r;   r   r"   rz   prefixZfuzzynumr   Zwith_payloadsr0   retresultsparserr#   r#   r$   sugget  s    "



zSearchCommands.suggetc                 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;   )r"   ZgroupidZskipinitialr   r   r#   r#   r$   	synupdate5  s
    
zSearchCommands.synupdatec                    s,   |  t| j  fddtdt dD S )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>`_.
        c                    s   i | ]} |  |d   qS )r	   r#   )r+   ir   r#   r$   rb   W  s      z*SearchCommands.syndump.<locals>.<dictcomp>r   r   )r;   SYNDUMP_CMDr/   ranger7   )r"   r#   r   r$   syndumpM  s    	zSearchCommands.syndump)r    )	FFNNFNFFF)F)NFrE   NFFNF)NrE   NF)FrE   NFFNF)rE   NF)NF)N)N)N)FN)NNN)Fr   FF)F)2__name__
__module____qualname____doc__r%   r>   r@   rD   rU   rW   r   rZ   r[   r]   ri   rl   rv   r   r   r}   r3   floatr|   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   r   r#   r#   r#   r$   r   ?   s   
	         
G
        
+       
        5 
  
" 
 
  1
>
       
2
r   c                   @   s   e Zd Zdd Zdeeef eeeeee	f f dddZ
deeef eeeeee	f f dddZdd	d
Zdd Zdd Zdd Zdd ZdddZdS )AsyncSearchCommandsc                    s,   |  t| jI dH }tt|}tt||S )rm   Nrn   rs   r#   r#   r$   rv   [  s    
zAsyncSearchCommands.infoNr   c                    sd   | j ||d\}}t }| jtf| I dH }t|tr>|S t||j t | d |j|j	dS )r   rw   Nr   r   r   r   r#   r#   r$   r   g  s    
zAsyncSearchCommands.searchc                    s   t |tr(t|j}t| jg|  }n.t |trLd}td| jg|  }n
t	d||| 
|7 }| j| I dH }| |||S )r   Tr   r   Nr   r   r#   r#   r$   r     s    



zAsyncSearchCommands.aggregatec           	         s   t | j|g}|r|d|g |r2|dd|g |rF|dd|g | j| I dH }i }|dkrf|S |D ]X}t|tr|dkrqjt|dkrqj|d sqj|d d sqjd	d
 |d D ||d < qj|S )r   r   r   r   r   Nr   r   r   c                 S   s   g | ]}|d  |d dqS r   r#   r   r#   r#   r$   r     s    z2AsyncSearchCommands.spellcheck.<locals>.<listcomp>r	   r   r   r#   r#   r$   r     s0    zAsyncSearchCommands.spellcheckc                    s$   t d||g}| j| I dH }|dkS )r   r   Nr   r   r   r#   r#   r$   r     s    
zAsyncSearchCommands.config_setc                    s@   t d|g}i }| j| I dH }|r<|D ]}|d ||d < q&|S )r   r   Nr	   r   r   r   r#   r#   r$   r     s    	
zAsyncSearchCommands.config_getc                    sZ   | j |I dH }dd | D }|}z
|d= W n tk
rF   Y nX tf d|i|S )r^   Nc                 S   s   i | ]\}}t |t |qS r#   r
   r_   r#   r#   r$   rb     s      z5AsyncSearchCommands.load_document.<locals>.<dictcomp>rc   rd   rg   r#   r#   r$   ri     s    
z!AsyncSearchCommands.load_documentc                    sr   | j dd}|D ]N}t||j|jg}|dr8|d |jrT|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>`_.
        Fr   r   r   rF   Nr   r   r   r#   r#   r$   r     s    



zAsyncSearchCommands.sugaddFr   c                    sn   t ||d|g}|r|t |r*|t |r8|t | j| I dH }g }	|sT|	S t|||}
dd |
D S )r   r   Nc                 S   s   g | ]}|qS r#   r#   r   r#   r#   r$   r   H  s     z.AsyncSearchCommands.sugget.<locals>.<listcomp>r   r   r#   r#   r$   r     s    "


zAsyncSearchCommands.sugget)N)N)NNN)Fr   FF)r   r   r  rv   r   r}   r   r   r3   r  r   r   r   r   r   ri   r   r   r#   r#   r#   r$   r  Z  s*    
" 

/       r  )Gr8   r   typingr   r   r   Zredis.clientr   Zredis.utilsr   Zhelpersr   Z_utilr   Zaggregationr   r   r   documentr   r   r   r   r   r   r   r   r.   r?   r   rJ   rV   ZDROP_CMDrC   r   ZEXPLAINCLI_CMDr\   r   r   r   r   r   r   r   ZGET_CMDrj   r   r   r   r   r   ro   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r#   r#   r#   r$   <module>   s|         !