【发布时间】:2018-07-06 14:06:35
【问题描述】:
我想在文本上应用 Whoosh 搜索。现在这仅适用于标记的完全匹配(空格分隔)。我也想在一个令牌内匹配(例如:在一个令牌“added”中匹配add)。我知道词干和变体,但这不是我要找的。感谢您的帮助!
from whoosh.index import create_in
from whoosh.fields import Schema, TEXT, KEYWORD, ID, STORED
from whoosh.qparser import QueryParser
schema = Schema(title=TEXT(), content=TEXT())
indexpath = (r"C:\Users\rettenma\.jupyter\JupyterWork"+
r"folder\Python_Repository\bin\index")
ix = create_in(indexpath, schema)
writer = ix.writer()
writer.add_document(title=u"First document",
content=u"This is the first document we've added!")
writer.commit()
with ix.searcher() as searcher:
query = QueryParser("content", ix.schema).parse("add")
results = searcher.search(query, terms=True)
print(results[0])
由于结果为空,这将引发错误。
【问题讨论】:
标签: python search match token whoosh