日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
mongodbIndex(3)-創(chuàng)新互聯(lián)

全文索引

成都創(chuàng)新互聯(lián)主營歙縣網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,app軟件開發(fā)公司,歙縣h5小程序設(shè)計搭建,歙縣網(wǎng)站營銷推廣歡迎歙縣等地區(qū)企業(yè)咨詢

    MongoDB有一個特殊的索引用在文檔中搜索文本,之前的博客都是用精確匹配來查詢字符串,這些技術(shù)有一定的限制。在搜索大塊文本的速度非常慢,而且無法處理自然語言禮節(jié)的問題。全文本索引使用的是“倒排索引”的思想來做的,和當前非常開源的lucene(全文檢索)項目是一樣的思想來實現(xiàn)的。使用全文本索引可以非常快的進行文本搜索,MongoDB支持多種語言,可惜在免費版中,并不支持漢語。查MongoDB的官網(wǎng)可以看到,在企業(yè)版中安裝第三方插件可以支持中文的全文索引。

    使用全文本檢索需要專門開啟這個功能才能進行使用。啟動MongoDB時指定--setParameter textSearchEnabled=true選項,或者在運行時執(zhí)行setParameter命令,都可以啟用全文本索引。如 db.adminCommand({"setParameter":1,"textSearchEnabled":true});

例:

db.news.insert({"title":"SEOUL","context":"SEOUL, June 10 (Reuters) - South Korean prosecutors raided the offices of Lotte Group, the country's fifth-largest conglomerate, and several affiliates on Friday, dealing a further blow to its hotel unit's planned IPO, billed as the world's biggest this year."});

db.news.insert({"title":"Many Chinese people","context":"Many Chinese people think that a job on a diplomatic team is too good to quit. So when 28-year-old Liu Xiaoxi left her embassy post as an attache late last year to start a career in photography, she quickly became a popular topic among the Chinese online community."});

db.news.insert({"title":"About","context":"About 200 investigators searched 17 locations including group headquarters in central Seoul and the homes of Chairman Shin Dong-bin and other key executives, local news agency Yonhap reported, citing the Seoul Central Prosecutor's office."});

db.news.insert({"title":"Three people","context":"Three people with direct knowledge of the matter told Reuters that Friday's raids were part of an investigation into a possible slush fund. They also declined to be identified."});

db.news.insert({"title":"A Lotte Group spokesman","context":"A Lotte Group spokesman on Friday declined to comment on the reason for the raid, when asked whether it concerned a possible slush fund. He noted, however, that the situation was difficult given the IPO plans and Lotte Chemical's Axiall bid."});

db.news.insert({"title":"According","context":"According to bourse rules, the deadline for Hotel Lotte to list is July 27, six months from the preliminary approval for the IPO. If it needed to refile its prospectus to warn investors about risks from Friday's probe, which appeared likely, it would probably not be able to meet that deadline, an exchange official told Reuters on Friday."});

db.news.insert({"title":"Friday","context":"On Friday, dozens of Chinese tourists queued as usual to access elevators to the flagship Lotte Duty Free outlet in the group's headquarters complex, as TV cameras waited for investigators to emerge from office doors around the corner."});

db.news.insert({"title":"Named","context":"Named after the heroine of an 18th century Goethe novel, Lotte has grown from its founding in Japan 68 years ago as a maker of chewing gum to a corporate giant with interests ranging from hotels and retail to food and chemicals. The group has annual revenue of around $60 billion in Korea."});

db.news.insert({"title":"Hotel Lotte's","context":"Hotel Lotte's planned flotation of around 35 percent of its shares was intended to bring transparency and improve corporate governance at a group whose ownership structure is convoluted even by the opaque standards of South Korea's conglomerates."});

db.news.insert({"title":"Shares","context":"Shares in Lotte Shopping (023530.KS) , whose units Lotte Department Store and Lotte Home Shopping were raided, fell 1.6 percent on Friday. Lotte Himart (071840.KS) , a consumer electronics retailer, dropped 2.1 percent."});

> db.news.ensureIndex({"title":"text","context":"text"},{"weights":{"title":2,"context":1}})

{

"createdCollectionAutomatically" : false,

"numIndexesBefore" : 1,

"numIndexesAfter" : 2,

"ok" : 1

}

> db.news.find({$text:{$search:"flotation"}})

{ "_id" : ObjectId("57aa8a28fe5f255ba4328c0e"), "title" : "Hotel Lotte's", "context" : "Hotel Lotte's planned flotation of around 35 percent of its shares was intended to bring transparency and improve corporate governance at a group whose ownership structure is convoluted even by the opaque standards of South Korea's conglomerates." }

>

