
    /
i&                        d dl Z d dlZd dlmZmZmZmZmZ d dlm	Z	 d dl
mZmZ d dlmZmZmZmZ d dlmZmZ d dlmZmZ dd	lmZ d
dlmZ d
dlmZmZmZ d
dl m!Z! d
dl"m#Z# d
dl$m%Z% d
dl&m'Z' d
dl(m)Z) d
dl*m+Z+ d
dl,m-Z- dZ.dZ/dZ0dZ1dZ2dZ3dZ4dZ5dZ6dZ7dZ8dZ9d Z:d!Z;d"Z<d#Z=d$Z>d%Z?d&Z@d'ZAd(ZBd)ZCd*ZDd+ZEd,ZFd-ZGd.ZHd/ZId0ZJd1ZKd2ZLd3ZMd4ZNd5ZOd6ZPd7ZQd8ZRd9ZSd:ZTd;ZUd<ZVd=ZW G d> d?          ZX G d@ dAeX          ZYdS )B    N)AnyDictListOptionalUnion)pairs_to_dict)NEVER_DECODEPipeline)CombineResultsMethodHybridCursorQueryHybridPostProcessingConfigHybridQuery)HybridCursorResultHybridResult)deprecated_functionexperimental_method   )get_protocol_version   	to_string)AggregateRequestAggregateResultCursor)Document)Field)IndexDefinition)ProfileInformation)Query)Result)SuggestionParserNUMERICz	FT.CREATEzFT.ALTERz	FT.SEARCHzFT.ADDz
FT.ADDHASHzFT.DROPINDEXz
FT.EXPLAINzFT.EXPLAINCLIzFT.DELzFT.AGGREGATE
FT.PROFILEz	FT.CURSORzFT.SPELLCHECKz
FT.DICTADDz
FT.DICTDELzFT.DICTDUMPzFT.MGETz	FT.CONFIGz
FT.TAGVALSzFT.ALIASADDzFT.ALIASUPDATEzFT.ALIASDELzFT.INFOz	FT.SUGADDz	FT.SUGDELz	FT.SUGLENz	FT.SUGGETzFT.SYNUPDATEz
FT.SYNDUMPz	FT.HYBRID	NOOFFSETSNOFIELDSNOHLNOFREQSMAXTEXTFIELDS	TEMPORARY	STOPWORDSSKIPINITIALSCAN
WITHSCORESFUZZYWITHPAYLOADSc                   z   e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 ZdgdZ	 	 	 	 	 	 	 	 	 dhdee         dededeee                  dee         dededefdZdeeee         f         fdZdidefdZ	 	 	 	 	 	 	 	 djdZ	 dkdZ edd           	 	 	 	 	 	 	 dld!ed"ed#ed$ee         d%ed&ed'ee         d(edee         fd)            Z edd           dmd*            Z edd+           dnd,            Zd- Z edd+           d.             Z d/ Z!d0ee"eeee#ee$f         f                  fd1Z%d0ee"eeee#ee$f         f                  fd2Z&	 dod3eee'f         d0ee"eeee#ee$f         f         df         fd4Z( e)            	 	 	 	 	 dpd3e*d5ee+         d6ee,         d7ee"eeee#ee$f         f                  d8ee#         d9ee-         d:ee.e/e0f         fd;            Z1	 dod3eee'f         d0ee"eeee#ee$f         f                  fd<Z2d3eee'f         fd=Z3	 dod3ee4e5f         d0ee"eeee#ee$f         f                  fd>Z6d?ed3ee4e5f         d@efdAZ7	 	 dqd3ee'e4f         dBed0ee"eeee#ee$f         f                  fdCZ8drdDZ9dEedFee         fdGZ:dEedFee         fdHZ;dEefdIZ< edJdK           dLedMed:efdN            Z= edJdO           dLed:efdP            Z>dQefdRZ?dSefdTZ@dSefdUZAdSefdVZBdW ZCdXed:e#fdYZDdXedZed:e#fd[ZE	 	 	 	 dsdXed]ed^ed_e#d`edaed:eeF         fdbZGdidceddedFee         fdeZHdf ZIdS )tSearchCommandszSearch commands.c                     t          | j                  dv r|dk    rt          |          n|S  | j        |         |fi |S )N3   r#   )r   clientr   _RESP2_MODULE_CALLBACKS)selfcmdreskwargss       C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\redis/commands/search/commands.py_parse_resultszSearchCommands._parse_resultsP   sU    ,,88.1\.A.A%c***sJ44/4SCCFCCC    c                 f    t          t          |          }t          t          ||                    S N)mapr   dictzip)r7   r9   r:   its       r;   _parse_infozSearchCommands._parse_infoV   s'    C  CBKK   r=   c           	          t          ||d         j         |d         |d         j        |d         j        |d         j                  S )Nqueryduration)rG   has_payloadwith_scoresfield_encodings)r    _no_content_with_payloads_with_scores_return_fields_decode_asr7   r9   r:   s      r;   _parse_searchzSearchCommands._parse_searchZ   sO    w++J'w6w4"7OD
 
 
 	
