本文整理汇总了Python中whoosh.filedb.filestore.RamStorage.optimize方法的典型用法代码示例。如果您正苦于以下问题:Python RamStorage.optimize方法的具体用法?Python RamStorage.optimize怎么用?Python RamStorage.optimize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类whoosh.filedb.filestore.RamStorage
的用法示例。
在下文中一共展示了RamStorage.optimize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_multisegment
# 需要导入模块: from whoosh.filedb.filestore import RamStorage [as 别名]
# 或者: from whoosh.filedb.filestore.RamStorage import optimize [as 别名]
def test_multisegment():
schema = fields.Schema(text=fields.TEXT(spelling=True))
ix = RamStorage().create_index(schema)
domain = u("special specious spectacular spongy spring specials").split()
for word in domain:
w = ix.writer()
w.add_document(text=word)
w.commit(merge=False)
with ix.reader() as r:
assert not r.is_atomic()
assert r.has_word_graph("text")
words = list(r.word_graph("text").flatten_strings())
assert words == sorted(domain)
corr = r.corrector("text")
assert corr.suggest("specail", maxdist=2) == ["special", "specials"]
ix.optimize()
with ix.reader() as r:
assert r.is_atomic()
fieldobj = schema["text"]
assert [fieldobj.from_bytes(t) for t in r.lexicon("text")] == sorted(domain)
assert r.has_word_graph("text")
words = list(r.word_graph("text").flatten_strings())
assert words == sorted(domain)
corr = r.corrector("text")
assert corr.suggest("specail", maxdist=2) == ["special", "specials"]
示例2: test_multisegment
# 需要导入模块: from whoosh.filedb.filestore import RamStorage [as 别名]
# 或者: from whoosh.filedb.filestore.RamStorage import optimize [as 别名]
def test_multisegment():
schema = fields.Schema(text=fields.TEXT(spelling=True))
ix = RamStorage().create_index(schema)
domain = u("special specious spectacular spongy spring specials").split()
for word in domain:
w = ix.writer()
w.add_document(text=word)
w.commit(merge=False)
with ix.reader() as r:
assert not r.is_atomic()
words = list(dawg.flatten(r.word_graph("text")))
assert_equal(words, sorted(domain))
corr = r.corrector("text")
assert_equal(corr.suggest("specail", maxdist=2), ["special", "specials"])
ix.optimize()
with ix.reader() as r:
assert r.is_atomic()
assert_equal(list(r.lexicon("text")), sorted(domain))
assert r.has_word_graph("text")
words = list(dawg.flatten(r.word_graph("text")))
assert_equal(words, sorted(domain))
corr = r.corrector("text")
assert_equal(corr.suggest("specail", maxdist=2), ["special", "specials"])
示例3: test_doc_count
# 需要导入模块: from whoosh.filedb.filestore import RamStorage [as 别名]
# 或者: from whoosh.filedb.filestore.RamStorage import optimize [as 别名]
def test_doc_count():
schema = fields.Schema(id=fields.NUMERIC)
ix = RamStorage().create_index(schema)
w = ix.writer()
for i in xrange(10):
w.add_document(id=i)
w.commit()
r = ix.reader()
assert_equal(r.doc_count(), 10)
assert_equal(r.doc_count_all(), 10)
w = ix.writer()
w.delete_document(2)
w.delete_document(4)
w.delete_document(6)
w.delete_document(8)
w.commit()
r = ix.reader()
assert_equal(r.doc_count(), 6)
assert_equal(r.doc_count_all(), 10)
w = ix.writer()
for i in xrange(10, 15):
w.add_document(id=i)
w.commit(merge=False)
r = ix.reader()
assert_equal(r.doc_count(), 11)
assert_equal(r.doc_count_all(), 15)
w = ix.writer()
w.delete_document(10)
w.delete_document(12)
w.delete_document(14)
w.commit(merge=False)
r = ix.reader()
assert_equal(r.doc_count(), 8)
assert_equal(r.doc_count_all(), 15)
ix.optimize()
r = ix.reader()
assert_equal(r.doc_count(), 8)
assert_equal(r.doc_count_all(), 8)
示例4: test_doc_count
# 需要导入模块: from whoosh.filedb.filestore import RamStorage [as 别名]
# 或者: from whoosh.filedb.filestore.RamStorage import optimize [as 别名]
def test_doc_count():
schema = fields.Schema(id=fields.NUMERIC)
ix = RamStorage().create_index(schema)
with ix.writer() as w:
for i in xrange(10):
w.add_document(id=i)
r = ix.reader()
assert r.doc_count() == 10
assert r.doc_count_all() == 10
w = ix.writer()
w.delete_document(2)
w.delete_document(4)
w.delete_document(6)
w.delete_document(8)
w.commit()
r = ix.reader()
assert r.doc_count() == 6
assert r.doc_count_all() == 10
w = ix.writer()
for i in xrange(10, 15):
w.add_document(id=i)
w.commit(merge=False)
r = ix.reader()
assert r.doc_count() == 11
assert r.doc_count_all() == 15
w = ix.writer()
w.delete_document(10)
w.delete_document(12)
w.delete_document(14)
w.commit(merge=False)
r = ix.reader()
assert r.doc_count() == 8
assert r.doc_count_all() == 15
ix.optimize()
r = ix.reader()
assert r.doc_count() == 8
assert r.doc_count_all() == 8