如何使用mongoDB全文搜索获得更多相关结果

时间:2017-08-01 12:32:35

标签: mongodb full-text-search

我在架构中为name字段创建了索引。 这是我的代码。

`Product.find( {$text : {$search : "apple macbook pro"} }, {score : { $meta: "textScore" }}).sort({ score: { $meta: "textScore" }}).exec((err,res)=>{

      console.log("res is  "+JSON.stringify(res));
 })`

我的json回复是

[
{
"name":"Macbook Pro 13 and Pro Touch 13\" (2016, 2017) Case, Snugg Apple Macbook Pro 13 and Pro Touch 13\" (2016, 2017) Retina Cover [Deluxe Satin Touch] Ultra-Slim Shell Skin Design - Gold Marble", {
"name":"ProCase 12 - 12.9 Inch Laptop Sleeve Case Cover Bag for Macbook Surface Pro 4 3, Apple iPad Pro, Most 11\" 12\" Laptop Ultrabook Notebook MacBook Chromebook -Grey" }, {
"name":"Macbook Pro Touch 15\" (2016, 2017) Case, Snugg Apple Macbook Pro Touch 15\" (2016, 2017) Retina Cover [Deluxe Satin Touch] Ultra-Slim Shell Skin Design - Gold Marble" }, {
"name":"MacBook Pro 15 Case 2017 & 2016 A1707, ProCase Rubberized Hard Case Shell Cover and Keyboard Cover for Apple Macbook Pro 15\" (Newest 2017 & 2016 Release) with Touch Bar and Touch ID -Black" }, {
"name":"Apple MacBook Pro MC118LL/A 15.4-Inch Laptop" },
/ * I need to get this record at top as gave key word as apple macbook pro */ ]

我需要将最后一张唱片放在最前面,因为我给出了关键词#34; apple macbook pro"

请帮助我解决此问题,以获得更好的相关结果。

0 个答案:

没有答案