r=   c           	      ~   t          |d          }d|v r7t          t          |d                   t          |d                             S g }|d         D ](}t          |d          }|                    |           )t	          t          |d                   ||d	         t          |d
                             S )NT)decode_keyscursorSEARCHVSIM)search_cursor_idvsim_cursor_idresultstotal_resultswarningsexecution_time)rY   rX   rZ   r[   )r   r   intappendr   float)r7   r9   r:   res_dictrX   res_item	item_dicts          r;   _parse_hybrid_searchz#SearchCommands._parse_hybrid_searchd   s     $777v%!$Xh%7!8!8"8F#344   
 )+ !+ 	& 	&H%hDAAAINN9%%%%h788j) *:!;<<	
 
 
 	
r=   c                 H    |                      ||d         |d                   S )NrF   
has_cursor)_get_aggregate_resultrO   s      r;   _parse_aggregatezSearchCommands._parse_aggregatez   s#    ))#vg|@TUUUr=   c                    |d         }t          |t                    r#|                     |d         ||j                  }n0t	          |d         |j         |d         |j        |j                  }|t          |d                   fS )NrF   r   rG   )rG   rH   rI   r   )	
isinstancer   re   _cursorr    rK   rL   rM   r   )r7   r9   r:   rF   results        r;   _parse_profilezSearchCommands._parse_profile}   s    we-.. 		//Au}MMFFA%%
+!0!.  F )#a&1111r=   c                     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 )Nr   r4   r   c                 0    g | ]}|d          |d         dS )r   r   )score
suggestion ).0_items     r;   
<listcomp>z4SearchCommands._parse_spellcheck.<locals>.<listcomp>   s5     + + +@E%(%(;;+ + +r=   r   )rh   r\   len)r7   r9   r:   corrections_corrections        r;   _parse_spellcheckz SearchCommands._parse_spellcheck   s    !88 	 	K+s++ q0@0@;1$$q> q>!$ "+ +ITUV+ + +KA'' r=   c                 "    |rd |D             ni S )Nc                 ,    i | ]}|d          |d         S )r   r   rp   )rq   kvss     r;   
<dictcomp>z4SearchCommands._parse_config_get.<locals>.<dictcomp>   s"    ...3AA...r=   rp   rO   s      r;   _parse_config_getz SearchCommands._parse_config_get   s!    25=..#....2=r=   c                 X    fdt          dt                    d          D             S )Nc                 4    i | ]}|         |d z            S )r   rp   )rq   ir9   s     r;   r{   z1SearchCommands._parse_syndump.<locals>.<dictcomp>   s'    BBBqAAE
BBBr=   r   r   )rangert   rO   s    ` r;   _parse_syndumpzSearchCommands._parse_syndump   s/    BBBBE!SXXq,A,ABBBBr=   d   c                 0    |                      | |          S )zT
        Create a new batch indexer from the client with a given chunk size
        )
chunk_size)BatchIndexer)r7   r   s     r;   batch_indexerzSearchCommands.batch_indexer   s       * ===r=   FNfieldsno_term_offsetsno_field_flags	stopwords
definitionno_highlightno_term_frequenciesskip_initial_scanc                    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  
        Creates the search index. The index must not already exist.

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

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

        Nr   SCHEMAc              3   >   K   | ]}|                                 V  d S r?   
redis_argsrq   fs     r;   	<genexpr>z.SearchCommands.create_index.<locals>.<genexpr>   *      *J*Ja1<<>>*J*J*J*J*J*Jr=   )
CREATE_CMD
index_nameargsr]   r(   rh   r\   r)   r$   r&   r%   r'   r+   listtuplesetr*   rt   	itertoolschain	TypeErrorr   execute_command)r7   r   r   r   r   r   max_text_fields	temporaryr   r   r   r   s               r;   create_indexzSearchCommands.create_index   s   N 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   r   s     r;   r   z2SearchCommands.alter_schema_add.<locals>.<genexpr>  r   r=   )	ALTER_CMDr   r   r   r   r   r   r   )r7   r   r   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delete_documentsc                     t           | j        g}t          |t                    r|du rdnd}|r|                    |            | j        | S )ai  
        Drop the index if it exists.
        Replaced `drop_index` in RediSearch 2.0.
        Default behavior was changed to not delete the indexed documents.

        ### Parameters:

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

        For more information see `FT.DROPINDEX <https://redis.io/commands/ft.dropindex>`_.
        TDD )DROPINDEX_CMDr   rh   boolr]   r   )r7   r   r   
