本文整理匯總了Python中whoosh.highlight.HtmlFormatter方法的典型用法代碼示例。如果您正苦於以下問題:Python highlight.HtmlFormatter方法的具體用法?Python highlight.HtmlFormatter怎麽用?Python highlight.HtmlFormatter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類whoosh.highlight
的用法示例。
在下文中一共展示了highlight.HtmlFormatter方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_html_format
# 需要導入模塊: from whoosh import highlight [as 別名]
# 或者: from whoosh.highlight import HtmlFormatter [as 別名]
def test_html_format():
terms = frozenset(("bravo", "india"))
sa = analysis.StandardAnalyzer()
cf = highlight.ContextFragmenter(surround=6)
hf = highlight.HtmlFormatter()
htext = highlight.highlight(_doc, terms, sa, cf, hf)
assert htext == 'alfa <strong class="match term0">bravo</strong> charlie...hotel <strong class="match term1">india</strong> juliet'
示例2: test_html_escape
# 需要導入模塊: from whoosh import highlight [as 別名]
# 或者: from whoosh.highlight import HtmlFormatter [as 別名]
def test_html_escape():
terms = frozenset(["bravo"])
sa = analysis.StandardAnalyzer()
wf = highlight.WholeFragmenter()
hf = highlight.HtmlFormatter()
htext = highlight.highlight(u('alfa <bravo "charlie"> delta'), terms, sa,
wf, hf)
assert htext == 'alfa <<strong class="match term0">bravo</strong> "charlie"> delta'
示例3: test_maxclasses
# 需要導入模塊: from whoosh import highlight [as 別名]
# 或者: from whoosh.highlight import HtmlFormatter [as 別名]
def test_maxclasses():
terms = frozenset(("alfa", "bravo", "charlie", "delta", "echo"))
sa = analysis.StandardAnalyzer()
cf = highlight.ContextFragmenter(surround=6)
hf = highlight.HtmlFormatter(tagname="b", termclass="t", maxclasses=2)
htext = highlight.highlight(_doc, terms, sa, cf, hf)
assert htext == '<b class="match t0">alfa</b> <b class="match t1">bravo</b> <b class="match t0">charlie</b>...<b class="match t1">delta</b> <b class="match t0">echo</b> foxtrot'
示例4: test_query_highlight
# 需要導入模塊: from whoosh import highlight [as 別名]
# 或者: from whoosh.highlight import HtmlFormatter [as 別名]
def test_query_highlight():
qp = QueryParser("a", None)
hf = highlight.HtmlFormatter()
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)
assert do("a b c d", ["b"]) == 'a <strong class="match term0">b</strong> c d'
assert do('a (x:b OR y:"c d") e', ("b", "c")) == 'a (x:<strong class="match term0">b</strong> OR y:"<strong class="match term1">c</strong> d") e'
示例5: test_correct_query
# 需要導入模塊: from whoosh import highlight [as 別名]
# 或者: from whoosh.highlight import HtmlFormatter [as 別名]
def test_correct_query():
schema = fields.Schema(a=fields.TEXT(spelling=True), b=fields.TEXT)
ix = RamStorage().create_index(schema)
w = ix.writer()
w.add_document(a=u("alfa bravo charlie delta"))
w.add_document(a=u("delta echo foxtrot golf"))
w.add_document(a=u("golf hotel india juliet"))
w.add_document(a=u("juliet kilo lima mike"))
w.commit()
s = ix.searcher()
qp = QueryParser("a", ix.schema)
qtext = u('alpha ("brovo november" OR b:dolta) detail')
q = qp.parse(qtext, ix.schema)
c = s.correct_query(q, qtext)
assert c.query.__unicode__() == '(a:alfa AND (a:"bravo november" OR b:dolta) AND a:detail)'
assert c.string == 'alfa ("bravo november" OR b:dolta) detail'
qtext = u('alpha b:("brovo november" a:delta) detail')
q = qp.parse(qtext, ix.schema)
c = s.correct_query(q, qtext)
assert c.query.__unicode__() == '(a:alfa AND b:"brovo november" AND a:delta AND a:detail)'
assert c.string == 'alfa b:("brovo november" a:delta) detail'
hf = highlight.HtmlFormatter(classname="c")
assert c.format_string(hf) == '<strong class="c term0">alfa</strong> b:("brovo november" a:delta) detail'
示例6: highlight
# 需要導入模塊: from whoosh import highlight [as 別名]
# 或者: from whoosh.highlight import HtmlFormatter [as 別名]
def highlight(self, text, words):
fragmenter = ContextFragmenter()
formatter = HtmlFormatter()
analyzer = self.project_schema['text'].analyzer
return highlight(text, words, analyzer, fragmenter, formatter, top=1)