
    ,i                         d dl m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mZ  G d de      Z G d dee      Z G d	 d
ee      Z G d deee      Zy)    )Pipeline      )
AGGREGATE_CMD
CONFIG_CMD
HYBRID_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      c/var/www/html/langgraph-service/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   r3   r+   r-   s       r    add_document_hashz%Search.BatchIndexer.add_document_hashH   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.commitT   s     NN""$!"Dr"   )i  F      ?NFFF)r>   F)	__name__
__module____qualname____doc__r!   r&   r5   r8   r$    r"   r    BatchIndexerr      s4    	
	#	 	<
		#r"   rD   c                    i | _         || _        || _        |j                  | _        |j                  | _        t        | 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_hybrid_searchr   _parse_aggregater
   _parse_profiler   _parse_spellcheckr   _parse_config_getr   _parse_syndump_RESP2_MODULE_CALLBACKS)r   r   rG   s      r    r!   zSearch.__init__[   s     "$$%55d&&**11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   rS   rF   rG   r   r   r   ps       r    r   zSearch.pipeliner   s<      KK77#55#!	
 r"   )idxTN)r?   r@   rA   rB   rD   r!   r   rC   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(   r0   r2   s	            r    r5   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)r:   Nr   r;   r%   s    r    r$   zAsyncSearch.BatchIndexer.commit   s+      ..((***!"D +s   /-/r=   )r?   r@   rA   rB   r5   r$   rC   r"   r    rD   r\      s%    	 	$<	#r"   rD   Nc                     t        | j                  j                  | j                  ||      }| j                  |_        |S rR   )AsyncPipeliner   rS   rF   rG   rU   s       r    r   zAsyncSearch.pipeline   s<      KK77#55#!	
 r"   rX   )r?   r@   rA   r   rD   r   rC   r"   r    rZ   rZ      s    )#v** )#Vr"   rZ   c                       e Zd ZdZy)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y)r`   zAsyncPipeline for the module.Nrb   rC   r"   r    r`   r`      s    'r"   r`   N)redis.clientr   RedisPipelineasyncio.clientAsyncioPipelinecommandsr   r   r   r	   r
   r   r   r   r   r   r   rZ   r`   rC   r"   r    <module>ri      sX    2 9  k^ k\7&- 7t#~} #('( (r"   