Fix a bug that throwing an error when enableLunrPipeline is off

Also, enableLunrPipeline option should match on restoring lunr.
This commit is contained in:
Seongjae Lee
2016-07-05 01:05:42 -07:00
parent 4eb6ada48a
commit a73b308639
2 changed files with 8 additions and 7 deletions
+2 -6
View File
@@ -18,15 +18,13 @@ class NotationalVelocityView extends SelectListView
@skipPopulateList = false
@prevCursorPosition = 0
@documentsLoaded = false
@noteWatcher = new NoteWatcher(@rootDirectory, atom.config.get('nvatom.extensions'), @maxItems)
@noteWatcher = new NoteWatcher(@rootDirectory, atom.config.get('nvatom.extensions'), @maxItems, atom.config.get('nvatom.enableLunrPipeline'))
@noteWatcher.on "ready", () =>
@documentsLoaded = true
@setLoading()
@populateList()
@noteWatcher.on "update", () =>
@populateList() if @documentsLoaded
unless atom.config.get('nvatom.enableLunrPipeline')
@noteWatcher.searchIndex.pipeline.reset()
isCursorProceeded: ->
editor = @filterEditorView.model
@@ -74,14 +72,12 @@ class NotationalVelocityView extends SelectListView
@show()
viewForItem: (item) ->
content = item.body[0...100]
$$ ->
@li class: 'two-lines', =>
@div class: 'primary-line', =>
@span "#{item.title}"
@div class: 'metadata', "#{item.modifiedAt.toLocaleDateString()}"
@div class: 'secondary-line', "#{content}"
@div class: 'secondary-line', "#{item.body}"
confirmSelection: ->
item = @getSelectedItem()
+6 -1
View File
@@ -11,9 +11,10 @@ module.exports =
class NoteWatcher extends EventEmitter
@cacheVersion = 0
constructor: (@_baseDirectory, @_extensions, @_maxItems) ->
constructor: (@_baseDirectory, @_extensions, @_maxItems, @_enableLunrPipeline) ->
@_maxItems = @_maxItems ? 100
@_extensions = @_extensions ? ['.txt', '.md']
@_enableLunrPipeline = @_enableLunrPipeline ? false
@_noteCache = new NoteCache(@_baseDirectory, @_maxItems)
@_restoreSearchIndex() || @_initSearchIndex()
@_startWatcher()
@@ -23,6 +24,7 @@ class NoteWatcher extends EventEmitter
cache = {
baseDirectory: @_baseDirectory,
extensions: @_extensions,
enableLunrPipeline: @_enableLunrPipeline,
version: @_cacheVersion,
searchIndex: JSON.stringify(@_searchIndex),
noteCache: @_noteCache.toJSON(),
@@ -51,6 +53,8 @@ class NoteWatcher extends EventEmitter
@field('title', { boost: 10 })
@field('body')
)
if !@_enableLunrPipeline
@_searchIndex.pipeline.reset()
_restoreSearchIndex: ->
cacheFilePath = path.join(@_baseDirectory, 'nvatom.cache')
@@ -59,6 +63,7 @@ class NoteWatcher extends EventEmitter
return false if cache == null
return false unless _.isEqual(cache.baseDirectory, @_baseDirectory)
return false unless _.isEqual(cache.extensions, @_extensions)
return false unless _.isEqual(cache.enableLunrPipeline, @_enableLunrPipeline)
return false unless _.isEqual(cache.version, @_cacheVersion)
@_searchIndex = lunr.Index.load(JSON.parse(cache.searchIndex))
# TODO: Make this as an interface. Old note cache does not have to know upsert, remove, ready and so on.