
    =wg&                         d dl mZ d dlmZ d dlmZ d dlmZ  G d dej                        Z G d de      Z	 G d	 d
e      Z
y)    )division)array)xrange)mcorec                   2    e Zd ZddZd Zd Zd Zd Zd Zy)	CombinationMatcherc                      || _         || _        y N)_submatchers_boost)selfsubmatchersboosts      L/var/www/horilla/myenv/lib/python3.12/site-packages/whoosh/matching/combo.py__init__zCombinationMatcher.__init__$   s    '    c                 :    t        d | j                  D              S )Nc              3   <   K   | ]  }|j                           y wr
   )supports_block_quality.0ms     r   	<genexpr>z<CombinationMatcher.supports_block_quality.<locals>.<genexpr>)   s     I!1++-I   allr   r   s    r   r   z)CombinationMatcher.supports_block_quality(   s    It7H7HIIIr   c                 T    t        d | j                  D              | j                  z  S )Nc              3   \   K   | ]$  }|j                         r|j                          & y wr
   )	is_activemax_qualityr   s     r   r   z1CombinationMatcher.max_quality.<locals>.<genexpr>,   s&      %qkkm ==? %s   *,)maxr   r   r   s    r   r!   zCombinationMatcher.max_quality+   s-     %D,=,= % %'+{{3 	3r   c                 @    t        fd| j                  D              S )Nc              3   @   K   | ]  }|j                          y wr
   )supports)r   r   astypes     r   r   z.CombinationMatcher.supports.<locals>.<genexpr>0   s     A!1::f%As   r   r   r&   s    `r   r%   zCombinationMatcher.supports/   s    At/@/@AAAr   c                 ,    t        | j                        S r
   )iterr   r   s    r   childrenzCombinationMatcher.children2   s    D%%&&r   c                 T    t        d | j                  D              | j                  z  S )Nc              3   <   K   | ]  }|j                           y wr
   )scorer   s     r   r   z+CombinationMatcher.score.<locals>.<genexpr>6   s     817798r   )sumr   r   r   s    r   r-   zCombinationMatcher.score5   s"    8d&7&7884;;FFr   N)      ?)	__name__
__module____qualname__r   r   r!   r%   r*   r-    r   r   r   r   #   s#    J3B'Gr   r   c                   T    e Zd ZdZddZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zy)PreloadedUnionMatchera  Instead of marching the sub-matchers along in parallel, this
    matcher pre-reads the scores for EVERY MATCHING DOCUMENT, trading memory
    for speed.

    This is faster than the implementation using a binary tree of
    :class:`~whoosh.matching.binary.UnionMatcher` objects (possibly just
    because of less overhead), but it doesn't allow getting information about
    the "current" document other than the score, because there isn't really a
    current document, just an array of scores.
    c           
         t         j                  | ||       || _        t        d      }| j                  D cg c]  }|j                         s| }}|rt        d |D              x}| _        |D ]  }	|	j                         s|r|	j                         |z  }
n|}
|	j                         }||z
  }t        |      |k  r0|j                  d t        |t        |      z
  dz         D               ||xx   |
z  cc<   |	j                          |	j                         r || _        || _        || _        y d| _        d| _        || _        y c c}w )Nr   dc              3   <   K   | ]  }|j                           y wr
   idr   s     r   r   z1PreloadedUnionMatcher.__init__.<locals>.<genexpr>M   s     '?1'?r   c              3       K   | ]  }d   ywr   Nr3   r   _s     r   r   z1PreloadedUnionMatcher.__init__.<locals>.<genexpr>X   s      Gq G      r   )r   r   	_doccountr   r   r    min_docnumr-   r;   lenextendr   next_a_offset)r   r   doccountr   scoredasubmactiveoffsetr   r-   docnumplaces                r   r   zPreloadedUnionMatcher.__init__E   s.   ##D+U#C!#J#'#4#4I48H$II$''?'?$??FT\ kkm !	E 1 %TTVF"VOE1v GF53q6>A3E,F GGeH%HFFH kkm DG!DL  DLDL+ Js   EEc                 `    | j                   | j                  z
  t        | j                        k  S r
   )rD   rI   rE   rH   r   s    r   r    zPreloadedUnionMatcher.is_activeb   s"    ||dll*S\99r   c                     | j                   S r
   rD   r   s    r   r;   zPreloadedUnionMatcher.ide       ||r   c                 N    | j                   | j                  | j                  z
     S r
   rH   rD   rI   r   s    r   r-   zPreloadedUnionMatcher.scoreh       wwt||dll233r   c                     | j                   }| j                  }| j                  |z
  }|dz  }|t        |      k  r$||   dk(  r|dz  }|t        |      k  r	||   dk(  r||z   | _        y )NrA   r   rH   rI   rD   rE   r   rL   rO   rQ   s       r   rG   zPreloadedUnionMatcher.nextk   sk    GGv%
c!fn5QQJE c!fn5Qv~r   c                 `    t        | j                  | j                  | j                  z
  d        S r
   )r"   rH   rD   rI   r   s    r   r!   z!PreloadedUnionMatcher.max_qualityu   s&    4774<<$,,67899r   c                 "    | j                         S r
   r!   r   s    r   block_qualityz#PreloadedUnionMatcher.block_qualityx   s    !!r   c                     || j                   k  ry || _         || j                  z
  }|t        | j                        k  r$| j                  |   dk(  r| j	                          y y y )Nr   )rD   rI   rE   rH   rG   )r   rP   is      r   skip_tozPreloadedUnionMatcher.skip_to{   sU    DLL T\\!s477|
aIIK !0r   c                     | j                   }| j                  }| j                  |z
  }d}|t        |      k  r&||   |k  r|dz  }d}|t        |      k  r	||   |k  r||z   | _        |S Nr   rA   rZ   )r   
minqualityrL   rO   rQ   skippeds         r   skip_to_qualityz%PreloadedUnionMatcher.skip_to_quality   su    GGv%c!fn5Z!7QJEG c!fn5Z!7 v~r   c                      yNFr3   r'   s     r   r%   zPreloadedUnionMatcher.supports       r   c              #      K   | j                   }| j                  }| j                  |z
  }|t        |      k  r$||   dkD  r||z    |dz  }|t        |      k  r#y y wrd   rZ   r[   s       r   all_idszPreloadedUnionMatcher.all_ids   s\     GGv%c!fnx!|fn$QJE c!fns   AAAN)r/   T)r0   r1   r2   __doc__r   r    r;   r-   rG   r!   r_   rb   rg   r%   rl   r3   r   r   r5   r5   9   s>    	::4&:"r   r5   c                   p    e Zd ZdZ	 	 d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 Zy)ArrayUnionMatchera  Instead of marching the sub-matchers along in parallel, this matcher
    pre-reads the scores for a large block of documents at a time from each
    matcher, accumulating the scores in an array.

    This is faster than the implementation using a binary tree of
    :class:`~whoosh.matching.binary.UnionMatcher` objects (possibly just
    because of less overhead), but it doesn't allow getting information about
    the "current" document other than the score, because there isn't really a
    current document, just an array of scores.
    c                    t         j                  | ||       || _        || _        |s|}|| _        t        dd t        | j                        D              | _        | j                         | _	        | j                          y )Nr7   r8   c              3       K   | ]  }d   ywr=   r3   r>   s     r   r   z-ArrayUnionMatcher.__init__.<locals>.<genexpr>   s     @Aa@r@   )r   r   _scoredrB   	_partsizer   r   rH   _min_idrD   
_read_part)r   r   rJ   r   rK   partsizes         r   r   zArrayUnionMatcher.__init__   sh    ##D+U#C!H!@)?@A||~r   c                     d| j                   j                  | j                  | j                  | j                  | j
                  fz  S )Nz(%s(%r, boost=%f, scored=%r, partsize=%d))	__class__r0   r   r   rr   rs   r   s    r   __repr__zArrayUnionMatcher.__repr__   s<    :>>**D,=,=t{{<<11 	2r   c                     | j                   D cg c]  }|j                         s| }}|rt        d |D              S | j                  S c c}w )Nc              3   <   K   | ]  }|j                           y wr
   r:   r   rM   s     r   r   z,ArrayUnionMatcher._min_id.<locals>.<genexpr>   s     4Ttwwy4r   )r   r    rC   rB   )r   rM   rN   s      r   rt   zArrayUnionMatcher._min_id   sH    #'#4#4I48H$II4V444>>!	 Js
   AAc                 `   | j                   }| j                  }t        | j                  | j                  z   | j
                        }| j                  }| j                  }t        | j                        D ]  }d||<   	 | j                  D ]  }|j                         s|j                         |k  s(|j                         |z
  }|r||xx   |j                         |z  z  cc<   nd||<   |j                          |j                         s|j                         |k  rn || _        || _        y rd   )rr   r   rC   rD   rs   rB   rH   r   r   r    r;   r-   rG   rI   _limit)r   rK   r   limitrO   rL   ra   r   s           r   ru   zArrayUnionMatcher._read_part   s    DLL4>>14>>BGG ' 	AAaD	 "" 	A++-ADDFUNDDFVOaDAGGI--DAaD ++-ADDFUN	 r   c                     | j                   }| j                  }| j                  }| j                  }||k  r|||z
     dkD  rn|dz  }||k  r||k(  r&| j	                         | _        | j                          y || _        y rd   )rH   rD   rI   r~   rt   ru   )r   rL   rP   rO   r   s        r   
_find_nextzArrayUnionMatcher._find_next   sz    GGun&!A%aKF un
 U?<<>DLOO!DLr   c                      yri   r3   r'   s     r   r%   zArrayUnionMatcher.supports   rj   r   c                 4    | j                   | j                  k  S r
   )rD   rB   r   s    r   r    zArrayUnionMatcher.is_active   s    ||dnn,,r   c                 :    t        d | j                  D              S )Nc              3   <   K   | ]  }|j                           y wr
   r^   r   s     r   r   z0ArrayUnionMatcher.max_quality.<locals>.<genexpr>   s     >q1==?>r   )r"   r   r   s    r   r!   zArrayUnionMatcher.max_quality   s    >D,=,=>>>r   c                 ,    t        | j                        S r
   )r"   rH   r   s    r   r_   zArrayUnionMatcher.block_quality   s    477|r   c                 r   || j                   k  ry || j                  k  r|| _        | j                          y | j                  }d}|D ]$  }|j                         s|j                  |       & t        d |D              r&| j                         | _        | j                          y | j                  | _        y )NFc              3   <   K   | ]  }|j                           y wr
   )r    r|   s     r   r   z,ArrayUnionMatcher.skip_to.<locals>.<genexpr>  s     8Dt~~8r   )rI   r~   rD   r   r   r    rb   anyrt   ru   rB   )r   rP   r   rN   rM   s        r   rb   zArrayUnionMatcher.skip_to   s    DLL dkk!!DLOO '' 	%D~~V$	% 8K88<<>DLOO>>DLr   c                 $   d}| j                         r]| j                         |k  rJ|dz  }| j                  | _        | j	                          | j                         r| j                         |k  rJ| j                         r| j                          |S rd   )r    r_   r~   rD   ru   r   )r   re   rf   s      r   rg   z!ArrayUnionMatcher.skip_to_quality  sv    nn4#5#5#7:#EqLG;;DLOO nn4#5#5#7:#E >>OOr   c                     | j                   S r
   rT   r   s    r   r;   zArrayUnionMatcher.id  rU   r   c              #   ,  K   | j                   }| j                  }| j                  }| j                  }| j                  }||k  rO|||z
     dkD  r| |dz  }||k(  r/|| _        | j                          | j                  }| j                  }||k  rNy y wrd   )rB   rD   rI   r~   rH   ru   )r   rJ   rP   rO   r   rL   s         r   rl   zArrayUnionMatcher.all_ids!  s     >>GGx&!A%aKF%! xs   BBBc                 L    | xj                   dz  c_         | j                         S )NrA   )rD   r   r   s    r   rG   zArrayUnionMatcher.next3  s      r   c                 N    | j                   | j                  | j                  z
     S r
   rW   r   s    r   r-   zArrayUnionMatcher.score7  rX   r   N)r/   Ti   )r0   r1   r2   rm   r   ry   rt   ru   r   r%   r    r!   r_   rb   rg   r;   rl   rG   r-   r3   r   r   ro   ro      s\    	 AE2
"0""-?*0$$!4r   ro   N)
__future__r   r   whoosh.compatr   whoosh.matchingr   Matcherr   r5   ro   r3   r   r   <module>r      sD   8      !G G,d. dNX4* X4r   