U
    g                     @   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                	   @   sp   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eee eeeeed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GEOSHAPEZINDEXMISSINGZ
INDEXEMPTYNF)nameargssortableno_indexindex_missingindex_emptyas_namec                 C   s   |dkrg }|| _ || _t | _|| _|r8| jtj |rJ| jtj |r\| jtj	 |rn| jtj
 |r~|s~td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   ?/tmp/pip-unpacked-wheel-f3sx1i9r/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      s<         +r   c                   @   s0   e Zd ZdZdZdZd
eeeeeddd	Z	dS )	TextFieldzI
    TextField is used to define a text field in a schema definition
    NOSTEMPHONETIC      ?FN)r   weightno_stemphonetic_matcherwithsuffixtriec                 K   sn   t j| |fdt jt j|gi| |r4t | | j |rZ|dkrZt | | j t | | |rjt | d d S )Nr   )zdm:enzdm:frzdm:ptzdm:esWITHSUFFIXTRIE)r   r   r   r   r"   r+   r,   )r   r   r.   r/   r0   r1   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                   @   s   e Zd ZdZedddZdS )NumericFieldzO
    NumericField is used to define a numeric field in a schema definition
    r   c                 K   s    t j| |fdt jgi| d S Nr   )r   r   r   r   r   r3   r   r   r   r   u   s    zNumericField.__init__Nr$   r%   r&   r'   r(   r   r   r   r   r   r5   p   s   r5   c                   @   s(   e Zd ZdZdZdZdedddZdS )	GeoShapeFieldzK
    GeoShapeField is used to enable within/contain indexing/searching
    	SPHERICALFLATNr6   c                 K   s2   t jg}|r|| t j| |fd|i| d S r7   )r   r   r   r   )r   r   Zcoord_systemr3   r   r   r   r   r      s    
zGeoShapeField.__init__)N)r$   r%   r&   r'   r;   r<   r(   r   r   r   r   r   r:   y   s   r:   c                   @   s   e Zd ZdZedddZdS )GeoFieldzP
    GeoField is used to define a geo-indexing field in a schema definition
    r6   c                 K   s    t j| |fdt jgi| d S r7   )r   r   r   r8   r   r   r   r      s    zGeoField.__init__Nr9   r   r   r   r   r=      s   r=   c                   @   s.   e Zd ZdZdZdZd
eeeedddZd	S )TagFieldzx
    TagField is a tag-indexing field with simpler compression and tokenization.
    See http://redisearch.io/Tags/
    	SEPARATORCASESENSITIVE,F)r   	separatorcase_sensitiver1   c                 K   sH   t j| j|g}|r|| j |r,|d t j| |fd|i| d S )Nr2   r   )r   r	   r?   r   r@   r   )r   r   rB   rC   r1   r3   r   r   r   r   r      s    
zTagField.__init__N)rA   FF)	r$   r%   r&   r'   r?   r@   r(   r)   r   r   r   r   r   r>      s      r>   c                   @   s"   e Zd ZdZeeed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kr<tdg }| D ]\}}	|||	g qHtj| |fdtj|t|f|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.)r<   ZHNSWzIRealtime vector indexing supporting 2 Indexing Methods:'FLAT' and 'HNSW'.r   N)	getr   upperitemsextendr   r   r
   len)
r   r   rE   rF   r3   sortZnoindexZattr_likeyr!   r   r   r   r      s&     zVectorField.__init__N)r$   r%   r&   r'   r(   dictr   r   r   r   r   rD      s   rD   N)typingr   Zredisr   r   r*   r5   r:   r=   r>   rD   r   r   r   r   <module>   s   I!		