2016-07-11 67 views
0

我很好奇MongoDB用來存儲全文搜索索引的數據結構。我無法在文檔中找到任何關於此的描述。MongoDB如何在內部存儲全文搜索索引?

initial commit,現在看來似乎習慣用一個B-tree:

/* 
    * GO: sets the tree cursors on each term in terms, processes the terms by advancing 
    * the terms cursors and storing the partial 
    * results and lastly calculates the top results 
    * @param results, the priority queue containing the top results 
    * @param limit, number of results in the priority queue 
    */ 
    void FTSSearch::go(Results* results, unsigned limit) { 
     vector< shared_ptr<BtreeCursor> > cursors; 

     for (unsigned i = 0; i < _query.getTerms().size(); i++) { 
      const string& term = _query.getTerms()[i]; 
      BSONObj min = FTSIndexFormat::getIndexKey(MAX_WEIGHT, term, _indexPrefix); 
      BSONObj max = FTSIndexFormat::getIndexKey(0, term, _indexPrefix); 
      shared_ptr<BtreeCursor> c(BtreeCursor::make(_ns, _id, min, max, true, -1)); 
      cursors.push_back(c); 
     } 

但fts_search.cpp在當前版本中不存在,我無法找到任何的參考數據結構在current implementation

它仍然是一棵B樹嗎? (它曾經嗎?)它是一個特里?它有什麼不同嗎?

回答

2

根據fts_index_format.cpp的當前最新標籤r3.3.9,它仍然是BTree。

另外值得一提的是,文本索引會對索引條目的索引字段中的術語進行標記並進行分詞。文本索引爲集合中的每個文檔的每個索引字段中的每個唯一詞幹術語存儲一個索引條目。

有多個版本的文本索引,在MongoDB v3.2中,文本索引版本3是新的text索引的默認版本。另請參閱Text Indexes

+0

非常感謝您的幫助! – mmaluff