Jump to content

Using a seed when getting random pages


neonwired
 Share

Recommended Posts

2 hours ago, neonwired said:

But it's still sorted randomly. So unless you can use a seed the order will change on every page.

You are right - interesting that this has not come up in the forums before (to my knowledge).

Thinking of ways of working around this, I think you'll need to find all your city pages without applying any limit so the random sort is only done once. Then you can "fake" the pagination, getting a slice() of the city pages on each results page. This technique for using array_chunk might also be handy:

See this post for how you can use MarkupPagerNav outside of its typical use:

If you have a large number of city pages you might not want to load them all into memory. So a couple of approaches you could look into:

1. $pages->findMany()

2. $pages->findIDs() to return an array of IDs, then use PHP's array_slice together with $pages->getById() to load each page of results.

  • Like 1
Link to comment
Share on other sites

I just wonder if there could be usability issues here? I don't know the background, obviously, but displaying a random selection and then making them look 'non-random', isn't that risking misleading (maybe that's too strong a word) users that they are seeing everything when they aren't?

  • Like 1
Link to comment
Share on other sites

On 5/16/2017 at 4:33 AM, DaveP said:

I just wonder if there could be usability issues here? I don't know the background, obviously, but displaying a random selection and then making them look 'non-random', isn't that risking misleading (maybe that's too strong a word) users that they are seeing everything when they aren't?

You're not really making them look non-random, it's just so you can paginate a random set of results, without a seed it would just pick a whole new set of random results on every page and potentially pick the same ones again which is definitively a usability issue.

What i'm doing is creating a page that uses ajax to load more items when scrolling downwards, i can't bootstrap all as there are thousands of items so without using a seed the best suggestion is Robin's to load IDs.

In wordpress you can pass the seed when you order by random, would be nice if processwire had something similar

Link to comment
Share on other sites

11 hours ago, Macrura said:

Cool, I haven't looked at that method before. But it only works with a PageArray/WireArray so not ideal if you have thousands of pages to sort. Would be good if there was something similar for PageFinder.

Link to comment
Share on other sites

I think the pagination behaviour with $pages->find("sort=random") is unexpected and so have opened a GitHub issue.

Looking at the PageFinder source code it isn't difficult to see how a seed could be used with the random sort, but the relevant method isn't hookable so any fix will require a core change.

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...