
     h                        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@d5ZAd6ZBd7ZCd8ZD G d9 d:          ZE G 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                   
   e Zd ZdZd1dZ	 	 	 	 	 	 	 	 	 d2dZd Zd3dZ	 	 	 	 	 	 	 	 d4d
Z	 d5dZ	 e
dd          	 	 	 	 	 	 	 d6d            Z e
dd          d7d            Zd8dZd Zd Zd Zdeeeeeeef         f         df         fdZdeeeeeef         f         fdZ	 d9deeef         deeeeeef         f         fdZ	 d9deeef         deeeeeef         f         fdZdeeef         fdZ	 d9deeef         deeeeeef         f         fdZd Z	 	 d:deeeef         dede eeeeeef         f                  fdZ!d;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<d.Z/d3d/Z0d0 Z1dS )=SearchCommandszSearch commands.d   c                 0    |                      | |          S )zT
        Create a new batch indexer from the client with a given chunk size
        )
chunk_size)BatchIndexer)selfr$   s     Z/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/redis/commands/search/commands.pybatch_indexerzSearchCommands.batch_indexerB   s       * ===    FNc                    t           | j        g}|
||j        z  }|r|                    t                     |Dt          |t                    r/|                    t                     |                    |           |r|                    t                     |r|                    t                     |r|                    t                     |	r|                    t                     |
r|                    t                     |`t          |t          t          t          f          r>|t           t#          |          gz  }t#          |          dk    r|t          |          z  }|                    d           	 |t          t%          j        d |D                        z  }n'# t(          $ r ||                                z  }Y nw xY 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              3   >   K   | ]}|                                 V  d S N
redis_args.0fs     r'   	<genexpr>z.SearchCommands.create_index.<locals>.<genexpr>   *      *J*Ja1<<>>*J*J*J*J*J*Jr)   )
CREATE_CMD
index_nameargsappendr   
isinstanceintr   r   r   r   r   r   listtuplesetr   len	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_scanr7   s               r'   create_indexzSearchCommands.create_indexH   s   P DO,!JO#D 	'KK&&& Z	3%?%? KK	"""KK	""" 	#KK	""" 	KK 	"KK!!! 	!KK    	)KK((( Z	D%;M%N%N YI//D9~~!!Y'H	(D*J*J6*J*J*JKLLLDD 	( 	( 	(F%%'''DDD	( $t#T**s   (F* *!GGc                     t           | j        ddg}	 |t          t          j        d |D                        z  }n'# t
          $ r ||                                z  }Y nw xY 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              3   >   K   | ]}|                                 V  d S r-   r.   r0   s     r'   r3   z2SearchCommands.alter_schema_add.<locals>.<genexpr>   r4   r)   )	ALTER_CMDr6   r;   r?   r@   rA   r/   rB   )r&   rC   r7   s      r'   alter_schema_addzSearchCommands.alter_schema_add   s     4?He<	(D*J*J6*J*J*JKLLLDD 	( 	( 	(F%%'''DDD	( $t#T**s   (; !AAc                 P    |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 )rB   DROPINDEX_CMDr6   )r&   delete_documents
delete_strs      r'   	dropindexzSearchCommands.dropindex   s,     .5TT2
##M4?JOOOr)         ?c
                    |s|	rd}t           | j        ||g}|r|                    d           |*|                    d           |                    |           |rC|                    d           |r|                    d           |	r|                    d           |r|d|gz  }|                    d	           |t          t	          j        |
                                           z  }|
 |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_CMDr6   r8   r;   r?   r@   itemsrB   )r&   doc_idconnnosavescorepayloadreplacepartiallanguage	no_createrC   r7   s               r'   _add_documentzSearchCommands._add_document   s*   "  	i 	G&%8 	"KK!!!KK	"""KK    	(KK	""" 'I&&& (J''' 	+Z**DHY_fllnn5666'4'..#t#T**r)   c                     t           | j        ||g}|r|                    d           |r|d|gz  }|
 |j        | S  | j        | S )zX
        Internal add_document_hash used for both batch and single doc indexing
        r^   ra   )ADDHASH_CMDr6   r8   rB   )r&   re   rf   rh   rl   rj   r7   s          r'   _add_document_hashz!SearchCommands._add_document_hash   sk     T_fe< 	#KK	""" 	+Z**D'4'..#t#T**r)   z2.0.0z2deprecated since redisearch 2.0, call hset instead)versionreasonc	                 0     | 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)rf   rg   rh   ri   rj   rk   rl   rm   )rn   )
r&   re   rg   rh   ri   rj   rk   rl   rm   rC   s
             r'   add_documentzSearchCommands.add_document   sK    V "t!

 
 
 
 	
r)   c                 6    |                      |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)rf   rh   rl   rj   )rq   )r&   re   rh   rl   rj   s        r'   add_document_hashz SearchCommands.add_document_hash(  s,      &&UXw ' 
 
 	
r)   c                 z    t           | j        |g}|r|                    d           |
 |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
        rT   )DEL_CMDr6   r8   rB   )r&   re   rf   delete_actual_documentr7   s        r'   delete_documentzSearchCommands.delete_document<  sR     &1! 	KK'4'..#t#T**r)   c                     | j                             |          }d |                                D             }|}	 |d= n# t          $ r Y nw xY wt	          dd|i|S ).
        Load a single document by id
        c                 N    i | ]"\  }}t          |          t          |          #S  r   r1   kvs      r'   
<dictcomp>z0SearchCommands.load_document.<locals>.<dictcomp>T  *    DDDTQillIaLLDDDr)   idr   clienthgetallrd   KeyErrorr   r&   r   rC   f2s       r'   load_documentzSearchCommands.load_documentO  s     $$R((DDV\\^^DDD	t 	 	 	D	 ((2((((s   A   
AAc                 4     | j         t          | j        g|R  S )z
        Returns the full contents of multiple documents.

        ### Parameters

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

        )rB   MGET_CMDr6   )r&   idss     r'   getzSearchCommands.get^  s#     $t#HdoDDDDDr)   c                     |                      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>`_.
        rB   INFO_CMDr6   mapr   dictzipr&   resits      r'   infozSearchCommands.infoj  s@     ""8T_==C  CBKK   r)   query_paramsc                 4   |g S g }t          |          dk    r~|                    d           |                    t          |          dz             |                                D ]/\  }}|                    |           |                    |           0|S )Nr   paramsr   )r>   r8   rd   )r&   r   r7   keyvalues        r'   get_params_argszSearchCommands.get_params_argsv  s     I|q  KK!!!KKL))A-...*0022 # #
