Order by sending 0 or empty to last results

I created two replicas to sort cars by price and kilometers in desc order.
I like to know if there are any way to avoid results with no price, or price == 0 (the same for kilometers) appear first
What I need is the cars order by price, but the cars with price == 0 should by at the end.

Thanks !

Hello there, thank you for reaching us out!

A good approach here would be to add a new boolean attribute that specifies if the car has a price or not.
This attribute could be has_price, always true or false. If price == 0 or price == nil, set this boolean to false.

Having this new has_price attribute, you can add it to your ranking formula to make sure has_price == false are always retrieved last. This would be a “sort_by” attribute on has_price, ascending, at the top of your ranking formula. It should look like asc(has_price), first element of your ranking formula.

Here is some documentation with a similar case (for filtering instead of sorting): https://www.algolia.com/doc/guides/managing-results/refine-results/filtering/how-to/filter-by-null-or-missing-attributes/
And the documentation for the ranking formula: https://www.algolia.com/doc/api-reference/api-parameters/ranking/

Let us know if this works for you, have a nice day!

Thank you @jvenezia. I will try, and let you know if everything is ok.

@jvenezia is working just fine in my stargin site … but in descending order :man_shrugging:
I will let you know if is ok in production, tomorrow.
Thanks a lot !

Thank you … this works just fine !!!