这段代码不是很漂亮,所以我想知道是否有更好的方法从索引中获取构面?
var algolia = algoliasearch('id', 'key');
var helper = algoliasearchHelper(algolia, 'getstarted_actors', {
facets: ['*'],
});
helper.on("result", results => console.log(Object.keys(results['_rawResults'][0].facets)));
答案 0 :(得分:0)
您还可以执行空查询搜索,然后对响应做任何您需要的事情-在下面的简单示例中,我们获得了构面并将其打印到控制台:
var algoliasearch = require('algoliasearch');
var client = algoliasearch('latency', '249078a3d4337a8231f1665ec5a44966');
var index = client.initIndex('bestbuy');
index.search(
{
query: '', // empty query
facets: ['*'], // retrieve all facets
},
function searchDone(err, content) {
if (err) throw err;
console.log(JSON.stringify(content.facets, undefined, 2)); // print
}
);