facetFilter没有从API请求返回预期的过滤响应



我试图过滤任天堂的Algolia回应,这样我就只能得到带有dlcType的非"个人"游戏,但出于某种原因,它不适合我。然而,如果我facetFilter一个包含数组的字段(例如可用性字段),它工作得很好。

这是我的请求:

{
"requests": [{
"indexName":"store_game_en_us", 
"params":"query=overcooked&hitsPerPage=5&page=0&analytics=false&facetFilters=%22dlcType%3A-Individual%22"
}]
}

这是我得到的响应/未经过滤:

{
"results": [
{
"hits": [
{
"availability": [
"Available now"
],
"classindDescriptors": null,
"classindRating": "L",
"corePlatforms": [
"Nintendo Switch"
],
"demoNsuid": null,
"editions": [
"Digital"
],
"esrbDescriptors": [
"Mild Cartoon Violence"
],
"esrbRating": "E",
"genres": [
"Simulation",
"Multiplayer",
"Strategy"
],
"nsoFeatures": [
"Online Play",
"Save Data Cloud"
],
"playModes": [
"TV mode",
"Tabletop mode",
"Handheld mode"
],
"playerCount": "4+",
"smecDescriptors": [
"Mild Cartoon Violence"
],
"smecRating": "A",
"softwareDeveloper": "Ghost Town Games and Team17",
"softwarePublisher": "Team17",
"createdAt": "2021-11-12T20:52:15.000Z",
"collectionPriceRange": "$10 - $19.99",
"description": "Enjoy hundreds of levels of cooperative cooking chaos across increasingly perilous and obscure kitchens. Overcooked! Goes Online For the first time ever, online multiplayer has been fully integrated into Overcooked! Revisit your favourite kitchens from t…",
"exclusive": false,
"featuredProduct": false,
"nsuid": "70010000029237",
"platinumPoints": null,
"platform": "Nintendo Switch",
"platformCode": "NINTENDO_SWITCH",
"price": {
"regPrice": 39.99,
"finalPrice": 19.99,
"salePrice": 19.99
},
"priceRange": "$10 - $19.99",
"productImage": "ncom/en_US/games/switch/o/overcooked-all-you-can-eat-switch/hero",
"franchises": [],
"title": "Overcooked! All You Can Eat",
"releaseDateDisplay": null,
"sku": "7100029237",
"updatedAt": "2022-05-03T19:19:56.000Z",
"url": "/store/products/overcooked-all-you-can-eat-switch/",
"urlKey": "overcooked-all-you-can-eat-switch",
"visibleInSearch": true,
"topLevelCategory": "Games",
"topLevelCategoryCode": "GAMES",
"topLevelFilters": [
"Deals"
],
"type": "game",
"dlcType": null,
"contentRatingCode": "E",
"hasDlc": false,
"objectID": "7100029237"
},
{
"availability": [
"Available now"
],
"classindDescriptors": null,
"classindRating": "L",
"corePlatforms": [
"Nintendo Switch"
],
"demoNsuid": null,
"editions": [
"Digital"
],
"esrbDescriptors": null,
"esrbRating": "E",
"genres": [
"Strategy",
"Party",
"Simulation"
],
"nsoFeatures": [
"Online Play",
"Save Data Cloud"
],
"playModes": [
"TV mode",
"Tabletop mode",
"Handheld mode"
],
"playerCount": "4+",
"smecDescriptors": null,
"smecRating": "A",
"softwareDeveloper": null,
"softwarePublisher": "Team17",
"createdAt": "2021-11-12T20:59:37.000Z",
"collectionPriceRange": "$20 - $39.99",
"description": "Out of the frying pan, into the fire... You’ve saved the world from the Ever Peckish. Now a new threat has arisen and it’s time to get back in the kitchen to stave off the hunger of The Unbread! ONLINE/LOCAL MULTIPLAYER MADNESS - You’ll knead to work tog…",
"exclusive": false,
"featuredProduct": false,
"nsuid": "70010000003402",
"platinumPoints": null,
"platform": "Nintendo Switch",
"platformCode": "NINTENDO_SWITCH",
"price": {
"regPrice": 24.99,
"finalPrice": 24.99,
"salePrice": null
},
"priceRange": "$20 - $39.99",
"productImage": "ncom/en_US/games/switch/o/overcooked-2-switch/hero",
"franchises": [],
"title": "Overcooked! 2",
"releaseDateDisplay": null,
"sku": "7100003402",
"updatedAt": "2022-05-06T16:57:52.000Z",
"url": "/store/products/overcooked-2-switch/",
"urlKey": "overcooked-2-switch",
"visibleInSearch": true,
"topLevelCategory": "Games",
"topLevelCategoryCode": "GAMES",
"topLevelFilters": [],
"type": "game",
"dlcType": null,
"contentRatingCode": "E",
"hasDlc": false,
"objectID": "7100003402"
},
{
"availability": [
"Available now"
],
"classindDescriptors": null,
"classindRating": "L",
"corePlatforms": [
"Nintendo Switch"
],
"demoNsuid": null,
"editions": [
"Digital"
],
"esrbDescriptors": [
"Mild Cartoon Violence"
],
"esrbRating": "E",
"genres": [
"Strategy",
"Party",
"Simulation"
],
"nsoFeatures": [
"Save Data Cloud"
],
"playModes": [
"TV mode",
"Tabletop mode",
"Handheld mode"
],
"playerCount": "4+",
"smecDescriptors": [
"Mild Cartoon Violence"
],
"smecRating": "A",
"softwareDeveloper": null,
"softwarePublisher": "Team17",
"createdAt": "2021-11-12T20:52:10.000Z",
"collectionPriceRange": "$10 - $19.99",
"description": "Working as a team, you and your fellow chefs must prepare, cook and serve up a variety of tasty orders before the baying customers storm out in a huff. Sharpen your knives and dust off your chef’s whites, there isn’t mushroom for error and the steaks are…",
"exclusive": false,
"featuredProduct": false,
"nsuid": "70010000000883",
"platinumPoints": null,
"platform": "Nintendo Switch",
"platformCode": "NINTENDO_SWITCH",
"price": {
"regPrice": 19.99,
"finalPrice": 19.99,
"salePrice": null
},
"priceRange": "$10 - $19.99",
"productImage": "ncom/en_US/games/switch/o/overcooked-special-edition-switch/hero",
"franchises": [],
"title": "Overcooked Special Edition",
"releaseDateDisplay": null,
"sku": "7100000883",
"updatedAt": "2022-05-03T21:23:00.000Z",
"url": "/store/products/overcooked-special-edition-switch/",
"urlKey": "overcooked-special-edition-switch",
"visibleInSearch": true,
"topLevelCategory": "Games",
"topLevelCategoryCode": "GAMES",
"topLevelFilters": [],
"type": "game",
"dlcType": null,
"contentRatingCode": "E",
"hasDlc": false,
"objectID": "7100000883"
},
{
"availability": [
"Available now"
],
"classindDescriptors": null,
"classindRating": "L",
"corePlatforms": [
"Nintendo Switch"
],
"demoNsuid": null,
"editions": [
"Digital"
],
"esrbDescriptors": null,
"esrbRating": "E",
"genres": null,
"nsoFeatures": null,
"playModes": [
"TV mode",
"Tabletop mode",
"Handheld mode"
],
"playerCount": null,
"smecDescriptors": null,
"smecRating": "A",
"softwareDeveloper": null,
"softwarePublisher": "Team17",
"createdAt": "2021-11-12T23:40:55.000Z",
"collectionPriceRange": "$10 - $19.99",
"description": "Cook alone or with friends as you travel through the onion kingdom and master over 20 recipes across 130 sizzling levels.  Overcooked! 2: Gourmet Edition The Overcooked! 2 Gourmet Edition gives players every course of award-winning chaotic cooking fun wi…",
"exclusive": false,
"featuredProduct": false,
"nsuid": "70070000010201",
"platinumPoints": null,
"platform": "Nintendo Switch",
"platformCode": "NINTENDO_SWITCH",
"price": {
"regPrice": 48.49,
"finalPrice": 12.12,
"salePrice": 12.12
},
"priceRange": "$10 - $19.99",
"productImage": "ncom/en_US/dlc/switch-dlc/overcooked-2-dlc/rom-bundle/overcooked-2-gourmet-edition/image",
"franchises": [],
"title": "Overcooked! 2 - Gourmet Edition",
"releaseDateDisplay": null,
"sku": "7700010201",
"updatedAt": "2022-05-06T17:49:37.000Z",
"url": "/store/products/overcooked-2-gourmet-edition-switch/",
"urlKey": "overcooked-2-gourmet-edition-switch",
"visibleInSearch": true,
"topLevelCategory": "Games",
"topLevelCategoryCode": "GAMES",
"topLevelFilters": [
"Deals",
"Games with DLC"
],
"type": "game",
"dlcType": "ROM Bundle",
"contentRatingCode": "E",
"hasDlc": true,
"objectID": "7700010201"
},
{
"availability": [
"Available now"
],
"classindDescriptors": null,
"classindRating": "L",
"corePlatforms": [
"Nintendo Switch"
],
"demoNsuid": null,
"editions": [
"Digital"
],
"esrbDescriptors": null,
"esrbRating": "E",
"genres": null,
"nsoFeatures": null,
"playModes": [
"Handheld mode",
"Tabletop mode",
"TV mode"
],
"playerCount": null,
"smecDescriptors": null,
"smecRating": "A",
"softwareDeveloper": null,
"softwarePublisher": "Team17",
"createdAt": "2021-11-12T22:17:33.000Z",
"collectionPriceRange": "$0 - $9.99",
"description": "Overcooked! 2 Carnival of Chaos invites players to a celebration of all things cooking, co-op and chaos! This colourful new DLC will put players to the test as you take on combo meals and that kitchen essential, the canon! Canons!  An unconventional kitc…",
"exclusive": false,
"featuredProduct": false,
"nsuid": "70050000011524",
"platinumPoints": null,
"platform": "Nintendo Switch",
"platformCode": "NINTENDO_SWITCH",
"price": {
"regPrice": 5.99,
"finalPrice": 5.99,
"salePrice": null
},
"priceRange": "$5 - $9.99",
"productImage": "ncom/en_US/dlc/switch-dlc/overcooked-2-dlc/individual/overcooked-2-carnival-of-chaos/image",
"franchises": [],
"title": "Overcooked! 2 - Carnival of Chaos",
"releaseDateDisplay": null,
"sku": "7500011524",
"updatedAt": "2022-05-06T22:25:01.000Z",
"url": "/store/products/overcooked-2-carnival-of-chaos-70050000011524-switch/",
"urlKey": "overcooked-2-carnival-of-chaos-70050000011524-switch",
"visibleInSearch": true,
"topLevelCategory": "Games",
"topLevelCategoryCode": "GAMES",
"topLevelFilters": [
"DLC"
],
"type": "game",
"dlcType": "Individual",
"contentRatingCode": "E",
"hasDlc": true,
"objectID": "7500011524"
}
],
"nbHits": 11,
"page": 0,
"nbPages": 3,
"hitsPerPage": 5,
"exhaustiveNbHits": true,
"exhaustiveTypo": true,
"query": "overcooked",
"params": "query=overcooked&hitsPerPage=5&page=0&analytics=false&facetFilters=",
"index": "store_game_en_us",
"renderingContent": {},
"processingTimeMS": 1
}
]
}

