Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best practice to store a "saved search" in a database

I am working an a search page that allows users to search for houses for sale. Typical search criteria include price/zip code/# bedrooms/etc.

I would like to allow the user to save this criteria in a database and email new homes daily.

I could either:

1) Serialize a "SavedSearch" object into a string and save that to the database, then deserialize as needed.

2) Have a list of columns in a tblSavedSearch corresponding to the search criteria - price/zip/# bedrooms/etc.

I am concerned that if I choose option 1, my saved search criteria will change and leave the searialized objects in the database invalid, but option 2 doesn't feel like an optimal solution either.

How have others solved this problem?

like image 838
Julius Seizure Avatar asked Nov 10 '08 20:11

Julius Seizure


People also ask

What should I store in a database?

The purpose of every database is to store information, texts, images, even media files. All dynamic modern websites rely on one or more databases for storing articles and other published content, information about the users, contact information, connections to other websites, ads, etc.

Can I save a search on Pubmed?

To save a search: Enter the search in the search box. Click the Create Alert link under the search box.


1 Answers

I assume you will need to re-run the search daily in order to find new additions to the results. Maybe it is possible to make sure that you search form specifies a get method so that the search criteria is appended to the url as a query string then save the entire querystring in the database.

So if you have a search program called search.action you will request the search like this:

search.action?price=20000&rooms=3

You can save the price=20000&rooms=3 part into the database. To retrieve this search simply append the query string onto the url and request the seach page again.

The only caveat is as the search action changes you have to make intelligent defaults to avoid breaking old searches. For example, suppose you start searching by color, none of the old searches will have a color criteria so your search action will have to cater for this and make sure that something reasonable like ALL colors is used instead.

like image 132
Vincent Ramdhanie Avatar answered Oct 18 '22 12:10

Vincent Ramdhanie