【发布时间】:2010-04-16 23:30:48
【问题描述】:
我有一个非常大的 CSV 文件,其中仅包含两个字段(id、url)。我想用 python 对 url 字段做一些索引,我知道有一些工具,比如 Whoosh 或 Pylucene。但我无法让这些例子起作用。有人可以帮我解决这个问题吗?
【问题讨论】:
-
索引是什么意思?
标签: python indexing full-text-indexing whoosh
我有一个非常大的 CSV 文件,其中仅包含两个字段(id、url)。我想用 python 对 url 字段做一些索引,我知道有一些工具,比如 Whoosh 或 Pylucene。但我无法让这些例子起作用。有人可以帮我解决这个问题吗?
【问题讨论】:
标签: python indexing full-text-indexing whoosh
PyLucene 非常易于使用,但由于您尚未发布示例,我不确定您面临什么问题。
或者,当您只有 key:value 类型的数据时,可能比 Pylucene 更好的是 DB,例如 Berkeley DB(python bindings pybsddb)。它会像 python 字典一样工作,应该和 lucene 一样快,你可以试试。
【讨论】:
file.csv 内容:
a,b
d,f
g,h
将所有内容加载到一个巨大的字典中的 Python 脚本:
#Python 3.1
giant_dict = {id.strip(): url.strip() for id, url in (line.split(',') for line in open('file.csv', 'r'))}
print(giant_dict)
{'a': 'b', 'd': 'f', 'g': 'h'}
【讨论】: