"目录不存在"在Python上设置Whoosh时出错

时间:2014-06-04 14:07:38

标签: python whoosh

我有一系列文档,我想为我的网站创建一个搜索引擎。这些文件是静态的,在另一个问题上,他们建议我飞快移动。但是,我甚至无法通过文档帮助代码进行设置。

   from whoosh.fields import *
   from whoosh.index import create_in

   # Create an index
   schema = Schema(content=TEXT)

   ix = create_in("indexdir", schema)

   writer = ix.writer()

   writer.add_document(content=u"This is the first document we've added!")
   writer.add_document(content=u"The second one is even more interesting!")

   writer.commit()

这是错误:

ix = create_in("indexdir", schema)
  File "build\bdist.win-amd64\egg\whoosh\index.py", line 90, in create_in
    storage = FileStorage(dirname)
  File "build\bdist.win-amd64\egg\whoosh\filedb\filestore.py", line 70, in __init__
    raise IOError("Directory %s does not exist" % path)
IOError: Directory indexdir does not exist

我还需要在indexdir上添加其他内容吗?

1 个答案:

答案 0 :(得分:0)

首先你必须使用例如os.mkdir(“indexdir”)

创建一个目录