
    Pf                         d dl mZ d dlmZ  G d d          Z G d de          Z G d de          Z G d	 d
e          Z G d de          Z G d de          Z	 G d de          Z
dS )    )List)	DataErrorc                       e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZ	 	 	 	 	 	 ddedee         dededededefdZd Zd ZdS )Fieldz5
    A class representing a field in a document.
    NUMERICTEXTWEIGHTGEOTAGVECTORSORTABLENOINDEXASGEOSHAPEINDEXMISSING
INDEXEMPTYNFnameargssortableno_indexindex_missingindex_emptyas_namec                    |g }|| _         || _        t                      | _        || _        |r$| j                            t          j                   |r$| j                            t          j                   |r$| j                            t          j	                   |r$| j                            t          j
                   |r|st          d          dS dS )aL  
        Create a new field object.

        Args:
            name: The name of the field.
            args:
            sortable: If `True`, the field will be sortable.
            no_index: If `True`, the field will not be indexed.
            index_missing: If `True`, it will be possible to search for documents that
                           have this field missing.
            index_empty: If `True`, it will be possible to search for documents that
                         have this field empty.
            as_name: If provided, this alias will be used for the field.
        Nz-Non-Sortable non-Indexable fields are ignored)r   r   listargs_suffixr   appendr   r   r   INDEX_MISSINGINDEX_EMPTY
ValueError)selfr   r   r   r   r   r   r   s           M/var/www/html/env/lib/python3.11/site-packages/redis/commands/search/field.py__init__zField.__init__   s    0 <D		66 	4##EN333 	3##EM222 	9##E$7888 	7##E$5666 	NH 	NLMMM	N 	N 	N 	N    c                 :    | j                             |           d S N)r   r   )r!   values     r"   
append_argzField.append_argC   s    	r$   c                 n    | j         g}| j        r|| j        | j        gz  }|| j        z  }|| j        z  }|S r&   )r   r   r   r   r   )r!   r   s     r"   
redis_argszField.redis_argsF   sF    	{< 	,TWdl++D	  r$   )NFFFFN)__name__
__module____qualname____doc__r   r   r	   r
   r   r   r   r   r   r   r   r   strr   boolr#   r(   r*    r$   r"   r   r      s          GDF
C
CFHG	BH"MK
 #!)N )N)N 3i)N 	)N
 )N )N )N )N )N )N )NV         r$   r   c                   @    e Zd ZdZdZdZ	 	 	 	 ddeded	ed
edef
dZ	dS )	TextFieldzI
    TextField is used to define a text field in a schema definition
    NOSTEMPHONETIC      ?FNr   weightno_stemphonetic_matcherwithsuffixtriec                 b   t          j        | |fdt           j        t           j        |gi| |r t                               | | j                   |r?|dv r;t                               | | j                   t                               | |           |rt                               | d           d S d S )Nr   )zdm:enzdm:frzdm:ptzdm:esWITHSUFFIXTRIE)r   r#   r   r	   r(   r4   r5   )r!   r   r7   r8   r9   r:   kwargss          r"   r#   zTextField.__init__W   s     	tTUUU\6(JUfUUU 	0T4;/// 	5 0 5
 !
 !
 T4=111T#3444 	5T#344444	5 	5r$   )r6   FNF)
