Added a new searchStrings property to level components to improve their search.

This commit is contained in:
Scott Erickson 2014-09-03 17:33:10 -07:00
parent 7fb89a9e7e
commit 65c0d74a79
2 changed files with 15 additions and 1 deletions
app/schemas/models
server/levels/components

View file

@ -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

View file

@ -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)