
    Ih                        d dl Z d dlZd dlmZmZ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 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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=d-Z>d.Z?d/Z@d0ZAd1ZBd2ZCd3ZDd4ZEd5ZFd6ZGd7ZHd8ZId9ZJ G d: d;      ZK G d< d=eK      ZLy)>    N)DictListOptionalUnion)NEVER_DECODEPipeline)deprecated_function   )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.SYNDUMP	NOOFFSETSNOFIELDSNOHLNOFREQSMAXTEXTFIELDS	TEMPORARY	STOPWORDSSKIPINITIALSCAN
WITHSCORESFUZZYWITHPAYLOADSc                   r   e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd\d
Z	 	 	 	 	 	 	 	 	 d]dee   dededeee      dee   dededefdZdee   fdZd^defdZ	 	 	 	 	 	 	 	 d_dZ	 d`dZ edd      	 	 	 	 	 	 	 dadededed ed!ed"ed#ee   d$edee   fd%       Z edd      dbd&       Z edd'      dcd(       Zd) Z edd'      d*        Zd+ Zd,e e!ee ee"ee#f   f   df   fd-Z$d,e e!ee ee"ee#f   f   df   fd.Z%	 ddd/e ee&f   d,e e!ee ee"ee#f   f   df   fd0Z'	 ddd/e ee&f   d,e!ee ee"ef   f   fd1Z(d/e ee&f   fd2Z)	 ddd/e ee&f   d,e!ee ee"ef   f   fd3Z*d4ed/e ee&e+f   d5efd6Z,	 	 ded/e e&e+f   d7ed,ee!ee ee"ef   f      fd8Z-dfd9Z.d:ed;ee   fd<Z/d:ed;ee   fd=Z0d:efd>Z1 ed?d@      dAedBedCefdD       Z2 ed?dE      dAedCefdF       Z3dGefdHZ4dIefdJZ5dIefdKZ6dIefdLZ7dM Z8dNedCe"fdOZ9dNedPedCe"fdQZ:	 	 	 	 dgdNedRedSedTe"dUedVedCee;   fdWZ<d^dXedYed;ee   fdZZ=d[ Z>y)hSearchCommandszSearch commands.c                     t        | j                        dv r|dk(  rt        |      S |S  | j                  |   |fi |S )N3   r   )r   clientr   _RESP2_MODULE_CALLBACKS)selfcmdreskwargss       W/var/www/html/planif/env/lib/python3.12/site-packages/redis/commands/search/commands.py_parse_resultszSearchCommands._parse_resultsC   sH    ,8.1\.A%c*JsJ44//4SCFCC    c                 L    t        t        |      }t        t        ||            S N)mapr   dictzip)r-   r/   r0   its       r1   _parse_infozSearchCommands._parse_infoI   s    C CBK  r3   c           	          t        ||d   j                   |d   |d   j                  |d   j                  |d   j                        S )Nqueryduration)r=   has_payloadwith_scoresfield_encodings)r   _no_content_with_payloads_with_scores_return_fields_decode_asr-   r/   r0   s      r1   _parse_searchzSearchCommands._parse_searchM   sQ    w+++J'w66w44"7ODD
 	
r3   c                 4    | j                  ||d   |d         S )Nr<   
has_cursor)_get_aggregate_resultrE   s      r1   _parse_aggregatezSearchCommands._parse_aggregateW   s     ))#vg|@TUUr3   c                     |d   }t        |t              r!| j                  |d   ||j                        }n5t	        |d   |j
                   |d   |j                  |j                        }|t        |d         fS )Nr<   r   r=   )r=   r>   r?   r   )	
isinstancer   rI   _cursorr   rA   rB   rC   r   )r-   r/   r0   r<   results        r1   _parse_profilezSearchCommands._parse_profileZ   s    we-.//Au}}MFA%%%
+!00!..F )#a&111r3   c                     i }|dk(  r|S |D ]X  }t        |t              r|dk(  rt        |      dk7  r(|d   s.|d   d   s7|d   D cg c]  }|d   |d   d c}||d   <   Z |S c c}w )Nr   r*   r
   r   )score
suggestion)rL   intlen)r-   r/   r0   corrections_correction_items         r1   _parse_spellcheckz SearchCommands._parse_spellchecki   s    !8 	K+s+q0@;1$q>q>!$$ JUUV+@E%(%(;+KA'5	< 	+s   
A)c                 B    |r|D ci c]  }|d   |d    c}S i S c c}w )Nr   r    )r-   r/   r0   kvss       r1   _parse_config_getz SearchCommands._parse_config_get   s)    25#.3AA.=2=.s   c                 h    t        dt        |      d      D ci c]  }||   ||dz       c}S c c}w )Nr   r
   r   )rangerT   )r-   r/   r0   is       r1   _parse_syndumpzSearchCommands._parse_syndump   s4    ,1!SXq,ABqAAE
"BBBs   /c                 (    | j                  | |      S )zT
        Create a new batch indexer from the client with a given chunk size
        )
chunk_size)BatchIndexer)r-   rb   s     r1   batch_indexerzSearchCommands.batch_indexer   s       * ==r3   Nfieldsno_term_offsetsno_field_flags	stopwords
definitionno_highlightno_term_frequenciesskip_initial_scanc                 6   t         | j                  g}|||j                  z  }|r|j                  t               |6t        |t              r&|j                  t               |j                  |       |r|j                  t               |r|j                  t               |r|j                  t               |	r|j                  t               |
r|j                  t               |Kt        |t        t        t        f      r0|t         t#        |      gz  }t#        |      dkD  r|t        |      z  }|j                  d       	 |t        t%        j&                  d |D               z  } | j,                  | S # t(        $ r ||j+                         z  }Y -w xY w)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.

        r   SCHEMAc              3   <   K   | ]  }|j                           y wr5   
redis_args.0fs     r1   	<genexpr>z.SearchCommands.create_index.<locals>.<genexpr>        *Ja1<<>*J   )
CREATE_CMD
index_nameargsappendr   rL   rS   r   r   r   r   r   r!   listtuplesetr    rT   	itertoolschain	TypeErrorrq   execute_command)r-   re   rf   rg   rh   ri   max_text_fields	temporaryrj   rk   rl   rz   s               r1   create_indexzSearchCommands.create_index   sS   N DOO,!JOO#DKK& Z	3%?KK	"KK	"KK	"KKKK!KK KK( Z	D%;M%NYI//D9~!Y'H	(D*J6*JKLLD $t##T**  	(F%%''D	(s   %E9 9FFc                     t         | j                  ddg}	 |t        t        j                  d |D               z  } | j                  | S # t
        $ r ||j                         z  }Y -w xY w)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>`_.
        rn   ADDc              3   <   K   | ]  }|j                           y wr5   rp   rr   s     r1   ru   z2SearchCommands.alter_schema_add.<locals>.<genexpr>   rv   rw   )	ALTER_CMDry   r|   r   r   r   rq   r   )r-   re   rz   s      r1   alter_schema_addzSearchCommands.alter_schema_add   sr     4??He<	(D*J6*JKLLD $t##T**  	(F%%''D	(s   %A
 
A)(A)delete_documentsc                     t         | j                  g}t        |t              r|du rdnd}|r|j	                  |        | 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_CMDry   rL   boolr{   r   )r-   r   rz   
delete_strs       r1   	dropindexzSearchCommands.dropindex   sX     t/ *D16F$6N  	 KK
##t##T**r3   c
                    |s|	rd}t         | j                  ||g}|r|j                  d       |"|j                  d       |j                  |       |r7|j                  d       |r|j                  d       |	r|j                  d       |r|d|gz  }|j                  d       |t        t	        j
                  |
