我有以下两种模式,
Schema.extraOptions = new SimpleSchema({
name: {
type: String
},
content: {
type: String
},
note: {
type: String
}
});
var wordFields = {
_id: {
type: String,
optional: true,
autoform: {
omit: true
}
},
name: {
type: String,
label: 'Name'
}
'extraOptions.$': {
type: Schema.extraOptions,
optional: true
}
};
如何在wordFields中搜索name,extraOptions.name和extraOptions.content?
我尝试使用easySearch
,但它没有按预期工作。
WordsIndex = new EasySearch.Index({
collection: Words,
fields: ['name', '_id', 'extraOptions' ],
selectorPerField: function (field, searchString) {
console.log("searchString " + searchString);
console.log("field " + field);
if ('extraOptions' === field) {
// return this selector if the email field is being searched
console.log("searchString " + searchString);
console.log("field " + field);
return {
extraOptions: {
$elemMatch: {
name: { '$regex' : '.*' + searchString + '.*', '$options' : 'i' },
content: { '$regex' : '.*' + searchString + '.*', '$options' : 'i' }
}
}
};
}
return this.defaultConfiguration().selectorPerField(field, searchString);
},
engine: new EasySearch.Minimongo()
});
在这种情况下,哪种方式最适合搜索值?