赞
踩
> db.ttlsa_com.insert({"song":"1. Hotel California", "lyrics": "On a dark desert highway, cool wind in my hair. Warm smell of colitas, rising up through the air."})
> db.ttlsa_com.insert({"song":"2. Hotel California", "lyrics": "Up ahead in the distance, I saw a shimmering light. My head grew heavy and my sight grew dim."})
> db.ttlsa_com.insert({"song":"3. Hotel California", "lyrics": "Such a lovely place, Such a lovely face."})
> db.ttlsa_com.insert({"song":"4. Hotel California", "lyrics": "Some dance to remember, some dance to forget."})
> db.ttlsa_com.insert({"song":"5. Hotel California", "lyrics": "Welcome to the Hotel California"})
> db.ttlsa_com.insert({"song":"hell world", "lyrics": "Welcome to beijing"})
> db.ttlsa_com.insert({"song":"加州旅馆", "lyrics": "Welcome to the Hotel California"})
>db.system.indexes.find().toArray()
[{
"v": 1,
"key": {
"_id": 1
},
"name": "_id_",
"ns": "test.ttlsa_com"
},
{
"v": 1,
"key": {
"_fts": "text",
"_ftsx": 1
},
"name": "song__lyrics_",
"ns": "test.ttlsa_com",
"weights": {
"lyrics": 1,
"song": 1
},
"default_language": "english",
"language_override": "language",
"textIndexVersion": 2
}]
五、查询
> db.ttlsa_com.runCommand("text",{search:"Welcome"})
{
"results" : [
{
"score" : 0.6666666666666666,
"obj" : {
"_id" : ObjectId("550a615dd8511e4dbcb8c77a"),
"song" : "5. Hotel California",
"lyrics" : "Welcome to the Hotel California"
}
},
{
"score" : 0.6666666666666666,
"obj" : {
"_id" : ObjectId("550a6163d8511e4dbcb8c77b"),
"song" : "加州旅馆",
"lyrics" : "Welcome to the Hotel California"
}
}
],
"stats" : {
"nscanned" : 2,
"nscannedObjects" : 2,
"n" : 2,
"timeMicros" : 1486,
"shards" : {
"shard_a" : {
"nscanned" : NumberLong(2),
"nscannedObjects" : NumberLong(2),
"n" : 2,
"timeMicros" : 917
}
}
},
"ok" : 1
}
2.模糊搜索
> db.ttlsa_com.runCommand("text",{search:"Such lovely"})
{
"results" : [
{
"score" : 1.125,
"obj" : {
"_id" : ObjectId("550a6154d8511e4dbcb8c778"),
"song" : "3. Hotel California",
"lyrics" : "Such a lovely place, Such a lovely face."
}
}
],
"stats" : {
"nscanned" : 1,
"nscannedObjects" : 1,
"n" : 1,
"timeMicros" : 618,
"shards" : {
"shard_a" : {
"nscanned" : NumberLong(1),
"nscannedObjects" : NumberLong(1),
"n" : 1,
"timeMicros" : 272
}
}
},
"ok" : 1
}
3.匹配短语
> db.ttlsa_com.runCommand("text",{search:"\"Some dance to remember\""})
{
"results" : [
{
"score" : 1.75,
"obj" : {
"_id" : ObjectId("550a6158d8511e4dbcb8c779"),
"song" : "4. Hotel California",
"lyrics" : "Some dance to remember, some dance to forget."
}
}
],
"stats" : {
"nscanned" : 2,
"nscannedObjects" : 1,
"n" : 1,
"timeMicros" : 743,
"shards" : {
"shard_a" : {
"nscanned" : NumberLong(2),
"nscannedObjects" : NumberLong(1),
"n" : 1,
"timeMicros" : 306
}
}
},
"ok" : 1
}
4.匹配一些词但是不能包含指定的词
> db.ttlsa_com.runCommand("text",{search:"Welcome -California"})
{
"results" : [
{
"score" : 0.75,
"obj" : {
"_id" : ObjectId("550a687fd8511e4dbcb8c781"),
"song" : "hell world",
"lyrics" : "Welcome to beijing"
}
}
],
"stats" : {
"nscanned" : 4,
"nscannedObjects" : 4,
"n" : 1,
"timeMicros" : 743,
"shards" : {
"shard_a" : {
"nscanned" : NumberLong(4),
"nscannedObjects" : NumberLong(4),
"n" : 1,
"timeMicros" : 345
}
}
},
"ok" : 1
}
5.限制结果集条目
>db.ttlsa_com.runCommand("text",{search:"the"})
{
"results" : [ ],
"stats" : {
"nscanned" : 0,
"nscannedObjects" : 0,
"n" : 0,
"timeMicros" : 432,
"shards" : {
"shard_a" : {
"nscanned" : NumberLong(0),
"nscannedObjects" : NumberLong(0),
"n" : 0,
"timeMicros" : 151
}
}
},
"ok" : 1
}
就搜索不到的。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。