每個集合上最多只能有一個全文本索引,但是全文本索引可以包含多個字段。全文索引與“普通”的多鍵索引不同,全文本索引中的字段順序不重要:每個字段都被同等對待,可以為每個字段指定不同的權(quán)重來控制不同字段的相對重要性。

給title和context字段建立全文本索引,給title字段2的權(quán)重,context字段1的權(quán)重。(權(quán)重的范圍可以是1~1,000,000,000,默認權(quán)重是1)

2d索引

2d索引也是MongoDB最常用的地理空間索引之一,用于游戲地圖。2d索引用于扁平表面,而不是球體表面。如果用在球體表面上,在極點附近會出現(xiàn)大量的扭曲變形

> var map = [{

...  "gis" : {

...   "x" : 185,

...   "y" : 150

...  }

... },{

...  "gis" : {

...   "x" : 70,

...   "y" : 180

...  }

... },{

...  "gis" : {

...   "x" : 75,

...   "y" : 180

...  }

... },{

...  "gis" : {

...   "x" : 185,

...   "y" : 185

...  }

... },{

...  "gis" : {

...   "x" : 65,

...   "y" : 185

...  }

... },{

...  "gis" : {

...   "x" : 50,

...   "y" : 50

...  }

... },{

...  "gis" : {

...   "x" : 50,

...   "y" : 50

...  }

... },{

...  "gis" : {

...   "x" : 60,

...   "y" : 55

...  }

... },{

...  "gis" : {

...   "x" : 65,

...   "y" : 80

...  }

... },{

...  "gis" : {

...   "x" : 55,

...   "y" : 80

...  }

... },{

...  "gis" : {

...   "x" : 0,

...   "y" : 0

...  }

... },{

...  "gis" : {

...   "x" : 0,

...   "y" : 200

...  }

... },{

...  "gis" : {

...   "x" : 200,

...   "y" : 0

...  }

... },{

...  "gis" : {

...   "x" : 200,

...   "y" : 200

...  }

... }]

>

> for(var i=0;i

WriteResult({ "nInserted" : 1 })

> db.map.ensureIndex({gis:"2d"},{min:-1,max:201})

{

"createdCollectionAutomatically" : false,

"numIndexesBefore" : 1,

"numIndexesAfter" : 2,

"ok" : 1

}

查詢(70,180)最近的3個點

> db.map.find({"gis":{$near:[70,180]}}).limit(3)

{ "_id" : ObjectId("57ab8ac5893a4e222430fcc1"), "gis" : { "x" : 70, "y" : 180 } }

{ "_id" : ObjectId("57ab8ac5893a4e222430fcc2"), "gis" : { "x" : 75, "y" : 180 } }

{ "_id" : ObjectId("57ab8ac5893a4e222430fcc4"), "gis" : { "x" : 65, "y" : 185 } }

>

查詢以點(50,50)和點(190,190)為對角線的正方形中的所有點:

> db.map.find({gis:{"$within":{$box:[[50,50],[190,190]]}}},{_id:0,gis:1})

{ "gis" : { "x" : 50, "y" : 50 } }

{ "gis" : { "x" : 50, "y" : 50 } }

{ "gis" : { "x" : 60, "y" : 55 } }

{ "gis" : { "x" : 55, "y" : 80 } }

{ "gis" : { "x" : 65, "y" : 80 } }

{ "gis" : { "x" : 65, "y" : 185 } }

{ "gis" : { "x" : 70, "y" : 180 } }

{ "gis" : { "x" : 75, "y" : 180 } }

{ "gis" : { "x" : 185, "y" : 150 } }

{ "gis" : { "x" : 185, "y" : 185 } }

查詢出以(56,80)為圓心,半徑為50,圓面積中的點,如下所示:

> db.map.find({gis:{"$within":{$center:[[56,80],50]}}},{_id:0,gis:1})

{ "gis" : { "x" : 50, "y" : 50 } }

{ "gis" : { "x" : 50, "y" : 50 } }

{ "gis" : { "x" : 60, "y" : 55 } }

{ "gis" : { "x" : 55, "y" : 80 } }

{ "gis" : { "x" : 65, "y" : 80 } }

查看三角形內(nèi)的所有點,如下所示:

> db.map.find({"gis": {"$within":{"$polygon":[[50,70],[70,90],[90,70]]}} })

{ "_id" : ObjectId("57ab8ac5893a4e222430fcc8"), "gis" : { "x" : 65, "y" : 80 } }

>多邊形,可以指定$polygon($ploygon接受一個多元素的數(shù)組,每個元素對應(yīng)多邊形的點)

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。


本文標題:mongodbIndex(3)-創(chuàng)新互聯(lián)
網(wǎng)站URL:http://www.dlmjj.cn/article/hocjd.html