ó ÿgdSc@€sdZddlmZddlZddlZddlmZmZm Z m Z m Z m Z ddl mZmZdefd„ƒYZddlmZmZiejd 6ejd 6Zd efd „ƒYZeƒZd e fd„ƒYZdefd„ƒYZdS(sÐ sphinx.search ~~~~~~~~~~~~~ Create a full-text search index for offline search. :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. iÿÿÿÿ(twith_statementN(trawtcommentttitletTextt NodeVisitortSkipNode(tjsdumpt rpartitiontSearchLanguagecB€s_eZdZdZeƒZdZej dƒZ d„Z d„Z d„Z d„Zd„ZRS( sI This class is the base class for search natural language preprocessors. If you want to add support for a new language, you should override the methods of this class. You should override `lang` class property too (e.g. 'en', 'fr' and so on). .. attribute:: stopwords This is a set of stop words of the target language. Default `stopwords` is empty. This word is used for building index and embedded in JS. .. attribute:: js_stemmer_code Return stemmer class of JavaScript version. This class' name should be ``Stemmer`` and this class must have ``stemWord`` method. This string is embedded as-is in searchtools.js. This class is used to preprocess search word which Sphinx HTML readers type, before searching index. Default implementation does nothing. s /** * Dummy stemmer for languages without stemming rules. */ var Stemmer = function() { this.stemWord = function(w) { return w; } } s\w+(?u)cC€s||_|j|ƒdS(N(toptionstinit(tselfR ((s@/usr/local/lib/python2.7/site-packages/sphinx/search/__init__.pyt__init__9s cC€sdS(sK Initialize the class with the options the user has given. N((R R ((s@/usr/local/lib/python2.7/site-packages/sphinx/search/__init__.pyR =scC€s|jj|ƒS(s» This method splits a sentence into words. Default splitter splits input at white spaces, which should be enough for most languages except CJK languages. (t_word_retfindall(R tinput((s@/usr/local/lib/python2.7/site-packages/sphinx/search/__init__.pytsplitBscC€s|S(s³ This method implements stemming algorithm of the Python version. Default implementation does nothing. You should implement this if the language has any stemming rules. This class is used to preprocess search words before registering them in the search index. The stemming of the Python version and the JS version (given in the js_stemmer_code attribute) must be compatible. ((R tword((s@/usr/local/lib/python2.7/site-packages/sphinx/search/__init__.pytstemJs cC€szt|ƒdkr8dt|dƒko3dknpxt|dƒdkoxt|ƒdkpx||jkpx|jƒ S(sˆ Return true if the target word should be registered in the search index. This method is called after stemming. iiA0ii”0i(tlentordt stopwordstisdigit(R R((s@/usr/local/lib/python2.7/site-packages/sphinx/search/__init__.pyt word_filterWs87N(t__name__t __module__t__doc__tNonetlangtsetRtjs_stemmer_codetretcompileRR R RRR(((s@/usr/local/lib/python2.7/site-packages/sphinx/search/__init__.pyR s     (tentjaR"R#t_JavaScriptIndexcB€s>eZdZdZdZd„Zd„Zd„Zd„ZRS(s The search index as javascript file that calls a function on the documentation search object to register the index. sSearch.setIndex(t)cC€s|jtj|ƒ|jS(N(tPREFIXRtdumpstSUFFIX(R tdata((s@/usr/local/lib/python2.7/site-packages/sphinx/search/__init__.pyR'rscC€si|t|jƒt|jƒ !}| sM|j|jƒ sM|j|jƒ r\tdƒ‚ntj|ƒS(Ns invalid data(RR&R(t startswithtendswitht ValueErrorRtloads(R tsR)((s@/usr/local/lib/python2.7/site-packages/sphinx/search/__init__.pyR-us  cC€s|j|j|ƒƒdS(N(twriteR'(R R)tf((s@/usr/local/lib/python2.7/site-packages/sphinx/search/__init__.pytdump|scC€s|j|jƒƒS(N(R-tread(R R0((s@/usr/local/lib/python2.7/site-packages/sphinx/search/__init__.pytloads( RRRR&R(R'R-R1R3(((s@/usr/local/lib/python2.7/site-packages/sphinx/search/__init__.pyR$is   t WordCollectorcB€s eZdZd„Zd„ZRS(sG A special visitor that collects words for the `IndexBuilder`. cC€s/tj||ƒg|_g|_||_dS(N(RR t found_wordstfound_title_wordsR(R tdocumentR((s@/usr/local/lib/python2.7/site-packages/sphinx/search/__init__.pyR ‹s  cC€sý|jtkrt‚n|jtkr‘tjdd|jƒƒ}tjdd|ƒ}tjdd|ƒ}|jj|j j |ƒƒt‚n|jt krÅ|jj|j j |jƒƒƒn4|jt krù|j j|j j |jƒƒƒndS(Ns(?is)ts(?is)s<[^<]+?>(t __class__RRRR tsubtastextR5textendRRRRR6(R tnodetnodetext((s@/usr/local/lib/python2.7/site-packages/sphinx/search/__init__.pytdispatch_visit‘s  %(RRRR R?(((s@/usr/local/lib/python2.7/site-packages/sphinx/search/__init__.pyR4†s t IndexBuildercB€sseZdZied6ed6Zd„Zd„Zd„Zd„Z d„Z d„Z d „Z d „Z d „ZRS( sh Helper class that creates a searchindex based on the doctrees passed to the `feed` method. RtpicklecC€s˜||_i|_i|_i|_i|_i|_i|_t||ƒ|_|r‹t |dƒ}|j ƒj dƒ|_ WdQXn d|_ dS(Ntrbsutf-8u( tenvt_titlest_mappingt_title_mappingt _stem_cachet _objtypest _objnamest languagesRtopenR2tdecodetjs_scorer_code(R RCRR tscoringtfp((s@/usr/local/lib/python2.7/site-packages/sphinx/search/__init__.pyR ­s       !c€sÇt|tƒr|j|}n|j|ƒ}t|tƒ sY|jdƒ|jjkrhtdƒ‚n|d‰tt ˆ|dƒƒ|_ ‡fd†}||dƒ|_ ||dƒ|_ dS( sReconstruct from frozen data.t envversions old formatt filenamesttitlesc€spi}xc|jƒD]U\}}t|tƒrHtˆ|gƒ||Ös(t iteritemst isinstancetintR(tmappingtrvtktv(RU(s@/usr/local/lib/python2.7/site-packages/sphinx/search/__init__.pyt load_termsÐs $ttermst titletermsN( RWt basestringtformatsR3tdicttgetRCtversionR,tzipRDRERF(R tstreamtformattfrozenR]((RUs@/usr/local/lib/python2.7/site-packages/sphinx/search/__init__.pyR3Äs  cC€s9t|tƒr|j|}n|j|jƒ|ƒdS(s"Dump the frozen index to a stream.N(RWR`RaR1tfreeze(R RfRg((s@/usr/local/lib/python2.7/site-packages/sphinx/search/__init__.pyR1ÝscC€s™i}|j}|j}xz|jjjƒD]f\}}xW|jƒD]I\}}} } } } | |krnqDn| dkr€qDnt|dƒ\} }|j| iƒ}y||| f}Wn}tk r:t |ƒ}|||| f<|j j | ƒ}|r$|| t |j |ƒƒf||scs€s1|]'\}}||dd|dfVqdS(it:iN((RSR[R\((s@/usr/local/lib/python2.7/site-packages/sphinx/search/__init__.pys sRQRRR^tobjectstobjtypestobjnamesR_RP( RDtkeystvaluesRbt enumerateR†RmRHRVRIRCRd( R RQRRRsR^t title_termsRˆR‰RŠ((s@/usr/local/lib/python2.7/site-packages/sphinx/search/__init__.pyRis  cC€s•i}x1|D])}||jkr |j||| s  .M