
    h                     N    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y)    )DictTupleUnion)
Comparator
Comparison	OperationOperatorStructuredQueryVisitorc                   L   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y)OpenSearchTranslatorz]Translate `OpenSearch` internal query domain-specific
    language elements to valid filters.funcreturnc                 r   | j                  |       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wildcardfuzzymustshouldmust_not)_validate_funcr   EQLTLTEGTGTECONTAINLIKEr	   ANDORNOT)selfr   comp_operator_maps      o/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/langchain_community/query_constructors/opensearch.py_format_funcz!OpenSearchTranslator._format_func   s    D!MM6MM4NNEMM4NNE
OOWLL&KKLL*
 !&&    	operationc                     |j                   D cg c]  }|j                  |        }}d| j                  |j                        |iiS c c}w )Nbool)	argumentsacceptr)   operator)r&   r+   argargss       r(   visit_operationz$OpenSearchTranslator.visit_operation/   sK    ,5,?,?@S

4 @@**9+=+=>EFF As   A
comparisonc                 R   d|j                    }|j                  t        j                  t        j                  t        j
                  t        j                  fv rt        |j                  t              r<d|j                  v rYd|| j                  |j                        |j                  d   iiiS d|| j                  |j                        |j                  iiiS |j                  t        j                  k(  r+| j                  |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                        ||j                  iiS )Nz	metadata.daterangevaluez.keyword)	attribute
comparatorr   r   r   r   r    
isinstancer8   dictr)   r"   str)r&   r4   fields      r(   visit_comparisonz%OpenSearchTranslator.visit_comparison4   s   J0012  MMNNMMNN	%
 
 ***D1Z---! $ 1 1$.$9$9!"#-#3#3F#;$"   --j.C.CDjFVFV     JOO3!!*"7"78GZ%5%56;  '11A1A3&G5'"Uj&&-)))#-#3#3F#;
 !!*"7"785*BRBR:STTr*   structured_queryc                 v    |j                   i }nd|j                   j                  |       i}|j                  |fS )Nfilter)rB   r/   query)r&   r@   kwargss      r(   visit_structured_queryz+OpenSearchTranslator.visit_structured_query`   sB     ""*F 0 7 7 > >t DEF%%v--r*   N)__name__
__module____qualname____doc__r   r   r   r   r   r    r!   r"   allowed_comparatorsr	   r#   r$   r%   allowed_operatorsr   r=   r)   r   r   r3   r   r?   r
   r   r<   rE    r*   r(   r   r      s    + 	 1!x{{HLLA.'x';!< ' ' G Gt G
*U: *U$ *UX. /.	sDy	.r*   r   N)typingr   r   r   langchain_core.structured_queryr   r   r   r	   r
   r   r   rL   r*   r(   <module>rO      s#    % % [.7 [.r*   