I had to implement advanced search algorithm which supports pagination and multiple open sessions at one browser. My main issues were the following:
- how am I able to support the pagination?
- where am I going to save the search parameters?
- what happens when I open 3 tabs and search simultaneously?
- when am I going to flush the recorded results?
It was clear that I had to persist the data to each page. My first idea was saving the params into flashdata() (the temporary 1-time session or rather request forwarding). It was good solution if you restrict yourself to one tab only and navigation only page-to-page. The problem was my 'details' page where parameters got lost. As well as the 'back' button, too.
CodeIgniter itself doesn't allow GET queries in the URL. Actually it does, but not by default and it's bad practise to do it.
Therefore I decided to resend the flashdata on all required pages. But what happens if you open few tabs at the same time? All search results get mixed up and all tabs get the data from the last query called.
Another popular trick is persisting into multidimensional $_SESSION array - the name (unique) of the session and all the params. I actually can't think of a reasonable way to flush the sessions regularly and manage big sessions (cookie limit is 4K after all).
So we decided to create a new DB table for sessions. There we save all the params as serialized array. We use both the session unique ID and the page number when navigating.
Code snippet and explaining in the CI forums - How to implement complex search