Browse Source

Fix search aliases not applying properly on versioned docs

Fixes #461.
Thibaut Courouble 9 years ago
parent
commit
c63be6889d
2 changed files with 13 additions and 4 deletions
  1. 4 1
      assets/javascripts/models/doc.coffee
  2. 9 3
      assets/javascripts/models/entry.coffee

+ 4 - 1
assets/javascripts/models/doc.coffee

@@ -39,10 +39,13 @@ class app.models.Doc extends app.Model
     "#{app.indexHost()}/#{@slug}/#{app.config.index_filename}?#{@mtime}"
 
   toEntry: ->
-    @entry ||= new app.models.Entry
+    return @entry if @entry
+    @entry = new app.models.Entry
       doc: @
       name: @fullName
       path: 'index'
+    @entry.addAlias(@name) if @version
+    @entry
 
   findEntryByPathAndHash: (path, hash) ->
     if hash and entry = @entries.findBy 'path', "#{path}##{hash}"

+ 9 - 3
assets/javascripts/models/entry.coffee

@@ -5,8 +5,13 @@ class app.models.Entry extends app.Model
 
   constructor: ->
     super
-    @text = app.Searcher.normalizeString(@name)
-    @text = applyAliases(@text)
+    @text = applyAliases(app.Searcher.normalizeString(@name))
+
+  addAlias: (name) ->
+    text = applyAliases(app.Searcher.normalizeString(name))
+    @text = [@text] unless Array.isArray(@text)
+    @text.push(if Array.isArray(text) then text[1] else text)
+    return
 
   fullPath: ->
     @doc.fullPath if @isIndex() then '' else @path
@@ -45,8 +50,9 @@ class app.models.Entry extends app.Model
     return string
 
   @ALIASES = ALIASES =
+    'angular': 'ng'
     'angular.js': 'ng'
-    'backbone': 'bb'
+    'backbone.js': 'bb'
     'c++': 'cpp'
     'coffeescript': 'cs'
     'elixir': 'ex'