tags:

views:

113

answers:

1

I have a mysql database that stores mainly JSON objects. I am thinking of using Sphinx to search through it - but i was wondering how would i index and retrieve these json objects?

+1  A: 

It would be wise to have a field in the database which contains the important text stored in the JSON object. If your JSON objects are books, I would store the title, author and publisher as plain text in a database field search_text as you commit the JSON to the database.

Your SQL Query for the indexer might look like this

sql_query = SELECT id, search_text FROM json_object;

I haven't tested how Sphinx handles raw JSON, although it can strip HTML via the html_strip = 1 conf setting. If you wanted something REALLY dirty, you could strip punctuation and JavaScript syntax from the json field with a series of nested MySQL string REPLACE() functions at indexing time.

sql_query = SELECT id, REPLACE( REPLACE(raw_json, ']', ' '), '[', ' ') as search_text FROM json_object;

But you wouldn't want to do that would you?

richbs
Thanks for the great tips! haha, no, i do not really want to do that, but that is a great alternative if everything else fails. hmmm
ming yeow