delete_strs       r;   	dropindexzSearchCommands.dropindex  sk     t/ *D116F$6N6N D 	  	$KK
####t#T**r=         ?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_CMDr   r]   r   r   r   itemsr   )r7   doc_idconnnosavern   payloadreplacepartiallanguage	no_creater   r   s               r;   _add_documentzSearchCommands._add_document0  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   r   )ADDHASH_CMDr   r]   r   )r7   r   r   rn   r   r   r   s          r;   _add_document_hashz!SearchCommands._add_document_hashZ  sk     T_fe< 	#KK	""" 	+Z**D'4'..#t#T**r=   z2.0.0z2deprecated since redisearch 2.0, call hset insteadversionreasonr   r   rn   r   r   r   r   r   c	                 0     | j         |fd|||||||d|	S )a  
        Add a single document to the index.

        Args:

            doc_id: the id of the saved document.
            nosave: if set to true, we just index the document, and don't
                      save a copy of it. This means that searches will just
                      return ids.
            score: the document ranking, between 0.0 and 1.0
            payload: optional inner-index payload we can save for fast
                     access in scoring functions
            replace: if True, and the document already is in the index,
                     we perform an update and reindex the document
            partial: if True, the fields specified will be added to the
                       existing document.
                       This has the added benefit that any fields specified
                       with `no_index`
                       will not be reindexed again. Implies `replace`
            language: Specify the language used for document tokenization.
            no_create: if True, the document is only updated and reindexed
                         if it already exists.
                         If the document does not exist, an error will be
                         returned. Implies `replace`
            fields: kwargs dictionary of the document fields to be saved
                    and/or indexed.
                    NOTE: Geo points shoule be encoded as strings of "lon,lat"
        N)r   r   rn   r   r   r   r   r   )r   )
r7   r   r   rn   r   r   r   r   r   r   s
             r;   add_documentzSearchCommands.add_documentn  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)r   rn   r   r   )r   )r7   r   rn   r   r   s        r;   add_document_hashz SearchCommands.add_document_hash  s,      &&UXw ' 
 
 	
