0
林試圖在與角2流星全文檢索,這正是我發佈FUNC:流星全文搜索。在客戶認購後,收集包含舊的搜索結果
Meteor.publish("search", (searchValue) => {
console.log(searchValue);
if (searchValue) {
return Nutrition.find(
{$text: {$search: searchValue}},
{
// `fields` is where we can add MongoDB projections. Here we're causing
// each document published to include a property named `score`, which
// contains the document's search rank, a numerical value, with more
// relevant documents having a higher score.
fields: {
'name.long': 1,
score: {$meta: "textScore"}
},
// This indicates that we wish the publication to be sorted by the
// `score` property specified in the projection fields above.
sort: {
score: {$meta: "textScore"},
},
limit: 20
}
);
} else {
return Nutrition.find({})
}
});
和客戶端:
public searchProducts = _.debounce((query) => {
Meteor.subscribe('search', query);
Nutrition.find({}).subscribe(data=>{
console.log(data.length);
});
}, 500);
,但在每個訂閱集合包含新值(來自實際搜索)和舊值(來自舊搜索)之後。
這是什麼原因?我能做些什麼來避免這種情況?