By default, Algolia puts the most relevant items first in results.
However, you might want to sort results by a specific attribute, like price or date.
To sort your search results by a specific attribute:
Think of a replica index as a duplicate of your primary index but with a different sorting of results.
Choose from two types of replicas: standard or virtual:
Use a standard replica for exhaustive sorting. This method sorts results by the chosen attribute.
Use a virtual replica for relevant sorting. This method prioritizes relevant results while still incorporating the sorting preference for the chosen attribute.
Configure an attribute for sorting in the Algolia dashboard
On the Configuration tab, go to Relevant sort or Ranking and Sorting.
You’ll see either option, depending on the type of replica you want to configure (virtual or standard).
Click +Add a sort attribute or +Add sort-by attribute
Type in the name of the attribute you want to sort. Be careful here: Algolia doesn’t check to see if what you type matches the name of an attribute in the index.
Determine the sort direction (Ascending or Descending).
response,err:=client.SetSettings(client.NewApiSetSettingsRequest("ALGOLIA_INDEX_NAME",search.NewEmptyIndexSettings().SetCustomRanking([]string{"desc(price)"})))iferr!=nil{// handle the eventual errorpanic(err)}
response,err:=client.SetSettings(client.NewApiSetSettingsRequest("ALGOLIA_INDEX_NAME",search.NewEmptyIndexSettings().SetRanking([]string{"desc(price)","typo","geo","words","filters","proximity","attribute","exact","custom"})))iferr!=nil{// handle the eventual errorpanic(err)}