I have a application which stores documents created by users. These documents have authors, creation dates. The authors can have roles. Additionally a given document may get tagged with keywords. There are ~16K documents in the database, and a user may want to view the documents with any combination of this information as a limit. For example, see all documents by a given author, or published in a given time window, or from authors in this role, etc (and any combination of these).
Is there a recommended best way to implement this? In general I have passed the desired conditions in the params hash and then either used a complicated if ... elsif.... else.. to decode the passed conditions directly into different Model.find calls. Alternatively, I will use a similar if sequence to construct the proper SQL conditions phrase and then use a single find call.
Both of these seem like hacks and there should be a better way to do it with named scopes, but I can't figure out a clean way to deal with the permutations.