Link to home
Start Free TrialLog in
Avatar of gdemaria
gdemariaFlag for United States of America

asked on

maintaining search filters/order-by while paging

Just taking a survey of other developers for best practices in maintaining your search filters and order-by while paging through multiple pages of search results.

Typical scenario.. user enters a few search filters and presses search.   Say, 500 results and showing 25 records per page.  The user changes the display order and clicks through to page 2, page 3, etc.  

What approach are people using to maintain the where-clause (search filters) and the order by so that each page, the same results are shown, but a different page.

Store SQL where clause in session variable?
Save filter criteria to the database?
Save search results to a temporary table and page through them?
Put search fields and order-by fields inside the search form and resubmit them each time?

Pros and cons for all approaches.
Just curious to change/improve my method.
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gdemaria

ASKER

agx, when stored in the database, how do you maintain the key/ identifier for the stored records?   If using the user's login ID or session variables that means if the user opens another browser tab, the sessions will conflict so a new search will alter the first session's results, yes?   Do you accept that or keep a instance identifier on the URL (such a pain)
Thanks!
Yes, we just accept it.  Most of our apps are internal, so we can be more restrictive.

I'd also be curious how other folks handle it. Since this really isn't cfml specific, might extend the question tags to encourage opinions from other folks.
My app behind a login, I do just that.  I have an ID on the user record that points to storage of filters and search results.   Our search results are complex as they require calculations based on search criteria so storing them seems to be the only way.  And it is nice to have search filters in the database to add some features like saving searches, etc.

For the simpler searches that do not have calculations and are not behind a login, I do wonder what others are doing.  The GET form is good for bookmarking and maintaining the search, but the URL gets huge and messy with all the unused search criteria.  I am tempted to run a script on it to remove unused parameters and the redirect with the shorter query string

I am also curious about other people's views... added a few more tags
Technically, there's nothing stopping you from combining the database and querystring methods. For example, when a user does a search, save the save criteria into a database with a generated key of some sort, and then use that key in the querystring, along with any other per-request options. Something like this:

yourPage.php?searchId=sj4us7ehs7&pageNum=5

The search ID would be used to query the database.