views:

245

answers:

4

I have a php classifieds website (mostly) and I am currently using MYSQL as a database. Later on I will use SOLR or maybe Sphinx as a "search engine".

I want to make it possible for users to view "results" of searches they have made before, but I don't know where to start...

How is this done?

Currently I have a form which is filled in and when submitted, the php just checks agains a mysql table to see if there are any matches.

Should I store the 'Search criteria' and do a new search every time the users click on one of their previous searches, or should I store the results? I would prefer to make a new search because new items may have been inserted since the last search!

If you need more input, just let me know and I will update this Q.

Thanks

A: 

You already have said it: if users should see the new results of old queries, you'll have to store the search parameters somehow and re-do the search when a users requests it.

David Schmitt
A: 

Well... if you're basically talking about "saved searches", I'm doing something similar currently so that I just have a separate table where....

saved_search_id (primary) | user_id (foreign) | search_name | criteria1 | criteria2 | criteria3 ... etc

So basically I can now display to the user a list of saved searches they've created, and the table stores the criteria that were part of that search. I can then use those saved criteria to run a saved search anytime.

Does that help?

Tom
A: 

Store the search criteria. This is quite obivious as if the data changes users will get old results. And consider the space the results might take after a while :)

I would also consider really storing the search criteria not the actual query. If you change the database the stored searches would still work as you need to update the query generation engine also but you would most likely forgot to update every stored query.

Calmar
+1  A: 

Use query-string parameters ($_GET) for the search form. Then the user can bookmark the search. If you want, you could create a bookmarking feature in your application, but there really is no need.

If you are concerned about performance, make sure that your database' cache settings are tuned correctly, and that you don't write too often to the table. MySql will do a good job of caching then.

troelskn