2016-06-15 26 views
0

私の製品コレクションにテキストインデックスがあります。このインデックスは、以下に示すように異なる重みを持つ3つの列を使用します。私が検索すると「りんご」と言えば、同じ商品が何回も返されることがわかります。しかし、1つの製品だけではなく、ほとんどの製品が複製されています。これは何が原因でしょうか?コレクションのインデックスを再作成する必要がありますか? おかげ複数のフィールドを持つMongoDBテキスト検索重複結果セット

{ 
    "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 
} 
+2

「Apple」を検索した後に出力を共有できますか? – Neville

+0

@Nev _idとObjectIdの間に問題があるようです。助言がありますか? – gamegeek24

+0

あなたが共有しているクエリ結果に基づいて、 '_id'フィールドにはObjectIdがいくつかあり、他にはありません。あなたはそのフィールドを上書きしていますか、それともすべての場合に自動生成されますか? 「Apple」の検索に使用したクエリは何ですか? – Neville

答えて

0

問題がsailsjsから.native()を使用することによって引き起こされました。これを使うと、システムはモデルを返さず、代わりに配列を返します。その配列内のオブジェクトはオブジェクト(objectId)として指定されたIDフィールドを持たないため、関連する文書(カート)にレコードを挿入する前に、それらを新しい製品と見なして製品コレクションに挿入します。文字列IDを使って製品ドキュメントを削除し、idフィールドの追加チェックをアプリに追加することで問題は解決されました。

関連する問題