r=   zdeprecated since redisearch 2.0c                 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
        r   )DEL_CMDr   r]   r   )r7   r   r   delete_actual_documentr   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 rp   r   rq   kvs      r;   r{   z0SearchCommands.load_document.<locals>.<dictcomp>  *    DDDTQillIaLLDDDr=   idrp   r5   hgetallr   KeyErrorr   r7   r   r   f2s       r;   load_documentzSearchCommands.load_document  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.

        )r   MGET_CMDr   )r7   idss     r;   getzSearchCommands.get  s#     $t#HdoDDDDDr=   c                 x    |                      t          | j                  }|                     t          |          S )
        Get info an stats about the the current index, including the number of
        documents, memory consumption, etc

        For more information see `FT.INFO <https://redis.io/commands/ft.info>`_.
        r   INFO_CMDr   r<   r7   r9   s     r;   infozSearchCommands.info  s1     ""8T_==""8S111r=   query_paramsc                 4   |g S g }t          |          dk    r~|                    d           |                    t          |          dz             |                                D ]/\  }}|                    |           |                    |           0|S )Nr   PARAMSr   )rt   r]   r   )r7   r   r   keyvalues        r;   get_params_argszSearchCommands.get_params_args  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 )r   rh   strr   
ValueErrortypeget_argsr   )r7   rF   r   r   s       r;   _mk_query_argszSearchCommands._mk_query_args  s      eS!! 	!%LLE%'' 	><tE{{<<===   $$\222U{r=   rF   c                 d   |                      ||          \  }}t          j                    }i }t          | j                  dvr
d|t
          <    | j        t          g|R i |}t          |t                    r|S | 
                    t          ||t          j                    |z
  dz            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   r2   T     @@rF   rG   r   time	monotonicr   r5   r	   r   
SEARCH_CMDrh   r
   r<   r7   rF   r   r   stoptionsr9   s          r;   searchzSearchCommands.search  s      ))%l)KKe^,,H<<$(GL!"d":@@@@@@c8$$ 	J""5DN4D4Dr4IV3S # 
 
 	
r=   combine_methodpost_processingparams_substitutiontimeoutrS   returnc                    | j         }i }t          |g}	|	                    |                                           |r'|	                    |                                           |r'|	                    |                                           |r(|	                    |                     |                     |r|	                    d|f           |r,d|d<   |	                    |                                           t          | j                  dvr
d|t          <    | j	        |	i |}
t          |
t                    r|
S  | j        t          |
fi |S )M  
        Execute a hybrid search using both text and vector queries

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


        For more information see `FT.SEARCH <https://redis.io/commands/ft.hybrid>`.
        TIMEOUTTrS   r2   r   
