Q:

Algolia: How to implement customized Featured Products in a results page?

I want to feature (move to top of results) certain products on only certain search result pages. With only a single search performed. A Custom Ranking Attribute would boost a product's ranking for all pages, instead of certain pages.
A somewhat working solution is to add an attribute like "featuredin":"[searchterm]", and move "featuredin" to top of Searchable Attributes. However, products with similar searchterm could be featured on the wrong page. 
example:
There are products with "featuredin":"iphone", and products with "featuredin":"iphone accessories". Since searching 'iphone' in attribute 'featuredin' will also get hits on products with "featuredin":"iphone accessories", I'm getting iphone accessories featured on iphone search results.
This solution could work if there's a way to force 'true' exact match for an attribute. But I couldn't find something like that.
Thanks.

A:

There is actually a nice way to implement that behavior using "optional" facet filters (a soon to be released advanced feature - as of 2016/11/15).
An "Optional Facet Filter" is a facet filter that doesn't need to match to retrieve a result but that will - by default - make sure the hits that have the facet value are retrieved first (thanks to the filters criterion of Algolia's tie-breaking ranking formula).
This is exactly what you want: on every single page where you want some results sharing a featuredin value to be retrieved first; just query the Algolia index with the featuredin:"a value" optional facet filter.

make sure your featuredin attribute is part of your attributesForFacet index setting
at query time, query the index with index.search('', { optionalFacetFilters: ["featuredin:iphone accessories"])

You can read more on this (beta) documentation page.

