Advanced Searching with Algolia on Statamic

April 25, 2024 · 3 min read

Using advanced Algolia features
You’ve got the basics down and your Statamic site is happily communicating with Algolia, giving you search results faster than ever. But why stop there? Algolia has a lot of advanced features to make your search even stronger. Let’s look at how you can make your search experience better and really impress your users. We assume you’ve already set up Algolia with Statamic using JavaScript, following the second part of that article.
Typo tolerance
No one's perfect, and that includes your users when they're typing. Algolia has your back with typo tolerance. It's smart enough to know that when someone types "iphnoe", they're probably looking for "iPhone". You can set how forgiving your search is:
this.index.setSettings({
typoTolerance: "true",
minWordSizefor1Typo: 2, // Minimum character length for 1 typo
minWordSizefor2Typos: 4, // Minimum character length for 2 typos
})With these settings, Algolia starts forgiving typos once words hit 4 characters, and it’ll even forgive two typos in words of 8 characters or more.
Custom ranking and faceting
Your content is unique, so your search results should be too. Algolia lets you make custom ranking criteria to prioritize on what’s most important. Maybe it’s how new the content is, the number of likes, or some other important measure you’ve come up with.
this.index.setSettings({
// other settings
customRanking: ["asc(date)"], // rank the results by date in ascending order
attributesForFaceting: ["tags"], // enable faceted search on the tags attribute.
})Faceting adds another level, letting users dig deeper into their search results. Think of it like those useful filters on e-commerce sites that let you sort by price range, brand, or color.
Synonyms and query expansion
Sometimes, what your users search for and the terms you use on your site don't match up. That's where synonyms come in. You can teach Algolia that "sofa", "couch", and "settee" are all buddies.
this.index.saveSynonym({
objectID: "a-unique-id-1",
type: "synonym",
synonyms: ["sofa", "couch", "settee"],
});Query expansion helps you catch searches that might not have hit the mark. It’s like throwing a bigger net to make sure you’re catching all those possible fish.
Personalization
Algolia can customize search results for each user with personalization. This means that the more your users use your site, the better Algolia gets at giving them the content they’ll probably like.
this.index.setSettings({
// other settings
enablePersonalization: true
});To use personalization, you’ll need to tell Algolia some signals about your users’ preferences. This could be what they click on, what they ignore, and other actions that show what they like.
Geo-search
Got a site with a local focus? Algolia’s geo-search lets users find results based on their location. Whether it’s the nearest coffee shop or a service provider in their area, geo-search brings the relevant local world to your users.
this.index.search(this.query, {
// other settings
aroundLatLng: "40.71, -74.01",
aroundRadius: 1000 // 1km
});Monitoring and analytics
Algolia provides detailed analytics and monitoring tools. You can see what your users are searching for, which results they’re clicking on, and where you might need to improve your content or search settings.
Conclusion
With these advanced features, your Statamic site’s search isn’t just fast, it’s clever, too. You’re giving a search experience that’s tailored, forgiving, and easy to use. Dive into Algolia’s documentation to learn more about each feature and how to use them.
Bring Your Ideas to Life 🚀
Kickstart Your Statamic Project with the #1 Statamic Agency
Are you planning a new Statamic project or thinking about migrating your WordPress site to Statamic? Learn more about our expertise as a renowned Statamic development agency.
Technologies

Stay up-to-date
Be updated with all news, products and tips we share!

