开发者

Instant search with Whoosh - Index and search a MySQL table using Whoosh outputing JSON results

I want to index a MySQL table using Whoosh and create an instant search page, so I need the results of the Whoosh search to be in JSON. Is there a script or a project that implements this already? I've tried searching but I only find Haystack search for Django.

If not can I get some broad pointers how I should go about doing this.

开发者_如何学运维

Thanks.


The Whoosh Results object is basically a list of dictionaries. From the examples:

>>> # Show the best hit's stored fields
>>> results[0]
{"title": u"Hello World in Python", "path": u"/a/b/c"}
>>> results[0:2]
[{"title": u"Hello World in Python", "path": u"/a/b/c"}, {"title": u"Foo", "path": u"/bar"}]

You could very easily turn this into JSON:

import json
def results2json(results):
   return json.dumps([r for r in results])
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