o
    rPf                     @   sn  d dl Z d dlZd dlmZmZmZmZ d dlmZ d dl	m
Z
 ddlmZ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"Z0d#Z1d$Z2d%Z3d&Z4d'Z5d(Z6d)Z7d*Z8d+Z9d,Z:d-Z;d.Z<d/Z=d0Z>d1Z?d2Z@d3ZAd4ZBd5ZCd6ZDd7ZEd8ZFG d9d: d:ZGG d;d< d<eGZHdS )=    N)DictListOptionalUnion)Pipeline)deprecated_function   )get_protocol_version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dd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd ZdddZ									dddZdee fddZddefddZ								dd d!Z	dd"d#Zed$d%d&							dd'ed(ed)ed*ed+ed,ed-ee d.edee fd/d0Zed$d%d&dd1d2Zdd3d4Zd5d6 Zd7d8 Zd9d: Zd;eeeeee ee!f f df fd<d=Z"d;eeeeee ee!f f df fd>d?Z#	dd@eee$f d;eeeeee ee!f f df fdAdBZ%	dd@eee$f d;eeeee ef f fdCdDZ&d@eee$f fdEdFZ'	dd@eee$f d;eeeee ef f fdGdHZ(dIed@eee$e)f dJefdKdLZ*		dd@eee$e)f dMed;eeeeee ef f  fdNdOZ+ddPdQZ,dRedSee fdTdUZ-dRedSee fdVdWZ.dRefdXdYZ/dZed[ed\efd]d^Z0dZed\efd_d`Z1daefdbdcZ2ddefdedfZ3ddefdgdhZ4ddefdidjZ5dkdl Z6dmed\e fdndoZ7dmedped\e fdqdrZ8		s		ddmedteduedve dwedxed\ee9 fdydzZ:dd{ed|edSee fd}d~Z;dd Z<dS )SearchCommandszSearch commands.c                 K   s(   t | jdv r	|S | j| |fi |S )N)3   )r	   client_RESP2_MODULE_CALLBACKS)selfcmdreskwargs r*   _/var/www/html/humari/django-venv/lib/python3.10/site-packages/redis/commands/search/commands.py_parse_resultsB   s   zSearchCommands._parse_resultsc                 K   s   t t|}tt||S N)mapr   dictzip)r&   r(   r)   itr*   r*   r+   _parse_infoH   s   
zSearchCommands._parse_infoc                 K   s*   t ||d j |d |d j|d jdS )Nquerydurationr4   has_payloadwith_scores)r   _no_content_with_payloads_with_scoresr&   r(   r)   r*   r*   r+   _parse_searchL   s   
zSearchCommands._parse_searchc                 K   s   |  ||d |d S )Nr3   
has_cursor)_get_aggregate_resultr;   r*   r*   r+   _parse_aggregateU      zSearchCommands._parse_aggregatec                 K   sZ   |d }t |tr| |d ||j}nt|d |j |d |j|jd}|t|d fS )Nr3   r   r4   r5   r   )	
isinstancer   r>   _cursorr   r8   r9   r:   r
   )r&   r(   r)   r3   resultr*   r*   r+   _parse_profileX   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   r#   r   c                 S   s   g | ]}|d  |d dqS )r   r   )score
suggestionr*   ).0_itemr*   r*   r+   
<listcomp>   s    z4SearchCommands._parse_spellcheck.<locals>.<listcomp>r   )rA   intlen)r&   r(   r)   corrections_correctionr*   r*   r+   _parse_spellcheckg   s    z SearchCommands._parse_spellcheckc                 K   s   |r	dd |D S i S )Nc                 S   s   i | ]	}|d  |d qS )r   r   r*   )rG   kvsr*   r*   r+   
<dictcomp>   s    z4SearchCommands._parse_config_get.<locals>.<dictcomp>r*   r;   r*   r*   r+   _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   r*   )rG   ir(   r*   r+   rP          z1SearchCommands._parse_syndump.<locals>.<dictcomp>r   r   )rangerK   r;   r*   rS   r+   _parse_syndump   s   zSearchCommands._parse_syndumpd   c                 C   s   | j | |dS )zT
        Create a new batch indexer from the client with a given chunk size
        )
chunk_size)BatchIndexer)r&   rX   r*   r*   r+   batch_indexer   s   zSearchCommands.batch_indexerFNc                 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  
        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       | ]}|  V  qd S r-   
