0
votes

I have been searching around for a way to search multiple unrelated models, meaning there are no associations between the models being searched, and I have not found any documentation so far on how to do this.

The idea is, is that I have a search form on each page where I would like the user to be able to search through several of the models present on the site. Some of the models are associated, some of them are not.

For instance

Ledgers, Plates, and Essays are related by ledger_id
Comments, and Galleries are related to Plates via plate_id
Discussions is not related or associated to any of the above
Products are not related or associated to any of the above

All of the tables have a created field.

So I would like my search form to search all of the tables listed above sorted by the created field, Ledger, Plates, Essays, Comments, Galleries, Discussions, and Products...

Any ideas on how I can do this with one set of results?

1
Search them separately and create a custom result set? It's hard to give you a more specific answer, as it's unclear as to what your requirements for the result set are.ndm

1 Answers

1
votes

Use Elastic Search put your data in multiple indexes / types or one. If you do some researchon on Elastic Search you'll figure out how to do this.

The alternative is to also denormalize all of your data in a single table and JSON field. Postgres and even MySQL support the search in JSON data inside a tables field.

There is not much else you can do if you want to query all this different data at the same time.