简体   繁体   English

Algolia搜索,其中索引中的字段等于字符串

[英]Algolia search where field in index equals to a string

I'm using Algolia on a Rails application for search: 我在Rails应用程序上使用Algolia进行搜索:

index = Algolia::Index.new("Search_production")
results = index.search('heroku')

I have an attribute in that index, called type , that's a string. 我在该索引中有一个名为type的属性,它是一个字符串。

I want to search only for records with type service . 我只想搜索type service记录。

Can I apply a filter to the Ruby Algolia search? 我可以将过滤器应用于Ruby Algolia搜索吗? Something like? 就像是?

results = index.search(query, { facets: '*', facetFilter: ['type:Service' ]})

Yes, using faceting & facetFilters is the way to go to implemented what you're describing, aka "Faceted search"! 是的,使用faceting和facetFilters可以实现您所描述的内容,也就是“ Faceted搜索”! Don't forget to configure your attributesForFaceting setting in your index settings. 不要忘记在索引设置中配置attributesForFaceting设置。

PS: you don't need facets: '*' here, that's not used for the filtering but just to actually retrieve facet values. PS:您不需要facets: '*'这里的facets: '*'并不用于过滤,而只是用于实际获取构面值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM