cbadger1
Occasional Observer

G2 Random Sorting

Is there a way to sort G2 search results randomly? Googling about random sorting with Solr in general points to a field type of "random". https://stackoverflow.com/questions/25234102/solr-return-random-results-sort-by-random Not sure if this is a supported custom field type in G2, or if there's another way to get random sorting. Thanks!
9 Replies
EdwardChan
Crownpeak Employee

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!

--


Edward Chan
Sr Product Consultant

## 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..

0 Kudos

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).

0 Kudos
JakeMaier
Crownpeak (Retired)

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.  

0 Kudos

This is great news, @JakeMaier .  I will watch for this update so we can let the team now! 🙂

Beverly Dunn
Sr. Director - Customer Success

If you enjoyed this content, please give me a thumbs up or mark as a solution!
0 Kudos

Any update on if this got implemented yet?

0 Kudos

The random sort order feature is now generally available. More information in this blog article.

0 Kudos

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.

0 Kudos

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.

--


Edward Chan
Sr Product Consultant

## 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..

0 Kudos

@cbadger1 

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.

--


Ari Weissman
Sr Director of UX & Community

## 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..

0 Kudos