【问题标题】:MongoDB search with multiple keywords and sorted result使用多个关键字和排序结果进行 MongoDB 搜索
【发布时间】:2017-05-01 01:41:54
【问题描述】:

我有 mongo 文档,其中包含有关组织中员工的数据。 我想用多个关键字搜索文档并获得更好的结果。

    eg:**search with "Java, Spring, Hibernate, HTML"** 

should return documents which contains whole keywords and with maximum
number of keywords and so on until it reaches with at least any of the keyword.
Please help me to solve this problem.

【问题讨论】:

    标签: java mongodb search text search-engine


    【解决方案1】:

    试一试:

     db.collection_name.find("text", {search:"Java spring hibernate html"})
    

    $text 对使用文本索引索引的字段的内容执行文本搜索。 $text 表达式具有以下语法:

    在 3.2 版中更改。

    {
    $text:
    {
      $search: <string>,
      $language: <string>,
      $caseSensitive: <boolean>,
      $diacriticSensitive: <boolean>
      }
    }
    

    请记住,这将返回与单个术语(例如仅 java 或 html)匹配的文档。

    【讨论】:

    • 感谢您的回答。我明白了,但我需要知道是否有任何方法可以找到包含全部内容的文档,如果不是,那么至少 3 个关键字,然后是 2 个,然后是 1 个等
    • 是的,这种方法可以找到包含一个关键字和全部或更少的文档。搜索方法将返回带有 Java 或 spring 或 hibernate 或 html 甚至 2 个或更多关键字的文档。尝试使用一次。
    猜你喜欢
    • 2012-01-24
    • 1970-01-01
    • 2018-03-04
    • 1970-01-01
    • 2012-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-03
    相关资源
    最近更新 更多