o k`< @sFddlZddlTGdddeZddZddZd gd d fd d ZdS)N)*c@s eZdZdZddZddZdS) ISearchSourcezRExtension point interface for adding search sources to the search system. cCdS)aOReturn a list of filters that this search source supports. Each filter must be a `(name, label[, default])` tuple, where `name` is the internal name, `label` is a human-readable name for display and `default` is an optional boolean for determining whether this filter is searchable by default. N)reqrr1/usr/lib/python3/dist-packages/trac/search/api.pyget_search_filtersz ISearchSource.get_search_filterscCr)a[Return a list of search results matching each search term in `terms`. The `filters` parameters is a list of the enabled filters, each item being the name of the tuples returned by `get_search_events`. The events returned by this function must be tuples of the form `(href, title, date, author, excerpt).` Nr)rtermsfiltersrrrget_search_results!r z ISearchSource.get_search_resultsN)__name__ __module__ __qualname____doc__rr rrrrrs rcs|r|sJfdd|D}d|}dd|gt|d}g}|D]}|d|dgt|q&|t|fS)zConvert a search query into an SQL WHERE clause and corresponding parameters. The result is returned as an `(sql, params)` tuple. csg|] }d|fqS)z%s %s)like).0idbrr 4sz!search_to_sql..z OR (z) AND ()%)joinlenextend like_escapetuple)rcolumnsr likescsqlargstrrr search_to_sql,s  $ r%cCsdd|DS)z4Convert search query terms into regular expressions.cSs&g|]}tt|tjtjBqSr)recompileescape IGNORECASEUNICODE)rtermrrrr?sz%search_to_regexps..r)r rrrsearch_to_regexps=sr,<c Cs|sd}|}d}|D]}||}d|kr|ks$n|dkr&|}q d}||krMdD]} || |||d} | dkrF| d7} nq/||} | }|dkrSd}||||} ||krcd| } |t||kro| d7} | S)Nr-r).:;=z... z ...)lowerfindr) textkeywordsmaxlenfuzztext_lowbegkr excerpt_begsepebmsgrrrshorten_resultCs6rC)r& trac.core Interfacerr%r,rCrrrrs