UC   E""""r)   c                 (   | j         g}t          |t                    rt          |          }t          |t                    st	          dt          |                     ||                                z  }||                     |          z  }||fS )NzBad query type )r6   r9   strr   
ValueErrortypeget_argsr   )r&   queryr   r7   s       r'   _mk_query_argszSearchCommands._mk_query_args  s     eS!! 	!%LLE%'' 	><tE{{<<===   $$\222U{r)   r   c                 &   |                      ||          \  }}t          j                    } | j        t          g|R  }t	          |t
                    r|S t          ||j         t          j                    |z
  dz  |j        |j	                  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        @@durationhas_payloadwith_scores
r   timerB   
SEARCH_CMDr9   r   r   _no_content_with_payloads_with_scoresr&   r   r   r7   str   s         r'   searchzSearchCommands.search  s      ))%l)KKeY[["d":5555c8$$ 	J!!ikkB&&0,*
 
 
 	
r)   c                 \    |                      ||          \  }} | 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   rB   EXPLAIN_CMD)r&   r   r   r7   
query_texts        r'   explainzSearchCommands.explain  s<      ..u<.PPj#t#K7$7777r)   c                      t          d          )Nz#EXPLAINCLI will not be implemented.)NotImplementedError)r&   r   s     r'   explain_clizSearchCommands.explain_cli  s    !"GHHHr)   c                    t          |t                    r8t          |j                  }t          | j        g|                                z   }nLt          |t                    r'd}t          d| j        g|                                z   }nt          d|          || 
                    |          z  } | 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r9   r   bool_cursorAGGREGATE_CMDr6   
build_argsr   
CURSOR_CMDr   r   rB   _get_aggregate_resultr&   r   r   
has_cursorcmdraws         r'   	aggregatezSearchCommands.aggregate  s    " e-.. 	1em,,J $/2U5E5E5G5GGCCv&& 	1Jvt7%:J:J:L:LLCC[%000t##L111"d"C())#ujAAAr)   c                 (   |rCt          |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   )r9   r   cidr   _with_schemar   )r&   r   r   r   cursorschemarowss          r'   r   z$SearchCommands._get_aggregate_result  s     	%(( (F	Aa&CCFe-.. 	53E 	VFqrr7DDFqrr7DtVV444r)   limitedc                    t          j                     }t          | j        dg}|r|                    d           |                    d           t	          |t
                    rd|d<   ||                                z  }nYt	          |t                    r5d|d<   ||                                z  }|| 	                    |          z  }nt          d           | j        | }t	          |t
                    r#|                     |d         ||j                  }nAt          |d         |j         t          j                     |z
  d	z  |j        |j        
          }|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.

        rU   LIMITEDQUERY	AGGREGATEr   SEARCHz5Must provide AggregateRequest object or Query object.r   r   r   r
   )r   PROFILE_CMDr6   r8   r9   r   r   r   r   r   r   rB   r   r   r   r   r   r   r	   )r&   r   r   r   r   r   r   results           r'   profilezSearchCommands.profile  st   $ Y[[DOR0 	"JJy!!!

7e-.. 	V CF5##%%%CCu%% 	VCF5>>###C4''555CCTUUU"d"C(e-.. 		//Au}MMFFA%%)++*f4!0!.  F }SV,,,,r)   c                    t           | j        |g}|r|                    d|g           |r|                    dd|g           |r|                    dd|g            | j        | }i }|dk    r|S |D ]e}t	          |t
                    r|dk    rt          |          dk    r2|d         s;|d         d         sJd |d         D             ||d	         <   f|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                 0    g | ]}|d          |d         dS r   r
   )rh   
suggestionr   r1   _items     r'   
<listcomp>z-SearchCommands.spellcheck.<locals>.<listcomp>[  5     + + +@E%(%(;;+ + +r)   r
   SPELLCHECK_CMDr6   extendrB   r9   r:   r>   	r&   r   distanceincludeexcluder   r   corrections_corrections	            r'   
spellcheckzSearchCommands.spellcheck#  s4    t6 	/JJ
H-... 	6JJG4555 	6JJG4555"d"C(!88 	 	K+s++ q0@0@;1$$q> q>!$ "+ +ITUV+ + +KA'' r)   c                 R    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   rB   r&   nametermsr   s       r'   dict_addzSearchCommands.dict_adda  0     T"

5#t#S))r)   c                 R    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   rB   r   s       r'   dict_delzSearchCommands.dict_delo  r   r)   c                 (    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_CMDrB   )r&   r   r   s      r'   	dict_dumpzSearchCommands.dict_dump}  s     d##t#S))r)   c                 8    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_CMDrB   r&   optionr   r   r   s        r'   
config_setzSearchCommands.config_set  s+     5&%0"d"C(d{r)   c                 b    t           d|g}i } | j        | }|r|D ]}|d         ||d         <   |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   r   r   kvss         r'   
config_getzSearchCommands.config_get  sS     5&)"d"C( 	% % %!!fCF
r)   c                 D    |                      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>`_.
        )rB   TAGVALS_CMDr6   )r&   tagfields     r'   tagvalszSearchCommands.tagvals  s     ##K(KKKr)   c                 D    |                      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>`_.
        )rB   ALIAS_ADD_CMDr6   r&   aliass     r'   aliasaddzSearchCommands.aliasadd  s     ##M5$/JJJr)   c                 D    |                      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>`_.
        )rB   ALIAS_UPDATE_CMDr6   r  s     r'   aliasupdatezSearchCommands.aliasupdate  s     ##$4eT_MMMr)   c                 8    |                      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>`_.
        )rB   ALIAS_DEL_CMDr  s     r'   aliasdelzSearchCommands.aliasdel  s     ##M5999r)   c                 j   |                      d          }|D ]}t          ||j        |j        g}|                    d          r|                    d           |j        r/|                    d           |                    |j                    |j        |  |                                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stringrh   r   r8   ri   rB   executer&   r   suggestionskwargspipesugr7   s          r'   sugaddzSearchCommands.sugadd  s     }}}// 	( 	(C"CSY?Dzz+&& $F###{ )I&&&CK((( D $'''||~~b!!r)   c                 8    |                      t          |          S )z
        Return the number of entries in the AutoCompleter index.

        For more information see `FT.SUGLEN <https://redis.io/commands/ft.suglen>`_.
        )rB   SUGLEN_COMMAND)r&   r   s     r'   suglenzSearchCommands.suglen  s     ##NC888r)   c                 :    |                      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>`_.
        )rB   SUGDEL_COMMAND)r&   r   r,  s      r'   sugdelzSearchCommands.sugdel  s     ##NC@@@r)   
   c                    t           ||d|g}|r|                    t                     |r|                    t                     |r|                    t                      | j        | }g }	|s|	S t          |||          }
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                     g | ]}|S r   r   r1   ss     r'   r   z)SearchCommands.sugget.<locals>.<listcomp>3      """a"""r)   SUGGET_COMMANDr8   r   r   r   rB   r   r&   r   prefixfuzzynumr   with_payloadsr7   retresultsparsers              r'   suggetzSearchCommands.sugget  s    D VUC8 	KK 	$KK
### 	&KK%%%"d"D) 	N!+}cBB""6""""r)   c                     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_CMDr6   r   rB   )r&   groupidskipinitialr   r   s        r'   	synupdatezSearchCommands.synupdate5  sR    $ dow7 	,JJ)*+++

