views:

45

answers:

2

I have a classifieds website where users may search ads.

I wonder if I can somehow store search criteria and whenever the users wishes, reuse that search criteria to make another search again, exactly the same... ?

This would make it easier for users to search for a specific car for instance, and not have to fill in all the details such as year, make, mileage, fuel etc...

BTW, I am planning on using either Sphinx or SOLR as a "search engine"... Currently it is MYSQL but I have to change that...

And the website is mostly PHP based.

Thanks

A: 

Sure, it's possible. Those search criteria are data, just likely everything else. You can store them in the DB, in a file, in the user session, in a cookie, whatever.

Michael Borgwardt
I would recommend the session, or at most a cookie. This does not sound like a situation where a user would often want to log into another machine and still have easy access to previous searches.
Craig Young
A: 

You could have a table that logs user ID, query ID, time, the search term and the search value, and then log search criteria in the table.

So for example, if a user searches for a blue car built in 1998, you could add two records like the following:

user_id | query_id | timestamp           | term  | value
=======   ========   ===================   =====   =====
1001      326        2010-01-07 11:01:30   color   blue
1001      326        2010-01-07 11:01:30   year    1998

This makes your database table scalable, but you can then also pull out individual results for all searches made for say, a particular color, or model, or year etc. You can also refine these results by time period as the time-stamp of each search is recorded, or even pull out a particular user's preferences and send them targeted listings. The possibilities are endless.

Martin Bean