redis_argsrG   fr*   r*   r+   	<genexpr>       z.SearchCommands.create_index.<locals>.<genexpr>)
CREATE_CMD
index_nameargsappendr   rA   rJ   r   r   r   r   r   r   listtuplesetr   rK   	itertoolschain	TypeErrorr^   execute_command)r&   fieldsno_term_offsetsno_field_flags	stopwords
definitionmax_text_fields	temporaryno_highlightno_term_frequenciesskip_initial_scanre   r*   r*   r+   create_index   s:   
(









 
zSearchCommands.create_indexrn   c                 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_   r*   r*   r+   ra      rb   z2SearchCommands.alter_schema_add.<locals>.<genexpr>)	ALTER_CMDrd   rg   rj   rk   rl   r^   rm   )r&   rn   re   r*   r*   r+   alter_schema_add   s    
zSearchCommands.alter_schema_adddelete_documentsc                 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 )rm   DROPINDEX_CMDrd   )r&   r|   
delete_strr*   r*   r+   	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_CMDrd   rf   rg   rj   rk   itemsrm   )r&   doc_idconnnosaverE   payloadreplacepartiallanguage	no_creatern   re   r*   r*   r+   _add_document  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_CMDrd   rf   rm   )r&   r   r   rE   r   r   re   r*   r*   r+   _add_document_hash,  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.

        ### 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)r   r   rE   r   r   r   r   r   )r   )
r&   r   r   rE   r   r   r   r   r   rn   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)r   rE   r   r   )r   )r&   r   rE   r   r   r*   r*   r+   add_document_hashx  s   
z SearchCommands.add_document_hashc                 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_CMDrd   rf   rm   )r&   r   r   delete_actual_documentre   r*   r*   r+   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 r*   r   rG   kvr*   r*   r+   rP     rT   z0SearchCommands.load_document.<locals>.<dictcomp>idNr*   r$   hgetallr   KeyErrorr   r&   r   rn   f2r*   r*   r+   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.

        )rm   MGET_CMDrd   )r&   idsr*   r*   r+   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>`_.
        rm   INFO_CMDrd   r,   r&   r(   r*   r*   r+   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   )rK   rf   r   )r&   r   re   keyvaluer*   r*   r+   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 )rd   rA   strr   
ValueErrortypeget_argsr   )r&   r3   r   re   r*   r*   r+   _mk_query_args  s   

zSearchCommands._mk_query_argsr3   c                 C   sX   | j ||d\}}t }| jtg|R  }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        @@r3   r4   r   timerm   
SEARCH_CMDrA   r   r,   r&   r3   r   re   str(   r*   r*   r+   search  s   
zSearchCommands.searchc                 C   s$   | j ||d\}}| jtg|R  S )zReturns the execution plan for a complex query.

        For more information see `FT.EXPLAIN <https://redis.io/commands/ft.explain>`_.
        r   )r   rm   EXPLAIN_CMD)r&   r3   r   re   
query_textr*   r*   r+   explain  s   	zSearchCommands.explainc                 C   s   t d)Nz#EXPLAINCLI will not be implemented.)NotImplementedError)r&   r3   r*   r*   r+   explain_cli
  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r3   r=   rA   r   boolrB   AGGREGATE_CMDrd   
build_argsr   
CURSOR_CMDr   r   rm   r,   r&   r3   r   r=   r'   rawr*   r*   r+   	aggregate  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   )r&   r   r3   r=   cursorschemarowsr*   r*   r+   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`, `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.

        r~   LIMITEDQUERY	AGGREGATEr   SEARCHz5Must provide AggregateRequest object or Query object.r   r   )r   PROFILE_CMDrd   rf   rA   r   r   r   r   r   r   rm   r,   )r&   r3   r   r   r   r'   r(   r*   r*   r+   profileC  s"   




zSearchCommands.profilec                 C   s\   t | j|g}|r|d|g |r|dd|g |r#|dd|g | j| }| t |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EXCLUDESPELLCHECK_CMDrd   extendrm   r,   r&   r3   distanceincludeexcluder'   r(   r*   r*   r+   
spellcheckk  s   
zSearchCommands.spellchecknametermsc                 G      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   rm   r&   r   r   r'   r*   r*   r+   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   rm   r   r*   r*   r+   dict_del  r   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_CMDrm   )r&   r   r'   r*   r*   r+   	dict_dump  s   	
zSearchCommands.dict_dumpoptionr   returnc                 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_CMDrm   r&   r   r   r'   r   r*   r*   r+   
config_set  s   

