There is a similar question here Best way to implement <next>, <prev> element links from search list But I'm not satisfied with that answer, and my case is slightly different, and I want to know the best way more commonly.
I have a search page, let's say, searching poems. (currently the data is from mysql, but I'm planning to index them into apache solr)
Each result on the search result page (let's say, /search?keyword=flower&author=john) is a link, which you can click and will be redirected to the poem detail page. (let's say, /poem/1234/This-is-the-best-poem)
Now I want "prev" and "next" links on the detail page if the page is clicked from a search result page. and it uses the same order of the search results.
What I can think is to add full search parameters to the detail page, so the "detail page with pagination" actually is a search results but perpage = 1. But I have to do the full query everytime showing a poem detail page.
I wonder is there a better way ?
Thanks and apologize for my bad English.
You have to get the poem from the db for the detail. But the rest of the parameters can be passed on from the list page, including a list (array) of poem IDs retrieved in the paged list. You could use this until you reach the end of list, to retrieve the next page list.
You might also want to consider caching options available on the server. APC extension is common on PHP.
As for the Solr part of this, you can use DeepPaging, take a look here: http://heliosearch.org/solr/paging-and-deep-paging/
You get a 'cursorMark' from Solr when you use DeepPaging which works like sort of a book mark for your next query results.
You will have to requery, but you will stay in the same result set using that flag, so when you do this only for the next document you will have to get only one row, remember your current position where to start, save the cursor mark and repeat all of that for the next.
By remembering previous cursorMarks you can also go back.
Regards,
Markus