请建议 mongoDB 全文搜索的最佳解决方案
我的数据库中的文档有名称和描述以及其他字段。我想允许用户通过提供一些关键字来搜索这些文档。应该使用关键字在名称和描述字段中进行查找。我已阅读 有关全文搜索的 mongoDB 文档如果我想在文档的名称字段中搜索关键字,它看起来真的很好很容易。但是,描述字段包含自由格式的文本,最多可以包含 2000 个字符,因此每个文档可能有几百个单词。我可以像对待名称一样对待它们,只需将整个描述分成单独的单词并将其存储为另一个类似标签的数组(按照 Mongo 示例),但这似乎是一个糟糕的主意 - 每个文档的大小几乎会增加一倍,另外还有点、逗号等字符。
我知道有针对此类问题的专门解决方案,我只是在查看 Lucene.Net,我还看到到处提到 Solr。
我应该在 mongoDB 中实现此搜索功能还是应该使用专门的解决方案?目前我只有一个 mongod 实例和一个 Web 服务器实例。我们稍后可能需要扩展,但目前我只使用这些。对于如何实现此功能的任何建议,我将不胜感激。
The documents in my database have names and descriptions among other fields. I would like to allow the users to search for those documents by providing some keywords. The keywords should be used to lookup in both the name and the description field. I've read the mongoDB documentation on full text search and it looks really nice and easy if I want to search for keywords in the name field of my documents. However, the description field contains free form text and can take up to 2000 characters, so potentially there are a few hundred words per document. I could treat them the same way as names and just split the whole description into separate words and store it as another tag-like array (as per the Mongo example), but it seems like a terrible idea - each document's size could be almost doubled, plus there are characters like dots, commas, etc.
I know there are specialized solutions for exactly this kind of problems and I was just looking at Lucene.Net, I also saw Solr mentioned here and there.
Should I be looking to implement this search feature in mongoDB or should I use a specialized solution? Currently I just have one instance of mongod and one instance of a web server. We might need to scale later, but for now that is all I use. I'd appreciate any suggestions on how to implement this feature.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果按照记录的方法将文本拆分到数组中存储不可行(我可以理解您的担忧),那么我认为您应该寻找专门的解决方案。
引用 MongoDB 文档:
因此,对于更高级的全文搜索功能,我认为专用引擎会更适合。我在这方面没有经验,所以我不能在这里提供太多建议,除了我在同一条船上的想法之外:
If storing the text split out into an array per the documented approach is not viable (I can understand your concerns), then I think you should look into a specialised solution.
Quote from the MongoDB documentation:
So, for more advanced full text search functionality I think a dedicated engine would be more suited. I have no experience in this area so I can't offer much in the way of suggestions from here, other than what my thoughts would be if I was in the same boat:
未来计划支持全文搜索。然而现在你必须选择 Solr 和 Solr。朋友们。使用内置的“全文”功能并不真正适合现实世界的使用。
Fulltext search support is planned for the future. However right now you have to go with Solr & friends. Using the built-in "fulltext" functionality is not really suitable for real world usage.