0

我的产品集合上有一个文本索引。该索引使用具有不同权重的 3 列,如下所示。当我搜索让我们说“苹果”时,我看到多次返回相同的产品。但是,它不仅适用于一种产品,而且大多数产品都是重复的。这可能是什么原因?我需要重新索引我的收藏吗?谢谢

{
    "v": 1,
    "key": {
        "_fts": "text",
        "_ftsx": 1
    },
    "name": "searchCollection",
    "ns": "local.product",
    "weights": {
        "categoryList": 3,
        "productInformation": 1,
        "title": 5
    },
    "default_language": "english",
    "language_override": "language",
    "textIndexVersion": 2
}

这是结果:

/* 0 */
{
    "_id": ObjectId("56b122913fa3dac80849fa54"),
    "title": "Apple - Apple TV - Black",
    "urlTitle": "apple---apple-tv---black",
    "price": 75.0,
    "imageList": ["https://test.s3.amazonaws.com/test.png"],
    "boxPrice": 1.0,
    "upcCode": "IBXBB4854433",
    "categoryList": "electronics,televisions & home theater,home theater accessories,apple home theater accessories,Apple,",
    "productInformation": "<div class=\"feature\">\r\n<h4>1080p capability</h4>\r\n<p>Watch high-resolution movies and TV shows from the iTunes Store; view videos and photos from the Internet and your Mac or PC in crisp 1080p.</p>\r\n</div></div>",
    "productSpecification": "&lt;p&gt;Get access to a world of instant entertainment with this product. Just connect to the Internet and stream movies, listen to music, and access a wide variety of other content.&lt;/p&gt;",
    "user": "1",
    "isPromoted": false,
    "createdAt": ISODate("2016-02-02T21:41:37.508Z"),
    "updatedAt": ISODate("2016-06-15T02:52:39.761Z"),
    "weight": "2",
    "productOptions": null,
    "hiddenPrice": "69.99",
    "viewCount": 8.0
}

/* 1 */
{
    "_id": "56b122913fa3dac80849fa54",
    "title": "Apple - Apple TV - Black",
    "urlTitle": "apple---apple-tv---black",
    "price": 75.0,
    "imageList": ["https://test.s3.amazonaws.com/test.png"],
    "boxPrice": 1.0,
    "upcCode": "IBXBB4854433",
    "categoryList": "electronics,televisions & home theater,home theater accessories,apple home theater accessories,Apple,",
    "productInformation": "<div class=\"feature\">\r\n<h4>1080p capability</h4>\r\n<p>Watch high-resolution movies and TV shows from the iTunes Store; view videos and photos from the Internet and your Mac or PC in crisp 1080p.</p>\r\n</div></div>",
    "productSpecification": "&lt;p&gt;Get access to a world of instant entertainment with this product. Just connect to the Internet and stream movies, listen to music, and access a wide variety of other content.&lt;/p&gt;",
    "user": "1",
    "isPromoted": false,
    "createdAt": ISODate("2016-02-02T21:41:37.508Z"),
    "updatedAt": ISODate("2016-03-30T14:33:42.731Z"),
    "weight": "2",
    "productOptions": null,
    "hiddenPrice": "69.99",
    "viewCount": 1.0,
    "score": 9.231043781725889
}

/* 2 */
{
    "_id": ObjectId("57028d1d610bb00300e8b293"),
    "user": null,
    "title": "Apple Wired Mouse",
    "urlTitle": "apple-wired-mouse",
    "categoryList": "electronics,computers,computer accessories,apple computer accessories,Apple,",
    "boxPrice": 1.0,
    "imageList": ["https://test.s3.amazonaws.com/test.jpg"],
    "price": 47.0,
    "weight": "1",
    "productInformation": "<p style=\"color: rgb(0, 0, 0);background-color: rgb(255, 255, 255);\">It’s the wired mouse that reinvents the wheel — t</ul>",
    "productOptions": null,
    "hiddenPrice": "44",
    "isPromoted": false,
    "upcCode": "MB112LLB",
    "createdAt": ISODate("2016-04-04T15:49:49.760Z"),
    "updatedAt": ISODate("2016-06-14T13:15:11.174Z"),
    "viewCount": 1.0
}

/* 3 */
{
    "_id": "57028d1d610bb00300e8b293",
    "user": null,
    "title": "Apple Wired Mouse",
    "urlTitle": "apple-wired-mouse",
    "categoryList": "electronics,computers,computer accessories,apple computer accessories,Apple,",
    "boxPrice": 1.0,
    "imageList": ["https://test.s3.amazonaws.com/test.jpg"],
    "price": 47.0,
    "weight": "1",
    "productInformation": "<p style=\"color: rgb(0, 0, 0);background-color: rgb(255, 255, 255);\">It’s the wired mouse that reinvents the wheel</ul>",
    "productOptions": null,
    "hiddenPrice": "44",
    "isPromoted": false,
    "upcCode": "MB112LLB",
    "createdAt": ISODate("2016-04-04T15:49:49.760Z"),
    "updatedAt": ISODate("2016-04-07T13:22:09.108Z"),
    "score": 7.170701054107839
}

/* 4 */
{
    "_id": ObjectId("57028390610bb00300e8b286"),
    "user": null,
    "title": "Nomad Silver Stand Apple Watch Charger",
    "urlTitle": "nomad-silver-stand-apple-watch-charger",
    "categoryList": "watches,womens smart watches,mens smart watches,computer accessories,apple womens smart watches,apple mens smart watches,apple computer accessories,nomad womens smart watches,nomad mens smart watches,nomad computer accessories,Apple,Nomad,",
    "boxPrice": 1.0,
    "imageList": ["https://test.s3.amazonaws.com/test.jpg"],
    "price": 39.0,
    "weight": "1",
    "productInformation": "<p style=\"color: rgb(0, 0, 0);background-color: rgb(255, 255, 255);\">Keep your Apple Watch safe and secure while </ul>",
    "productOptions": null,
    "hiddenPrice": "30",
    "isPromoted": false,
    "upcCode": "STAND-APPLE-S-001",
    "createdAt": ISODate("2016-04-04T15:09:04.884Z"),
    "updatedAt": ISODate("2016-06-14T12:43:10.327Z"),
    "viewCount": 1.0
}
4

1 回答 1

0

该问题是由使用sailsjs 中的.native() 引起的。当我使用它时,系统不会返回模型,而是返回一个数组。由于该数组中的对象没有将其 id 字段指定为对象 (objectId),因此系统将它们视为新产品,并在将记录插入相关文档 (cart) 之前将它们插入产品集合中。删除带有字符串 id 的产品文档并在应用程序中添加额外的 id 字段检查解决了该问题。

于 2016-06-20T02:43:09.140 回答