U
    g@
                     @   s6   d dl mZ ddlmZ ddlmZ G dd dZdS )    )Optional   )	to_string)Documentc                   @   s2   e Zd ZdZdee dddZedd	d
ZdS )Resultz[
    Represents the result of a search query, and has an array of Document
    objects
    r   FN)field_encodingsc              	   C   s  |d | _ || _g | _d}|r&|d }|r2|d }|r>|d }|rFdnd}tdt||D ]}	t||	 }
|rt||	|  nd}|r|d n|}|rt||	d  nd}i }|r`||	|  dk	r`tt||	|  ddd }||	|  ddd }t||D ]Z\}}|dks ||kr0t|||< q|| }|dkrL|||< nt||d||< qz
|d= W n t	k
r   Y nX z|d |d< |d= W n t	k
r   Y nX |rt
|
f||d	|nt
|
fd
|i|}| j| qZdS )z
        - duration: the execution time of the query
        - has_payload: whether the query has payloads
        - with_scores: whether the query has scores
        - field_encodings: a dictionary of field encodings if any is provided
        r   r      N)encodingid$json)scorepayloadr   )totaldurationdocsrangelenr   floatmapzipKeyErrorr   append)selfresZ
hascontentr   Zhas_payloadZwith_scoresr   stepoffsetir
   r   Zfields_offsetr   fieldskeysvalueskeyvaluer	   doc r$   @/tmp/pip-unpacked-wheel-f3sx1i9r/redis/commands/search/result.py__init__   sT    




zResult.__init__)returnc                 C   s   d| j  d| j dS )NzResult{z total, docs: })r   r   )r   r$   r$   r%   __repr__V   s    zResult.__repr__)r   FFN)	__name__
__module____qualname____doc__r   dictr&   strr)   r$   r$   r$   r%   r      s   	    Ir   N)typingr   _utilr   documentr   r   r$   r$   r$   r%   <module>   s   