鉴于以下MongoDB文档集合:
{
title : 'shirt one'
tags : [
'shirt',
'cotton',
't-shirt',
'black'
]
},
{
title : 'shirt two'
tags : [
'shirt',
'white',
'button down collar'
]
},
{
title : 'shirt three'
tags : [
'shirt',
'cotton',
'red'
]
},
...
Run Code Online (Sandbox Code Playgroud)
如何检索匹配标签列表的项目列表,按匹配标签的总数排序?例如,给定此标记列表作为输入:
['shirt', 'cotton', 'black']
Run Code Online (Sandbox Code Playgroud)
我想通过匹配标签的总数检索按desc顺序排列的项目:
item total matches
-------- --------------
Shirt One 3 (matched shirt + cotton + black)
Shirt Three 2 (matched shirt + cotton)
Shirt Two 1 (matched shirt)
Run Code Online (Sandbox Code Playgroud)
在关系模式中,标记将是一个单独的表,您可以加入该表,计算匹配,并按计数排序.
但是,在Mongo ......?
似乎这种方法可行,
我建立了一个库存更新脚本-在这里,我在Magento中获取产品集合,并遍历结果集,并在进行时更新产品库存(基于单独的库存提要)。
我可以获取产品集合没有问题。
但是,我只想将“管理库存”字段(“库存”标签下的admin下拉菜单)设置为“是”的产品。
所以我尝试了:
// get all magento catalog products with "manage stock" field set to yes
$items = Mage::getModel('catalog/product')->getCollection();
$items
->addAttributeToSelect(array(
'id',
'sku'
))
->addFieldToFilter(array(
array(
'attribute' => 'manage_stock',
'eq' => '1'
),
));
Run Code Online (Sandbox Code Playgroud)
但是,出现错误:
无效的属性名称:manage_stock。