You might be familiar with hstore datatype in PostgreSQL - if you're not - check it out, as it is really cool. Basically it's hash in database, which you can search in.