Debunking the most common AI myths
ARTIFICIAL INTELLIGENCE CAN’T BE TRUSTED, shouts the headline on your social media newsfeed. Is that really true, or is ...
Senior Digital Marketing Manager, SEO

ARTIFICIAL INTELLIGENCE CAN’T BE TRUSTED, shouts the headline on your social media newsfeed. Is that really true, or is ...
Senior Digital Marketing Manager, SEO

Artificial intelligence is on a roll. It’s strengthening healthcare diagnostics, taking on office grunt work, helping banks combat fraud ...
Search and Discovery writer

Like other modern phenomena such as social media, artificial intelligence has landed on the ecommerce industry scene with a giant ...
Senior Digital Marketing Manager, SEO

Do you dream of having your own personal online shopper? Someone familiar and fun who pops up every time you ...
Search and Discovery writer

Retail’s big show, NRF 2024, once again brought together a wide spectrum of practitioners focused on innovation and transformation ...
Director of Product Marketing, Ecommerce

In a world of so many overwhelming choices for consumers, how can you best engage with the shoppers who visit ...
Senior Digital Marketing Manager, SEO

Get ready for an exhilarating journey into the future of retail as Algolia takes center stage at the NRF Retail ...
VP Corporate Marketing

Picture ecommerce in its early days: businesses were just beginning to discover the power of personalized marketing. They’d divide ...
AI Product Manager | On a mission to help people succeed through the use of AI

“Hello there, how can I help you today?”, asks the virtual shopping assistant in the lower right-hand corner ...
Senior Digital Marketing Manager, SEO

A good starting point for building a comprehensive search experience is a straightforward app template. When crafting your application’s ...
Senior Product Manager

The inviting ecommerce website template that balances bright colors with plenty of white space. The stylized fonts for the headers ...
Search and Discovery writer

Imagine an online shopping experience designed to reflect your unique consumer needs and preferences — a digital world shaped completely around ...
Senior Digital Marketing Manager, SEO

Winter is here for those in the northern hemisphere, with thoughts drifting toward cozy blankets and mulled wine. But before ...
Sr. Developer Relations Engineer

What if there were a way to persuade shoppers who find your ecommerce site, ultimately making it to a product ...
Senior Digital Marketing Manager, SEO

This year a bunch of our engineers from our Sydney office attended GopherCon AU at University of Technology, Sydney, in ...
David Howden &
James Kozianski

Second only to personalization, conversational commerce has been a hot topic of conversation (pun intended) amongst retailers for the better ...
Principal, Klein4Retail

Algolia’s Recommend complements site search and discovery. As customers browse or search your site, dynamic recommendations encourage customers to ...
Frontend Engineer

Winter is coming, along with a bunch of houseguests. You want to replace your battered old sofa — after all, the ...
Search and Discovery writer
While answering Algolia forum posts last week, I did a deep dive on Optional Filters for Algolia Search. Similar to filters and facet filters, optional filters are applied at query-time, allowing you to use all sorts of contextual information to improve results. Unlike the other filters, optional filters don’t remove records from the result set. Instead, they allow you to say, “If records match this filter, then move them up or down the ranking,” without changing the number of records returned.
Some interesting use cases:
You can use filters and facet filters to reduce the number of records in the result set at query-time, then optional filters to manipulate the rankings for the remaining records. You can even apply filter scoring to control the order of the records further.
Here’s an example that applies facet filters for product_type and price_range to an index from a Shopify store. The code selects the objectID of two records to promote, then injects them as optional filters into the query. If either of those products is part of the result set that matches the other criteria in the query, those products are pushed to the top of the ranking. The code uses filter scoring to ensure the featuredProduct will always appear above the alternateProduct.
import algoliasearch from 'algoliasearch';
const featuredProduct = '41469303161004';
const alternateProduct = '41469346644140';
const client = algoliasearch('H2M6B61JEG', 'b1bdfc3258823bb4468815a664dce649');
// Standard replica
const index = client.initIndex('shopify_algolia_products_price_asc_standard');
// with params
index.search(query, {
facetFilters: [[
"product_type:HardGood",
"price_range:75:100"
]],
optionalFilters: [[
`objectID:${featuredProduct}<score=500>`,
`objectID:${alternateProduct}<score=200>`
]],
hitsPerPage: 50,
}).then(({ hits }) => {
console.log(hits.map(item => `- ${item.title} | ${item.product_type} | ${item.objectID} | ${item.price_range}`).join('\n'));
});
Notice that this code uses a standard replica of the Shopify index sorted by price. Optional filters don’t play well with Virtual Replica indices since both re-rank records at query-time, leading to unpredictable results. If you plan to use optional filters, you should use a standard replica that applies ranking at index-time.
You can also use negative optional filters to push records down the ranking. For example, if you wanted to push posts written by the current user lower in the rankings but not remove them completely:
index.search('', {
filters: `date_timestamp > ${Math.floor(d.setDate(d.getDate() - 7) / 1000)}`,
optionalFilters: [
`author:-${user.name}`
],
hitsPerPage: 50,
}).then(({ hits }) => {
console.log(hits};
});
Optional filters are a powerful tool to add to your ranking tool belt, but remember that any query-time calculations will impact search performance. For instance, you shouldn’t use filter scoring on searches that may return more than 100,000 results. Always try to move ranking criteria to index configuration when possible. Use optional filters only when you need to further tune your results at query-time using more real-time context.
Let me know if you find a great (or not so great) use case for optional filters in your search UI!
Powered by Algolia Recommend