0

我不太确定从哪里开始,所以真的要寻找一些指针或关键字来搜索。

假设我们有一个文件:

myHugeFile = open('someGiganticFile.txt')

并且从上到下搜索需要 10 分钟,没有任何索引。

for line in myHugeFile:
    if 'keyword' in line:
        send_line_to_web_user(line)

我想将此搜索集成到 django 页面中,但页面加载可能会因大文件而超时。用户将能够进行搜索'keyword',然后页面上的列表会在他们弹出时实时填充到他们面前,其中包含搜索结果。

有什么东西可以做到这一点吗?这将节省我为每个用户会话存在的结果缓冲区制作一些超级复杂的轮询系统。也许是不同的框架或库?冒险进入 node.js 领域?除了“实时轮询 django”等等之外,我对要搜索的内容有点不知所措。

4

3 回答 3

1

这是考虑转向 node.js 或其他异步框架的理想案例。如果您想坚持使用 Python, Tornado是一个不错的选择。

另外,我记得一个朋友使用whoosh作为实习项目的搜索引擎。他对它相当满意,所以我可以推荐它。

于 2013-11-14T02:43:53.600 回答
0

You could get an initial request to kick off a thread to do the work of reading the file to a shared resource and return a 200 response immediately to the browser.

A Ajax poller on the client side can request periodically on a loop and pick up and display any new results in the resource until the file is read.

This is a quick and dirty approach and as @slider says an asynchronous framework is a better idea for long polling if your app relies on it a lot.

于 2013-11-14T10:25:33.967 回答
0

您可能想要预处理文件。假设在每个单词映射到它包含的行集时制作一个缓存,这样您就可以获取它并返回它们。

于 2013-11-14T00:57:24.147 回答