j                                z  }| |j                  | S  | j                  | S )	zS
        Internal add_document used for both batch and single doc indexing
        TNOSAVEPAYLOADREPLACEPARTIALNOCREATELANGUAGEFIELDS)ADD_CMDry   r{   r|   r   r   itemsr   )r-   doc_idconnnosaverQ   payloadreplacepartiallanguage	no_createre   rz   s               r1   _add_documentzSearchCommands._add_document  s    " iG&%8KK!KK	"KK KK	"I&J'Z**DHY__flln566'4''..#t##T**r3   c                     t         | j                  ||g}|r|j                  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_CMDry   r{   r   )r-   r   r   rQ   r   r   rz   s          r1   _add_document_hashz!SearchCommands._add_document_hash7  sc     T__fe<KK	"Z**D'4''..#t##T**r3   z2.0.0z2deprecated since redisearch 2.0, call hset insteadversionreasonr   r   rQ   r   r   r   r   r   c	                 :     | 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   rQ   r   r   r   r   r   )r   )
r-   r   r   rQ   r   r   r   r   r   re   s
             r1   add_documentzSearchCommands.add_documentK  sD    V "t!!

 
 	
r3   c                 .    | j                  |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   rQ   r   r   )r   )r-   r   rQ   r   r   s        r1   add_document_hashz SearchCommands.add_document_hash  s'      &&UXw ' 
 	