5#t#S))r)   c                     |                      t          | j                  f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                 4    i | ]}|         |d z            S )r
   r   )r1   ir   s     r'   r   z*SearchCommands.syndump.<locals>.<dictcomp>W  s'    BBBqAAE
BBBr)   r   r   )rB   SYNDUMP_CMDr6   ranger>   )r&   r   s    @r'   syndumpzSearchCommands.syndumpM  sH     "";@@BBBBE!SXXq,A,ABBBBr)   )r"   )	FFNNFNFFF)F)NFrZ   NFFNF)NrZ   NF)FrZ   NFFNF)rZ   NF)NFr-   )FNNNNFr:  FF)2__name__
__module____qualname____doc__r(   rM   rR   rY   rn   rq   r   ru   rw   r{   r   r   r   r   r   r   r:   floatr   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r"  r3  r6  r9  rL  rQ  rW  r   r)   r'   r!   r!   ?   s       > > > > !E+ E+ E+ E+N+ + +(P P P P$ (+ (+ (+ (+V DI+ + + +(  T   3
 3
 3
 3
j  T  
 
 
 
"+ + + +&) ) )
E 
E 
E
! 
! 
!!$sE#sE/,B'B"CT"IJ   $sE#sE/<R7R2S    " ;?
 
S%Z 
 3c3o 667
 
 
 
D ;?
8 
8S%Z 
8 3c3o 667
8 
8 
8 
8IsEz!2 I I I I ;?B BS%Z B 3c3o 667B B B B<5 5 5. DH	/- /-S%!112/- /- tCsC)?$?@A	/- /- /- /-b< < < <|* * ** * *
* 
* 
*    "L L LK K KN N N
: 
: 
:" " ".9 9 9A A A RW0# 0# 0# 0#d* * * *0
C 
C 
C 
C 
Cr)   r!   c            
           e Zd Zd Z	 ddeeef         deeeeee	f         f         fdZ
	 ddeeef         deeeeee	f         f         fdZddZd Zd	 Zd
 Zd Z	 ddZdS )AsyncSearchCommandsc                    K   |                      t          | j                   d{V }t          t          |          }t          t          ||                    S )r   Nr   r   s      r'   r   zAsyncSearchCommands.info[  sV       ((4?CCCCCCCCC  CBKK   r)   Nr   r   c                 6  K   |                      ||          \  }}t          j                    } | j        t          g|R   d{V }t	          |t
                    r|S t          ||j         t          j                    |z
  dz  |j        |j	                  S )r   r   Nr   r   r   r   s         r'   r   zAsyncSearchCommands.searchg  s        ))%l)KKeY[[(D(;d;;;;;;;;;c8$$ 	J!!ikkB&&0,*
 
 
 	
