在 Mongo 文本搜索之前缩小集合
Narrowing down collection prior to Mongo text search
我有一个集合,它是一个看起来有点像这样的简单模式
VendorCategories = new SimpleSchema({
name: {
type: String,
label: "Category"
},
slug: {
type: String,
label: "Slug"
}
});
VendorsSchema = new SimpleSchema({
vendorName: {
type: String,
label: "Vendor Name",
min: 3,
},
vendorCategory: {
type: VendorCategories,
},
vendorDescription: {
type: String,
label: "Vendor Description",
min: 45,
},
});
我有一个 mongo 这个集合的索引设置,就像这样。
Vendors._ensureIndex({
'vendorName': 'text',
'vendorDescription': 'text',
'VendorCategories.name': 'text',
});
目前这是我使用 Mongo 文本搜索 https://docs.mongodb.org/v3.0/reference/operator/query/text/ 通过此索引搜索的出版物的样子
Meteor.publish('searchVendors', function(query) {
if (query) {
return Vendors.find({
$text: {
$search: query
}
}, {
fields: {
score: {
$meta: 'textScore'
}
},
sort: {
score: {
$meta: 'textScore'
}
}
});
} else {
return Vendors.find();
}
});
我的辅助方法看起来像这样。
vendorSearchResults: function() {
var category = FlowRouter.getQueryParam("category");//narrow by this first
var terms = FlowRouter.getQueryParam("terms");
Meteor.subscribe("searchVendors", terms);
if (terms) {
return Vendors.find({}, { sort: [["score", "desc"]] });
} else {
return Vendors.find({});
}
}
目前 returns 搜索与供应商名称和描述相匹配的所有 var 术语。但我想要实现的是首先将收集结果缩小到 vendorName 和 [=28= 之前的 vendorCategories.name ]vendorDescription 被搜索。
如有任何帮助,我们将不胜感激,感谢您的阅读。
$text
运算符可以与其他匹配条件结合使用:
return Vendors.find({
"VendorCategories.name": "Acme Corporation",
$text: {
$search: query
}
},
我有一个集合,它是一个看起来有点像这样的简单模式
VendorCategories = new SimpleSchema({
name: {
type: String,
label: "Category"
},
slug: {
type: String,
label: "Slug"
}
});
VendorsSchema = new SimpleSchema({
vendorName: {
type: String,
label: "Vendor Name",
min: 3,
},
vendorCategory: {
type: VendorCategories,
},
vendorDescription: {
type: String,
label: "Vendor Description",
min: 45,
},
});
我有一个 mongo 这个集合的索引设置,就像这样。
Vendors._ensureIndex({
'vendorName': 'text',
'vendorDescription': 'text',
'VendorCategories.name': 'text',
});
目前这是我使用 Mongo 文本搜索 https://docs.mongodb.org/v3.0/reference/operator/query/text/ 通过此索引搜索的出版物的样子
Meteor.publish('searchVendors', function(query) {
if (query) {
return Vendors.find({
$text: {
$search: query
}
}, {
fields: {
score: {
$meta: 'textScore'
}
},
sort: {
score: {
$meta: 'textScore'
}
}
});
} else {
return Vendors.find();
}
});
我的辅助方法看起来像这样。
vendorSearchResults: function() {
var category = FlowRouter.getQueryParam("category");//narrow by this first
var terms = FlowRouter.getQueryParam("terms");
Meteor.subscribe("searchVendors", terms);
if (terms) {
return Vendors.find({}, { sort: [["score", "desc"]] });
} else {
return Vendors.find({});
}
}
目前 returns 搜索与供应商名称和描述相匹配的所有 var 术语。但我想要实现的是首先将收集结果缩小到 vendorName 和 [=28= 之前的 vendorCategories.name ]vendorDescription 被搜索。
如有任何帮助,我们将不胜感激,感谢您的阅读。
$text
运算符可以与其他匹配条件结合使用:
return Vendors.find({
"VendorCategories.name": "Acme Corporation",
$text: {
$search: query
}
},