mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-29 23:43:51 -04:00
Added a new searchStrings property to level components to improve their search.
This commit is contained in:
parent
7fb89a9e7e
commit
65c0d74a79
2 changed files with 15 additions and 1 deletions
|
@ -148,6 +148,10 @@ _.extend LevelComponentSchema.properties,
|
||||||
type: 'boolean'
|
type: 'boolean'
|
||||||
title: 'Official'
|
title: 'Official'
|
||||||
description: 'Whether this is an official CodeCombat Component.'
|
description: 'Whether this is an official CodeCombat Component.'
|
||||||
|
searchStrings: {
|
||||||
|
type: 'array'
|
||||||
|
items: { type: 'string' }
|
||||||
|
}
|
||||||
|
|
||||||
c.extendBasicProperties LevelComponentSchema, 'level.component'
|
c.extendBasicProperties LevelComponentSchema, 'level.component'
|
||||||
c.extendSearchableProperties LevelComponentSchema
|
c.extendSearchableProperties LevelComponentSchema
|
||||||
|
|
|
@ -10,7 +10,17 @@ LevelComponentSchema = new mongoose.Schema {
|
||||||
LevelComponentSchema.plugin plugins.NamedPlugin
|
LevelComponentSchema.plugin plugins.NamedPlugin
|
||||||
LevelComponentSchema.plugin plugins.PermissionsPlugin
|
LevelComponentSchema.plugin plugins.PermissionsPlugin
|
||||||
LevelComponentSchema.plugin plugins.VersionedPlugin
|
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.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)
|
module.exports = LevelComponent = mongoose.model('level.component', LevelComponentSchema)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue