本文整理汇总了Python中haystack.utils.Highlighter.find_highlightable_words方法的典型用法代码示例。如果您正苦于以下问题:Python Highlighter.find_highlightable_words方法的具体用法?Python Highlighter.find_highlightable_words怎么用?Python Highlighter.find_highlightable_words使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类haystack.utils.Highlighter
的用法示例。
在下文中一共展示了Highlighter.find_highlightable_words方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_find_highlightable_words
# 需要导入模块: from haystack.utils import Highlighter [as 别名]
# 或者: from haystack.utils.Highlighter import find_highlightable_words [as 别名]
def test_find_highlightable_words(self):
highlighter = Highlighter('this test')
highlighter.text_block = self.document_1
self.assertEqual(highlighter.find_highlightable_words(), {'this': [0, 53, 79], 'test': [10, 68]})
# We don't stem for now.
highlighter = Highlighter('highlight tests')
highlighter.text_block = self.document_1
self.assertEqual(highlighter.find_highlightable_words(), {'highlight': [22], 'tests': []})
# Ignore negated bits.
highlighter = Highlighter('highlight -test')
highlighter.text_block = self.document_1
self.assertEqual(highlighter.find_highlightable_words(), {'highlight': [22]})
示例2: execute_highlighter
# 需要导入模块: from haystack.utils import Highlighter [as 别名]
# 或者: from haystack.utils.Highlighter import find_highlightable_words [as 别名]
def execute_highlighter(query, text_key, results):
highlight = Highlighter(query)
for result in results:
highlight.text_block = result.get_additional_fields().get(text_key, "")
highlight_locations = highlight.find_highlightable_words()
result.highlight_locations = []
for q, locations in highlight_locations.iteritems():
result.highlight_locations.extend([[location, location + len(q)] for location in locations])