私はApache SolrまたはElasticSearchを使用すると柔軟性とパフォーマンスが向上すると思いますが、これはAggregation Frameworkを使用してサポートされています。
MongoDBを使用する主な問題は、N Times:最初に一致結果を取得してからグループごとに1回ずつ検索することです。フルテキスト検索エンジンを使用している間は、すべてを1つのクエリで取得できます。
例
//'tags' filter simulates the search
//this query gets the products
db.products.find({tags: {$all: ["tag1", "tag2"]}})
//this query gets the size facet
db.products.aggregate(
{$match: {tags: {$all: ["tag1", "tag2"]}}},
{$group: {_id: "$size"}, count: {$sum:1}},
{$sort: {count:-1}}
)
//this query gets the color facet
db.products.aggregate(
{$match: {tags: {$all: ["tag1", "tag2"]}}},
{$group: {_id: "$color"}, count: {$sum:1}},
{$sort: {count:-1}}
)
//this query gets the brand facet
db.products.aggregate(
{$match: {tags: {$all: ["tag1", "tag2"]}}},
{$group: {_id: "$brand"}, count: {$sum:1}},
{$sort: {count:-1}}
)
ユーザーがファセットを使用して検索をフィルタリングしたら、次のように述語と一致述語を照会するために、このフィルタを追加する必要があります。
//user clicks on "Brand 1" facet
db.products.find({tags: {$all: ["tag1", "tag2"]}, brand: "Brand 1"})
db.products.aggregate(
{$match: {tags: {$all: ["tag1", "tag2"]}}, brand: "Brand 1"},
{$group: {_id: "$size"}, count: {$sum:1}},
{$sort: {count:-1}}
)
db.products.aggregate(
{$match: {tags: {$all: ["tag1", "tag2"]}}, brand: "Brand 1"},
{$group: {_id: "$color"}, count: {$sum:1}},
{$sort: {count:-1}}
)
db.products.aggregate(
{$match: {tags: {$all: ["tag1", "tag2"]}}, brand: "Brand 1"},
{$group: {_id: "$brand"}, count: {$sum:1}},
{$sort: {count:-1}}
)
集約フレームワークのようなものが有望と思われるだろう。ファセットグループごとに追加のクエリを実行することに問題はありません。この実装を検証するPOCアプリケーションを作成しましょう。 –
はい、それは本当に強力で、多くの可能性をもたらします。このフレームワークの主な問題は、クエリの最適化です。シャーディングを使用すると、クエリの最適化が不足します。私はこの問題にパッチを当ててgithubで取り上げています。 –