首先确保该属性是作为faceting的属性添加的,您可以使用API或Algolia仪表板来查看

根据文档facetFilters需要是一个数组。从我看到的,你把它设置成像facetFilters:"dlcType:-Bundle"这样的字符串。相反,你需要facetFilters:["dlcType:-Bundle"]
,因此params将变成"query=overcooked&hitsPerPage=5&page=0&analytics=false&facetFilters=%5B%22dlcType%253A-Bundle%22%5D"

即使使用encodeURI,手写params作为字符串也是很麻烦的。相反,您可以将params定义为Javascript对象。下面是一个演示游乐场的请求数组的示例结构。您可以在这里学习编写facetFilters数组的规则

{
"requests": [
{
"indexName": "bestbuy",
"params": {
"query": "app",
"hitsPerPage": 7,
"maxValuesPerFacet": 3,
"page": 0,
"facets": [
"category"
],
"tagFilters": "",
"facetFilters": [
[
"category:Cell Phone Cases & Clips",
"category:Cases, Armbands & Watchbands"
]
]
}
},
{
"indexName": "bestbuy",
"params": {
"query": "app",
"hitsPerPage": 1,
"maxValuesPerFacet": 3,
"page": 0,
"attributesToRetrieve": [],
"attributesToHighlight": [],
"attributesToSnippet": [],
"tagFilters": "",
"analytics": false,
"clickAnalytics": false,
"facets": "category"
}
}
]
}

使用它并查看网络请求以了解requests数组结构。

相关内容

  • 没有找到相关文章

最新更新