mongoDB全文索引

來源:互聯網
上載者:User

標籤:des   blog   http   io   ar   os   使用   sp   for   

相關文章:php使用Coreseek實現全文索引

Introduction
Mongo provides some functionality that is useful for text search and tagging.
MongoDB提供了一些擁有的功能用於全文檢索搜尋與標記。

Multikeys (Indexing Values in an Array)多建(數組中得索引值)
The Mongo multikey feature can automatically index arrays of values. Tagging is a good example of where this feature is useful. Suppose you have an article object/document which is tagged with some category names:

obj = {  name: "Apollo",  text: "Some text about Apollo moon landings",   //本文  tags: [ "moon", "apollo", "spaceflight" ]      //索引標記}

and that this object is stored in db.articles. The command

db.articles.ensureIndex( { tags: 1 } );
will index all the tags on the document, and create index entries for “moon”, “apollo” and “spaceflight” for that document.

索引使用例子
You may then query on these items in the usual way:

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

Apollo
The database creates an index entry for each item in the array. Note an array with many elements (hundreds or thousands) can make inserts very expensive. (Although for the example above, alternate implementations are equally expensive.)

Text Search
It is fairly easy to implement basic full text search using multikeys. What we recommend is having a field that has all of the keywords in it, something like:

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

Your code must split the title above into the keywords before saving. Note that this code (which is not part of Mongo DB) could do stemming, etc. too. (Perhaps someone in the community would like to write a standard module that does this…)

相關文章:php使用Coreseek實現全文索引

轉載請註明:FKBlog » mongoDB全文索引(http://www.fkblog.org/blog485)

mongoDB全文索引

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.