UNPKG

494 Btext/coffeescriptView Raw
1lunr = require('lunr')
2
3index = null
4
5exports.loadIndex = (config) ->
6 indexDump = require(config.buildLunrIndex)
7
8 index = {
9 lunr: lunr.Index.load(indexDump.idx),
10 docs: indexDump.docsIdx
11 }
12
13exports.search = (searchTerm) ->
14 if not index?
15 throw new Error('Doxx: Lunr index must be loaded before using search.')
16
17 return index.lunr.search(searchTerm)
18 .map (result) ->
19 { ref } = result
20 return {
21 id: ref,
22 title: index.docs[ref],
23 link: '/' + ref
24 }