Php Doctrine MongoDB地图缩减参考文件
这可能是我问的另一个问题的重复,但我试图用Mongo map reduce和think从不同的角度来处理它 形势 我有两份文件Php Doctrine MongoDB地图缩减参考文件,php,mongodb,doctrine,doctrine-odm,Php,Mongodb,Doctrine,Doctrine Odm,这可能是我问的另一个问题的重复,但我试图用Mongo map reduce和think从不同的角度来处理它 形势 我有两份文件 Content id - ID title - String contentType - Reference One Tag audienceType - Reference One Tag Tag id - ID title - String type - String 我使用标记作为所有元信息的存储库,并按
Content
id - ID
title - String
contentType - Reference One Tag
audienceType - Reference One Tag
Tag
id - ID
title - String
type - String
我使用标记作为所有元信息的存储库,并按类型将它们拆分,因此,进入Content contentType的是类型为“Content type”的标记,进入Content audienceType的是类型为“audience type”的标记
标记是分层的,但仅通过使用连字符,因此,以内容类型为例,标题可能有:
action
action - swordplay
action - spy
action - space
romance
romance - historical
romance - historical - boy/girl
romance - historical - boy/boy
romance - historical - girl/girl
romance - modern
romance - modern - boy/girl
romance - modern - boy/boy
romance - modern - girl/girl
问题
我希望能够提供标题的一部分(如果有帮助的话,也可以编制索引),并找到属于该“组”的所有条目。比如说
如果搜索“操作”,查询将返回所有引用到以下内容的文档:
action
action - swordplay
action - spy
action - space
romance - modern
romance - modern - boy/girl
romance - modern - boy/boy
romance - modern - girl/girl
如果寻找“浪漫-现代”。查询将返回所有引用了以下内容的文档:
action
action - swordplay
action - spy
action - space
romance - modern
romance - modern - boy/girl
romance - modern - boy/boy
romance - modern - girl/girl
示例文档
根据评论中的要求,以下是一些为解决此问题而简化的示例:
content
{
_id: ObjectId(1),
title: "Film A",
contentType: ObjectId(11)
audienceType: ObjectId(21)
}
{
_id: ObjectId(2),
title: "Film B",
contentType: ObjectId(12)
audienceType: ObjectId(21)
}
{
_id: ObjectId(3),
title: "Film C",
contentType: ObjectId(12)
audienceType: ObjectId(21)
}
Tag
{
_id: ObjectId(11),
title: "romance - historical",
type: "content-type"
}
{
_id: ObjectId(12),
title: "romance - historical - boy/girl",
type: "content-type"
}
{
_id: ObjectId(21),
title: "adults",
type: "audience-type"
}
尝试
因为查询是使用条令构建的,它也是用PHP实现的,所以我可以手动将搜索值放入map reduce函数中。但我不确定这是否是解决问题的方法
/* Manually setting the value so that it can make sense in question. This should return all the records */
$searchTitle = 'romance - historical';
$queryBuilder
->where('function() {
return this.contentType.title.search("'.$searchTitle.'");
}');
当我执行上述操作时,条令(通过resultant异常)总是抱怨我试图搜索的内容未定义。请有人告诉我,MapReduce对我来说是一碗全新的鱼MongoDB中的文档是什么样子的?目前还不清楚搜索需要在什么地方进行。只需向我们展示相关集合中的数据结构。对我来说,这听起来像是一个正则表达式搜索,但解释并不十分清楚。
->where
几乎是$where
查询运算符的包装,有关如何将map/reduce与ODM结合使用的文档,请参阅其,也有助于理解map/reduce的概念。