Push zero stock products to bottom


I was wondering if it’s possible to push zero stock products to bottom in search results.

Is there some functionality for this?

Hello luke,

This is perfectly doable and a perfect use-case for our Custom Ranking option. As you did not mention if you were using one of our integrations (Wordpress, Magento, Shopify, etc) I will just assume that you are building it directly with our API client.

The custom ranking let you define the field(s) that should be used for ordering results in case there is a tie on the matched words. For example, if you’re searching for “luke” and it matches both “Luke Skywalker” and “Luke Cage”, you need a way to tell the engine which one should be first.

If you’d like the most recent character first, you could set customRanking to desc(creationDate) while if you want the most popular then desc(popularity) would work. Of course you’ll need actual fields named creationDate and popularity in your records, with a numeric value.

To get back to your example, if you have a key stock in your records, you can set your customRanking to desc(stock) so the items with the highest stock will be ranked higher and the out of stock items will be lower.

Note that if you only care about “in stock” / “out of stock” (no matter how many items are left in stock), you might have to add a new field outOfStock set to true/false and set your custom ranking on that (it also works for boolean, they are implicitely converted to 1/0).

Hope that helps. If your question was specific to one of our plugins, just let us know and I’ll adapt my answer.

Hi Pixelastic,

Working great! Thanks.