简体   繁体   English

加快搜寻速度

[英]Speed up search

I have collection with around 2.5million records. 我收集了约250万条记录。 Currently I'm using nodejs with mongoose. 目前,我正在使用nodejs和猫鼬。 I'm open to any suggestions which would improve efficiency of current search. 我愿意接受任何可以提高当前搜索效率的建议。

Artist collection schema is something like that: 艺术家收藏模式是这样的:

var Artist = new mongoose.Schema({
    realname: String,
    names: Array
});

User passes string for example: Michael Jackson was contacted by police or Michael Jackson-Jillie bean . 例如,用户传递字符串: 警察Michael Jackson-Jillie bean 联系了 Michael Jackson Now I have to find artist/singer/person so the only logical thing I could find was: Iterate through all documents in collection, check if any of names is in given string if YES we have match -> stop loop. 现在我必须找到艺术家/歌手/人物,所以我唯一能找到的逻辑就是:遍历集合中的所有文档,如果给定的字符串匹配,请检查给定的字符串中是否有任何名称->停止循环。

But this is very memory inefficient since it has to load whole collection to memory so nodejs can iterate through and check all records. 但这是非常低效的内存,因为它必须将整个集合加载到内存中,以便nodejs可以遍历并检查所有记录。

It seems that retrieving whole collection takes most of time. 似乎检索整个集合要花费大部分时间。 Any way to speed this up? 有什么办法可以加快速度吗? In mongoshell db.collection.find() is pretty fast. 在mongoshell中,db.collection.find()非常快。 But using mongoose in nodejs takes waaay too long. 但是在nodejs中使用猫鼬会花费很长时间。

  • Why is .find() so slow used with mongoose? 为什么.find()与猫鼬一起使用这么慢?
  • Are there any other databases for designed for this purpose? 是否还有其他为此目的设计的数据库?
  • How would you solve this problem more efficiently? 您将如何更有效地解决这个问题?
  • Could map reduce be for any use here? 地图可以在这里减少使用吗?

What you need is a full-text search. 您需要的是全文搜索。 Possible options: 可能的选择:

  • Use MongoDB text index . 使用MongoDB text索引 (new in 2.4) (2.4版中的新功能)
  • Use an addition full text index. 使用附加全文索引。 In my opinion elasticsearch is very performant and easy to understand for beginners. 在我看来, elasticsearch非常有效,对于初学者来说很容易理解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM