diff --git a/app/schemas/models/level_component.coffee b/app/schemas/models/level_component.coffee index 40e55800e..352573ad0 100644 --- a/app/schemas/models/level_component.coffee +++ b/app/schemas/models/level_component.coffee @@ -148,6 +148,10 @@ _.extend LevelComponentSchema.properties, type: 'boolean' title: 'Official' description: 'Whether this is an official CodeCombat Component.' + searchStrings: { + type: 'array' + items: { type: 'string' } + } c.extendBasicProperties LevelComponentSchema, 'level.component' c.extendSearchableProperties LevelComponentSchema diff --git a/server/levels/components/LevelComponent.coffee b/server/levels/components/LevelComponent.coffee index ffd7b6468..d5eb14672 100644 --- a/server/levels/components/LevelComponent.coffee +++ b/server/levels/components/LevelComponent.coffee @@ -10,7 +10,17 @@ LevelComponentSchema = new mongoose.Schema { LevelComponentSchema.plugin plugins.NamedPlugin LevelComponentSchema.plugin plugins.PermissionsPlugin LevelComponentSchema.plugin plugins.VersionedPlugin -LevelComponentSchema.plugin plugins.SearchablePlugin, {searchable: ['name', 'description', 'system']} +LevelComponentSchema.plugin plugins.SearchablePlugin, {searchable: ['name', 'searchStrings', 'description']} LevelComponentSchema.plugin plugins.PatchablePlugin +LevelComponentSchema.pre('save', (next) -> + name = @get('name') + strings = _.str.humanize(name).toLowerCase().split(' ') + for char, index in name + continue if index is 0 + continue if index is name.length - 1 + strings.push(name.slice(0,index).toLowerCase()) + @set('searchStrings', strings.join(' ')) + next() +) module.exports = LevelComponent = mongoose.model('level.component', LevelComponentSchema)