r+   r,   r-   r.   r4   r5   r/   floatr0   r#   r1   r$   r"   r3   r3   O   s          FH
  $$5 55 5 	5
 5 5 5 5 5 5 5r$   r3   c                       e Zd ZdZdefdZdS )NumericFieldzO
    NumericField is used to define a numeric field in a schema definition
    r   c                 F    t          j        | |fdt           j        gi| d S Nr   )r   r#   r   r!   r   r=   s      r"   r#   zNumericField.__init__u   s+    tTBBB6BBBBBr$   Nr+   r,   r-   r.   r/   r#   r1   r$   r"   r@   r@   p   s@         CS C C C C C Cr$   r@   c                   (    e Zd ZdZdZdZddefdZdS )GeoShapeFieldzK
    GeoShapeField is used to enable within/contain indexing/searching
    	SPHERICALFLATNr   c                 x    t           j        g}|r|                    |           t          j        | |fd|i| d S rB   )r   r   r   r#   )r!   r   coord_systemr=   r   s        r"   r#   zGeoShapeField.__init__   sK     	&KK%%%tT77777777r$   r&   )r+   r,   r-   r.   rG   rH   r/   r#   r1   r$   r"   rF   rF   y   sJ          ID8 8S 8 8 8 8 8 8r$   rF   c                       e Zd ZdZdefdZdS )GeoFieldzP
    GeoField is used to define a geo-indexing field in a schema definition
    r   c                 F    t          j        | |fdt           j        gi| d S rB   )r   r#   r
   rC   s      r"   r#   zGeoField.__init__   s+    tT>>>v>>>>>r$   NrD   r1   r$   r"   rL   rL      s9         ?S ? ? ? ? ? ?r$   rL   c            	       :    e Zd ZdZdZdZ	 	 	 ddededed	efd
ZdS )TagFieldzx
    TagField is a tag-indexing field with simpler compression and tokenization.
    See http://redisearch.io/Tags/
    	SEPARATORCASESENSITIVE,Fr   	separatorcase_sensitiver:   c                     t           j        | j        |g}|r|                    | j                   |r|                    d           t          j        | |fd|i| d S )Nr<   r   )r   r   rP   r   rQ   r#   )r!   r   rS   rT   r:   r=   r   s          r"   r#   zTagField.__init__   sq     	4>95 	,KK*+++ 	*KK()))tT77777777r$   N)rR   FF)	r+   r,   r-   r.   rP   rQ   r/   r0   r#   r1   r$   r"   rO   rO      st         
 I#M
 $$8 88 8 	8
 8 8 8 8 8 8r$   rO   c                   &    e Zd ZdZdededefdZdS )VectorFieldz
    Allows vector similarity queries against the value in this attribute.
    See https://oss.redis.com/redisearch/Vectors/#vector_fields.
    r   	algorithm
attributesc           	         |                     dd          }|                     dd          }|s|rt          d          |                                dvrt          d          g }|                                D ]\  }}	|                    ||	g           t          j        | |fdt
          j        |t          |          g|i| dS )	a  
        Create Vector Field. Notice that Vector cannot have sortable or no_index tag,
        although it's also a Field.

        ``name`` is the name of the field.

        ``algorithm`` can be "FLAT" or "HNSW".

        ``attributes`` each algorithm can have specific attributes. Some of them
        are mandatory and some of them are optional. See
        https://oss.redis.com/redisearch/master/Vectors/#specific_creation_attributes_per_algorithm
        for more information.
        r   Fr   z5Cannot set 'sortable' or 'no_index' in Vector fields.)rH   HNSWzIRealtime vector indexing supporting 2 Indexing Methods:'FLAT' and 'HNSW'.r   N)	getr   upperitemsextendr   r#   r   len)
r!   r   rX   rY   r=   sortnoindexattr_likeyr'   s
             r"   r#   zVectorField.__init__   s    zz*e,,**Z// 	U7 	USTTT??$444%  
 $**,, 	) 	)JCNNC<(((($	
 	
#lIs7||NgN	
RX	
 	
 	
 	
 	
r$   N)r+   r,   r-   r.   r/   dictr#   r1   r$   r"   rW   rW      sG         
!
S !
S !
d !
 !
 !
 !
 !
 !
r$   rW   N)typingr   redisr   r   r3   r@   rF   rL   rO   rW   r1   r$   r"   <module>rh      si              F F F F F F F FR5 5 5 5 5 5 5 5BC C C C C5 C C C8 8 8 8 8E 8 8 8? ? ? ? ?u ? ? ?8 8 8 8 8u 8 8 84'
 '
 '
 '
 '
% '
 '
 '
 '
 '
r$   