麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 數據庫 > MongoDB > 正文

mongodb處理中文索引與查找字符串詳解

2020-03-14 12:58:32
字體:
來源:轉載
供稿:網友

參考文獻

首先自打3.2版本之后,就開始支持中文索引了,支持的所有的語言參考這里:

https://docs.mongodb.com/manual/reference/text-search-languages/

然后,對于要支持索引的表需要建議text index,如何建立參考這里:

https://docs.mongodb.com/manual/core/index-text/

在建好索引text之后,如果檢索參考:

https://docs.mongodb.com/manual/reference/operator/query/text/

實例

我有一個表,定義如下:

var ArticleSchema = new Schema({ created: { type: Date, default: Date.now }, title: { type: String, default: '', trim: true, required: 'Title cannot be blank' }, abstract: { type: String, default: '', trim: true }, abstractImg: { type: String, default: 'http://www.doocr.com/modules/core/client/img/brand/font-ocr.png', trim: true }, content: { type: String, default: '', trim: true }, category: { type: String, default: 'news', trim: true }, user: { type: Schema.ObjectId, ref: 'User' }, toPublish: { type: Boolean, default: true }, comments: [CommentSchema] });

然后,里面有數據的,所以我直接檢索,得到結果:

> db.articles.find( { $text: { $search: "coffee" } } )Error: error: { "waitedMS" : NumberLong(0), "ok" : 0, "errmsg" : "text index required for $text query", "code" : 27}

說明沒有建議text索引,那么建一個:

db.articles.createIndex( {title: "text", content: "text" })

看看效果:

> db.articles.createIndex(... {... title: "text",... content: "text"... }... )

下面是結果,成功了

{ "createdCollectionAutomatically" : false, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1}

然后我開始檢索:

> db.articles.find( { $text: { $search: "coffee" } } )

什么都沒有。

我檢索一個存在的中文:

> db.articles.find( { $text: { $search: "操作" } } ){ "_id" : ObjectId("58b0eb5a136dc51b541eaf81"), "user" : ObjectId("589c8d22f7d9dc15989be255"), "comments" : [ ], "toPublish" : true, "category" : "blog", "content" : "<p> </p><p><br/></p><p>其實就是使用ubuntu 16的安裝方式,參考網址:</p><p><a href=/"https://docs.mongodb/202794.html">mongodb.com/master/tutorial/install-mongodb-on-ubuntu//" target=/"_blank/">https://docs.mongodb.com/master/tutorial/install-mongodb-on-ubuntu/</a></p><p><br/></p><p>我的操作步驟:</p><pre>1.倒入key:sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927</pre><p><br/></p><p>2. 創建mongodb的軟件源:</p><p>/etc/apt/sources.list.d/mongodb-org-3.2.list</p><p>操作:</p><pre>echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list</pre><p><br/></p><p>3. 更新系統:</p><p>sudo apt update</p><p>之后查看所有可以更新的軟件:</p><p>sudo apt list --upgradable</p><p>然后升級所有軟件:</p><p>sudo apt upgrade</p><p><br/></p><p>4. 安裝mongodb :</p><p>sudo apt install -y mongodb-org</p><p>也可以指定版本安裝:</p><p>sudo apt-get install -y mongodb-org=3.2.8 mongodb-org-server=3.2.8 mongodb-org-shell=3.2.8 mongodb-org-mongos=3.2.8 mongodb-org-tools=3.2.8</p><p>不過我不使用這種方式。</p><p><br/></p><p>5. 添加systemd 自啟動條目:</p><p>sudo vim /lib/systemd/system/mongod.service</p><p>添加內容:</p><p>[Unit]</p><p>Description=High-performance, schema-free document-oriented database</p><p>After=network.target</p><p>Documentation=https://docs.mongodb.org/manual</p><p><br/></p><p>[Service]</p><p>User=mongodb</p><p>Group=mongodb</p><p>ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf</p><p><br/></p><p>[Install]</p><p>WantedBy=multi-user.target</p><p><br/></p><h2>6. 使能和啟動服務:</h2><p>sudo systemctl enable mongod.service</p><p>sudo systemctl start mongod.service</p><p><br/></p><h2>查看狀態,一切ok。</h2><p>sudo systemctl status mongod.service</p><p>● mongod.service - High-performance, schema-free document-oriented database</p><p>Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)</p><p>Active: active (running) since Sun 2016-07-31 21:59:00 CST; 13min ago</p><p>Docs: https://docs.mongodb.org/manual</p><p>Main PID: 19374 (mongod)</p><p>CGroup: /system.slice/mongod.service</p><p>└─19374 /usr/bin/mongod --quiet --config /etc/mongod.conf</p><p><br/></p><p>Jul 31 21:59:00 mint systemd[1]: Started High-performance, schema-free document-oriented database.</p><p><br/></p><p>7. 查看服務啟動端口是否ok:</p><p>azuo1228@mint ~/webproj/mjs2/meanjs $ netstat -apn | grep mong</p><p>(Not all processes could be identified, non-owned process info</p><p>will not be shown, you would have to be root to see it all.)</p><p>unix 2 [ ACC ] STREAM LISTENING 76731 - /tmp/mongodb-27017.sock</p><p><br/></p><p><br/></p>", "abstractImg" : "http://www.doocr.com/modules/core/client/img/brand/font-ocr.png", "abstract" : "其實就是使用ubuntu 16的安裝方式,參考網址:", "title" : "其實就是使用ubuntu 16的安裝方式,參考網址:", "created" : ISODate("2017-02-25T02:26:34.483Z"), "__v" : 0 }>

最后

但是這種檢索都是不完美的,如果需要更好的支持,就需要參考:

https://docs.mongodb.com/manual/tutorial/text-search-with-rlp/

安裝rlp支持mongodb檢索中文,但是不是免費的。。。

所以,最好的方式就是使用Elastic Search同步mongodb,然后通過它檢索,超出本文范圍了,以后再說。

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對VEVB武林網的支持。


注:相關教程知識閱讀請移步到MongoDB頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 国产精品久久久久网站 | 久久99国产精品久久 | 手机在线看片国产 | 蜜桃久久一区二区三区 | 毛片电影网址 | 免费在线看黄 | 在线播放免费视频 | 性高湖久久久久久久久aaaaa | 精久久久| 午夜视频在线观看免费视频 | videos高潮| 成人福利在线观看 | 水多视频在线观看 | 久久免费观看一级毛片 | 国产精品自拍av | 欧美a级一区二区 | 女人叉开腿让男人桶 | 国产成人高潮免费观看精品 | 中文字幕www| 免费99热在线观看 | 一区二区久久电影 | 91免费高清视频 | 欧美性生活久久 | 91成人在线免费 | h视频在线免费观看 | 成人黄色短视频在线观看 | 久久久久久久久久久久久久av | 成熟女人特级毛片www免费 | 欧美成人一区二区三区 | 久草手机在线观看视频 | 男女生羞羞视频网站在线观看 | 海外中文字幕在线观看 | 97久久曰曰久久久 | 亚洲国产精品久久久久久久久久久 | 韩国一大片a毛片 | www国产免费 | 草免费视频 | 免费看a级片 | 精国产品一区二区三区四季综 | 久久视讯 | 国产成人精品区 |