Problem/Motivation

Sort: global random is refreshed, when a pager is used. The expected behavior is to have results of the view sorted randomly, and display them in that order no matter the pager configuration, but at the moment it is showing random nodes on each pager page and even show the same nodes on the different pages.

Steps to reproduce

  • Install Drupal
  • Create 50 dummy pages
  • Create a view (either page or block)
  • Set the view to show the field title (or teaser content)
  • Add sort criteria as Global: Random (asc)
  • Make sure no other sort criteria is listed
  • Add a pager to show 5 items (Full | Paged, 5 Items)

Navigate to the view that you have created. This should results in showing 50 unique nodes being randomly sorted and displayed 5 per page.

What actually happens when clicking through pager is that we get duplicates appearing. It would appear that the pager is requesting 5 nodes and sorting these by random. The next pager repeats this request, resulting in duplicates being pulled through. The nodes are not seeded in a sequence between pages.

Using AJAX makes no difference the issue is present in both AJAX and Non AJAX views.

Proposed resolution

This will probably not be fixed in Drupal core.

As a workaround, you can use https://www.drupal.org/project/views_random_seed if you use Search API Solr. But it does not work with standard Search API database backend: #3229841: Not working with search_api.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#28 screen-capture (1).gif2.14 MBkostyashupenko

Comments

sittard created an issue. See original summary.

lendude’s picture

Version: 8.2.6 » 8.4.x-dev
Category: Bug report » Feature request

This would be a new feature (and indeed better handled in contrib I feel).

Yes the random sort is applied anew for every page. Yes this leads to strange results when combining random sorting with a pager. The core random sort is only usable for simple 'show a set number of random things' use case.

sittard’s picture

Related issues: +#2820021: Port to Drupal 8

OK - I've put a request in to port the contrib Drupal 7 Views Random Seed Module (https://www.drupal.org/node/2820021) to Drupal 8. But as that module owner has not released an update in 5 years I'm not holding out much hope for this happening quick.

Any other workarounds would be appreciated.

dawehner’s picture

I'm not holding out much hope for this happening quick.

Yeah, I don't have too much hope either ;)

sittard’s picture

OK so we now have a working patch (see https://www.drupal.org/node/2820021) - big credit to @dawehner

I'm tending to disagree with @lendude on this:

This would be a new feature (and indeed better handled in contrib I feel).

If we offer 'random' sort in Views core then really it should work regardless of whether the view has a pager or not. The site builder shouldn't need to install a contrib module to get it working.

Thanks to all for moving this forward.

dawehner’s picture

It is technically a feature ... as it doesn't exist yet in the module. Also keep in mind that it might be exactly what people expect it to do at the moment. Random is random.
Also I think having a pager and random is more of an edge case. I think the way more common usecase is to just show a single item on the frontpage, for example, in which case this feature doesn't matter.

marassa’s picture

First of all, huge thanks to dawehner for the working solution!
And I tend to agree with sittard that this really should be in the Views core. It might be an edge case but it certainly isn't for me and my users: I store thousands of tagged pictures and let users select all pictures having a certain tag (from a tag cloud). I need a pager because the result list can be very long. I would prefer a random order so that the user doesn't start with the same old set of pictures any time they would like to revisit the view (on another day). But seeing the same picture(s) reappearing again and again while paging through the view is frustrating and not at all what my users expect. In case someone actually prefers such behavior ("random is random") then I suppose there should be a checkbox whether to use seed or not, effectively merging the functionality of two handlers into one.
So I urge the module maintainers to give it one more think ;)

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tom3b’s picture

Definitely feel this should be marked as a Bug and not a Feature Request. I can't think of a reason why pagination should re-randomise the data. The whole premise of pagination is to cater for when you have more data than you can display on one page, the next logical page should continue in the same order as the first.

tetranz’s picture

I think the obvious question to anyone thinking about implementing this is: How?

The randomness data (sort order / weight) would need to persist between requests so where would that be stored? It would need to be saved in a temporary table or something. Saving it in session is possibly an option but that might have caching issues and there's probably a maximum size issue.

How long should the random sort order persist? If I go page 1, page 2 and back to page 1 then page 1 should be unchanged but if I come back to page 1 tomorrow should it still be the same? I guess that needs to be configurable. i.e., a "randomness lifetime" setting or maybe it's unique to the user session. i.e., logout and login and get a different order.

This is quite a difficult issue to solve and it probably means different things to different people.

marassa’s picture

This obvious question has an obvious answer: https://www.drupal.org/project/views_random_seed
And it is already implemented. And it actually works.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

handkerchief’s picture

any news on this?

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

msypes’s picture

Currently (2020-04-22) the recommended contrib module, Views random seed = https://www.drupal.org/project/views_random_seed, is in alpha, and hasn't been updated in over two years.
Also, this thread looks like a duplicate of https://www.drupal.org/project/views/issues/1131940

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

back-2-95’s picture

Now that Drupal 8 is released views_random_seed is not an option anymore.

Site cannot be upgraded to D9 with Composer if views_random_seed is installed.

maskedjellybean’s picture

This is definitely a bug. Random sort and pagination are both core views functionality and yet when you combine them what you get is 10 links at the bottom of your view that all do the exact same thing.

I was able to get views_random_seed to work with Drupal 8, but the lack of maintenance and a Drupal 9 release is concerning. I'll cross that bridge later...

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

john.glynn.davies’s picture

Looks like the Views Random Seed module is now available for D8, D9 and D10.

https://www.drupal.org/project/views_random_seed

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kostyashupenko’s picture

Status: Active » Needs work
StatusFileSize
new2.14 MB

Bump. This is still an issue in Drupal 10.2

Test

I just have generated several nodes of some content type -> then I created new view with random sorting (no matter if Ajax enabled or not).
Look at `16` number on the gif above, it's often appears on several pages.

Moreover, here is another use case.
Let's say we have some taxonomy terms of some vocabulary. And some terms has same weight. And guess a view which is displaying those terms with the sorting only by weight (no matter asc or desc and no matter if ajax enabled). In the end some of the terms will be duplicated on different pages.

marassa’s picture

@kostyashupenko, the core developers clearly don't agree that this is an issue. And with a contrib workaround available - https://www.drupal.org/project/views_random_seed - who cares?

ressa’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

Updating the Issue Summary. Can this issue be closed, since there is a solution available? Feel free to re-open if not.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

ressa’s picture

Issue summary: View changes
Related issues: +#3229841: Not working with search_api

Add note that https://www.drupal.org/project/views_random_seed/ only works with Solr.