Algolia 按多个方面检索结果
Algolia retrieve results by multiple facets
首先,我使用的是Algolia JavaScript API Client V3 (Deprecated)
我有以下记录
{
category: SEDAN,
manufacturer: Volkswagen,
id: '123'
},
{
category: COUPE,
manufacturer: Renault,
id: '234'
},
{
category: SEDAN,
manufacturer: Fiat,
id: '345'
},
{
category: COUPE,
manufacturer: Peugeot,
id: '456'
},
{
category: SUV,
manufacturer: Volkswagen,
id: '567'
}
我想查询 Algolia 并得到类似下面的内容 json
{
categories: {
SEDAN: {
count: 2
items: [{
Volkswagen: {
count 1,
items: [{
id: '123'
}]
}
},
{
Fiat: {
count 1,
items: [{
id: '345'
}]
}
}]
},
COUPE: {
count: 2
items: [{
Renault: {
count 1,
items: [{
id: '234'
}]
}
},
{
Peugeot: {
count 1,
items: [{
id: '456'
}]
}
}]
},
SUV: {
count: 1,
items: [{
Volkswagen: {
count 1,
items: [{
id: '567'
}]
}
}]
}
}
}
我一直在尝试查询Algolia
index
.search({
query: '',
facets: ['category', 'manufacturer'],
attributesToRetrieve: []
})
.then((result) => {
console.log(result.facets);
});
但我不确定是否可以合并这些方面
添加到查询中的 facets
不能那样工作。它只是 return 每个方面值的记录计数,而不是实际记录 (https://www.algolia.com/doc/api-reference/api-parameters/facets/)
您可以围绕构面创建过滤器并使用这些过滤器按构面值显示结果,但是没有办法构建单个响应 JSON 已经像上面显示的那样按构面分组。 https://www.algolia.com/doc/api-reference/api-parameters/filters/
首先,我使用的是Algolia JavaScript API Client V3 (Deprecated)
我有以下记录
{
category: SEDAN,
manufacturer: Volkswagen,
id: '123'
},
{
category: COUPE,
manufacturer: Renault,
id: '234'
},
{
category: SEDAN,
manufacturer: Fiat,
id: '345'
},
{
category: COUPE,
manufacturer: Peugeot,
id: '456'
},
{
category: SUV,
manufacturer: Volkswagen,
id: '567'
}
我想查询 Algolia 并得到类似下面的内容 json
{
categories: {
SEDAN: {
count: 2
items: [{
Volkswagen: {
count 1,
items: [{
id: '123'
}]
}
},
{
Fiat: {
count 1,
items: [{
id: '345'
}]
}
}]
},
COUPE: {
count: 2
items: [{
Renault: {
count 1,
items: [{
id: '234'
}]
}
},
{
Peugeot: {
count 1,
items: [{
id: '456'
}]
}
}]
},
SUV: {
count: 1,
items: [{
Volkswagen: {
count 1,
items: [{
id: '567'
}]
}
}]
}
}
}
我一直在尝试查询Algolia
index
.search({
query: '',
facets: ['category', 'manufacturer'],
attributesToRetrieve: []
})
.then((result) => {
console.log(result.facets);
});
但我不确定是否可以合并这些方面
facets
不能那样工作。它只是 return 每个方面值的记录计数,而不是实际记录 (https://www.algolia.com/doc/api-reference/api-parameters/facets/)
您可以围绕构面创建过滤器并使用这些过滤器按构面值显示结果,但是没有办法构建单个响应 JSON 已经像上面显示的那样按构面分组。 https://www.algolia.com/doc/api-reference/api-parameters/filters/