码迷,mamicode.com
首页 > 数据库 > 详细

mongoDB全文索引

时间:2014-11-11 18:52:00      阅读:238      评论:0      收藏:0      [点我收藏+]

标签: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全文索引

标签:des   blog   http   io   ar   os   使用   sp   for   

原文地址:http://www.cnblogs.com/seasonzone/p/4090116.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!