o
    Š¨Êh  ã                   @   sŠ   d dl mZ d dlmZ G dd„ dƒZG dd„ deƒZG dd„ deƒZG d	d
„ d
eƒZG dd„ deƒZG dd„ deƒZ	G dd„ deƒZ
dS )é    )ÚList)Ú	DataErrorc                   @   sˆ   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d„Zdd„ Zd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                 C   s†   |du rg }|| _ || _tƒ | _|| _|r| j tj¡ |r%| j tj¡ |r.| j tj	¡ |r7| j tj
¡ |r?|sAt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   © r   úM/var/www/html/env/lib/python3.10/site-packages/redis/commands/search/field.pyÚ__init__   s"   ÿzField.__init__c                 C   s   | j  |¡ d S ©N)r   r   )r   Úvaluer   r   r    Ú
append_argC   s   zField.append_argc                 C   s6   | j g}| jr|| j| jg7 }|| j7 }|| j7 }|S r"   )r   r   r   r   r   )r   r   r   r   r    Ú
redis_argsF   s   

zField.redis_args)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    r      sJ    øþýüûúù
ø+r   c                   @   s@   e Zd ZdZdZdZ				ddeded	ed
edef
d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                 K   sr   t j| |fdt jt j|gi|¤Ž |rt  | | j¡ |r-|dv r-t  | | j¡ t  | |¡ |r7t  | d¡ d S d S )Nr   )zdm:enzdm:frzdm:ptzdm:esÚWITHSUFFIXTRIE)r   r!   r   r   r$   r-   r.   )r   r   r0   r1   r2   r3   Úkwargsr   r   r    r!   W   s   "	ÿzTextField.__init__)r/   FNF)
r&   r'   r(   r)   r-   r.   r*   Úfloatr+   r!   r   r   r   r    r,   O   s&    úþýüûúr,   c                   @   ó   e Zd ZdZdefdd„ZdS )ÚNumericFieldzO
    NumericField is used to define a numeric field in a schema definition
    r   c                 K   ó    t j| |fdt jgi|¤Ž d S ©Nr   )r   r!   r   ©r   r   r5   r   r   r    r!   u   ó    zNumericField.__init__N©r&   r'   r(   r)   r*   r!   r   r   r   r    r8   p   ó    r8   c                   @   s(   e Zd ZdZdZdZddefdd„ZdS )	ÚGeoShapeFieldzK
    GeoShapeField is used to enable within/contain indexing/searching
    Ú	SPHERICALÚFLATNr   c                 K   s2   t jg}|r| |¡ t j| |fd|i|¤Ž d S r:   )r   r   r   r!   )r   r   Úcoord_systemr5   r   r   r   r    r!   �   s   
zGeoShapeField.__init__r"   )r&   r'   r(   r)   r@   rA   r*   r!   r   r   r   r    r?   y   s
    r?   c                   @   r7   )ÚGeoFieldzP
    GeoField is used to define a geo-indexing field in a schema definition
    r   c                 K   r9   r:   )r   r!   r   r;   r   r   r    r!   �   r<   zGeoField.__init__Nr=   r   r   r   r    rC   ˆ   r>   rC   c                	   @   s:   e Zd ZdZdZdZ			ddededed	efd
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_sensitiver3   c                 K   sH   t j| j|g}|r| | j¡ |r| d¡ t j| |fd|i|¤Ž d S )Nr4   r   )r   r	   rE   r   rF   r!   )r   r   rH   rI   r3   r5   r   r   r   r    r!   š   s   
zTagField.__init__N)rG   FF)	r&   r'   r(   r)   rE   rF   r*   r+   r!   r   r   r   r    rD   ‘   s     ûþýüûrD   c                   @   s&   e Zd ZdZdededefd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           
      K   sŒ   |  dd¡}|  dd¡}|s|rtdƒ‚| ¡ dvrtdƒ‚g }| ¡ D ]\}}	| ||	g¡ q$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.)rA   ÚHNSWzIRealtime vector indexing supporting 2 Indexing Methods:'FLAT' and 'HNSW'.r   N)	Úgetr   ÚupperÚitemsÚextendr   r!   r
   Úlen)
r   r   rK   rL   r5   ÚsortÚnoindexÚattr_liÚkeyr#   r   r   r    r!   ±   s$   ÿÿÿ
ÿzVectorField.__init__N)r&   r'   r(   r)   r*   Údictr!   r   r   r   r    rJ   «   s    rJ   N)Útypingr   Úredisr   r   r,   r8   r?   rC   rD   rJ   r   r   r   r    Ú<module>   s    I!		