閱讀288 返回首頁    go 阿裏雲 go 技術社區[雲棲]


MongoDB 全文檢索和標簽功能

簡單翻譯。

原文:https://www.mongodb.org/display/DOCS/Full+Text+Search+in+Mongo


MongoDB是通過增加一個tags的數組來實現標簽功能(tagging)。


obj = {
  name:     "Apollo"     ,      
  text:  "Some text about Apollo moon landings", 
  tags: [ "moon"  ,  "apollo"    "spaceflight" , ]     
}


建立索引:

db.articles.ensureIndex( { tags: 1 } );


搜索:

//查找一個articles中標簽為"apollo"的文檔,並輸出這個文檔的name屬性。

> print(db.articles.findOne( { tags: "apollo"} ).name);  
Apollo


全文搜索則是把所有的文本分詞後放到一個keywords數組中,實質和tag功能一樣:


{ title :  " this    is fun" ,           
  _keywords : ["this", "is" , "fun"]
}


和專門的全文搜索引擎比較:

    MongoDB隻是內置功能可以實現全文搜索,它並不是一個專門的全文搜索引擎。

    專門的全文搜索引擎提供以下的功能:

        1.分詞

        2.排名(rank)查詢(MongoDB可以實現,但需要自已寫代碼)

        3.bulk index building

    盡管bulk index building可以讓索引很快地建立,但是這並不能達到實時的效果,MongoDB有一大好處,可以實時,傳統的工具很難達到這樣的效果。


實際使用的例子:

The Business Insider web site uses MongoDB for its blog search function in production.
Mark Watson's opinions on Java, Ruby, Lisp, AI, and the Semantic Web - A recipe example in Ruby.
Full text search with MongoDB at Flowdock

最後更新:2017-04-02 18:44:44

  上一篇:go 以大三本科生角度談計算機學習:關於開源產品與學習書籍
  下一篇:go 典型的 C++ 程序員成長經曆