
    +hp                         d dl Z ddlmZ ddlmZmZmZmZm	Z	m
Z
mZmZmZ  G d de      Z G d d	ee      Z G d
 dee j                   j                        Z G d deee      Zy)    N   )Pipeline   )	AGGREGATE_CMD
CONFIG_CMDINFO_CMDPROFILE_CMD
SEARCH_CMDSPELLCHECK_CMDSYNDUMP_CMDAsyncSearchCommandsSearchCommandsc                   4    e Zd ZdZ G d d      ZddZddZy)	Searchzy
    Create a client for talking to search.
    It abstracts the API of the module and lets you just use the engine.
    c                   @    e Zd ZdZddZd Z	 	 	 	 	 	 d	dZd
dZd Zy)Search.BatchIndexer
        A batch indexer allows you to automatically batch
        document indexing in pipelines, flushing it every N documents.
        c                     || _         |j                  | _        |j                  dd       | _        d| _        || _        d| _        y )NF)transaction
shard_hintr   )clientexecute_commandpipeline	_pipelinetotal
chunk_sizecurrent_chunk)selfr   r   s      Q/var/www/html/venv/lib/python3.12/site-packages/redis/commands/search/__init__.py__init__zSearch.BatchIndexer.__init__   sA     DK#)#9#9D #__4_PDNDJ(DO!"D    c                 >    | j                   r| j                          y y )N)r   commitr   s    r   __del__zSearch.BatchIndexer.__del__%   s    !! "r!   Nc                 
    | j                   j                  |f| j                  ||||||d| | xj                  dz  c_        | xj                  dz  c_        | j                  | j
                  k\  r| j                          yyz;
            Add a document to the batch query
            )connnosavescorepayloadreplacepartial	no_creater   Nr   _add_documentr   r   r   r   r#   	r   doc_idr)   r*   r+   r,   r-   r.   fieldss	            r   add_documentz Search.BatchIndexer.add_document)   s     &DKK%%
^^#
 
 !#JJ!OJ!!T__4 5r!   c                     | j                   j                  || j                  ||       | xj                  dz  c_        | xj                  dz  c_        | j                  | j
                  k\  r| j                          yy)z7
            Add a hash to the batch query
            )r(   r*   r,   r   N)r   _add_document_hashr   r   r   r   r#   )r   r2   r*   r,   s       r   add_document_hashz%Search.BatchIndexer.add_document_hashG   sh     KK**T^^5' +  !#JJ!OJ!!T__4 5r!   c                 F    | j                   j                          d| _        y)L
            Manually commit and flush the batch indexing query
            r   Nr   executer   r$   s    r   r#   zSearch.BatchIndexer.commitS   s     NN""$!"Dr!   )i  F      ?NFFF)r=   F)	__name__
__module____qualname____doc__r    r%   r4   r7   r#    r!   r   BatchIndexerr      s4    	
	#	 	<
		#r!   rC   c                 `   i | _         || _        || _        |j                  | _        |j                  | _        t        | j                  t        | j                  t        | j                  t        | j                  t        | j                  t         | j"                  t$        | j&                  i| _        y)z
        Create a new Client for the given index_name.
        The default name is `idx`

        If conn is not None, we employ an already existing redis connection
        N)_MODULE_CALLBACKSr   
index_namer   r   r   r   _parse_infor
   _parse_searchr   _parse_aggregater	   _parse_profiler   _parse_spellcheckr   _parse_config_getr   _parse_syndump_RESP2_MODULE_CALLBACKS)r   r   rF   s      r   r    zSearch.__init__Z   s     "$$%55d&&**400,,D22..,,(
$r!   Nc                     t        | j                  j                  | j                  ||      }| j                  |_        |S zCreates a pipeline for the SEARCH module, that can be used for executing
        SEARCH commands, as well as classic core commands.
        )connection_poolresponse_callbacksr   r   )r   r   rQ   rE   rF   r   r   r   ps       r   r   zSearch.pipelinep   s<      KK77#55#!	
 r!   )idxTN)r>   r?   r@   rA   rC   r    r   rB   r!   r   r   r      s    
A# A#F
,r!   r   c                   >    e Zd Z G d dej                        ZddZy)AsyncSearchc                   *    e Zd ZdZ	 	 	 	 	 	 ddZd Zy)AsyncSearch.BatchIndexerr   Nc                 &  K    | j                   j                  |f| j                  ||||||d| | xj                  dz  c_        | xj                  dz  c_        | j                  | j
                  k\  r| j                          d{    yy7 wr'   r/   r1   s	            r   r4   z%AsyncSearch.BatchIndexer.add_document   s      &DKK%%
^^#
 
 !#JJ!OJ!!T__4kkm## 5#s   BBB	Bc                 b   K   | j                   j                          d{    d| _        y7 w)r9   Nr   r:   r$   s    r   r#   zAsyncSearch.BatchIndexer.commit   s+      ..((***!"D +s   /-/r<   )r>   r?   r@   rA   r4   r#   rB   r!   r   rC   rZ      s%    	 	$<	#r!   rC   Nc                     t        | j                  j                  | j                  ||      }| j                  |_        |S rP   )AsyncPipeliner   rQ   rE   rF   rS   s       r   r   zAsyncSearch.pipeline   s<      KK77#55#!	
 r!   rV   )r>   r?   r@   r   rC   r   rB   r!   r   rX   rX   ~   s    )#v** )#Vr!   rX   c                       e Zd ZdZy)r   zPipeline for the module.Nr>   r?   r@   rA   rB   r!   r   r   r      s    "r!   r   c                       e Zd ZdZy)r^   zAsyncPipeline for the module.Nr`   rB   r!   r   r^   r^      s    'r!   r^   )redisasyncio.clientr   AsyncioPipelinecommandsr   r   r   r	   r
   r   r   r   r   r   rX   r   r^   rB   r!   r   <module>rf      sb     9
 
 
j^ jZ7&- 7t#~u||44 #('( (r!   