Algolia for WooCommerce - 仅通过自动填充中的标题进行过滤

时间:2018-04-28 14:22:03

标签: woocommerce algolia

我正试图通过“post_title”过滤Algolia(在Woocommerce中)的自动完成结果。

我在child-theme / algolia / autocomplete.php中修改了模板:

attributesToSnippet: [
    'content:10'
],

通过

attributesToSnippet: [
    'post_title'              
],

但它不起作用,我有不相关的结果,如图所示:https://imgur.com/a/9dEv7bI

如何达到预期效果?谢谢。

1 个答案:

答案 0 :(得分:6)

我的理解是,您希望Algolia只通过搜索帖子标题来返回结果。

attributesToSnippet要求引擎返回与查询匹配的给定属性的给定大小的相关片段。但是,在您的情况下,这不是您想要更改的内容,只是对帖子标题进行搜索。

相反,您应该更改searchableAttributes。 您可以通过进入Algolia仪表板,转到指数选项卡并选择索引来完成此操作。然后转到Ranking标签,删除您不希望引擎搜索的属性。

仅将post_title保留在可搜索的属性中,您的自动填充功能应仅根据post_title内的匹配项返回结果。