def do(text, terms): q = qp.parse(text) tks = [tk for tk in q.all_tokens() if tk.text in terms] for tk in tks: if tk.startchar is None or tk.endchar is None: assert False, tk fragment = highlight.Fragment(text, tks) return hf.format_fragment(fragment)
def format_string(self, formatter): if not (self.original_string and self.tokens): raise Exception("The original query isn't available") if isinstance(formatter, type): formatter = formatter() fragment = highlight.Fragment(self.original_string, self.tokens) return formatter.format_fragment(fragment, replace=True)
def format_string(self, formatter): """ Highlights the corrected words in the original query string using the given :class:`~whoosh.highlight.Formatter`. :param formatter: A :class:`whoosh.highlight.Formatter` instance. :return: the output of the formatter (usually a string). """ if not self.original_string: return '' if isinstance(formatter, type): formatter = formatter() fragment = highlight.Fragment(self.original_string, self.tokens) return formatter.format_fragment(fragment, replace=True)