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". Not sure if this is a supported custom field type in G2, or if there's another way to get random sorting. Thanks!
0 Kudos
2 Replies
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

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 for an example).

0 Kudos