HYBRID_CMDextendr   
build_argsr   r   r5   r	   r   rh   r
   r<   r7   rF   r  r  r  r  rS   indexr  piecesr9   s              r;   hybrid_searchzSearchCommands.hybrid_search3  se   8 e$enn&&''' 	5MM.1133444 	8MM/4466777 	EMM$../BCCDDD 	0MM9g./// 	/ $GHMM&++--...,,H<<$(GL!"d"F6g66c8$$ 	J"t":s>>g>>>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   r   EXPLAIN_CMD)r7   rF   r   r   
query_texts        r;   explainzSearchCommands.explaini  s<      ..u<.PPj#t#K7$7777r=   c                      t          d          )Nz#EXPLAINCLI will not be implemented.)NotImplementedError)r7   rF   s     r;   explain_clizSearchCommands.explain_cliu  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        | }|                     t          |||          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rF   rd   rh   r   r   ri   AGGREGATE_CMDr   r  r   
CURSOR_CMDr   r   r   r<   r7   rF   r   rd   r8   raws         r;   	aggregatezSearchCommands.aggregatex  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(""3e
 # 
 
 	
r=   r%  rd   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   )rh   r   cidr   _with_schemar   )r7   r%  rF   rd   rS   schemarowss          r;   re   z$SearchCommands._get_aggregate_result  s      	%(( (F	Aa&CCFe-.. 	53E 	VFqrr7DDFqrr7DtVV444r=   limitedc                 2   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          j                    |z
  dz  	          S )
a  
        Performs a search or aggregate command and collects performance
        information.

        ### Parameters

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

        r   LIMITEDQUERY	AGGREGATEr   rT   z5Must provide AggregateRequest object or Query object.r   r   )r   r   PROFILE_CMDr   r]   rh   r   r  r   r   r   r   r   r<   )r7   rF   r,  r   r  r8   r9   s          r;   profilezSearchCommands.profile  s    $ ^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(""ET^5E5E5Jf4T # 
 
 	
r=   c                    t           | j        |g}|r|                    d|g           |r|                    dd|g           |r|                    dd|g            | j        | }|                     t           |          S )a  
        Issue a spellcheck query

        Args:

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

        For more information see `FT.SPELLCHECK <https://redis.io/commands/ft.spellcheck>`_.
        DISTANCETERMSINCLUDEEXCLUDESPELLCHECK_CMDr   r  r   r<   r7   rF   distanceincludeexcluder8   r9   s          r;   
spellcheckzSearchCommands.spellcheck  s     t6 	/JJ
H-... 	6JJG4555 	6JJG4555"d"C("">3777r=   nametermsc                 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  r   r7   r?  r@  r8   s       r;   dict_addzSearchCommands.dict_add  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  r   rC  s       r;   dict_delzSearchCommands.dict_del   rE  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_CMDr   )r7   r?  r8   s      r;   	dict_dumpzSearchCommands.dict_dump  s     d##t#S))r=   8.0.0Ddeprecated since Redis 8.0, call config_set from core module insteadoptionr   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_CMDr   r7   rN  r   r8   r%  s        r;   
config_setzSearchCommands.config_set  s+     5&%0"d"C(d{r=   Ddeprecated since Redis 8.0, call config_get from core module insteadc                 `    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rT  r   r<   r7   rN  r8   r9   s       r;   
config_getzSearchCommands.config_get,  s5     5&)"d"C("":s333r=   tagfieldc                 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>`_.
        )r   TAGVALS_CMDr   )r7   r^  s     r;   tagvalszSearchCommands.tagvals=  s     ##K(KKKr=   aliasc                 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>`_.
        )r   ALIAS_ADD_CMDr   r7   rb  s     r;   aliasaddzSearchCommands.aliasaddJ  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>`_.
        )r   ALIAS_UPDATE_CMDr   re  s     r;   aliasupdatezSearchCommands.aliasupdateW  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>`_.
        )r   ALIAS_DEL_CMDre  s     r;   aliasdelzSearchCommands.aliasdeld  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stringrn   r   r]   r   r   executer7   r   suggestionsr:   pipesugr   s          r;   sugaddzSearchCommands.sugaddp  s     }}}// 	( 	(C"CSY?Dzz+&& $F###{ )I&&&CK((( D $'''||~~b!!r=   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>`_.
        )r   SUGLEN_COMMAND)r7   r   s     r;   suglenzSearchCommands.suglen  s     ##NC888r=   rv  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>`_.
        )r   SUGDEL_COMMAND)r7   r   rv  s      r;   sugdelzSearchCommands.sugdel  s     ##NC@@@r=   
   prefixfuzzynumrI   with_payloadsc                    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 rp   rp   rq   ss     r;   rs   z)SearchCommands.sugget.<locals>.<listcomp>      """a"""r=   SUGGET_COMMANDr]   r-   r,   r.   r   r!   )r7   r   r  r  r  rI   r  r   r9   rX   parsers              r;   suggetzSearchCommands.sugget  s    P VUC8 	KK 	$KK
### 	&KK%%%"d"D) 	N!+}cBB""6""""r=   groupidskipinitialc                     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   )r7   r  r  r@  r8   s        r;   	synupdatezSearchCommands.synupdate  sR    $ dow7 	,JJ)*+++

5#t#S))r=   c                 x    |                      t          | j                  }|                     t          |          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>`_.
        )r   SYNDUMP_CMDr   r<   r   s     r;   syndumpzSearchCommands.syndump  s1     "";@@"";444r=   )r   )	FFNNFNFFF)F)NFr   NFFNF)Nr   NF)Fr   NFFNF)r   NF)NFr?   NNNNN)FNNNNFr  FF)J__name__
