<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # MongoDB 全文檢索 全文檢索對每一個詞建立一個索引,指明該詞在文章中出現的次數和位置,當用戶查詢時,檢索程序就根據事先建立的索引進行查找,并將查找的結果反饋給用戶的檢索方式。 這個過程類似于通過字典中的檢索字表查字的過程。 MongoDB 從 2.4 版本開始支持全文檢索,目前支持15種語言(暫時不支持中文)的全文索引。 * danish * dutch * english * finnish * french * german * hungarian * italian * norwegian * portuguese * romanian * russian * spanish * swedish * turkish ## 啟用全文檢索 MongoDB 在 2.6 版本以后是默認開啟全文檢索的,如果你使用之前的版本,你需要使用以下代碼來啟用全文檢索: ``` >db.adminCommand({setParameter:true,textSearchEnabled:true}) ``` 或者使用命令: ``` mongod --setParameter textSearchEnabled=true ``` ## 創建全文索引 考慮以下 posts 集合的文檔數據,包含了文章內容(post_text)及標簽(tags): ``` { "post_text": "enjoy the mongodb articles on w3cschool.cc", "tags": [ "mongodb", "w3cschool" ] } ``` 我們可以對 post_text 字段建立全文索引,這樣我們可以搜索文章內的內容: ``` >db.posts.ensureIndex({post_text:"text"}) ``` ## 使用全文索引 現在我們已經對 post_text 建立了全文索引,我們可以搜索文章中的關鍵詞w3cschool.cc: ``` >db.posts.find({$text:{$search:"w3cschool.cc"}}) ``` 以下命令返回了如下包含w3cschool.cc關鍵詞的文檔數據: ``` { "_id" : ObjectId("53493d14d852429c10000002"), "post_text" : "enjoy the mongodb articles on w3cschool.cc", "tags" : [ "mongodb", "w3cschool" ] } { "_id" : ObjectId("53493d1fd852429c10000003"), "post_text" : "writing tutorials on w3cschool.cc", "tags" : [ "mongodb", "tutorial" ] } ``` 如果你使用的是舊版本的MongoDB,你可以使用以下命令: ``` >db.posts.runCommand("text",{search:" w3cschool.cc"}) ``` 使用全文索引可以提高搜索效率。 ## 刪除全文索引 刪除已存在的全文索引,可以使用 find 命令查找索引名: ``` >db.posts.getIndexes() ``` 通過以上命令獲取索引名,本例的索引名為post_text_text,執行以下命令來刪除索引: ``` >db.posts.dropIndex("post_text_text") ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看