具有属性名称的 Algolia 搜索

Algolia search with attribute name

algolia上的数据是这样的

objectID:3464542
Type:"Accelerator"
Country:"Germany"
City:null
Name:"ProsiebenSat1 Accelerator Batch #8"

我想搜索在德国的任何名字。我该怎么做?

当我执行 Contact.raw_search("Batch") 时,我会得到所有记录,即使其名称包含此甚至非德语。我想获得特定国家/地区的所有那些。

为此,您首先需要将 Country 属性放入 attributesForFaceting 列表中。您可以使用 REST API、您选择的客户端或从 Algolia 仪表板执行此操作。使用后者,转到 Indices 页面,select 您的索引,然后单击 Display 选项卡。在这里,您可以将 Country 字段添加到 Attributes for faceting 列表中。之后,点击保存,您的索引将被重建。

现在,您的索引已准备就绪,可以根据您想要的国家/地区过滤搜索查询。要执行搜索查询,您可以使用(使用 Ruby 客户端):

Contact.search("Batch", {
    facets: ["Country"],
    facetFilters: ["Country:Germany"]
})

有关分面的更多信息,这里是 FAQ and a more detailed guide in the documentation 的快速介绍。