本文整理匯總了Python中whoosh.highlight.UppercaseFormatter方法的典型用法代碼示例。如果您正苦於以下問題:Python highlight.UppercaseFormatter方法的具體用法?Python highlight.UppercaseFormatter怎麽用?Python highlight.UppercaseFormatter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類whoosh.highlight
的用法示例。
在下文中一共展示了highlight.UppercaseFormatter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_workflow_easy
# 需要導入模塊: from whoosh import highlight [as 別名]
# 或者: from whoosh.highlight import UppercaseFormatter [as 別名]
def test_workflow_easy():
schema = fields.Schema(id=fields.ID(stored=True),
title=fields.TEXT(stored=True))
ix = RamStorage().create_index(schema)
w = ix.writer()
w.add_document(id=u("1"), title=u("The man who wasn't there"))
w.add_document(id=u("2"), title=u("The dog who barked at midnight"))
w.add_document(id=u("3"), title=u("The invisible man"))
w.add_document(id=u("4"), title=u("The girl with the dragon tattoo"))
w.add_document(id=u("5"), title=u("The woman who disappeared"))
w.commit()
with ix.searcher() as s:
# Parse the user query
parser = qparser.QueryParser("title", schema=ix.schema)
q = parser.parse(u("man"))
r = s.search(q, terms=True)
assert len(r) == 2
r.fragmenter = highlight.WholeFragmenter()
r.formatter = highlight.UppercaseFormatter()
outputs = [hit.highlights("title") for hit in r]
assert outputs == ["The invisible MAN", "The MAN who wasn't there"]
示例2: test_pinpoint
# 需要導入模塊: from whoosh import highlight [as 別名]
# 或者: from whoosh.highlight import UppercaseFormatter [as 別名]
def test_pinpoint():
domain = u("alfa bravo charlie delta echo foxtrot golf hotel india juliet "
"kilo lima mike november oskar papa quebec romeo sierra tango")
schema = fields.Schema(text=fields.TEXT(stored=True, chars=True))
ix = RamStorage().create_index(schema)
w = ix.writer()
w.add_document(text=domain)
w.commit()
assert ix.schema["text"].supports("characters")
with ix.searcher() as s:
r = s.search(query.Term("text", "juliet"), terms=True)
hit = r[0]
hi = highlight.Highlighter()
hi.formatter = highlight.UppercaseFormatter()
assert not hi.can_load_chars(r, "text")
assert hi.highlight_hit(hit, "text") == "golf hotel india JULIET kilo lima mike november"
hi.fragmenter = highlight.PinpointFragmenter()
assert hi.can_load_chars(r, "text")
assert hi.highlight_hit(hit, "text") == "ot golf hotel india JULIET kilo lima mike nove"
hi.fragmenter.autotrim = True
assert hi.highlight_hit(hit, "text") == "golf hotel india JULIET kilo lima mike"
示例3: test_highlight_ngrams
# 需要導入模塊: from whoosh import highlight [as 別名]
# 或者: from whoosh.highlight import UppercaseFormatter [as 別名]
def test_highlight_ngrams():
schema = fields.Schema(text=fields.NGRAMWORDS(stored=True))
ix = RamStorage().create_index(schema)
with ix.writer() as w:
w.add_document(text=u("Multiplication and subtraction are good"))
with ix.searcher() as s:
qp = qparser.QueryParser("text", ix.schema)
q = qp.parse(u("multiplication"))
r = s.search(q)
assert r.scored_length() == 1
r.fragmenter = highlight.SentenceFragmenter()
r.formatter = highlight.UppercaseFormatter()
snippet = r[0].highlights("text")
assert snippet == "MULTIPLICATIon and subtracTION are good"
示例4: test_whole_noterms
# 需要導入模塊: from whoosh import highlight [as 別名]
# 或者: from whoosh.highlight import UppercaseFormatter [as 別名]
def test_whole_noterms():
schema = fields.Schema(text=fields.TEXT(stored=True), tag=fields.KEYWORD)
ix = RamStorage().create_index(schema)
with ix.writer() as w:
w.add_document(text=u("alfa bravo charlie delta echo foxtrot golf"),
tag=u("foo"))
with ix.searcher() as s:
r = s.search(query.Term("text", u("delta")))
assert len(r) == 1
r.fragmenter = highlight.WholeFragmenter()
r.formatter = highlight.UppercaseFormatter()
hi = r[0].highlights("text")
assert hi == u("alfa bravo charlie DELTA echo foxtrot golf")
r = s.search(query.Term("tag", u("foo")))
assert len(r) == 1
r.fragmenter = highlight.WholeFragmenter()
r.formatter = highlight.UppercaseFormatter()
hi = r[0].highlights("text")
assert hi == u("")
hi = r[0].highlights("text", minscore=0)
assert hi == u("alfa bravo charlie delta echo foxtrot golf")
示例5: test_snippets
# 需要導入模塊: from whoosh import highlight [as 別名]
# 或者: from whoosh.highlight import UppercaseFormatter [as 別名]
def test_snippets():
ana = analysis.StemmingAnalyzer()
schema = fields.Schema(text=fields.TEXT(stored=True, analyzer=ana))
ix = RamStorage().create_index(schema)
w = ix.writer()
w.add_document(text=u("Lay out the rough animation by creating the important poses where they occur on the timeline."))
w.add_document(text=u("Set key frames on everything that's key-able. This is for control and predictability: you don't want to accidentally leave something un-keyed. This is also much faster than selecting the parameters to key."))
w.add_document(text=u("Use constant (straight) or sometimes linear transitions between keyframes in the channel editor. This makes the character jump between poses."))
w.add_document(text=u("Keying everything gives quick, immediate results. But it can become difficult to tweak the animation later, especially for complex characters."))
w.add_document(text=u("Copy the current pose to create the next one: pose the character, key everything, then copy the keyframe in the playbar to another frame, and key everything at that frame."))
w.commit()
target = ["Set KEY frames on everything that's KEY-able",
"Copy the current pose to create the next one: pose the character, KEY everything, then copy the keyframe in the playbar to another frame, and KEY everything at that frame",
"KEYING everything gives quick, immediate results"]
with ix.searcher() as s:
qp = qparser.QueryParser("text", ix.schema)
q = qp.parse(u("key"))
r = s.search(q, terms=True)
r.fragmenter = highlight.SentenceFragmenter()
r.formatter = highlight.UppercaseFormatter()
assert sorted([hit.highlights("text", top=1) for hit in r]) == sorted(target)
示例6: test_paged_highlights
# 需要導入模塊: from whoosh import highlight [as 別名]
# 或者: from whoosh.highlight import UppercaseFormatter [as 別名]
def test_paged_highlights():
schema = fields.Schema(text=fields.TEXT(stored=True))
ix = RamStorage().create_index(schema)
with ix.writer() as w:
w.add_document(text=u("alfa bravo charlie delta echo foxtrot"))
w.add_document(text=u("bravo charlie delta echo foxtrot golf"))
w.add_document(text=u("charlie delta echo foxtrot golf hotel"))
w.add_document(text=u("delta echo foxtrot golf hotel india"))
w.add_document(text=u("echo foxtrot golf hotel india juliet"))
w.add_document(text=u("foxtrot golf hotel india juliet kilo"))
with ix.searcher() as s:
q = query.Term("text", u("alfa"))
page = s.search_page(q, 1, pagelen=3)
page.results.fragmenter = highlight.WholeFragmenter()
page.results.formatter = highlight.UppercaseFormatter()
hi = page[0].highlights("text")
assert hi == u("ALFA bravo charlie delta echo foxtrot")
示例7: test_null_fragment
# 需要導入模塊: from whoosh import highlight [as 別名]
# 或者: from whoosh.highlight import UppercaseFormatter [as 別名]
def test_null_fragment():
terms = frozenset(("bravo", "india"))
sa = analysis.StandardAnalyzer()
nf = highlight.WholeFragmenter()
uc = highlight.UppercaseFormatter()
htext = highlight.highlight(_doc, terms, sa, nf, uc)
assert htext == "alfa BRAVO charlie delta echo foxtrot golf hotel INDIA juliet kilo lima"
示例8: test_sentence_fragment
# 需要導入模塊: from whoosh import highlight [as 別名]
# 或者: from whoosh.highlight import UppercaseFormatter [as 別名]
def test_sentence_fragment():
text = u("This is the first sentence. This one doesn't have the word. " +
"This sentence is the second. Third sentence here.")
terms = ("sentence",)
sa = analysis.StandardAnalyzer(stoplist=None)
sf = highlight.SentenceFragmenter()
uc = highlight.UppercaseFormatter()
htext = highlight.highlight(text, terms, sa, sf, uc)
assert htext == "This is the first SENTENCE...This SENTENCE is the second...Third SENTENCE here"
示例9: test_context_fragment
# 需要導入模塊: from whoosh import highlight [as 別名]
# 或者: from whoosh.highlight import UppercaseFormatter [as 別名]
def test_context_fragment():
terms = frozenset(("bravo", "india"))
sa = analysis.StandardAnalyzer()
cf = highlight.ContextFragmenter(surround=6)
uc = highlight.UppercaseFormatter()
htext = highlight.highlight(_doc, terms, sa, cf, uc)
assert htext == "alfa BRAVO charlie...hotel INDIA juliet"
示例10: test_context_at_start
# 需要導入模塊: from whoosh import highlight [as 別名]
# 或者: from whoosh.highlight import UppercaseFormatter [as 別名]
def test_context_at_start():
terms = frozenset(["alfa"])
sa = analysis.StandardAnalyzer()
cf = highlight.ContextFragmenter(surround=15)
uc = highlight.UppercaseFormatter()
htext = highlight.highlight(_doc, terms, sa, cf, uc)
assert htext == "ALFA bravo charlie delta echo foxtrot"
示例11: test_highlight_wildcards
# 需要導入模塊: from whoosh import highlight [as 別名]
# 或者: from whoosh.highlight import UppercaseFormatter [as 別名]
def test_highlight_wildcards():
schema = fields.Schema(text=fields.TEXT(stored=True))
ix = RamStorage().create_index(schema)
with ix.writer() as w:
w.add_document(text=u("alfa bravo charlie delta cookie echo"))
with ix.searcher() as s:
qp = qparser.QueryParser("text", ix.schema)
q = qp.parse(u("c*"))
r = s.search(q)
assert r.scored_length() == 1
r.formatter = highlight.UppercaseFormatter()
hit = r[0]
assert hit.highlights("text") == "alfa bravo CHARLIE delta COOKIE echo"
示例12: test_issue324
# 需要導入模塊: from whoosh import highlight [as 別名]
# 或者: from whoosh.highlight import UppercaseFormatter [as 別名]
def test_issue324():
sa = analysis.StemmingAnalyzer()
result = highlight.highlight(u("Indexed!\n1"), [u("index")], sa,
fragmenter=highlight.ContextFragmenter(),
formatter=highlight.UppercaseFormatter())
assert result == "INDEXED!\n1"
示例13: test_highlight_setters
# 需要導入模塊: from whoosh import highlight [as 別名]
# 或者: from whoosh.highlight import UppercaseFormatter [as 別名]
def test_highlight_setters():
schema = fields.Schema(text=fields.TEXT)
ix = RamStorage().create_index(schema)
w = ix.writer()
w.add_document(text=u("Hello"))
w.commit()
r = ix.searcher().search(query.Term("text", "hello"))
hl = highlight.Highlighter()
ucf = highlight.UppercaseFormatter()
r.highlighter = hl
r.formatter = ucf
assert hl.formatter is ucf
示例14: find
# 需要導入模塊: from whoosh import highlight [as 別名]
# 或者: from whoosh.highlight import UppercaseFormatter [as 別名]
def find(criteria, reindex=False):
"""
Search for Azure CLI commands
:param str criteria: Query text to search for.
:param bool reindex: Clear the current index and reindex the command modules.
:return:
:rtype: None
"""
from whoosh.qparser import MultifieldParser
if reindex:
_create_index()
try:
ix = _get_index()
except ValueError:
# got a pickle error because the index was written by a different python version
# recreate the index and proceed
_create_index()
ix = _get_index()
qp = MultifieldParser(
['cmd_name', 'short_summary', 'long_summary', 'examples'],
schema=_get_schema()
)
if 'OR' in criteria or 'AND' in criteria:
# looks more advanced, let's trust them to make a great query
q = qp.parse(" ".join(criteria))
else:
# let's help out with some OR's to provide a less restrictive search
expanded_query = " OR ".join(criteria) + " OR '{}'".format(criteria)
q = qp.parse(expanded_query)
with ix.searcher() as searcher:
from whoosh.highlight import UppercaseFormatter, ContextFragmenter
results = searcher.search(q)
results.fragmenter = ContextFragmenter(maxchars=300, surround=200)
results.formatter = UppercaseFormatter()
for hit in results:
_print_hit(hit)
示例15: search
# 需要導入模塊: from whoosh import highlight [as 別名]
# 或者: from whoosh.highlight import UppercaseFormatter [as 別名]
def search(self, term):
results = []
suggestions = [term]+(self.corrector.suggest(term, limit=5))
for t in suggestions:
query = self.parser.parse(t)
query_res = self.searcher.search(query, limit=100)
query_res.fragmenter.maxchars = 300
query_res.fragmenter.surround = 100
query_res.formatter = UppercaseFormatter()
results.append((t, query_res))
return results