__module____qualname____doc__r<   rD   rP   rb   rf   rk   rw   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\   bytesr   r   r   r  r   r   r   r   r   r   r   r
   r  r  r  r   r   r&  re   r2  r>  rD  rH  rK  rV  r]  ra  rf  ri  rl  r|  r  r  r!   r  r  r  rp   r=   r;   r0   r0   M   s 	       D D D! ! !
 
 

 
 
,V V V2 2 2# # #J> > >C C C> > > > !&$)-04"$)"'D+ D+UD+ D+ 	D+
 DI&D+ _-D+ D+ "D+  D+ D+ D+ D+L+uUDK-?'@ + + + +(+ +$ + + + +8 (+ (+ (+ (+V DI+ + + +(  T   "&"&3
 3
3
 3
 	3

 $3
 3
 3
 3-3
 3
 s)3
 3
 3
 3
j  T  
 
 
 
" 1RSSS+ + + TS+&) ) ) 1RSSS
E 
E TS
E	2 	2 	2$T#uS#ue5K/L*L%MN   #+DeCeU<R6S1S,T#U   & OS
 
S%Z 
 DeCeU,B&C!CDdJK
 
 
 
@  :>@DRV!%.23? 3?3? !!563? ""<=	3?
 &d3c3u6L0M+M&NO3? #3? *+3? 
|/9	:3? 3? 3? 3?p LP
8 
8S%Z 
8 tCsC/E)F$FGH
8 
8 
8 
8IsEz!2 I I I I LP
 
%v-.
 tCsC/E)F$FGH
 
 
 
@55 %&6&> ?5MQ5 5 5 52 KO	&
 &
U,,-&
 &
 tCsC/E)F$FGH	&
 &
 &
 &
P8 8 8 88*S *$s) * * * **S *$s) * * * *
*c 
* 
* 
* 
* U   S T   	  U  4 4 4 4 4	 4L L L L LKc K K K KN N N N N
:c 
: 
: 
: 
:" " ".9# 9# 9 9 9 9A# As As A A A A !#6# 6#6# 6# 	6#
 6# 6# 6# 
	6# 6# 6# 6#p* * *4 *c * * * *0
