b#(lGddZGddZGddeZGddeZGdd Zy ) ceZdZdZdZdZdZdZddZdZ dd Z d d Z d Z d Z d ZdZdZdZdZdZdZdZdZdZdZdZd!dZdZdeddfdZy)"QueryaB Query is used to build complex queries that have more parameters than just the query string. The query string is set in the constructor, and other options have setter functions. The setter functions return the query object, so they can be chained, i.e. `Query("foo").verbatim().filter(...)` etc. c:||_d|_d|_d|_d|_d|_d|_d|_d|_d|_ t|_ d|_ d|_ d|_d|_g|_g|_g|_d|_d|_d|_y)z Create a new query object. The query string is set in the constructor, and other options have setter functions. FN) _query_string_offset_num _no_content _no_stopwords_fields _verbatim_with_payloads _with_scores_scorerlist_filters_ids_slop _in_order_sortby_return_fields_summarize_fields_highlight_fields _language _expander_dialect)self query_strings =/usr/lib/python3/dist-packages/redis/commands/search/query.py__init__zQuery.__init__ s*   " #!      !#!# c|jS)z+Return the query string of this query only.)rrs r rzQuery.query_string(s!!!r"c||_|S)zTLimit the results to a specific set of pre-known document ids of any length.)r)ridss r limit_idszQuery.limit_ids,s  r"c0|xj|z c_|S)zAdd fields to return fields.)rrfieldss r return_fieldszQuery.return_fields2s v% r"Ncn|jj|||xjd|fz c_|S)zJAdd field to return fields (Optional: add 'AS' name to the field).AS)rappend)rfieldas_fields r return_fieldzQuery.return_field7s9 ""5)     D(#3 3  r"cF|sgSt|tr|gSt|SN) isinstancestrrr)s r _mk_field_listzQuery._mk_field_list?s$I%fc2xDV Dr"cdg}|j|}|r|dtt|g|zz }||dt|gz }||dt|gz }||d|gz }||_|S)a Return an abridged format of the field, containing only the segments of the field which contain the matching term(s). If `fields` is specified, then only the mentioned fields are summarized; otherwise all results are summarized. Server side defaults are used for each option (except `fields`) if not specified - **fields** List of fields to summarize. All fields are summarized if not specified - **context_len** Amount of context to include with each fragment - **num_frags** Number of fragments per document - **sep** Separator string to separate fragments SUMMARIZEFIELDSLENFRAGS SEPARATOR)r6r5lenr)rr* context_len num_fragssepargss r summarizezQuery.summarizeDs"}$$V,  Xs3v;/069 9D  " UC ,- -D  Wc)n- -D ? [#& &D!% r"cdg}|j|}|r|dtt|g|zz }|r|dgt|zz }||_|S)a Apply specified markup to matched term(s) within the returned field(s). - **fields** If specified then only those mentioned fields are highlighted, otherwise all fields are highlighted - **tags** A list of two strings to surround the match. HIGHLIGHTr9TAGS)r6r5r=rr)rr*tagsrAs r highlightzQuery.highlightds`}$$V,  Xs3v;/069 9D  VHtDz) )D!% r"c||_|S)z Analyze the query as being in the specified language. :param language: The language (e.g. `chinese` or `english`) )r)rlanguages r rIzQuery.languagev " r"c||_|S)zpAllow a maximum of N intervening non matched terms between phrase terms (0 means exact phrase). )r)rslops r rLz Query.slops  r"cd|_|S)z Match only documents where the query terms appear in the same order in the document. i.e. for the query "hello world", we do not match "world hello" T)rr$s r in_orderzQuery.in_orders  r"c||_|S)z Use a different scoring function to evaluate document relevance. Default is `TFIDF`. :param scorer: The scoring function to use (e.g. `TFIDF.DOCNORM` or `BM25`) )r)rscorers r rPz Query.scorers  r"c|jg}||jz }||j|jzz }|d|j|j gz }|S)z:Format the redis arguments for this query and return them.LIMIT)r_get_args_tagsrrr r )rrAs r get_argszQuery.get_argss\""# ##%% &&)?)??? $,, 22 r"cg}|jr|jd|jrD|jd|jt|j||jz }|jr|jd|j r|jd|j r;|j D],}t|ts td||jz }.|jr|jd|jr|d|jgz }|jr|jd|jrD|jd |jt|j||jz }|jd k\r|d |jgz }|j r|jd |j"rD|jd |jt|j"||j"z }|j$rOt|j$t&s td|jd||j$jz }|j(r|d|j(gz }|j*r|d|j*gz }|j,r|d|j,gz }|S)N NOCONTENTINFIELDSVERBATIM NOSTOPWORDSz Did not receive a Filter object. WITHPAYLOADSSCORER WITHSCORESINKEYSrSLOPINORDERRETURNzDid not receive a SortByField.SORTBYLANGUAGEEXPANDERDIALECT)r r.r r=rr rr4FilterAttributeErrorrArrrrrrrr SortbyFieldrrr)rrAflts r rSzQuery._get_args_tagss4    KK $ << KK # KKDLL) * DLL D >> KK #    KK & ==}} !!#v.()KLL  !    KK ' << Xt||, ,D    KK % 99 KK ! KKDII ' DII D ::? VTZZ( (D >> KK "    KK ! KKD//0 1 D'' 'D <<dllK8$%EFF KK ! DLL%% %D >> Z0 0D >> Z0 0D == Y . .D r"c"||_||_|S)z Set the paging for the query (defaults to 0..10). - **offset**: Paging offset for the results. Defaults to 0 - **num**: How many results do we want )r r )roffsetnums r pagingz Query.pagings   r"cd|_|S)zWSet the query to be verbatim, i.e. use no query expansion or stemming. T)rr$s r verbatimzQuery.verbatims r"cd|_|S)z>Set the query to only return ids and not the document content.T)r r$s r no_contentzQuery.no_contents r"cd|_|S)z Prevent the query from being filtered for stopwords. Only useful in very big queries that you are certain contain no stopwords. T)r r$s r no_stopwordszQuery.no_stopwordss " r"cd|_|S)z+Ask the engine to return document payloads.T)rr$s r with_payloadszQuery.with_payloadss" r"cd|_|S)z0Ask the engine to return document search scores.T)rr$s r with_scoreszQuery.with_scoress  r"c||_|S)z Limit the search to specific TEXT fields only. - **fields**: A list of strings, case sensitive field names from the defined schema. )r r)s r limit_fieldszQuery.limit_fieldss  r"c<|jj||S)z Add a numeric or geo filter to the query. **Currently only one of each filter is supported by the engine** - **flt**: A NumericFilter or GeoFilter object, used on a corresponding field )rr.)rrhs r add_filterzQuery.add_filters S! r"c(t|||_|S)z Add a sortby field to the query. - **field** - the name of the field to sort by - **asc** - when `True`, sorting will be done in asceding order )rgrrr/ascs r sort_byz Query.sort_bys#5#.  r"c||_|S)zg Add a expander field to the query. - **expander** - the name of the expander )r)rexpanders r rzQuery.expanderrJr"dialectreturnc||_|S)zw Add a dialect field to the query. - **dialect** - dialect version to execute the query under )r)rrs r rz Query.dialect&s    r"r3)NNNN)NNT)__name__ __module__ __qualname____doc__r!rr'r+r1r6rBrGrIrLrNrPrTrSrlrnrprrrtrvrxrzr~rintrr"r rrs:"  E @$ /b     swr"rceZdZdZy)rec.||gt|z|_yr3)rrA)rkeywordr/rAs r r!zFilter.__init__1se$tDz1 r"Nrrrr!rr"r rere0s2r"receZdZdZdZddZy) NumericFilterz+infz-infcX|s|nd||s|nd|g}tj|d|g|y)N(FILTERrer!)rr/minvalmaxval minExclusive maxExclusiverAs r r!zNumericFilter.__init__9s:&FaxL&FaxL  h55r"N)FF)rrrINFNEG_INFr!rr"r rr5s CG6r"rc&eZdZdZdZdZdZefdZy) GeoFiltermkmftmic :tj|d|||||y)N GEOFILTERr)rr/lonlatradiusunits r r!zGeoFilter.__init__Hsk5#sFDIr"N)rrrMETERS KILOMETERSFEETMILESr!rr"r rrBs FJ D E5?Jr"rceZdZddZy)rgc,||r dg|_ydg|_y)NASCDESC)rAr|s r r!zSortbyField.__init__MsSE5 f5 r"Nrrrr"r rgrgLs6r"rgN)rrerrrgrr"r rs@ll^ 22 6F 6JJ66r"