Topic: virtual folders / smart filtering
Having recently started coding Rails, I'm now stuck at drafting something we all know and like: virtual folders (or what's called 'smart playlist' in iTunes). The concept is the following:
Users can create [many] filters. These filters have [many] rules and [many] data sources. Each data source has [many] data.
Here's a real world example of a personalized news poll: User A likes digg, slashdot and del.ico.us. He dislikes all other (similar) services. He's interested in articles related to technology and/or science. He's also interested in content with lots of comments or lots of diggs, but also stories from the author X. First he'll tell the new filter to only be applied to his favourite services (via multiple checkboxes), then with the following configuration:
Notify me if at least  of the following criterias are met:
- Category is [Technology]
- Category is [Science]
- Has more than  comments
- Has more than  diggs
- Author is [X]
(e.g. the notification could be a daily email with the aggregated links)
Now the question is how to implement the rules database-wise. Let them have a seperate table? Probably - but with which columns (I could make this more complex with rules such as 'has more comments than the monthly average comment count')? Plus, do we convert all these rules to AcriveRecord queries on the fly? Won't we run into major problems once all the filters and rules have to be evaluated every time a new post is being polled by the system?
Or, should rules and filters have a many-to-many relationship (therefor removing all the duplicate rules), should rules be evaluated on each new incoming content snippet, then tell their parented filters if the specific rule has evaluated true or false? This still leaves the question on how to store the search queries.
Any thoughts/ideas/suggestions highly appreciated.