Malcom
Malcom

Reputation: 478

Algolia for WooCommerce - Filter only through titles in the autocomplete

I'm trying to filter the autocomplete results in Algolia (in Woocommerce) by "post_title" only.

I have modified the template in child-theme/algolia/autocomplete.php :

attributesToSnippet: [
    'content:10'
],

by

attributesToSnippet: [
    'post_title'              
],

but it doesn't work, I have irrelevant results, as shown : https://i.sstatic.net/e1SKt.jpg

How can I achieve the desired result ? Thank you.

Upvotes: 1

Views: 154

Answers (1)

rayrutjes
rayrutjes

Reputation: 798

My understanding is that you would like Algolia only to return results by searching into the post titles.

The attributesToSnippet asks the engine to return a relevant snippet of a given size for a given attribute that matched the query. However in your case, this is not what you will want to change in order to only have the search operate on post titles.

Instead you should be changing the searchableAttributes. You can do so by heading into your Algolia dashboard, going to the Indices tab and select your index. Then head to the Ranking tab and remove the attributes you don't want the engine to search on.

By only leaving the post_title in the searchable attributes, your autocomplete should only return results based on matches inside the post_title.

Upvotes: 1

Related Questions