我想按欄位過濾資料庫中的專案,并回傳每個過濾器的計數。 例如,當我選擇回傳特定品牌名稱時,我想查看可用品牌名稱的數量。
有沒有我可以使用的搜索服務,比如 Azure 搜索,或者在 NestJs 和 mongodb 中實作它的方法
這是資料庫集合
{
"brand": "Screaming Eagle, The Flight",
"producer": "Screaming Eagle",
"productionCountry": "America",
"region": "Napa Valley",
"appellation": "Oakville",
"vintage": "2016",
"grape": "Cabernet Sauvignon",
"maturity": "25",
"case": "3 bottles",
"origin": "SECONDARYMARKET",
"type": "Red"
},{
"brand": "Joseph Phelps, Insignia",
"producer": "Joseph Phelps",
"productionCountry": "America",
"region": "Napa Valley",
"appellation": "St. Helena",
"vintage": "2012",
"grape": "Cabernet Sauvignon",
"maturity": "25",
"case": "6 bottles",
"origin": "SECONDARYMARKET",
"type": "Red"
},{
"brand": "Joseph Phelps, Insignia",
"producer": "Joseph Phelps",
"productionCountry": "America",
"region": "Napa Valley",
"appellation": "St. Helena",
"vintage": "2012",
"grape": "Cabernet Sauvignon",
"maturity": "25",
"case": "6 bottles",
"origin": "SECONDARYMARKET",
"type": "Red"
},{
"brand": "Continuum",
"producer": "Continuum",
"productionCountry": "America",
"region": "Napa Valley",
"appellation": "Oakville",
"vintage": "2017",
"grape": "Cabernet Sauvignon",
"maturity": "26",
"case": "6 bottles",
"origin": "SECONDARYMARKET",
"type": "Red"
},{
"brand": "Continuum",
"producer": "Continuum",
"productionCountry": "America",
"region": "Napa Valley",
"appellation": "Oakville",
"vintage": "2017",
"grape": "Cabernet Sauvignon",
"maturity": "26",
"case": "6 bottles",
"origin": "SECONDARYMARKET",
"type": "Red"
}
uj5u.com熱心網友回復:
這稱為“方面”,它受 Azure 認知搜索和 MongoDB 的支持。在 Azure 認知搜索中,您必須將facetable要獲取計數的欄位設定為 true,例如brand然后在查詢中指定"facets": ["brand"]。
有關 Azure 搜索的詳細資訊,請參閱:https ://learn.microsoft.com/en-us/azure/search/search-faceted-navigation
這可以使用聚合運算子在 MongoDb 中作業$facet,您可以在此處閱讀更多資訊:https: //www.mongodb.com/docs/manual/reference/operator/aggregation/facet/
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/523563.html
