Sometimes you would like your out of stock products to always appear after your in stock products.
By default in_stock is set as a Custom ranking attribute in our Magento extension. This will not achieve what you are looking for with regards to always seeing out of stock items at the bottom, but it does interfere less with the ranking of your results. You can find this in your ranking section in Stores > Algolia Search Products
How to rank in stock items first
If you want to go one step further than this you can essentially divide your search results in two sections, the first section would be all items in stock, and then the second section would be all of your out of stock items and we would then rank results within these sections as usual.
You can achieve this by going to your algolia dashboard for your _product index and changing your ranking settings:
You would want to make in_stock your top ranking criteria and set is as descending:
You should then see all the in_stock records at the top of your search results.
You will need to then remove in_stock from your custom ranking:
If you want to change the way the purchase button works for out of stock results you would need to modify your hits template. You can find details on how to modify this template here: https://www.algolia.com/doc/integration/magento-2/customize/instant-search-page/?language=php#instant-search-results-page
Last reviewed 29-04-22.