How to code a 'Next in Results' within search results in PHP
Posted
by thebluefox
on Stack Overflow
See other posts from Stack Overflow
or by thebluefox
Published on 2010-05-13T11:53:23Z
Indexed on
2010/05/13
11:54 UTC
Read the original article
Hit count: 270
Right, bit of a head scratcher, although I've got a feeling there's an obvious answer and I'm just not seeing the wood for the trees.
Baiscally, using Solr as a search engine for my site, bringing back 15 results per page. When you click on a result, you get a detail page, that has a "Next in Results" link on it, which obviously forwards you on to the next result.
Whats the best way of doing this? I've come up with a few solutions but they're either too inpractical or just don't work.
I could store all the ids in a session array, then grab the one after the current one and put that in the link. But with possibly hundreds/thousands of results, the memory that array would need, and the performance hit of dealing with it isn't practical.
I could take the same approach and put it into the db, but I'll still have to deal with a potentially huge array when I grab them out of the db.
Or; I could do the search again, only returning the id's, and grab the one after the one we're currently looking at. I think this could be the best option? Although it does seem kind of messy, namely because of when I have to select the id thats on a different 'page' (ie the 16th, 31st etc result). Unless I pass through where it was in the results, and select from there, but that still doesn't seem like the right way to do it.
I'm really sorry if this is just complete nonsense, any help is massively appreciated as always,
Cheers guys!
© Stack Overflow or respective owner