def _parse_macro_content(self, content, req): args, kwargs = parse_args(content, strict=False) assert not args and not ('status' in kwargs or 'format' in kwargs), \ "Invalid input!" # hack the `format` kwarg in order to display all-tickets stats when # no kwargs are supplied kwargs['format'] = 'count' # special case for values equal to 'self': replace with current ticket # number, if available for key in kwargs.keys(): if kwargs[key] == 'self': current_ticket = self._this_ticket(req) if current_ticket: kwargs[key] = current_ticket try: spkw = kwargs.pop('stats_provider') xtnpt = ExtensionPoint(ITicketGroupStatsProvider) found = False for impl in xtnpt.extensions(self): if impl.__class__.__name__ == spkw: found = True stats_provider = impl break if not found: raise TracError("Supplied stats provider does not exist!") except KeyError: # if the `stats_provider` keyword argument is not provided, # propagate the stats provider defined in the config file stats_provider = self._sp return stats_provider, kwargs
class DefaultQueryParser(Component): implements(IQueryParser) #todo: make field boost configurable e.g. read from config setting. #This is prototype implementation ,the fields boost must be tuned later field_boosts = dict( id = 6, name = 6, type = 2, summary = 5, author = 3, milestone = 2, keywords = 2, component = 2, status = 2, content = 1, changes = 1, message = 1, query_suggestion_basket = 0, relations = 1, ) meta_keyword_parsers = ExtensionPoint(IMetaKeywordParser) def parse(self, query_string, context=None): parser = self._create_parser(context) query_string = query_string.strip() if query_string == "" or query_string == "*" or query_string == "*:*": return query.Every() query_string = unicode(query_string) parsed_query = parser.parse(query_string) parsed_query.original_query_string = query_string return parsed_query def parse_filters(self, filters): """Parse query filters""" if not filters: return None parsed_filters = [self._parse_filter(filter) for filter in filters] return query.And(parsed_filters).normalize() def _parse_filter(self, filter): return self.parse(unicode(filter)) def _create_parser(self, context): parser = MultifieldParser( self.field_boosts.keys(), WhooshBackend.SCHEMA, fieldboosts=self.field_boosts ) parser.add_plugin( MetaKeywordPlugin(meta_keyword_parsers=self.meta_keyword_parsers, context=context) ) return parser
class DocTypeMetaKeywordParser(Component): implements(IMetaKeywordParser) search_participants = ExtensionPoint(ISearchParticipant) def match(self, text, context): # pylint: disable=unused-argument documents = [p.get_participant_type() for p in self.search_participants] if text in documents: return u'type:%s' % text
def _parse_macro_content(self, content, req): args, kwargs = parse_args(content, strict=False) kwargs['max'] = 0 kwargs['order'] = 'id' kwargs['col'] = 'id' # special case for values equal to 'self': replace with current ticket # number, if available preview = False for key in kwargs.keys(): if kwargs[key] == 'self': current_ticket = self._this_ticket(req) if current_ticket: kwargs[key] = current_ticket else: # id=0 basically causes a dummy preview of the meter # to be rendered preview = True kwargs = {'id': 0} break try: spkw = kwargs.pop('stats_provider') xtnpt = ExtensionPoint(ITicketGroupStatsProvider) found = False for impl in xtnpt.extensions(self): if impl.__class__.__name__ == spkw: found = True stats_provider = impl break if not found: raise TracError("Supplied stats provider does not exist!") except KeyError: # if the `stats_provider` keyword argument is not provided, # propagate the stats provider defined in the config file stats_provider = self._sp return stats_provider, kwargs, preview