Ë
    cQêj
  ã                   óN  — d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	m
Z
 ddlmZmZmZmZ ddlmZmZmZ  ed	«      Z G d
„ d«      Ze	 G d„ de«      «       Ze	 G d„ de«      «       Ze	 G d„ de«      «       Ze	 G d„ de«      «       Ze	 G d„ de«      «       Z G d„ deee   «      Zy)zResult classes.é    )ÚABC)ÚCounter)ÚCallableÚMapping)Ú	dataclassÚfield)ÚAnyÚClassVarÚGenericÚTypeVaré   )Ú_normalize_dateÚ_normalize_textÚ_normalize_urlÚTc                   óf   — e Zd ZU dZeeeeeeeeeedœ
Zee	e
eege
f   f      ed<   de
de
ddfd„Zy)	Ú
BaseResultz=Base class for all results. Contains normalization functions.)
ÚtitleÚbodyÚhrefÚurlÚ	thumbnailÚimageÚdateÚauthorÚ	publisherÚinfoÚ_normalizersÚnameÚvalueÚreturnNc                 ó€   — |r%| j                   j                  |«      x}r ||«      }t        j                  | ||«       y)zHOverride setattr to apply normalization functions to certain attributes.N)r   ÚgetÚobjectÚ__setattr__)Úselfr   r    Ú
normalizers       úQ/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/ddgs/results.pyr%   zBaseResult.__setattr__   s<   € á D×$5Ñ$5×$9Ñ$9¸$Ó$?Ð?�jÐ?Ù˜uÓ%ˆEÜ×Ñ˜4  uÕ-ó    )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r
   r   Ústrr   r	   Ú__annotations__r%   © r)   r(   r   r      sh   … ÙGð !ØØØØ#ØØØ!Ø$ØñB€L�(˜7 3¨°#°¸°Ñ(<Ð#<Ñ=Ñ>ó ð. ð .¨Cð .°Dô .r)   r   c                   ó<   — e Zd ZU dZdZeed<   dZeed<   dZeed<   y)Ú
TextResultzText search result.Ú r   r   r   N)	r*   r+   r,   r-   r   r.   r/   r   r   r0   r)   r(   r2   r2   %   s    … áà€Eˆ3ƒOØ€Dˆ#ƒNØ€Dˆ#„Nr)   r2   c                   ót   — e Zd ZU dZdZeed<   dZeed<   dZeed<   dZ	eed<   dZ
eed<   dZeed<   dZeed	<   y
)ÚImagesResultzImage search result.r3   r   r   r   r   ÚheightÚwidthÚsourceN)r*   r+   r,   r-   r   r.   r/   r   r   r   r6   r7   r8   r0   r)   r(   r5   r5   .   sG   … áà€Eˆ3ƒOØ€Eˆ3ƒOØ€IˆsÓØ€CˆƒMØ€FˆCÓØ€Eˆ3ƒOØ€FˆCÔr)   r5   c                   óf   — e Zd ZU dZdZeed<   dZeed<   dZeed<   dZ	eed<   dZ
eed<   dZeed<   y	)
Ú
NewsResultzNews search result.r3   r   r   r   r   r   r8   N)r*   r+   r,   r-   r   r.   r/   r   r   r   r   r8   r0   r)   r(   r:   r:   ;   s<   … áà€Dˆ#ƒNØ€Eˆ3ƒOØ€Dˆ#ƒNØ€CˆƒMØ€Eˆ3ƒOØ€FˆCÔr)   r:   c                   óø   — e Zd ZU dZdZeed<   dZeed<   dZeed<   dZ	eed<   dZ
eed<   dZeed<   dZeed	<    ee¬
«      Zeeef   ed<   dZeed<   dZeed<   dZeed<    ee¬
«      Zeeef   ed<   dZeed<   y)ÚVideosResultzVideo search result.r3   r   ÚcontentÚdescriptionÚdurationÚ
embed_htmlÚ	embed_urlÚimage_token)Údefault_factoryÚimagesÚproviderÚ	publishedr   Ú
statisticsÚuploaderN)r*   r+   r,   r-   r   r.   r/   r=   r>   r?   r@   rA   rB   r   ÚdictrD   rE   rF   r   rG   rH   r0   r)   r(   r<   r<   G   s    … áà€Eˆ3ƒOØ€GˆSÓØ€K�ÓØ€HˆcÓØ€J�ÓØ€IˆsÓØ€K�ÓÙ"°4Ô8€FˆD��c�‰NÓ8Ø€HˆcÓØ€IˆsÓØ€IˆsÓÙ!&°tÔ!<€J��S˜#�X‘Ó<Ø€HˆcÔr)   r<   c                   óf   — e Zd ZU dZdZeed<   dZeed<   dZeed<   dZ	eed<   dZ
eed<   dZeed<   y	)
ÚBooksResultzBook search result.r3   r   r   r   r   r   r   N)r*   r+   r,   r-   r   r.   r/   r   r   r   r   r   r0   r)   r(   rK   rK   Z   s>   … áà€Eˆ3ƒOØ€FˆCÓØ€IˆsÓØ€Dˆ#ƒNØ€CˆƒMØ€IˆsÔr)   rK   c                   ó„   — e Zd ZdZdee   ddfd„Zdedefd„Zde	fd„Z
deddfd	„Zd
ee   ddfd„Zdeeeef      fd„Zy)ÚResultsAggregatorzµAggregates incoming results.

    Items are deduplicated by `cache_field`. Append just increments a counter;
    `extract_results` returns items sorted by descending frequency.
    Úcache_fieldsr!   Nc                 ón   — |sd}t        |«      ‚t        |«      | _        t        «       | _        i | _        y )Nz)At least one cache_field must be provided)Ú