r3   zdeprecated since redisearch 2.0c                     t         | j                  |g}|r|j                  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_CMDry   r{   r   )r-   r   r   delete_actual_documentrz   s        r1   delete_documentzSearchCommands.delete_document  sO     &1!KK'4''..#t##T**r3   c                     | j                   j                  |      }|j                         D ci c]  \  }}t        |      t        |       }}}|}	 |d= t        dd|i|S c c}}w # t        $ r Y w xY w).
        Load a single document by id
        idrZ   r+   hgetallr   r   KeyErrorr   r-   r   re   kvf2s         r1   load_documentzSearchCommands.load_document  s     $$R(5;\\^DTQilIaL(DD	t (2((( E
  		s   A$A* *	A65A6c                 F     | j                   t        | j                  g| S )z
        Returns the full contents of multiple documents.

        ### Parameters

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

        )r   MGET_CMDry   )r-   idss     r1   getzSearchCommands.get  s"     $t##HdooDDDr3   c                 n    | j                  t        | j                        }| 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_CMDry   r2   r-   r/   s     r1   infozSearchCommands.info  s-     ""8T__=""8S11r3   query_paramsc                     |g S g }t        |      dkD  rh|j                  d       |j                  t        |      dz         |j                         D ]'  \  }}|j                  |       |j                  |       ) |S )Nr   paramsr
   )rT   r{   r   )r-   r   rz   keyvalues        r1   get_params_argszSearchCommands.get_params_args  s~     I|q KK!KKL)A-.*002 #
UC E"# r3   c                     | j                   g}t        |t              rt        |      }t        |t              st	        dt        |             ||j                         z  }|| j                  |      z  }||fS )NzBad query type )ry   rL   strr   
ValueErrortypeget_argsr   )r-   r<   r   rz   s       r1   _mk_query_argszSearchCommands._mk_query_args  ss      eS!%LE%'tE{m<==  $$\22U{r3   r<   c                 T   | j                  ||      \  }}t        j                         }i }t        | j                        dvr	d|t
        <    | j                  t        g|i |}t        |t              r|S | j                  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   r(   T     @@r<   r=   r   time	monotonicr   r+   r   r   
SEARCH_CMDrL   r   r2   r-   r<   r   rz   stoptionsr/   s          r1   searchzSearchCommands.search  s      ))%l)Ke^^,H<$(GL!"d"":@@@c8$J""5DNN4Dr4IV3S # 
 	
r3   c                 \    | j                  ||      \  }} | j                  t        g| 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)r-   r<   r   rz   
query_texts        r1   explainzSearchCommands.explain  s6      ..u<.Pj#t##K7$77r3   c                     t        d      )Nz#EXPLAINCLI will not be implemented.)NotImplementedError)r-   r<   s     r1   explain_clizSearchCommands.explain_cli  s    !"GHHr3   c                    t        |t              r9t        |j                        }t        | j
                  g|j                         z   }nCt        |t              r'd}t        d| j
                  g|j                         z   }nt        d|      || j                  |      z  } | j                  | }| 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r<   rH   rL   r   r   rM   AGGREGATE_CMDry   
