2016-02-26 62 views
0

我有以下兩個模式,如何在集合中的數組內部搜索流星?

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搜索名稱,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() 
}); 

在這種情況下,哪種方式最適合搜索值?

回答

0

看看這個Link。這裏說你應該使用關鍵字this