r)   c                   K   t          |t                    r8t          |j                  }t          | j        g|                                z   }nLt          |t                    r'd}t          d| j        g|                                z   }nt          d|          || 
                    |          z  } | j        |  d{V }|                     |||          S )r   Tr   r   Nr   r   s         r'   r   zAsyncSearchCommands.aggregate  s      " e-.. 	1em,,J $/2U5E5E5G5GGCCv&& 	1Jvt7%:J:J:L:LLCC[%000t##L111(D(#.......))#ujAAAr)   c                   K   t           | j        |g}|r|                    d|g           |r|                    dd|g           |r|                    dd|g            | j        |  d{V }i }|dk    r|S |D ]e}t	          |t
                    r|dk    rt          |          dk    r2|d         s;|d         d         sJd	 |d         D             ||d
         <   f|S )r   r   r   r   r   Nr   r   r   c                 0    g | ]}|d          |d         dS r   r   r   s     r'   r   z2AsyncSearchCommands.spellcheck.<locals>.<listcomp>  r   r)   r
   r   r   s	            r'   r   zAsyncSearchCommands.spellcheck  sJ      t6 	/JJ
H-... 	6JJG4555 	6JJG4555(D(#.......!88 	 	K+s++ q0@0@;1$$q> q>!$ + +ITUV+ + +KA'' r)   c                 H   K   t           d||g} | j        |  d{V }|dk    S )r  r  Nr  r	  r  s        r'   r  zAsyncSearchCommands.config_set  sA       5&%0(D(#.......d{r)   c                 r   K   t           d|g}i } | j        |  d{V }|r|D ]}|d         ||d         <   |S )r  r  Nr
   r   r	  r  s         r'   r  zAsyncSearchCommands.config_get  si       5&)(D(#....... 	% % %!!fCF
r)   c                    K   | j                             |           d{V }d |                                D             }|}	 |d= n# t          $ r Y nw xY wt	          dd|i|S )r}   Nc                 N    i | ]"\  }}t          |          t          |          #S r   r   r   s      r'   r   z5AsyncSearchCommands.load_document.<locals>.<dictcomp>  r   r)   r   r   r   r   s       r'   r   z!AsyncSearchCommands.load_document  s       {**2........DDV\\^^DDD	t 	 	 	D	 ((2((((s   A 
AAc                 z  K   |                      d          }|D ]}t          ||j        |j        g}|                    d          r|                    d           |j        r/|                    d           |                    |j                    |j        |  |                                 d{V 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.  s          r'   r3  zAsyncSearchCommands.sugadd  s       }}}// 	( 	(C"CSY?Dzz+&& $F###{ )I&&&CK((( D $'''llnn$$$$$$b))r)   Fr:  c                 ,  K   t           ||d|g}|r|                    t                     |r|                    t                     |r|                    t                      | j        |  d{V }g }	|s|	S t          |||          }
d |
D             S )r<  r=  Nc                     g | ]}|S r   r   r?  s     r'   r   z.AsyncSearchCommands.sugget.<locals>.<listcomp>H  rA  r)   rB  rD  s              r'   rL  zAsyncSearchCommands.sugget  s      D VUC8 	KK 	$KK
### 	&KK%%%(D($/////// 	N!+}cBB""6""""r)   r-   rX  rY  )rZ  r[  r\  r   r   r   r   r   r:   r^  r   r   r   r  r  r   r3  rL  r   r)   r'   r`  r`  Z  s3       
! 
! 
! ;?
 
S%Z 
 3c3o 667
 
 
 
D ;?B BS%Z B 3c3o 667B B B B<- - - -^    ") ) )* * *0 RW0# 0# 0# 0# 0# 0#r)   r`  )Gr?   r   typingr   r   r   redis.clientr   redis.utilsr   helpersr	   _utilr   aggregationr   r   r   documentr   r   r   r   r   r   r   r   r5   rQ   r   rc   rp   DROP_CMDrV   r   EXPLAINCLI_CMDry   r   r   r   r   r   r   r  GET_CMDr   r
  r  r  r  r!  r   r+  r8  r5  rC  rN  rU  r   r   r   r   r   r   r   r   r   r   r   r!   r`  r   r)   r'   <module>rw     s5        ( ( ( ( ( ( ( ( ( ( ! ! ! ! ! ! + + + + + + # # # # # #       B B B B B B B B B B                   ( ( ( ( ( (

	

 

 

# 	
		#
XC XC XC XC XC XC XC XCvn# n# n# n# n#. n# n# n# n# n#r)   