build_argsr   
CURSOR_CMDr   r   r   r2   r-   r<   r   rH   r.   raws         r1   	aggregatezSearchCommands.aggregate  s    " e-.emm,J $//2U5E5E5GGCv&Jvt7%:J:J:LLC[%00t##L11"d""C(""3e
 # 
 	
r3   r   rH   c                     |r1t        |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
   )rL   r   cidr   _with_schemar   )r-   r   r<   rH   cursorschemarowss          r1   rI   z$SearchCommands._get_aggregate_result?  s     %(F	Aa&CFe-.53E3EVFqr7DFqr7DtVV44r3   limitedc                    t        j                         }t        | j                  dg}|r|j	                  d       |j	                  d       t        |t              rd|d<   ||j                         z  }nHt        |t              r-d|d<   ||j                         z  }|| j                  |      z  }nt        d       | j                  | }| 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
   SEARCHz5Must provide AggregateRequest object or Query object.r   r   )r   r   PROFILE_CMDry   r{   rL   r   r   r   r   r   r   r   r2   )r-   r<   r   r   r   r.   r/   s          r1   profilezSearchCommands.profileU  s    $ ^^DOOR0JJy!

7e-. CF5##%%Cu%CF5>>##C4''55CTUU"d""C(""ET^^5E5Jf4T # 
 	
r3   c                     t         | j                  |g}|r|j                  d|g       |r|j                  dd|g       |r|j                  dd|g        | j                  | }| 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_CMDry   extendr   r2   r-   r<   distanceincludeexcluder.   r/   s          r1   
spellcheckzSearchCommands.spellcheck}  sy     t6JJ
H-.JJG45JJG45"d""C("">377r3   nametermsc                 R    t         |g}|j                  |        | j                  | S )zAdds terms to a dictionary.

        ### Parameters

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

        For more information see `FT.DICTADD <https://redis.io/commands/ft.dictadd>`_.
        )DICT_ADD_CMDr
  r   r-   r  r  r.   s       r1   dict_addzSearchCommands.dict_add  -     T"

5#t##S))r3   c                 R    t         |g}|j                  |        | j                  | S )a  Deletes terms from a dictionary.

        ### Parameters

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

        For more information see `FT.DICTDEL <https://redis.io/commands/ft.dictdel>`_.
        )DICT_DEL_CMDr
  r   r  s       r1   dict_delzSearchCommands.dict_del  r  r3   c                 0    t         |g} | j                  | S )zDumps all terms in the given dictionary.

        ### Parameters

        - **name**: Dictionary name.

        For more information see `FT.DICTDUMP <https://redis.io/commands/ft.dictdump>`_.
        )DICT_DUMP_CMDr   )r-   r  r.   s      r1   	dict_dumpzSearchCommands.dict_dump  s!     d##t##S))r3   8.0.0Ddeprecated since Redis 8.0, call config_set from core module insteadoptionr   returnc                 >    t         d||g} | j                  | }|dk(  S )  Set runtime configuration option.

        ### Parameters

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

        For more information see `FT.CONFIG SET <https://redis.io/commands/ft.config-set>`_.
        SETOK
CONFIG_CMDr   r-   r  r   r.   r   s        r1   
config_setzSearchCommands.config_set  s.     5&%0"d""C(d{r3   Ddeprecated since Redis 8.0, call config_get from core module insteadc                 ^    t         d|g} | j                  | }| j                  t         |      S )Get runtime configuration option value.

        ### Parameters

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

        For more information see `FT.CONFIG GET <https://redis.io/commands/ft.config-get>`_.
        GETr&  r   r2   r-   r  r.   r/   s       r1   
config_getzSearchCommands.config_get  s5     5&)"d""C("":s33r3   tagfieldc                 D    | j                  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_CMDry   )r-   r0  s     r1   tagvalszSearchCommands.tagvals  s     ##K(KKr3   aliasc                 D    | j                  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_CMDry   r-   r4  s     r1   aliasaddzSearchCommands.aliasadd  s     ##M5$//JJr3   c                 D    | j                  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_CMDry   r7  s     r1   aliasupdatezSearchCommands.aliasupdate  s     ##$4eT__MMr3   c                 .    | j                  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_CMDr7  s     r1   aliasdelzSearchCommands.aliasdel  s     ##M599r3   c                 h   | j                  d      }|D ]  }t        ||j                  |j                  g}|j	                  d      r|j                  d       |j                  r,|j                  d       |j                  |j                          |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stringrQ   r   r{   r   r   executer-   r   suggestionsr0   pipesugrz   s          r1   sugaddzSearchCommands.sugadd  s     }}}/ 	(C"CSYY?Dzz+&F#{{I&CKK( D  $'	( ||~b!!r3   r   c                 .    | j                  t        |      S )z
        Return the number of entries in the AutoCompleter index.

        For more information see `FT.SUGLEN <https://redis.io/commands/ft.suglen>`_.
        )r   SUGLEN_COMMAND)r-   r   s     r1   suglenzSearchCommands.suglen.  s     ##NC88r3   rH  c                 0    | j                  t        ||      S )z
        Delete a string from the AutoCompleter index.
        Returns 1 if the string was found and deleted, 0 otherwise.

        For more information see `FT.SUGDEL <https://redis.io/commands/ft.sugdel>`_.
        )r   SUGDEL_COMMAND)r-   r   rH  s      r1   sugdelzSearchCommands.sugdel6  s     ##NC@@r3   prefixfuzzynumr?   with_payloadsc                    t         ||d|g}|r|j                  t               |r|j                  t               |r|j                  t                | j
                  | }g }	|s|	S t        |||      }