zSearchCommands.config_setc                 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  rm   r,   r&   r   r'   r(   r*   r*   r+   
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>`_.
        )rm   TAGVALS_CMDrd   )r&   r
  r*   r*   r+   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>`_.
        )rm   ALIAS_ADD_CMDrd   r&   r  r*   r*   r+   aliasadd  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>`_.
        )rm   ALIAS_UPDATE_CMDrd   r  r*   r*   r+   aliasupdate  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>`_.
        )rm   ALIAS_DEL_CMDr  r*   r*   r+   aliasdel  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   rf   r   rm   executer&   r   suggestionsr)   pipesugre   r*   r*   r+   sugadd  s   



zSearchCommands.sugaddr   c                 C   r  )z
        Return the number of entries in the AutoCompleter index.

        For more information see `FT.SUGLEN <https://redis.io/commands/ft.suglen>`_.
        )rm   SUGLEN_COMMAND)r&   r   r*   r*   r+   suglen  s   zSearchCommands.suglenr   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>`_.
        )rm   SUGDEL_COMMAND)r&   r   r   r*   r*   r+   sugdel  s   zSearchCommands.sugdel
   prefixfuzzynumr7   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 r*   r*   rG   sr*   r*   r+   rI   [      z)SearchCommands.sugget.<locals>.<listcomp>SUGGET_COMMANDrf   r   r   r    rm   r   )r&   r   r,  r-  r.  r7   r/  re   r(   resultsparserr*   r*   r+   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_CMDrd   r   rm   )r&   r;  r<  r   r'   r*   r*   r+   	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>`_.
        )rm   SYNDUMP_CMDrd   r,   r   r*   r*   r+   syndumpu  s   	zSearchCommands.syndump)rW   )	FFNNFNFFF)F)NFr   NFFNF)Nr   NF)Fr   NFFNF)r   NF)NFr-   )FNNNNFr+  FF)=__name__
__module____qualname____doc__r,   r2   r<   r?   rD   rN   rQ   rV   rZ   rx   r   r   r{   r   r   r   r   r   floatr   r   r   r   r   r   r   r   r   rJ   bytesr   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








 


(
8r!   c                   @   s   e Zd Zdd Z	d!deeef deeeeee	f f fddZ
	d!deeef deeeeee	f f fdd	Zd"d
dZdededefddZ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 )$AsyncSearchCommandsc                    s"   |  t| jI dH }| t|S )r   Nr   r   r*   r*   r+   r     s   zAsyncSearchCommands.infoNr3   r   c                    s`   | j ||d\}}t }| jtg|R  I dH }t|tr!|S | jt||t | d dS )r   r   Nr   r   r   r   r*   r*   r+   r     s   
zAsyncSearchCommands.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   r*   r*   r+   r     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 )r   r   r   r   r   Nr   r   r*   r*   r+   r     s   zAsyncSearchCommands.spellcheckr   r   r   c                    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 }| t |S )r  r  Nr  r  r*   r*   r+   r	    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   r*   r   r   r*   r*   r+   rP     rT   z5AsyncSearchCommands.load_document.<locals>.<dictcomp>r   r*   r   r   r*   r*   r+   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>`_.
        Fr  r  r  r   Nr  r  r"  r*   r*   r+   r&    s   



zAsyncSearchCommands.sugaddFr+  r   r,  r-  r.  r7   r/  c                    sp   t ||d|g}|r|t |r|t |r|t | j| I dH }g }	|s+|	S t|||}
dd |
D S )r0  r1  Nc                 S   r2  r*   r*   r3  r*   r*   r+   rI   ]  r5  z.AsyncSearchCommands.sugget.<locals>.<listcomp>r6  )r&   r   r,  r-  r.  r7   r/  re   retr8  r9  r*   r*   r+   r:  '  s   (


zAsyncSearchCommands.suggetr-   rA  rB  )rC  rD  rE  r   r   r   r   r   rJ   rG  r   r   r   r   r  r	  r   r&  r   r   r:  r*   r*   r*   r+   rI    sL    




 rI  )Irj   r   typingr   r   r   r   redis.clientr   redis.utilsr   helpersr	   r
   _utilr   aggregationr   r   r   documentr   r3   r   rC   r   rF   r   r   rc   rz   r   r   r   DROP_CMDr   r   EXPLAINCLI_CMDr   r   r   r   r   r   r   r   GET_CMDr   r  r  r  r  r  r   r  r)  r'  r7  r=  r?  r   r   r   r   r   r   r   r   r   r   r    r!   rI  r*   r*   r*   r+   <module>   s~          I