0

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.

seanieb
  • 1,196
  • 2
  • 14
  • 36

1 Answers1

4

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])
jterrace
  • 64,866
  • 22
  • 157
  • 202