在单个结果页面中实现“上一个”和“下一个”功能但保持先前搜索结果顺序的最佳方法是什么?
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.
此处有一个类似的问题实施的最佳方式&lt; next&gt;,&lt; prev&gt; 来自搜索列表的元素链接 但我对这个答案并不满意,我的情况略有不同,我想知道更常见的最佳方法。 p>
I 有一个搜索页面,比方说,搜索诗歌。 (目前数据来自mysql,但我打算将它们编入apache solr) p>
搜索结果页面上的每个结果(比方说,/ search?keyword = flower&amp; author = john)是一个链接,您可以单击该链接并将其重定向到诗歌详细信息页面。 (比如说,/ poem / 1234 /这是最好的诗歌) p>
如果从搜索结果页面点击页面,我现在想要详细页面上的“上一页”和“下一页”链接。 并且它使用相同的搜索结果顺序。 p>
我能想到的是将完整的搜索参数添加到详细信息页面,因此“带分页的详细信息页面”实际上是搜索结果 但perpage = 1. 但是我每次都要显示一个诗歌详细页面,我必须做完整的查询。 p>
我想知道有更好的方法吗? p>
谢谢并为我糟糕的英语道歉。 p> div>
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