Modifying the data: an example
Before
In this example, you’re adding search to a blog. Besides Algolia’s default ranking formula, you’ve set two custom ranking attributes:pageviews first, followed by comments. Here’s what the dataset would look like:
JSON
pageviews has more weight than comments. When you search for “Algolia”, the “Algolia + SeaUrchin IO” article comes before “Algolia Vault” only because it has one more unique page view. However, this additional view isn’t meaningful. It doesn’t make the article more relevant. Nonetheless, the engine ignores the next custom ranking attribute because of it.
For these two records, it would be better if the article with the most comments appeared first: namely, that “Algolia Vault” article should come first because it has significantly more comments.
But changing the order of the attributes in the customRanking parameter isn’t a good solution:
- it doesn’t necessarily make sense business-wise (in this example, unique page views matter more than the number of comments),
- you may face the same issue with the number of comments, so this doesn’t solve anything.
After
You can solve the issue by adding arounded_pageviews attribute where you reduce the precision of pageviews, and use it for custom ranking instead. For example, round page views to the nearest hundred.
JSON
rounded_pageviews attribute for custom ranking instead of pageviews. Now, searching for “Algolia” would return the “Algolia Vault” article first, based on the comments attribute.
pageviews from the dataset. You may want to keep it for display purposes.
To know more on how to rank per custom attributes, see the guide.