【发布时间】:2017-09-08 10:40:13
【问题描述】:
我正在尝试使用 angular 2 在流星中进行全文搜索。有我的发布功能:
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);
但在每次订阅后集合包含新值(来自实际搜索)和旧值(来自旧搜索)。
这可能是什么原因?我能做些什么来避免这种情况?
【问题讨论】: