m *Ec@sFdZdkZdkZdkZdklZdkTdklZdk l Z l Z dk l Z dklZdklZd klZlZlZd klZlZd klZd klZd klZdklZdk l!Z!dk"l#Z#dk$l%Z%dk$l&Z&dk'l'Z'edZ(dfdYZ)e)dZ*e)dZ+e)dZ,e)dZ-dZ.hde*<de+<de,<de-<de-<e*e*<e+e+<e,e,<e-e-RNtIISetR.RMt currentWidstunindex_objectWidst differenceRPtinserttwidtkeystwidsRB(RRMRTR:R$RSRfRlRhRURNRdRkRbR_R]R`Rn((Rt index_objectsX        #       cCsx|||D]n}|ddjo#|i|dd!|||}q ||joq n|}|i|dd||tKeyErrort IndexErrorR[RY(RRqRnRKRlRCRd((RRiss*     cCst|tjo,|ii|h}t||f|Sn=t|i i |}|pth|f|Snt |djo|d}|d djo|ddjo ||Sn|i i|}|o4|ii|dd}|djo h}qnh}t||f|Snd}x>|D]6}||}|djo |}q=|i|}q=W|SdS(sReturn an InvertedIndex-style result "list" Note that this differentiates between being passed an Integer and a String. Strings are looked up in the lexicon, whereas Integers are assumed to be resolved word ids. iit"iN(R3RbtIntTypeRR1RCtresultt ResultListRGR+R\t splitSourceRBRnR!trtrrR(RRbR}R{R|RyRn((Rt __getitem__s4 "     R2c Cs;t||i|i}|idjodSn|id|i }|i do|d}t i dnti|}|djotidt|nd}xX|iD]M}|i}|pqn|i||i}t||\} }qW|dj o||iffSnt|iffS(s Apply the index to query parameters given in the argument, request The argument should be a mapping object. If the request does not contain the needed parameters, then None is returned. Otherwise two objects are returned. The first object is a ResultSet containing the record numbers of the matching records. The second object is a tuple containing the names of all data fields used. Rttextindex_operatorsThe usage of the 'textindex_operator' is no longer recommended. Please use a mapping object and the 'operator' key to specify the operator.s%Invalid operator '%s' for a TextIndexN(tparseIndexRequesttrequestRRt query_optionstrecordRmR!RCRtqopthas_keytwarningstwarnt operator_dicttquery_operatort exceptionst RuntimeErrortescapeR|R?tstripRtbuckettbtweightedIntersectiontwR<( RRtcidRR?RRR|RR((Rt _apply_indexs,      cCsdgS|idjo t}nti}|i|i}|iot |t |i}nt |t |i}g}x0|D](}||ii|i|}qW|S(sYReturn the positions in the document for the given document id of the word, word.iN(Rt_schemaR!R*tfRR~RRRYRTtdocR|twordsRbR+R\tindexes(RtdocidRRRR|RbR((Rt positionss   &cCsRtidd|}t|}|ii|}t||}|i |S(s Evaluate a query string. Convert the query string into a data structure of nested lists and strings, based on the grouping of whitespace-separated strings by parentheses and quotes. The 'Near' operator is inserted between the strings of a quoted group. The Lexicon is given the opportunity to transform the data structure. Stemming, wildcards, and translation are possible Lexicon services. Finally, the query list is normalized so that it and every sub-list consist of non-operator strings or lists separated by operators. This list is evaluated. s(?i)\s+and\s*not\s+s andnot N( tretsubtstparsetqRR+t query_hooktparse2tdefault_operatortevaluate(RRRR((RRs  cCs3y ||d}||d}Wntj otdnXt|}|tjo||}nOt |t pt |t o||}n!|t jo|i|}nt|}|tjo||}nOt |t pt |t o||}n!|t jo|i|}n||fS(s?Evaluate and return the left and right operands for an operatorisMalformed queryN(RRqtlefttrightRvt QueryErrorR3t operandTypeRxRRWt StringTypeRXtListTypeR(RRRqRRR((Rt get_operands/s*        cCskx2t|to!t|djo|d}qWt|tp ||Snd}xv|t|job||tjoC|i||\}}|i |}|g||d|d+qZ|d}qZWd}xq|t|jo]||t jo>|i||\}}||@}|g||d|d+q|d}qWd}xq|t|jo]||t jo>|i||\}}||B}|g||d|d+qS|d}qSWd}xv|t|job||tjoC|i||\}}|i|}|g||d|d+q|d}qWt|djo tdn|dS(sEvaluate a parsed queryiiisMalformed queryN(RWRRRBRRqtAndNotRRRtand_nottvaltAndtOrtNearRR(RRRRRqR((RRIsR#    cCs |ifS(s# return name of indexed attributes N(RR(R((RtgetIndexSourceNames{scCs t|iS(s return number of index objects N(RBRR1(R((Rt numObjectsscCsG|i|jo|i||_n|o|i|dndS(s preferences of TextIndex s4/manage_main?manage_tabs_message=Preferences%20savedN(RR RR#tRESPONSEtredirecttURL2(RRtREQUESTRR((Rtmanage_setPreferencess   sdtml/manageTextIndexsdtml/manageVocabulary(s TextIndexsTextIndex_Settings.stx(+RR t__doc__tPluggableIndextPluggableIndexInterfacet__implements__t implementst ITextIndextIPluggableIndext meta_typetmanage_optionsRR!RR%R+R/R#R;R3R=RJRPRoRcRrRiR~RRRRRRRRRtDTMLFiletglobalstmanageRt_setNametmanage_vocabulary(((RR=s>   $ -      1 M  + 7  !  2    cCsg}|i}t|}xS|dj oE|t|d}|it |d|d}t|}q!W|t|S(sParse parentheses and quotesiiiN( tlRtlowerttmptparenstpR!tquotestappendR(RRRR((RRs    cCs|i}d}x|t|jo||}t|to@t ||||<|do|i |||d}qnI|do=||o||||