ValueErrorÚsetrN   r   Ú_counterÚ_cache)r&   rN   Úmsgs      r(   Ú__init__zResultsAggregator.__init__m   s1   € ÙØ=ˆCÜ˜S“/Ð!Ü Ó-ˆÔÜ&-£iˆŒØ$&ˆ�r)   Úitemc                 ó®   — |j                   D ]*  }|| j                  v sŒt        |j                   |   «      c S  d|›d| j                  › �}t        |«      ‚)NzItem z has none of the cache fields )Ú__dict__rN   r.   ÚAttributeError)r&   rV   ÚkeyrT   s       r(   Ú_get_keyzResultsAggregator._get_keyu   s^   € Ø—=‘=ò 	/ˆCØ�d×'Ñ'Ò'Ü˜4Ÿ=™=¨Ñ-Ó.Ò.ð	/ð �d�XÐ;¸D×<MÑ<MÐ;NÐOˆÜ˜SÓ!Ð!r)   c                 ó,   — t        | j                  «      S )z(Return the number of items in the cache.)ÚlenrS   )r&   s    r(   Ú__len__zResultsAggregator.__len__|   s   € ä�4—;‘;ÓÐr)   c                 ó>  — | j                  |«      }|| j                  vsXt        |j                  j	                  dd«      «      t        | j                  |   j                  j	                  dd«      «      kD  r|| j                  |<   | j
                  |xx   dz  cc<   y)z£Add an item to the cache.

        Register an occurrence of `item`. First time we see its key,
        we store the item; every time we bump the counter.
        r   r3   r   N)r[   rS   r]   rX   r#   rR   )r&   rV   rZ   s      r(   ÚappendzResultsAggregator.append€   s†   € ð �m‰m˜DÓ!ˆØ�d—k‘kÑ!¤S¨¯©×):Ñ):¸6À2Ó)FÓ%GÌ#Ø�K‰K˜Ñ×%Ñ%×)Ñ)¨&°"Ó5óK
ò &
ð  $ˆD�K‰K˜ÑØ�‰�cÓ˜aÑÔr)   Úitemsc                 ó4   — |D ]  }| j                  |«       Œ y)z!Add a list of items to the cache.N)r`   )r&   ra   rV   s      r(   ÚextendzResultsAggregator.extend�   s   € àò 	ˆDØ�K‰K˜Õñ	r)   c                 ó–   — | j                   j                  «       D ��cg c]  \  }}| j                  |   j                  ‘Œ  c}}S c c}}w )zXReturn a list of items, sorted by descending frequency. Each item is returned as a dict.)rR   Úmost_commonrS   rX   )r&   rZ   Ú_s      r(   Úextract_dictszResultsAggregator.extract_dicts’   s6   € à8<¿¹×8QÑ8QÓ8S×T©f¨c°1�—‘˜CÑ ×)Ó)ÓTÐTùÓTs   ž#A)r*   r+   r,   r-   rQ   r.   rU   r   r[   Úintr^   r`   Úlistrc   rI   r	   rg   r0   r)   r(   rM   rM   f   s‚   „ ñð' S¨¡Xð '°$ó 'ð"˜Qð " 3ó "ð ˜ó  ð ˜1ð   ó  ð˜D ™Gð ¨ó ð
U˜t D¨¨c¨¡NÑ3ô Ur)   rM   N)r-   Úabcr   Úcollectionsr   Úcollections.abcr   r   Údataclassesr   r   Útypingr	   r
   r   r   Úutilsr   r   r   r   r   r2   r5   r:   r<   rK   rM   r0   r)   r(   ú<module>rp      sÎ   ðÙ å Ý ß -ß (ß 2Ó 2ç CÑ CáˆCƒL€÷.ñ .ð. ô�ó ó ðð ô	�:ó 	ó ð	ð ô�ó ó ðð ô�:ó ó ðð$ ô�*ó ó ðô.U˜˜W Q™Zõ .Ur)   