-2
import os, os.path
from whoosh.index import create_in
from whoosh.fields import *
schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT)

if not os.path.exists("indexdir"):
    os.mkdir("indexdir")


ix = create_in("indexdir", schema)
writer = ix.writer()
writer.add_document(title=u"First document", path=u"/a",
                 content=u"This is the first document we've added!")
writer.add_document(title=u"Second document", path=u"/b",
                 content=u"The second one is even more interesting!")
writer.commit()
from whoosh.qparser import QueryParser

with ix.searcher() as searcher:
    query = QueryParser("content", ix.schema).parse("first")
    results = searcher.search(query)
    results[0]

看起来不错,但没有显示任何结果。

4

2 回答 2

1

我想你希望你的最后一行是:

print results[0]

于 2013-10-02T17:23:27.943 回答
0

Python 要求您使用以下命令显式打印输出print

print results[0]

但请注意,上述代码适用于 Python 2.x。在 Python 3.x 中,print被转换为函数

print(results[0])
于 2013-10-02T17:22:01.030 回答