|
D cg c]  }| c}S c c}w )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>`_.
        MAXSUGGET_COMMANDr{   r#   r"   r$   r   r   )r-   r   rU  rV  rW  r?   rX  rz   r/   resultsparserss               r1   suggetzSearchCommands.sugget?  s    P VUC8KKKK
#KK%"d""D)N!+}cB!"a"""s   7	Bgroupidskipinitialc                     t         | j                  |g}|r|j                  dg       |j                  |        | 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_CMDry   r
  r   )r-   rb  rc  r  r.   s        r1   	synupdatezSearchCommands.synupdatew  sF    $ doow7JJ)*+

5#t##S))r3   c                 n    | j                  t        | j                        }| 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_CMDry   r2   r   s     r1   syndumpzSearchCommands.syndump  s-     "";@"";44r3   )d   )	FFNNFNFFF)F)NF      ?NFFNF)Nrk  NF)Frk  NFFNF)rk  NF)NFr5   )FNNNNF
   FF)?__name__
__module____qualname____doc__r2   r:   rF   rJ   rO   rX   r\   r`   rd   r   r   r   r   r   r   r   r   r   r   r   r	   floatr   r   r   r   r   r   r   r   rS   bytesr   r   r   r   r   r   r   r   rI   r  r  r  r  r  r(  r/  r3  r8  r;  r>  rN  rQ  rT  r   ra  rf  ri  rZ   r3   r1   r&   r&   @   sA   D!
V2#J>C> !&$)-04"$)"'D+UD+ D+ 	D+
 DI&D+ _-D+ D+ "D+  D+L+tCy +(+$ +8 (+V DI+(  T "&3
3
 3
 	3

 3
 3
 3
 3-3
 3
 s)3
3
j  T

" 1RS+ T+&) 1RS
E T
E	2!$sE#sE52H,I'I"JD"PQ#(c5c5%9O3P.P)QSW)W#X& OS
S%Z 
 DeCeU,B&C!CDdJK
F ;?
8S%Z 
8 3c3o 667
8IsEz!2 I ;?
S%Z 
 3c3o 667
@55 %c52B&B C5QU52 DH	&
U,,-&
 &
 tCsC)?$?@A	&
P88*S *$s) **S *$s) *
*c 
* U S T 	 U4 4 4	4L LKc KN N
:c 
:".9# 9# 9A# As As A !#6#6# 6# 	6#
 6# 6# 6# 
	6#p* *4 *c *0
