| 1 |
/** |
| 2 |
* export the module via AMD, CommonJS or as a browser global |
| 3 |
* Export code from https://github.com/umdjs/umd/blob/master/returnExports.js |
| 4 |
*/ |
| 5 |
;(function (root, factory) { |
| 6 |
if (typeof define === 'function' && define.amd) { |
| 7 |
// AMD. Register as an anonymous module. |
| 8 |
define(factory) |
| 9 |
} else if (typeof exports === 'object') { |
| 10 |
/** |
| 11 |
* Node. Does not work with strict CommonJS, but |
| 12 |
* only CommonJS-like environments that support module.exports, |
| 13 |
* like Node. |
| 14 |
*/ |
| 15 |
module.exports = factory() |
| 16 |
} else { |
| 17 |
// Browser globals (root is window) |
| 18 |
factory()(root.lunr); |
| 19 |
} |
| 20 |
}(this, function () { |
| 21 |
/** |
| 22 |
* Just return a value to define the module export. |
| 23 |
* This example returns an object, but the module |
| 24 |
* can return a function as the exported value. |
| 25 |
*/ |
| 26 |
return function(lunr) { |
| 27 |
/* Set up the pipeline for indexing content in multiple languages. The |
| 28 |
corresponding lunr.{lang} files must be loaded before calling this |
| 29 |
function; English ('en') is built in. |
| 30 |
|
| 31 |
Returns: a lunr plugin for use in your indexer. |
| 32 |
|
| 33 |
Known drawback: every word will be stemmed with stemmers for every |
| 34 |
language. This could mean that sometimes words that have the same |
| 35 |
stemming root will not be stemmed as such. |
| 36 |
*/ |
| 37 |
lunr.multiLanguage = function(/* lang1, lang2, ... */) { |
| 38 |
var languages = Array.prototype.slice.call(arguments); |
| 39 |
var nameSuffix = languages.join('-'); |
| 40 |
var wordCharacters = ""; |
| 41 |
var pipeline = []; |
| 42 |
var searchPipeline = []; |
| 43 |
for (var i = 0; i < languages.length; ++i) { |
| 44 |
if (languages[i] == 'en') { |
| 45 |
wordCharacters += '\\w'; |
| 46 |
pipeline.unshift(lunr.stopWordFilter); |
| 47 |
pipeline.push(lunr.stemmer); |
| 48 |
searchPipeline.push(lunr.stemmer); |
| 49 |
} else { |
| 50 |
wordCharacters += lunr[languages[i]].wordCharacters; |
| 51 |
if (lunr[languages[i]].stopWordFilter) { |
| 52 |
pipeline.unshift(lunr[languages[i]].stopWordFilter); |
| 53 |
} |
| 54 |
if (lunr[languages[i]].stemmer) { |
| 55 |
pipeline.push(lunr[languages[i]].stemmer); |
| 56 |
searchPipeline.push(lunr[languages[i]].stemmer); |
| 57 |
} |
| 58 |
} |
| 59 |
}; |
| 60 |
var multiTrimmer = lunr.trimmerSupport.generateTrimmer(wordCharacters); |
| 61 |
lunr.Pipeline.registerFunction(multiTrimmer, 'lunr-multi-trimmer-' + nameSuffix); |
| 62 |
pipeline.unshift(multiTrimmer); |
| 63 |
|
| 64 |
return function() { |
| 65 |
this.pipeline.reset(); |
| 66 |
|
| 67 |
this.pipeline.add.apply(this.pipeline, pipeline); |
| 68 |
|
| 69 |
// for lunr version 2 |
| 70 |
// this is necessary so that every searched word is also stemmed before |
| 71 |
// in lunr <= 1 this is not needed, as it is done using the normal pipeline |
| 72 |
if (this.searchPipeline) { |
| 73 |
this.searchPipeline.reset(); |
| 74 |
this.searchPipeline.add.apply(this.searchPipeline, searchPipeline); |
| 75 |
} |
| 76 |
}; |
| 77 |
} |
| 78 |
} |
| 79 |
})); |