Search G2 updates: CORS headers and random sort order.

Crownpeak (Retired)
0 0 2,008

Several Search G2 updates have come out recently that I wanted to draw attention to.

CORS Headers

The Search G2 servers now respond correctly with CORS headers. 

Historically, the Search G2 servers in the cluster have not responded to CORS pre-flight requests, which has made using AJAX technologies in the browser to interact with Search G2 very difficult.

The Search G2 Javascript SDK resolved this problem by using JSONP. This approach has been adequate for some time, but it does have some security concerns and is not a technique that is in widespread use.

Note: this update to the Search G2 servers does not impact any existing code; it does enable developers who want to use AJAX technologies typical in modern single-page apps (React/VueJS/Angular etc.).

Random Sort Order

The ability to have search results returned in random order has also been deployed and is now generally available. 

Most search results are presented with some natural order (most recent, most relevant, etc.), but there are use cases where you might want to have a random order. One such use case is if you have a collection of related articles that you want to present to users and rather than having the same ones appear over and over, you can use random order to help visitors discover new content.

This feature is accessed by adding a "dynamic" field to the sort parameter in the format random_{seed}. The placeholder {seed} can be replaced with a random number seed but doesn't need to be replaced or updated on each call.




You can view a demo of these new features. You can also take a look at the underlying code by clicking the "Change View" button in the top right and picking "Editor View".

Version history
Last update:
‎02-26-2020 09:39 AM
Updated by: