highlight(self,
text,
query,
hl,
strip_tags=False)
| source code
|
Add highlights (string prefix/postfix) to a string.
text is the source to highlight.
query is either a Xapian query object or a list of (unstemmed) term strings.
hl is a pair of highlight strings, e.g. ('<i>', '</i>')
strip_tags strips HTML markout iff True
>>> hl = Highlighter()
>>> qp = xapian.QueryParser()
>>> q = qp.parse_query('cat dog')
>>> tags = ('[[', ']]')
>>> hl.highlight('The cat went Dogging; but was <i>dog tired</i>.', q, tags)
'The [[cat]] went [[Dogging]]; but was <i>[[dog]] tired</i>.'
|