
    Ng                     V    d dl mZmZmZ d dlmZmZmZmZm	Z	m
Z
  G d de
          ZdS )    )DictTupleUnion)
Comparator
Comparison	OperationOperatorStructuredQueryVisitorc                       e Zd ZdZej        ej        ej        ej        ej	        ej
        ej        gZ	 ej        ej        ej        gZ	 deeef         defdZdedefdZdedefdZd	edeeef         fd
ZdS )OpenSearchTranslatorz]Translate `OpenSearch` internal query domain-specific
    language elements to valid filters.funcreturnc                 0   |                      |           t          j        dt          j        dt          j        dt          j        dt          j        dt          j        dt          j        dt          j
        dt          j        d	t          j        d
i
}||         S )Ntermltltegtgtematchfuzzymustshouldmust_not)_validate_funcr   EQLTLTEGTGTECONTAINLIKEr	   ANDORNOT)selfr   comp_operator_maps      m/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/query_constructors/opensearch.py_format_funcz!OpenSearchTranslator._format_func   sr    D!!!M6M4NEM4NEOWL&KL*
 !&&    	operationc                 f      fd|j         D             }d                     |j                  |iiS )Nc                 :    g | ]}|                               S  )accept).0argr&   s     r(   
<listcomp>z8OpenSearchTranslator.visit_operation.<locals>.<listcomp>0   s%    @@@S

4  @@@r*   bool)	argumentsr)   operator)r&   r+   argss   `  r(   visit_operationz$OpenSearchTranslator.visit_operation/   s@    @@@@I,?@@@**9+=>>EFFr*   
comparisonc                    d|j          }|j        t          j        t          j        t          j        t          j        fv rtt          |j        t                    r5d|j        v r+d|| 
                    |j                  |j        d         iiiS n%d|| 
                    |j                  |j        iiiS |j        t          j        k    r%| 
                    |j                  |d|j        iiiS t          |j        t                    r| dn|}t          |j        t                    rd|j        v r|j        d         |_        | 
                    |j                  ||j        iiS )Nz	metadata.daterangevaluez.keyword)	attribute
comparatorr   r   r   r   r    
isinstancer<   dictr)   r"   str)r&   r8   fields      r(   visit_comparisonz%OpenSearchTranslator.visit_comparison4   s   2J022 MNMN	%
 
 
 **D11 Z---! $ 1 1$.$9!" !"#-#3F#;$"  .  --j.CDDjFV    JO33!!*"788GZ%56;  '11A3&G&GR5""""Uj&-- 	<)))#-#3F#;
 !!*"7885*BR:STTr*   structured_queryc                 `    |j         i }nd|j                             |           i}|j        |fS )Nfilter)rF   r/   query)r&   rD   kwargss      r(   visit_structured_queryz+OpenSearchTranslator.visit_structured_query`   s>     "*FF 0 7 > >t D DEF%v--r*   N)__name__
__module____qualname____doc__r   r   r   r   r   r    r!   r"   allowed_comparatorsr	   r#   r$   r%   allowed_operatorsr   rA   r)   r   r   r7   r   rC   r
   r   r@   rI   r.   r*   r(   r   r      s       + + 	 1!x{HLA.'x';!< ' ' ' ' ' G Gt G G G G
*U: *U$ *U *U *U *UX. /.	sDy	. . . . . .r*   r   N)typingr   r   r   langchain_core.structured_queryr   r   r   r	   r
   r   r   r.   r*   r(   <module>rR      s    % % % % % % % % % %               [. [. [. [. [.7 [. [. [. [. [.r*   