2
我正在使用mongodb進行簡單的標籤搜索,並將數據存儲在列表中。已預訂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']}
搜索字符串: '一個(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
會是什麼來達到同樣的最佳途徑?
當MongoDB返回1000個結果時,任何應用程序級別的實現都會非常低效。是不是有一些服務器端自定義JS實現?你能指出這個方向嗎? – Raj 2011-05-05 14:33:12
在這裏是正確的,在'sort()'中不支持應用函數。您實際上需要應用「最佳匹配」功能。 – 2011-05-05 22:23:45