5 
5 
5 
5 
5r=   r0   c                   <   e Zd Zd Z	 d"deeef         deeeeee	e
ef         f                  fdZ e            	 	 	 	 	 d#dedee         dee         deeeeee	e
ef         f                  d	ee	         d
ee         deeeef         fd            Z	 d"deeef         deeeeee	e
ef         f                  fdZd$dZ edd          dededefd            Z edd          dedefd            Zd Zd Z	 	 	 	 d%dededede	ded ede e!         fd!Z"dS )&AsyncSearchCommandsc                    K   |                      t          | j                   d{V }|                     t          |          S )r   Nr   r   s     r;   r   zAsyncSearchCommands.info  sG       ((4?CCCCCCCC""8S111r=   NrF   r   c                 t  K   |                      ||          \  }}t          j                    }i }t          | j                  dvr
d|t
          <    | j        t          g|R i | d{V }t          |t                    r|S | 
                    t          ||t          j                    |z
  dz            S )r   r   r2   TNr   r   r   r  s          r;   r  zAsyncSearchCommands.search  s        ))%l)KKe^,,H<<$(GL!(D(FdFFFgFFFFFFFFc8$$ 	J""5DN4D4Dr4IV3S # 
 
 	
r=   r  r  r  r  rS   r	  c                   K   | j         }i }t          |g}	|	                    |                                           |r'|	                    |                                           |r'|	                    |                                           |r(|	                    |                     |                     |r|	                    d|f           |r,d|d<   |	                    |                                           t          | j                  dvr
d|t          <    | j	        |	i | d{V }
t          |
t                    r|
S  | j        t          |
fi |S )r  r  TrS   r2   Nr  r  s              r;   r  z!AsyncSearchCommands.hybrid_search!  s{     8 e$enn&&''' 	5MM.1133444 	8MM/4466777 	EMM$../BCCDDD 	0MM9g./// 	/ $GHMM&++--...,,H<<$(GL!(D(&<G<<<<<<<<c8$$ 	J"t":s>>g>>>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 }|                     t          |||          S )r  Tr  r  Nr   r!  r$  s         r;   r&  zAsyncSearchCommands.aggregateW  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(#.......""3e
 # 
 
 	
r=   c                   K   t           | j        |g}|r|                    d|g           |r|                    dd|g           |r|                    dd|g            | j        |  d{V }|                     t           |          S )a  
        Issue a spellcheck query

        ### Parameters

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

        For more information see `FT.SPELLCHECK <https://redis.io/commands/ft.spellcheck>`_.
        r4  r5  r6  r7  Nr8  r:  s          r;   r>  zAsyncSearchCommands.spellcheckw  s       t6 	/JJ
H-... 	6JJG4555 	6JJG4555(D(#......."">3777r=   rL  rM  r   rN  r   c                 H   K   t           d||g} | j        |  d{V }|dk    S )rP  rQ  NrR  rS  rU  s        r;   rV  zAsyncSearchCommands.config_set  sA       5&%0(D(#.......d{r=   rW  c                 t   K   t           d|g}i } | j        |  d{V }|                     t           |          S )rY  rZ  Nr[  r\  s       r;   r]  zAsyncSearchCommands.config_get  sP       5&)(D(#......."":s333r=   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 rp   r   r   s      r;   r{   z5AsyncSearchCommands.load_document.<locals>.<dictcomp>  r   r=   r   rp   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>`_.
        Frn  rp  rq  r   Nrr  rs  rx  s          r;   r|  zAsyncSearchCommands.sugadd  s       }}}// 	( 	(C"CSY?Dzz+&& $F###{ )I&&&CK((( D $'''llnn$$$$$$b))r=   Fr  r   r  r  r  rI   r  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 rp   rp   r  s     r;   rs   z.AsyncSearchCommands.sugget.<locals>.<listcomp>  r  r=   r  )r7   r   r  r  r  rI   r  r   retrX   r  s              r;   r  zAsyncSearchCommands.sugget  s      P VUC8 	KK 	$KK
### 	&KK%%%(D($/////// 	N!+}cBB""6""""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   r   rV  r]  r   r|  r   r!   r  rp   r=   r;   r  r    s       	2 	2 	2 LP
 
S%Z 
 tCsC/E)F$FGH
 
 
 
@  :>@DRV!%.23? 3?3? !!563? ""<=	3?
 &d3c3u6L0M+M&NO3? #3? *+3? 
|/9	:3? 3? 3? 3?p LP
 
_f,-
 tCsC/E)F$FGH
 
 
 
@8 8 8 88 U  s 3 4   	  U  4s 4s 4 4 4	 4) ) )* * *6 !#6# 6#6# 6# 	6#
 6# 6# 6# 
	6# 6# 6# 6# 6# 6#r=   r  )Zr   r   typingr   r   r   r   r   redis._parsers.helpersr   redis.clientr	   r
   "redis.commands.search.hybrid_queryr   r   r   r   #redis.commands.search.hybrid_resultr   r   redis.utilsr   r   helpersr   _utilr   aggregationr   r   r   documentr   fieldr   index_definitionr   profile_informationr   rF   r   rj   r    ro   r!   r"   r   r   r   r   r   r   r  EXPLAINCLI_CMDr   r"  r1  r#  r9  rB  rG  rJ  r   rT  r`  rd  rh  rk  r   ru  r  r~  r  r  r  r  r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r0   r  rp   r=   r;   <module>r     s        3 3 3 3 3 3 3 3 3 3 3 3 3 3 0 0 0 0 0 0 / / / / / / / /            Q P P P P P P P @ @ @ @ @ @ @ @ * * * * * *               
             - - - - - - 3 3 3 3 3 3             ( ( ( ( ( (

	

 

 
# 
	
		#
e5 e5 e5 e5 e5 e5 e5 e5P^# ^# ^# ^# ^#. ^# ^# ^# ^# ^#r=   