【发布时间】:2011-08-18 22:25:00
【问题描述】:
我正在使用 mongodb 进行简单的标签搜索,数据存储在列表中。
Entity A {_id:...,tags : ['a','b','f']}
Entity B {_id:...,tags : ['g','a','v']}
Entity C {_id:...,tags : ['a','c','e']}
Entity D {_id:...,tags : ['c','s','e']}
Entity E {_id:...,tags : ['a','c','s']}
搜索字符串:'a c s g'
查询正在
db.collecction.find({tags:{$in:['a','c','s','g']}})
预期响应将是在顶部具有最多匹配标签的实体,然后是其余标签。
回复:
1.Entity E - 3 tags matched
2.Entity D/C/B - 2 tags matched
3.Entity C/B/D - 2 tags matched
4.Entity B/D/C - 2 tags matched
5.Entity A - 1 tag matched
实现相同目标的最佳方法是什么??
【问题讨论】:
标签: search full-text-search mongodb