How does one implement storage/retrieval of smart-search/mailbox features?
I have a question regarding implementation of smart-search features. For example, consider something like "smart mailboxes" in various email applications. Let's assume you have your data (emails) stored in a database and, depending on the field for which the query will be created, you present different options to the end user. At the moment let's assume the Subject, Verb, Object approach…
For instance, say you have the following:
SUBJECTs: message, to_address, from_address, subject, date_received
VERBs: contains, does_not_contain, is_equal_to, greater_than, less_than OBJECTs: ??????? Now, in case it isn't clear, I want a table structure (although I'm not opposed to an external XMLesque file of some sort) to store (and later retrieve/present) my criteria for smart searches/mailboxes for later use. As an example, using SVO I could easily store then reconstruct a query for "date between two dates" -- simply use "date greater than" AND "date less than". However, what if, in the same smart search, I wanted a "between" OR'ed with another criterion? You can see that it might get out of hand -- not necessarily in the query creation (开发者_如何学Pythonas that is rather simplistic), but in the option presentation and storage mechanism.Perhaps I need to think more on a more granular level. Perhaps I need to simply allow the user to select AND or OR for each entry independently instead of making it an ALL OR NOTHING type smart search (i.e. instead of MATCH ALL or MATCH ANY, I need to simply allow them to select -- I just don't want it to turn into a Hydra).
Any input would be most appreciated. My apologies if the question is a bit incoherent. It is late, and I my brain is toast.
Best.
The easiest way to do this is to store all of your mailbox information in an SQL database and translate your "subject verb objects" into SQL "where" clauses. Then you let the SQL query compiler do the work for you.
This is what Apple does in Mail.app, which uses an sqlite database to store all of message header information.
精彩评论