5r3   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 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y)AsyncSearchCommandsc                    K   | j                  t        | j                         d{   }| j                  t        |      S 7 w)r   Nr   r   s     r1   r   zAsyncSearchCommands.info  s:      ((4??CC""8S11 Ds   $AAANr<   r   c                 p  K   | j                  ||      \  }}t        j                         }i }t        | j                        dvr	d|t
        <    | j                  t        g|i | d{   }t        |t              r|S | j                  t        ||t        j                         |z
  dz        S 7 Gw)r   r   r(   TNr   r   r   r   s          r1   r   zAsyncSearchCommands.search  s       ))%l)Ke^^,H<$(GL!(D((FdFgFFc8$J""5DNN4Dr4IV3S # 
 	
 Gs   A*B6,B4-AB6c                   K   t        |t              r9t        |j                        }t        | j
                  g|j                         z   }nCt        |t              r'd}t        d| j
                  g|j                         z   }nt        d|      || j                  |      z  } | j                  |  d{   }| j                  t        |||      S 7 w)r   Tr   r   Nr   r   r   s         r1   r   zAsyncSearchCommands.aggregate  s     " e-.emm,J $//2U5E5E5GGCv&Jvt7%:J:J:LLC[%00t##L11(D((#..""3e
 # 
 	
 /s   B3C5C6Cc                   K   t         | j                  |g}|r|j                  d|g       |r|j                  dd|g       |r|j                  dd|g        | j                  |  d{   }| j	                  t         |      S 7 w)a  
        Issue a spellcheck query

        ### Parameters

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

        For more information see `FT.SPELLCHECK <https://redis.io/commands/ft.spellcheck>`_.
        r  r  r  r  Nr  r  s          r1   r  zAsyncSearchCommands.spellcheck  s      t6JJ
H-.JJG45JJG45(D((#.."">377 /s   A'B)B*Br  r  r   r  r   r   c                 Z   K   t         d||g} | j                  |  d{   }|dk(  S 7 	w)r"  r#  Nr$  r%  r'  s        r1   r(  zAsyncSearchCommands.config_set  s:      5&%0(D((#..d{ /s   +)
+r)  c                 ~   K   t         d|g}i } | j                  |  d{   }| j                  t         |      S 7 w)r+  r,  Nr-  r.  s       r1   r/  zAsyncSearchCommands.config_get  sF      5&)(D((#.."":s33 /s   =;=c                   K   | j                   j                  |       d{   }|j                         D ci c]  \  }}t        |      t        |       }}}|}	 |d= t        dd|i|S 7 Lc c}}w # t        $ r Y  w xY ww)r   Nr   rZ   r   r   s         r1   r   z!AsyncSearchCommands.load_document(  s      {{**2..5;\\^DTQilIaL(DD	t (2((( /D
  		sD   BA.BA0BA6 !B0B6	B?BBBc                   K   | j                  d      }|D ]  }t        ||j                  |j                  g}|j	                  d      r|j                  d       |j                  r,|j                  d       |j                  |j                          |j                  |   |j                          d{   d   S 7 w)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@  rB  rC  r   NrD  rE  rJ  s          r1   rN  zAsyncSearchCommands.sugadd7  s      }}}/ 	(C"CSYY?Dzz+&F#{{I&CKK( D  $'	( lln$b))$s   B4C 6B>7C r   rU  rV  rW  r?   rX  c                 ,  K   t         ||d|g}|r|j                  t               |r|j                  t               |r|j                  t                | j
                  |  d{   }g }	|s|	S t        |||      }
|
D cg c]  }| c}S 7 'c c}w w)rZ  r[  Nr\  )r-   r   rU  rV  rW  r?   rX  rz   retr^  r_  r`  s               r1   ra  zAsyncSearchCommands.suggetN  s     P VUC8KKKK
#KK%(D(($//N!+}cB!"a"" 0 #s$   A#B%B&B	B
BBr5   rl  rm  )ro  rp  rq  r   r   r   r   r   rS   rs  r   r   r  r	   r   r(  r/  r   rN  r   r   ra  rZ   r3   r1   rv  rv    sJ   	2 ;?
S%Z 
 3c3o 667
F ;?
S%Z 
 3c3o 667
@88 Us 3 4 	 U4s 4s 4	4)*6 !#6#6# 6# 	6#
 6# 6# 6# 
	6#r3   rv  )Mr   r   typingr   r   r   r   redis.clientr   r   redis.utilsr	   helpersr   _utilr   aggregationr   r   r   documentr   fieldr   index_definitionr   profile_informationr   r<   r   rN   r   rR   r   r   rx   r   r   r   r   r   r   EXPLAINCLI_CMDr   r   r  r   r	  r  r  r  r   r&  r2  r6  r:  r=  r   rG  rS  rP  r]  re  rh  r   r   r   r   r   r   r    r!   r"   r#   r$   r&   rv  rZ   r3   r1   <module>r     s!     . . / + *  B B   - 3   (

	

 

 
# 	
		#
Y5 Y5xh#. h#r3   