cbadger1
New Creator

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!
4 Replies
Highlighted
Crownpeak Employee EdwardChan
Crownpeak Employee

Re: G2 Random Sorting

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!

0 Kudos
Moderator
Moderator

This approach won't produce a random order on every query...

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
Crownpeak Employee JakeMaier
Crownpeak Employee

Re: G2 Random Sorting

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
Crownpeak Employee BeverlyDunn
Crownpeak Employee

Re: G2 Random Sorting

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

Beverly Dunn
Sr. Director - Customer Success

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