
    Pfp                         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dS )    N   )Pipeline   )	AGGREGATE_CMD
CONFIG_CMDINFO_CMDPROFILE_CMD
SEARCH_CMDSPELLCHECK_CMDSYNDUMP_CMDAsyncSearchCommandsSearchCommandsc                   <    e Zd ZdZ G d d          Zd	dZd
dZdS )Searchzy
    Create a client for talking to search.
    It abstracts the API of the module and lets you just use the engine.
    c                   B    e Zd ZdZddZd Z	 	 	 	 	 	 ddZdd	Zd
 ZdS )Search.BatchIndexer
        A batch indexer allows you to automatically batch
        document indexing in pipelines, flushing it every N documents.
          c                     || _         |j        | _        |                    dd           | _        d| _        || _        d| _        d S )NF)transaction
shard_hintr   )clientexecute_commandpipeline	_pipelinetotal
chunk_sizecurrent_chunk)selfr   r   s      P/var/www/html/env/lib/python3.11/site-packages/redis/commands/search/__init__.py__init__zSearch.BatchIndexer.__init__   sG     DK#)#9D #__4_PPDNDJ(DO!"D    c                 @    | j         r|                                  d S d S )N)r   commitr   s    r    __del__zSearch.BatchIndexer.__del__%   s(    !  r"   F      ?Nc                      | j         j        |f| j        ||||||d| | xj        dz  c_        | xj        dz  c_        | j        | j        k    r|                                  dS dS 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/   r0   fieldss	            r    add_documentz Search.BatchIndexer.add_document)   s     &DK%
^#
 
 
 
 
 !#JJ!OJJ!T_44 54r"   c                     | j                             || j        ||           | xj        dz  c_        | xj        dz  c_        | j        | j        k    r|                                  dS dS )z7
            Add a hash to the batch query
            )r*   r,   r.   r   N)r   _add_document_hashr   r   r   r   r$   )r   r4   r,   r.   s       r    add_document_hashz%Search.BatchIndexer.add_document_hashG   s|     K**T^5' +    !#JJ!OJJ!T_44 54r"   c                 F    | j                                          d| _        dS )L
            Manually commit and flush the batch indexing query
            r   Nr   executer   r%   s    r    r$   zSearch.BatchIndexer.commitS   s&     N""$$$!"Dr"   )r   Fr'   NFFF)r'   F)	__name__
__module____qualname____doc__r!   r&   r6   r9   r$    r"   r    BatchIndexerr      s        	 	
	# 	# 	# 	#	 	 	 	 	 	 	<
	 
	 
	 
		# 	# 	# 	# 	#r"   rD   idxc                    i | _         || _        || _        |j        | _        |j        | _        t          | j        t          | j	        t          | j        t          | j        t          | j        t           | j        t$          | j        i| _        dS )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   rH   s      r    r!   zSearch.__init__Z   sv     "$$%5d&*40,D2.,(
$$$r"   TNc                 b    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   rS   rG   rH   r   r   r   ps       r    r   zSearch.pipelinep   s<      K7#5#!	
 
 
 r"   )rE   TN)r?   r@   rA   rB   rD   r!   r   rC   r"   r    r   r      sw         
A# A# A# A# A# A# A# A#F
 
 
 
,     r"   r   c                   <    e Zd Z G d dej                  ZddZdS )AsyncSearchc                   ,    e Zd ZdZ	 	 	 	 	 	 ddZd ZdS )AsyncSearch.BatchIndexerr   Fr'   Nc                    K    | j         j        |f| j        ||||||d| | xj        dz  c_        | xj        dz  c_        | j        | j        k    r|                                  d{V  dS dS r)   r1   r3   s	            r    r6   z%AsyncSearch.BatchIndexer.add_document   s       &DK%
^#
 
 
 
 
 !#JJ!OJJ!T_44kkmm######### 54r"   c                 V   K   | j                                          d{V  d| _        dS )r;   Nr   r<   r%   s    r    r$   zAsyncSearch.BatchIndexer.commit   s<       .((*********!"Dr"   r>   )r?   r@   rA   rB   r6   r$   rC   r"   r    rD   r[      sU        	 	 	$ 	$ 	$ 	$<	# 	# 	# 	# 	#r"   rD   TNc                 b    t          | j        j        | j        ||          }| j        |_        |S rR   )AsyncPipeliner   rS   rG   rH   rU   s       r    r   zAsyncSearch.pipeline   s<      K7#5#!	
 
 
 r"   rW   )r?   r@   rA   r   rD   r   rC   r"   r    rY   rY   ~   sV        )# )# )# )# )#v* )# )# )#V     r"   rY   c                       e Zd ZdZdS )r   zPipeline for the module.Nr?   r@   rA   rB   rC   r"   r    r   r      s        """"r"   r   c                       e Zd ZdZdS )r_   zAsyncPipeline for the module.Nra   rC   r"   r    r_   r_      s        ''''r"   r_   )redisasyncio.clientr   AsyncioPipelinecommandsr   r   r   r	   r
   r   r   r   r   r   rY   r   r_   rC   r"   r    <module>rg      sY    9 9 9 9 9 9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
j j j j j^ j j jZ7 7 7 7 7&- 7 7 7t# # # # #~u|4 # # #( ( ( ( ('( ( ( ( ( (r"   