请建议 mongoDB 全文搜索的最佳解决方案

发布于 2024-10-22 17:32:54 字数 544 浏览 5 评论 0原文

我的数据库中的文档有名称和描述以及其他字段。我想允许用户通过提供一些关键字来搜索这些文档。应该使用关键字在名称和描述字段中进行查找。我已阅读 有关全文搜索的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

完美的未来在梦里 2024-10-29 17:32:54

如果按照记录的方法将文本拆分到数组中存储不可行(我可以理解您的担忧),那么我认为您应该寻找专门的解决方案。

引用 MongoDB 文档:

MongoDB 有有趣的功能
这使得某些搜索功能
简单的。也就是说,它不是专用的
全文搜索引擎。

因此,对于更高级的全文搜索功能,我认为专用引擎会更适合。我在这方面没有经验,所以我不能在这里提供太多建议,除了我在同一条船上的想法之外:

  • 使用专用全文搜索引擎涉及多少工作而不是 MongoDB 的功能?
  • 这会增加更多的复杂性/值得吗?
  • 使用 MongoDB 并占用额外的磁盘空间会更快/更简单吗?
  • 也许 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:

MongoDB has interesting functionality
that makes certain search functions
easy. That said, it is not a dedicated
full text search engine.

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:

  • how much work involved in using a dedicated full-text search engine instead of MongoDB's functionality?
  • does that add more complexity / is it worth it?
  • would it be quicker/simpler to use MongoDB and just take the hit on the extra disk space?
  • maybe MongoDB will support better full-text functionality in future (it is rapidly evolving after all)
奶气 2024-10-29 17:32:54

未来计划支持全文搜索。然而现在你必须选择 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文