ó
    [«ÑgK  ã                   ó€   • S SK Jr  S SKrS SKJrJrJrJr  S SKJ	r	  S SK
Jr  \R                  " \5      r " S S5      rg)é    )ÚdefaultdictN)ÚCallableÚDictÚListÚSet)ÚBaseLunrException)ÚTokenc                   ó¾   • \ rS rSr% Sr0 r\\\4   \	S'   S r
S rS r\SS j5       r\S	 5       rS
 rS rS rS rS rS\S\\   4S jrSS jrSS jrS rS rSrg)ÚPipelineé   z’lunr.Pipelines maintain a list of functions to be applied to all tokens
in documents entering the search index and queries ran agains the index.

Úregistered_functionsc                 ó:   • / U l         [        [        5      U l        g ©N)Ú_stackr   ÚsetÚ_skip©Úselfs    Ú//usr/lib/python3/dist-packages/lunr/pipeline.pyÚ__init__ÚPipeline.__init__   s   € Ø&(ˆŒÜ/:¼3Ó/?ˆ�
ó    c                 ó,   • [        U R                  5      $ r   )Úlenr   r   s    r   Ú__len__ÚPipeline.__len__   s   € Ü�4—;‘;ÓÐr   c                 ód   • SR                  SR                  S U R                   5       5      5      $ )Nz<Pipeline stack="{}">Ú,c              3   ó8   #   • U  H  oR                   v •  M     g 7fr   )Úlabel)Ú.0Úfns     r   Ú	<genexpr>Ú$Pipeline.__repr__.<locals>.<genexpr>   s   é € Ð6VÊ+ÀB·x¶xÊ+ùs   ‚)ÚformatÚjoinr   r   s    r   Ú__repr__ÚPipeline.__repr__   s&   € Ø&×-Ñ-¨c¯h©hÑ6VÈ$Ï+Ê+Ó6VÓ.VÓWÐWr   Nc                 ó´   • U=(       d    UR                   nX R                  ;   a  [        R                  SU5        X!l        XR                  UR                  '   g)z&Register a function with the pipeline.z+Overwriting existing registered function %sN)Ú__name__r   ÚlogÚwarningr    )Úclsr"   r    s      r   Úregister_functionÚPipeline.register_function   sD   € ð ×$˜Ÿ™ˆØ×,Ñ,Ó,Ü�K‰KÐEÀuÔMàŒØ-/× Ñ  §¡Ò*r   c                 ó¸   • U " 5       nU H$  n U R                   U   nUR                  U5        M&     U$ ! [         a    [        SR	                  U5      5      ef = f)z'Loads a previously serialised pipeline.z$Cannot load unregistered function {})r   ÚaddÚKeyErrorr   r%   )r-   Ú
serialisedÚpipelineÚfn_namer"   s        r   ÚloadÚPipeline.load)   sk   € ñ “5ˆÛ!ˆGð!Ø×-Ñ-¨gÑ6�ð —‘˜RÖ ñ "ð ˆøô ó Ü'Ø:×AÑAÀ'ÓJóð ðús	   Ž4´%Ac                 ón   • U H/  nU R                  U5        U R                  R                  U5        M1     g)záAdds new functions to the end of the pipeline.

Functions must accept three arguments:
- Token: A lunr.Token object which will be updated
- i: The index of the token in the set
- tokens: A list of tokens representing the set
N)Úwarn_if_function_not_registeredr   Úappend)r   Úargsr"   s      r   r1   ÚPipeline.add9   s.   € ó ˆBØ×0Ñ0°Ô4Ø�K‰K×Ñ˜rÖ"ò r   c           
      ó´   •  UR                   U R                  ;   $ ! [         a2    [        R	                  SR                  [        USU5      5      5         g f = f)NzbFunction "{}" is not registered with pipeline. This may cause problems when serialising the index.r    )r    r   ÚAttributeErrorr+   r,   r%   Úgetattr©r   r"   s     r   r9   Ú(Pipeline.warn_if_function_not_registeredE   sT   € ð	Ø—8‘8˜t×8Ñ8Ñ8Ð8øÜó 	Ü�K‰KðFßFLÁfÜ˜B ¨Ó,óGöð	ús   ‚ ›9AÁAc                 óØ   • U R                  U5         U R                  R                  U5      nU R                  R                  US-   U5        g! [         a  n[        S5      UeSnAff = f)zLAdds a single function after a function that already exists in the
pipeline.é   úCannot find existing_fnN©r9   r   ÚindexÚinsertÚ
ValueErrorr   ©r   Úexisting_fnÚnew_fnrF   Úes        r   ÚafterÚPipeline.afterP   sd   € ð 	×,Ñ,¨VÔ4ð	FØ—K‘K×%Ñ% kÓ2ˆEØ�K‰K×Ñ˜u q™y¨&Õ1øÜó 	FÜ#Ð$=Ó>ÀAÐEûð	Fús   “:A Á
A)ÁA$Á$A)c                 óÐ   • U R                  U5         U R                  R                  U5      nU R                  R                  X25        g! [         a  n[        S5      UeSnAff = f)zOAdds a single function before a function that already exists in the
pipeline.

rD   NrE   rI   s        r   ÚbeforeÚPipeline.beforeZ   s^   € ð
 	×,Ñ,¨VÔ4ð	FØ—K‘K×%Ñ% kÓ2ˆEØ�K‰K×Ñ˜uÕ-øÜó 	FÜ#Ð$=Ó>ÀAÐEûð	Fús   “6A
 Á

A%ÁA Á A%c                 ó\   •  U R                   R                  U5        g! [         a     gf = f)z%Removes a function from the pipeline.N)r   ÚremoverH   r@   s     r   rS   ÚPipeline.removef   s+   € ð	Ø�K‰K×Ñ˜rÕ"øÜó 	Ùð	ús   ‚ ž
+ª+r"   Úfield_namesc                 ó@   • U R                   U   R                  U5        g)z…
Make the pipeline skip the function based on field name we're processing.

This relies on passing the field name to Pipeline.run().
N)r   Úupdate)r   r"   rU   s      r   ÚskipÚPipeline.skipm   s   € ð 	�
‰
�2‰×Ñ˜kÕ*r   c                 ó4  • U R                    H‡  nU(       a  X R                  U   ;   a  M  / n[        U5       HV  u  pVU" XeU5      nU(       d  M  [        U[        [
        45      (       a  UR                  U5        ME  UR                  U5        MX     UnM‰     U$ )a  
Runs the current list of functions that make up the pipeline against
the passed tokens.

:param tokens: The tokens to process.
:param field_name: The name of the field these tokens belongs to, can be ommited.
    Used to skip some functions based on field names.
)r   r   Ú	enumerateÚ
isinstanceÚlistÚtupleÚextendr:   )r   ÚtokensÚ
field_namer"   ÚresultsÚiÚtokenÚresults           r   ÚrunÚPipeline.runu   s†   € ð —+”+ˆBæ˜j¯J©J°r©NÓ:ÙØˆGÜ% fÖ-‘�ñ ˜E fÓ-�ÞÙÜ˜f¤t¬U m×4Ñ4Ø—N‘N 6Ö*à—N‘N 6Ö*ñ .ð ŠFñ! ð$ ˆr   c                 óz   • [        X5      nU R                  U/5       Vs/ s H  n[        U5      PM     sn$ s  snf )a-  Convenience method for passing a string through a pipeline and
getting strings out. This method takes care of wrapping the passed
string in a token and mapping the resulting tokens back to strings.

.. note:: This ignores the skipped functions since we can't
    access field names from this context.
)r	   rf   Ústr)r   ÚstringÚmetadatard   Útkns        r   Ú
run_stringÚPipeline.run_string’   s7   € ô �fÓ'ˆØ$(§H¡H¨e¨WÔ$5Ó6Ò$5˜S”�C–Ñ$5Ñ6Ð6ùÒ6s    8c                 ó   • / U l         g r   )r   r   s    r   ÚresetÚPipeline.reset�   s	   € Øˆ�r   c                 óX   • U R                    Vs/ s H  oR                  PM     sn$ s  snf r   )r   r    r@   s     r   Ú	serializeÚPipeline.serialize    s    € Ø#'§;¢;Ó/¢;˜R—”¡;Ñ/Ð/ùÒ/s   �')r   r   r   )r*   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   ri   r   Ú__annotations__r   r   r'   Úclassmethodr.   r6   r1   r9   rM   rP   rS   r   rX   rf   rm   rp   rs   Ú__static_attributes__© r   r   r   r      sœ   ‡ ñð
 13Ð˜$˜s H˜}Ñ-Ó2ò@ò òXð
 ó0ó ð0ð ñó ðò
#ò	òFò
Fòð+�xð +¨d°3©iô +ôô:	7òõ0r   r   )Úcollectionsr   ÚloggingÚtypingr   r   r   r   Úlunr.exceptionsr   Ú
lunr.tokenr	   Ú	getLoggerr*   r+   r   r|   r   r   Ú<module>rƒ      s3   ðÝ #Û ß ,Ó ,å -Ý à×Ò˜Ó!€÷V0ò V0r   