Search DXM Forum
Unfortunately, "Random" field types are not supported in our installation at this time. Perhaps an alternative may be to use the CMS template API to generate random numbers and insert this into G2 search as an "int" field instead. You can then sort on that "int" field to give you a static random order. Static meaning that the order won't change on successive queries to search unlike with the "Random" field type where you can use different seeds in your query to change the order. The order here (eg. random number) would be generated at publish time via the CMS template API and won't change until the next publish. Hope this helps!
--
## If I’ve helped, accept this response as a solution so that other’s can find is more quickly in the future.
## Have thoughts on Crownpeak products? We'd love to hear them. Speak with the Crownpeak Product Team..
This approach won't produce a random order on every query so won't have the effect that most customers want.
The closest that we were able to get to a random sort order was to do two queries: the first query brings back no rows (rows=0) but does give us a search result count. We then generate a random number on the client between 0 and the result count less the number of required results; then re-query asking for rows=required_count and start=random_start.
This approach is used to render the "related content" rail for Worksafe Texas (see https://www.worksafetexas.com/blogs/safety-groups/texas-sign.aspx for an example).
Good news! Random sorting within G2 is a feature we are currently working on. The plan is to have it tested and deployed into production within the quarter.
This is great news, @JakeMaier . I will watch for this update so we can let the team now! 🙂
Any update on if this got implemented yet?
The random sort order feature is now generally available. More information in this blog article.
Is there a way to preserve the random sort order while paging? As it stands, the results get re-randomized with this solution every time you fetch a new page of results, even when using the same sort seed value. This is obviously undesirable.
Thank you.
Offhand, I do not see a way to do this but we will be looking into this internally and we'll update this post accordingly.
--
## If I’ve helped, accept this response as a solution so that other’s can find is more quickly in the future.
## Have thoughts on Crownpeak products? We'd love to hear them. Speak with the Crownpeak Product Team..
I've spoken with our engineering team and it does not look like there is a way to preserve the random sort order while paging.
You can add the feature request to our Ideas Exchange and it will be reviewed by the DX Product team.
If you have additional questions or would like to speak with us about this particular issue, please let me know. I'd be happy to set up some time to connect.
--
## If I’ve helped, accept this response as a solution so that other’s can find is more quickly in the future.
## Have thoughts on Crownpeak products? We'd love to hear them. Speak with the Crownpeak Product Team..