Advanced Searching with Algolia on Statamic

Arlind Musliu Portrait
Arlind Musliu

April 25, 2024 · 3 min read

Statamic and Algolia logos

Deep Dive in Algolia

You've got the basics down and your Statamic site is happily chatting with Algolia, delivering search results faster than ever. But why stop there? Algolia's got a treasure trove of advanced features to make your search even more powerful. Let's explore how you can fine-tune your search experience and really wow your users. We assume that you have already set up Algolia with Statamic by using JavaScript.

Typo Tolerance

Nobody's perfect, and that includes your users when they're typing. Algolia's got your back with typo tolerance. It's smart enough to understand that when someone types "iphnoe", they're probably looking for "iPhone". You can control how forgiving your search is with settings like these:

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 create custom ranking criteria to prioritize what matters most. Maybe it's the freshness of the content, the number of likes, or some other magic metric you've concocted.

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 layer, letting users drill down into their search results. Think of it like those handy 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 casting a wider net to make sure you're catching all those potential fish.

Personalization

Algolia can tailor search results to each user with personalization. This means that the more your users interact with your site, the better Algolia gets at serving them the content they're likely to love.

this.index.setSettings({ 
  // other settings
  enablePersonalization: true
});

To use personalization, you'll need to send Algolia some signals about your users' preferences. This could be what they click on, what they ignore, and other actions that paint a picture of 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 track 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 smart, too. You're providing a search experience that's tailored, forgiving, and intuitive. Dive into Algolia's documentation to learn more about each feature and how to implement 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.

Arlind Musliu Portrait
Arlind Musliu

Cofounder and CFO of Lucky Media

Technologies:

Statamic
Heading Pattern

Related Posts

Stay up to date

Be updated with all news, products and tips we share!