1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475 |
- ;(function(){
- var lunr = function (config) {
- var builder = new lunr.Builder
- builder.pipeline.add(
- lunr.trimmer,
- lunr.stopWordFilter,
- lunr.stemmer
- )
- builder.searchPipeline.add(
- lunr.stemmer
- )
- config.call(builder, builder)
- return builder.build()
- }
- lunr.version = "2.3.8"
- lunr.utils = {}
- lunr.utils.warn = (function (global) {
-
- return function (message) {
- if (global.console && console.warn) {
- console.warn(message)
- }
- }
-
- })(this)
- lunr.utils.asString = function (obj) {
- if (obj === void 0 || obj === null) {
- return ""
- } else {
- return obj.toString()
- }
- }
- lunr.utils.clone = function (obj) {
- if (obj === null || obj === undefined) {
- return obj
- }
- var clone = Object.create(null),
- keys = Object.keys(obj)
- for (var i = 0; i < keys.length; i++) {
- var key = keys[i],
- val = obj[key]
- if (Array.isArray(val)) {
- clone[key] = val.slice()
- continue
- }
- if (typeof val === 'string' ||
- typeof val === 'number' ||
- typeof val === 'boolean') {
- clone[key] = val
- continue
- }
- throw new TypeError("clone is not deep and does not support nested objects")
- }
- return clone
- }
- lunr.FieldRef = function (docRef, fieldName, stringValue) {
- this.docRef = docRef
- this.fieldName = fieldName
- this._stringValue = stringValue
- }
- lunr.FieldRef.joiner = "/"
- lunr.FieldRef.fromString = function (s) {
- var n = s.indexOf(lunr.FieldRef.joiner)
- if (n === -1) {
- throw "malformed field ref string"
- }
- var fieldRef = s.slice(0, n),
- docRef = s.slice(n + 1)
- return new lunr.FieldRef (docRef, fieldRef, s)
- }
- lunr.FieldRef.prototype.toString = function () {
- if (this._stringValue == undefined) {
- this._stringValue = this.fieldName + lunr.FieldRef.joiner + this.docRef
- }
- return this._stringValue
- }
- lunr.Set = function (elements) {
- this.elements = Object.create(null)
- if (elements) {
- this.length = elements.length
- for (var i = 0; i < this.length; i++) {
- this.elements[elements[i]] = true
- }
- } else {
- this.length = 0
- }
- }
- lunr.Set.complete = {
- intersect: function (other) {
- return other
- },
- union: function (other) {
- return other
- },
- contains: function () {
- return true
- }
- }
- lunr.Set.empty = {
- intersect: function () {
- return this
- },
- union: function (other) {
- return other
- },
- contains: function () {
- return false
- }
- }
- lunr.Set.prototype.contains = function (object) {
- return !!this.elements[object]
- }
- lunr.Set.prototype.intersect = function (other) {
- var a, b, elements, intersection = []
- if (other === lunr.Set.complete) {
- return this
- }
- if (other === lunr.Set.empty) {
- return other
- }
- if (this.length < other.length) {
- a = this
- b = other
- } else {
- a = other
- b = this
- }
- elements = Object.keys(a.elements)
- for (var i = 0; i < elements.length; i++) {
- var element = elements[i]
- if (element in b.elements) {
- intersection.push(element)
- }
- }
- return new lunr.Set (intersection)
- }
- lunr.Set.prototype.union = function (other) {
- if (other === lunr.Set.complete) {
- return lunr.Set.complete
- }
- if (other === lunr.Set.empty) {
- return this
- }
- return new lunr.Set(Object.keys(this.elements).concat(Object.keys(other.elements)))
- }
- lunr.idf = function (posting, documentCount) {
- var documentsWithTerm = 0
- for (var fieldName in posting) {
- if (fieldName == '_index') continue
- documentsWithTerm += Object.keys(posting[fieldName]).length
- }
- var x = (documentCount - documentsWithTerm + 0.5) / (documentsWithTerm + 0.5)
- return Math.log(1 + Math.abs(x))
- }
- lunr.Token = function (str, metadata) {
- this.str = str || ""
- this.metadata = metadata || {}
- }
- lunr.Token.prototype.toString = function () {
- return this.str
- }
- lunr.Token.prototype.update = function (fn) {
- this.str = fn(this.str, this.metadata)
- return this
- }
- lunr.Token.prototype.clone = function (fn) {
- fn = fn || function (s) { return s }
- return new lunr.Token (fn(this.str, this.metadata), this.metadata)
- }
- lunr.tokenizer = function (obj, metadata) {
- if (obj == null || obj == undefined) {
- return []
- }
- if (Array.isArray(obj)) {
- return obj.map(function (t) {
- return new lunr.Token(
- lunr.utils.asString(t).toLowerCase(),
- lunr.utils.clone(metadata)
- )
- })
- }
- var str = obj.toString().toLowerCase(),
- len = str.length,
- tokens = []
- for (var sliceEnd = 0, sliceStart = 0; sliceEnd <= len; sliceEnd++) {
- var char = str.charAt(sliceEnd),
- sliceLength = sliceEnd - sliceStart
- if ((char.match(lunr.tokenizer.separator) || sliceEnd == len)) {
- if (sliceLength > 0) {
- var tokenMetadata = lunr.utils.clone(metadata) || {}
- tokenMetadata["position"] = [sliceStart, sliceLength]
- tokenMetadata["index"] = tokens.length
- tokens.push(
- new lunr.Token (
- str.slice(sliceStart, sliceEnd),
- tokenMetadata
- )
- )
- }
- sliceStart = sliceEnd + 1
- }
- }
- return tokens
- }
- lunr.tokenizer.separator = /[\s\-]+/
- lunr.Pipeline = function () {
- this._stack = []
- }
- lunr.Pipeline.registeredFunctions = Object.create(null)
- lunr.Pipeline.registerFunction = function (fn, label) {
- if (label in this.registeredFunctions) {
- lunr.utils.warn('Overwriting existing registered function: ' + label)
- }
- fn.label = label
- lunr.Pipeline.registeredFunctions[fn.label] = fn
- }
- lunr.Pipeline.warnIfFunctionNotRegistered = function (fn) {
- var isRegistered = fn.label && (fn.label in this.registeredFunctions)
- if (!isRegistered) {
- lunr.utils.warn('Function is not registered with pipeline. This may cause problems when serialising the index.\n', fn)
- }
- }
- lunr.Pipeline.load = function (serialised) {
- var pipeline = new lunr.Pipeline
- serialised.forEach(function (fnName) {
- var fn = lunr.Pipeline.registeredFunctions[fnName]
- if (fn) {
- pipeline.add(fn)
- } else {
- throw new Error('Cannot load unregistered function: ' + fnName)
- }
- })
- return pipeline
- }
- lunr.Pipeline.prototype.add = function () {
- var fns = Array.prototype.slice.call(arguments)
- fns.forEach(function (fn) {
- lunr.Pipeline.warnIfFunctionNotRegistered(fn)
- this._stack.push(fn)
- }, this)
- }
- lunr.Pipeline.prototype.after = function (existingFn, newFn) {
- lunr.Pipeline.warnIfFunctionNotRegistered(newFn)
- var pos = this._stack.indexOf(existingFn)
- if (pos == -1) {
- throw new Error('Cannot find existingFn')
- }
- pos = pos + 1
- this._stack.splice(pos, 0, newFn)
- }
- lunr.Pipeline.prototype.before = function (existingFn, newFn) {
- lunr.Pipeline.warnIfFunctionNotRegistered(newFn)
- var pos = this._stack.indexOf(existingFn)
- if (pos == -1) {
- throw new Error('Cannot find existingFn')
- }
- this._stack.splice(pos, 0, newFn)
- }
- lunr.Pipeline.prototype.remove = function (fn) {
- var pos = this._stack.indexOf(fn)
- if (pos == -1) {
- return
- }
- this._stack.splice(pos, 1)
- }
- lunr.Pipeline.prototype.run = function (tokens) {
- var stackLength = this._stack.length
- for (var i = 0; i < stackLength; i++) {
- var fn = this._stack[i]
- var memo = []
- for (var j = 0; j < tokens.length; j++) {
- var result = fn(tokens[j], j, tokens)
- if (result === null || result === void 0 || result === '') continue
- if (Array.isArray(result)) {
- for (var k = 0; k < result.length; k++) {
- memo.push(result[k])
- }
- } else {
- memo.push(result)
- }
- }
- tokens = memo
- }
- return tokens
- }
- lunr.Pipeline.prototype.runString = function (str, metadata) {
- var token = new lunr.Token (str, metadata)
- return this.run([token]).map(function (t) {
- return t.toString()
- })
- }
- lunr.Pipeline.prototype.reset = function () {
- this._stack = []
- }
- lunr.Pipeline.prototype.toJSON = function () {
- return this._stack.map(function (fn) {
- lunr.Pipeline.warnIfFunctionNotRegistered(fn)
- return fn.label
- })
- }
- lunr.Vector = function (elements) {
- this._magnitude = 0
- this.elements = elements || []
- }
- lunr.Vector.prototype.positionForIndex = function (index) {
-
- if (this.elements.length == 0) {
- return 0
- }
- var start = 0,
- end = this.elements.length / 2,
- sliceLength = end - start,
- pivotPoint = Math.floor(sliceLength / 2),
- pivotIndex = this.elements[pivotPoint * 2]
- while (sliceLength > 1) {
- if (pivotIndex < index) {
- start = pivotPoint
- }
- if (pivotIndex > index) {
- end = pivotPoint
- }
- if (pivotIndex == index) {
- break
- }
- sliceLength = end - start
- pivotPoint = start + Math.floor(sliceLength / 2)
- pivotIndex = this.elements[pivotPoint * 2]
- }
- if (pivotIndex == index) {
- return pivotPoint * 2
- }
- if (pivotIndex > index) {
- return pivotPoint * 2
- }
- if (pivotIndex < index) {
- return (pivotPoint + 1) * 2
- }
- }
- lunr.Vector.prototype.insert = function (insertIdx, val) {
- this.upsert(insertIdx, val, function () {
- throw "duplicate index"
- })
- }
- lunr.Vector.prototype.upsert = function (insertIdx, val, fn) {
- this._magnitude = 0
- var position = this.positionForIndex(insertIdx)
- if (this.elements[position] == insertIdx) {
- this.elements[position + 1] = fn(this.elements[position + 1], val)
- } else {
- this.elements.splice(position, 0, insertIdx, val)
- }
- }
- lunr.Vector.prototype.magnitude = function () {
- if (this._magnitude) return this._magnitude
- var sumOfSquares = 0,
- elementsLength = this.elements.length
- for (var i = 1; i < elementsLength; i += 2) {
- var val = this.elements[i]
- sumOfSquares += val * val
- }
- return this._magnitude = Math.sqrt(sumOfSquares)
- }
- lunr.Vector.prototype.dot = function (otherVector) {
- var dotProduct = 0,
- a = this.elements, b = otherVector.elements,
- aLen = a.length, bLen = b.length,
- aVal = 0, bVal = 0,
- i = 0, j = 0
- while (i < aLen && j < bLen) {
- aVal = a[i], bVal = b[j]
- if (aVal < bVal) {
- i += 2
- } else if (aVal > bVal) {
- j += 2
- } else if (aVal == bVal) {
- dotProduct += a[i + 1] * b[j + 1]
- i += 2
- j += 2
- }
- }
- return dotProduct
- }
- lunr.Vector.prototype.similarity = function (otherVector) {
- return this.dot(otherVector) / this.magnitude() || 0
- }
- lunr.Vector.prototype.toArray = function () {
- var output = new Array (this.elements.length / 2)
- for (var i = 1, j = 0; i < this.elements.length; i += 2, j++) {
- output[j] = this.elements[i]
- }
- return output
- }
- lunr.Vector.prototype.toJSON = function () {
- return this.elements
- }
- lunr.stemmer = (function(){
- var step2list = {
- "ational" : "ate",
- "tional" : "tion",
- "enci" : "ence",
- "anci" : "ance",
- "izer" : "ize",
- "bli" : "ble",
- "alli" : "al",
- "entli" : "ent",
- "eli" : "e",
- "ousli" : "ous",
- "ization" : "ize",
- "ation" : "ate",
- "ator" : "ate",
- "alism" : "al",
- "iveness" : "ive",
- "fulness" : "ful",
- "ousness" : "ous",
- "aliti" : "al",
- "iviti" : "ive",
- "biliti" : "ble",
- "logi" : "log"
- },
- step3list = {
- "icate" : "ic",
- "ative" : "",
- "alize" : "al",
- "iciti" : "ic",
- "ical" : "ic",
- "ful" : "",
- "ness" : ""
- },
- c = "[^aeiou]",
- v = "[aeiouy]",
- C = c + "[^aeiouy]*",
- V = v + "[aeiou]*",
- mgr0 = "^(" + C + ")?" + V + C,
- meq1 = "^(" + C + ")?" + V + C + "(" + V + ")?$",
- mgr1 = "^(" + C + ")?" + V + C + V + C,
- s_v = "^(" + C + ")?" + v;
- var re_mgr0 = new RegExp(mgr0);
- var re_mgr1 = new RegExp(mgr1);
- var re_meq1 = new RegExp(meq1);
- var re_s_v = new RegExp(s_v);
- var re_1a = /^(.+?)(ss|i)es$/;
- var re2_1a = /^(.+?)([^s])s$/;
- var re_1b = /^(.+?)eed$/;
- var re2_1b = /^(.+?)(ed|ing)$/;
- var re_1b_2 = /.$/;
- var re2_1b_2 = /(at|bl|iz)$/;
- var re3_1b_2 = new RegExp("([^aeiouylsz])\\1$");
- var re4_1b_2 = new RegExp("^" + C + v + "[^aeiouwxy]$");
- var re_1c = /^(.+?[^aeiou])y$/;
- var re_2 = /^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/;
- var re_3 = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/;
- var re_4 = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/;
- var re2_4 = /^(.+?)(s|t)(ion)$/;
- var re_5 = /^(.+?)e$/;
- var re_5_1 = /ll$/;
- var re3_5 = new RegExp("^" + C + v + "[^aeiouwxy]$");
- var porterStemmer = function porterStemmer(w) {
- var stem,
- suffix,
- firstch,
- re,
- re2,
- re3,
- re4;
- if (w.length < 3) { return w; }
- firstch = w.substr(0,1);
- if (firstch == "y") {
- w = firstch.toUpperCase() + w.substr(1);
- }
-
- re = re_1a
- re2 = re2_1a;
- if (re.test(w)) { w = w.replace(re,"$1$2"); }
- else if (re2.test(w)) { w = w.replace(re2,"$1$2"); }
-
- re = re_1b;
- re2 = re2_1b;
- if (re.test(w)) {
- var fp = re.exec(w);
- re = re_mgr0;
- if (re.test(fp[1])) {
- re = re_1b_2;
- w = w.replace(re,"");
- }
- } else if (re2.test(w)) {
- var fp = re2.exec(w);
- stem = fp[1];
- re2 = re_s_v;
- if (re2.test(stem)) {
- w = stem;
- re2 = re2_1b_2;
- re3 = re3_1b_2;
- re4 = re4_1b_2;
- if (re2.test(w)) { w = w + "e"; }
- else if (re3.test(w)) { re = re_1b_2; w = w.replace(re,""); }
- else if (re4.test(w)) { w = w + "e"; }
- }
- }
-
- re = re_1c;
- if (re.test(w)) {
- var fp = re.exec(w);
- stem = fp[1];
- w = stem + "i";
- }
-
- re = re_2;
- if (re.test(w)) {
- var fp = re.exec(w);
- stem = fp[1];
- suffix = fp[2];
- re = re_mgr0;
- if (re.test(stem)) {
- w = stem + step2list[suffix];
- }
- }
-
- re = re_3;
- if (re.test(w)) {
- var fp = re.exec(w);
- stem = fp[1];
- suffix = fp[2];
- re = re_mgr0;
- if (re.test(stem)) {
- w = stem + step3list[suffix];
- }
- }
-
- re = re_4;
- re2 = re2_4;
- if (re.test(w)) {
- var fp = re.exec(w);
- stem = fp[1];
- re = re_mgr1;
- if (re.test(stem)) {
- w = stem;
- }
- } else if (re2.test(w)) {
- var fp = re2.exec(w);
- stem = fp[1] + fp[2];
- re2 = re_mgr1;
- if (re2.test(stem)) {
- w = stem;
- }
- }
-
- re = re_5;
- if (re.test(w)) {
- var fp = re.exec(w);
- stem = fp[1];
- re = re_mgr1;
- re2 = re_meq1;
- re3 = re3_5;
- if (re.test(stem) || (re2.test(stem) && !(re3.test(stem)))) {
- w = stem;
- }
- }
- re = re_5_1;
- re2 = re_mgr1;
- if (re.test(w) && re2.test(w)) {
- re = re_1b_2;
- w = w.replace(re,"");
- }
-
- if (firstch == "y") {
- w = firstch.toLowerCase() + w.substr(1);
- }
- return w;
- };
- return function (token) {
- return token.update(porterStemmer);
- }
- })();
- lunr.Pipeline.registerFunction(lunr.stemmer, 'stemmer')
- lunr.generateStopWordFilter = function (stopWords) {
- var words = stopWords.reduce(function (memo, stopWord) {
- memo[stopWord] = stopWord
- return memo
- }, {})
- return function (token) {
- if (token && words[token.toString()] !== token.toString()) return token
- }
- }
- lunr.stopWordFilter = lunr.generateStopWordFilter([
- 'a',
- 'able',
- 'about',
- 'across',
- 'after',
- 'all',
- 'almost',
- 'also',
- 'am',
- 'among',
- 'an',
- 'and',
- 'any',
- 'are',
- 'as',
- 'at',
- 'be',
- 'because',
- 'been',
- 'but',
- 'by',
- 'can',
- 'cannot',
- 'could',
- 'dear',
- 'did',
- 'do',
- 'does',
- 'either',
- 'else',
- 'ever',
- 'every',
- 'for',
- 'from',
- 'get',
- 'got',
- 'had',
- 'has',
- 'have',
- 'he',
- 'her',
- 'hers',
- 'him',
- 'his',
- 'how',
- 'however',
- 'i',
- 'if',
- 'in',
- 'into',
- 'is',
- 'it',
- 'its',
- 'just',
- 'least',
- 'let',
- 'like',
- 'likely',
- 'may',
- 'me',
- 'might',
- 'most',
- 'must',
- 'my',
- 'neither',
- 'no',
- 'nor',
- 'not',
- 'of',
- 'off',
- 'often',
- 'on',
- 'only',
- 'or',
- 'other',
- 'our',
- 'own',
- 'rather',
- 'said',
- 'say',
- 'says',
- 'she',
- 'should',
- 'since',
- 'so',
- 'some',
- 'than',
- 'that',
- 'the',
- 'their',
- 'them',
- 'then',
- 'there',
- 'these',
- 'they',
- 'this',
- 'tis',
- 'to',
- 'too',
- 'twas',
- 'us',
- 'wants',
- 'was',
- 'we',
- 'were',
- 'what',
- 'when',
- 'where',
- 'which',
- 'while',
- 'who',
- 'whom',
- 'why',
- 'will',
- 'with',
- 'would',
- 'yet',
- 'you',
- 'your'
- ])
- lunr.Pipeline.registerFunction(lunr.stopWordFilter, 'stopWordFilter')
- lunr.trimmer = function (token) {
- return token.update(function (s) {
- return s.replace(/^\W+/, '').replace(/\W+$/, '')
- })
- }
- lunr.Pipeline.registerFunction(lunr.trimmer, 'trimmer')
- lunr.TokenSet = function () {
- this.final = false
- this.edges = {}
- this.id = lunr.TokenSet._nextId
- lunr.TokenSet._nextId += 1
- }
- lunr.TokenSet._nextId = 1
- lunr.TokenSet.fromArray = function (arr) {
- var builder = new lunr.TokenSet.Builder
- for (var i = 0, len = arr.length; i < len; i++) {
- builder.insert(arr[i])
- }
- builder.finish()
- return builder.root
- }
- lunr.TokenSet.fromClause = function (clause) {
- if ('editDistance' in clause) {
- return lunr.TokenSet.fromFuzzyString(clause.term, clause.editDistance)
- } else {
- return lunr.TokenSet.fromString(clause.term)
- }
- }
- lunr.TokenSet.fromFuzzyString = function (str, editDistance) {
- var root = new lunr.TokenSet
- var stack = [{
- node: root,
- editsRemaining: editDistance,
- str: str
- }]
- while (stack.length) {
- var frame = stack.pop()
-
- if (frame.str.length > 0) {
- var char = frame.str.charAt(0),
- noEditNode
- if (char in frame.node.edges) {
- noEditNode = frame.node.edges[char]
- } else {
- noEditNode = new lunr.TokenSet
- frame.node.edges[char] = noEditNode
- }
- if (frame.str.length == 1) {
- noEditNode.final = true
- }
- stack.push({
- node: noEditNode,
- editsRemaining: frame.editsRemaining,
- str: frame.str.slice(1)
- })
- }
- if (frame.editsRemaining == 0) {
- continue
- }
-
- if ("*" in frame.node.edges) {
- var insertionNode = frame.node.edges["*"]
- } else {
- var insertionNode = new lunr.TokenSet
- frame.node.edges["*"] = insertionNode
- }
- if (frame.str.length == 0) {
- insertionNode.final = true
- }
- stack.push({
- node: insertionNode,
- editsRemaining: frame.editsRemaining - 1,
- str: frame.str
- })
-
-
-
- if (frame.str.length > 1) {
- stack.push({
- node: frame.node,
- editsRemaining: frame.editsRemaining - 1,
- str: frame.str.slice(1)
- })
- }
-
-
- if (frame.str.length == 1) {
- frame.node.final = true
- }
-
-
-
- if (frame.str.length >= 1) {
- if ("*" in frame.node.edges) {
- var substitutionNode = frame.node.edges["*"]
- } else {
- var substitutionNode = new lunr.TokenSet
- frame.node.edges["*"] = substitutionNode
- }
- if (frame.str.length == 1) {
- substitutionNode.final = true
- }
- stack.push({
- node: substitutionNode,
- editsRemaining: frame.editsRemaining - 1,
- str: frame.str.slice(1)
- })
- }
-
-
-
- if (frame.str.length > 1) {
- var charA = frame.str.charAt(0),
- charB = frame.str.charAt(1),
- transposeNode
- if (charB in frame.node.edges) {
- transposeNode = frame.node.edges[charB]
- } else {
- transposeNode = new lunr.TokenSet
- frame.node.edges[charB] = transposeNode
- }
- if (frame.str.length == 1) {
- transposeNode.final = true
- }
- stack.push({
- node: transposeNode,
- editsRemaining: frame.editsRemaining - 1,
- str: charA + frame.str.slice(2)
- })
- }
- }
- return root
- }
- lunr.TokenSet.fromString = function (str) {
- var node = new lunr.TokenSet,
- root = node
-
- for (var i = 0, len = str.length; i < len; i++) {
- var char = str[i],
- final = (i == len - 1)
- if (char == "*") {
- node.edges[char] = node
- node.final = final
- } else {
- var next = new lunr.TokenSet
- next.final = final
- node.edges[char] = next
- node = next
- }
- }
- return root
- }
- lunr.TokenSet.prototype.toArray = function () {
- var words = []
- var stack = [{
- prefix: "",
- node: this
- }]
- while (stack.length) {
- var frame = stack.pop(),
- edges = Object.keys(frame.node.edges),
- len = edges.length
- if (frame.node.final) {
-
- frame.prefix.charAt(0)
- words.push(frame.prefix)
- }
- for (var i = 0; i < len; i++) {
- var edge = edges[i]
- stack.push({
- prefix: frame.prefix.concat(edge),
- node: frame.node.edges[edge]
- })
- }
- }
- return words
- }
- lunr.TokenSet.prototype.toString = function () {
-
-
-
-
-
-
-
- if (this._str) {
- return this._str
- }
- var str = this.final ? '1' : '0',
- labels = Object.keys(this.edges).sort(),
- len = labels.length
- for (var i = 0; i < len; i++) {
- var label = labels[i],
- node = this.edges[label]
- str = str + label + node.id
- }
- return str
- }
- lunr.TokenSet.prototype.intersect = function (b) {
- var output = new lunr.TokenSet,
- frame = undefined
- var stack = [{
- qNode: b,
- output: output,
- node: this
- }]
- while (stack.length) {
- frame = stack.pop()
-
-
-
-
- var qEdges = Object.keys(frame.qNode.edges),
- qLen = qEdges.length,
- nEdges = Object.keys(frame.node.edges),
- nLen = nEdges.length
- for (var q = 0; q < qLen; q++) {
- var qEdge = qEdges[q]
- for (var n = 0; n < nLen; n++) {
- var nEdge = nEdges[n]
- if (nEdge == qEdge || qEdge == '*') {
- var node = frame.node.edges[nEdge],
- qNode = frame.qNode.edges[qEdge],
- final = node.final && qNode.final,
- next = undefined
- if (nEdge in frame.output.edges) {
-
-
-
- next = frame.output.edges[nEdge]
- next.final = next.final || final
- } else {
-
-
-
- next = new lunr.TokenSet
- next.final = final
- frame.output.edges[nEdge] = next
- }
- stack.push({
- qNode: qNode,
- output: next,
- node: node
- })
- }
- }
- }
- }
- return output
- }
- lunr.TokenSet.Builder = function () {
- this.previousWord = ""
- this.root = new lunr.TokenSet
- this.uncheckedNodes = []
- this.minimizedNodes = {}
- }
- lunr.TokenSet.Builder.prototype.insert = function (word) {
- var node,
- commonPrefix = 0
- if (word < this.previousWord) {
- throw new Error ("Out of order word insertion")
- }
- for (var i = 0; i < word.length && i < this.previousWord.length; i++) {
- if (word[i] != this.previousWord[i]) break
- commonPrefix++
- }
- this.minimize(commonPrefix)
- if (this.uncheckedNodes.length == 0) {
- node = this.root
- } else {
- node = this.uncheckedNodes[this.uncheckedNodes.length - 1].child
- }
- for (var i = commonPrefix; i < word.length; i++) {
- var nextNode = new lunr.TokenSet,
- char = word[i]
- node.edges[char] = nextNode
- this.uncheckedNodes.push({
- parent: node,
- char: char,
- child: nextNode
- })
- node = nextNode
- }
- node.final = true
- this.previousWord = word
- }
- lunr.TokenSet.Builder.prototype.finish = function () {
- this.minimize(0)
- }
- lunr.TokenSet.Builder.prototype.minimize = function (downTo) {
- for (var i = this.uncheckedNodes.length - 1; i >= downTo; i--) {
- var node = this.uncheckedNodes[i],
- childKey = node.child.toString()
- if (childKey in this.minimizedNodes) {
- node.parent.edges[node.char] = this.minimizedNodes[childKey]
- } else {
-
-
- node.child._str = childKey
- this.minimizedNodes[childKey] = node.child
- }
- this.uncheckedNodes.pop()
- }
- }
- lunr.Index = function (attrs) {
- this.invertedIndex = attrs.invertedIndex
- this.fieldVectors = attrs.fieldVectors
- this.tokenSet = attrs.tokenSet
- this.fields = attrs.fields
- this.pipeline = attrs.pipeline
- }
- lunr.Index.prototype.search = function (queryString) {
- return this.query(function (query) {
- var parser = new lunr.QueryParser(queryString, query)
- parser.parse()
- })
- }
- lunr.Index.prototype.query = function (fn) {
-
-
-
-
-
-
- var query = new lunr.Query(this.fields),
- matchingFields = Object.create(null),
- queryVectors = Object.create(null),
- termFieldCache = Object.create(null),
- requiredMatches = Object.create(null),
- prohibitedMatches = Object.create(null)
-
- for (var i = 0; i < this.fields.length; i++) {
- queryVectors[this.fields[i]] = new lunr.Vector
- }
- fn.call(query, query)
- for (var i = 0; i < query.clauses.length; i++) {
-
- var clause = query.clauses[i],
- terms = null,
- clauseMatches = lunr.Set.complete
- if (clause.usePipeline) {
- terms = this.pipeline.runString(clause.term, {
- fields: clause.fields
- })
- } else {
- terms = [clause.term]
- }
- for (var m = 0; m < terms.length; m++) {
- var term = terms[m]
-
- clause.term = term
-
- var termTokenSet = lunr.TokenSet.fromClause(clause),
- expandedTerms = this.tokenSet.intersect(termTokenSet).toArray()
-
- if (expandedTerms.length === 0 && clause.presence === lunr.Query.presence.REQUIRED) {
- for (var k = 0; k < clause.fields.length; k++) {
- var field = clause.fields[k]
- requiredMatches[field] = lunr.Set.empty
- }
- break
- }
- for (var j = 0; j < expandedTerms.length; j++) {
-
- var expandedTerm = expandedTerms[j],
- posting = this.invertedIndex[expandedTerm],
- termIndex = posting._index
- for (var k = 0; k < clause.fields.length; k++) {
-
- var field = clause.fields[k],
- fieldPosting = posting[field],
- matchingDocumentRefs = Object.keys(fieldPosting),
- termField = expandedTerm + "/" + field,
- matchingDocumentsSet = new lunr.Set(matchingDocumentRefs)
-
- if (clause.presence == lunr.Query.presence.REQUIRED) {
- clauseMatches = clauseMatches.union(matchingDocumentsSet)
- if (requiredMatches[field] === undefined) {
- requiredMatches[field] = lunr.Set.complete
- }
- }
-
- if (clause.presence == lunr.Query.presence.PROHIBITED) {
- if (prohibitedMatches[field] === undefined) {
- prohibitedMatches[field] = lunr.Set.empty
- }
- prohibitedMatches[field] = prohibitedMatches[field].union(matchingDocumentsSet)
-
- continue
- }
-
- queryVectors[field].upsert(termIndex, clause.boost, function (a, b) { return a + b })
-
- if (termFieldCache[termField]) {
- continue
- }
- for (var l = 0; l < matchingDocumentRefs.length; l++) {
-
- var matchingDocumentRef = matchingDocumentRefs[l],
- matchingFieldRef = new lunr.FieldRef (matchingDocumentRef, field),
- metadata = fieldPosting[matchingDocumentRef],
- fieldMatch
- if ((fieldMatch = matchingFields[matchingFieldRef]) === undefined) {
- matchingFields[matchingFieldRef] = new lunr.MatchData (expandedTerm, field, metadata)
- } else {
- fieldMatch.add(expandedTerm, field, metadata)
- }
- }
- termFieldCache[termField] = true
- }
- }
- }
-
- if (clause.presence === lunr.Query.presence.REQUIRED) {
- for (var k = 0; k < clause.fields.length; k++) {
- var field = clause.fields[k]
- requiredMatches[field] = requiredMatches[field].intersect(clauseMatches)
- }
- }
- }
-
- var allRequiredMatches = lunr.Set.complete,
- allProhibitedMatches = lunr.Set.empty
- for (var i = 0; i < this.fields.length; i++) {
- var field = this.fields[i]
- if (requiredMatches[field]) {
- allRequiredMatches = allRequiredMatches.intersect(requiredMatches[field])
- }
- if (prohibitedMatches[field]) {
- allProhibitedMatches = allProhibitedMatches.union(prohibitedMatches[field])
- }
- }
- var matchingFieldRefs = Object.keys(matchingFields),
- results = [],
- matches = Object.create(null)
-
- if (query.isNegated()) {
- matchingFieldRefs = Object.keys(this.fieldVectors)
- for (var i = 0; i < matchingFieldRefs.length; i++) {
- var matchingFieldRef = matchingFieldRefs[i]
- var fieldRef = lunr.FieldRef.fromString(matchingFieldRef)
- matchingFields[matchingFieldRef] = new lunr.MatchData
- }
- }
- for (var i = 0; i < matchingFieldRefs.length; i++) {
-
- var fieldRef = lunr.FieldRef.fromString(matchingFieldRefs[i]),
- docRef = fieldRef.docRef
- if (!allRequiredMatches.contains(docRef)) {
- continue
- }
- if (allProhibitedMatches.contains(docRef)) {
- continue
- }
- var fieldVector = this.fieldVectors[fieldRef],
- score = queryVectors[fieldRef.fieldName].similarity(fieldVector),
- docMatch
- if ((docMatch = matches[docRef]) !== undefined) {
- docMatch.score += score
- docMatch.matchData.combine(matchingFields[fieldRef])
- } else {
- var match = {
- ref: docRef,
- score: score,
- matchData: matchingFields[fieldRef]
- }
- matches[docRef] = match
- results.push(match)
- }
- }
-
- return results.sort(function (a, b) {
- return b.score - a.score
- })
- }
- lunr.Index.prototype.toJSON = function () {
- var invertedIndex = Object.keys(this.invertedIndex)
- .sort()
- .map(function (term) {
- return [term, this.invertedIndex[term]]
- }, this)
- var fieldVectors = Object.keys(this.fieldVectors)
- .map(function (ref) {
- return [ref, this.fieldVectors[ref].toJSON()]
- }, this)
- return {
- version: lunr.version,
- fields: this.fields,
- fieldVectors: fieldVectors,
- invertedIndex: invertedIndex,
- pipeline: this.pipeline.toJSON()
- }
- }
- lunr.Index.load = function (serializedIndex) {
- var attrs = {},
- fieldVectors = {},
- serializedVectors = serializedIndex.fieldVectors,
- invertedIndex = Object.create(null),
- serializedInvertedIndex = serializedIndex.invertedIndex,
- tokenSetBuilder = new lunr.TokenSet.Builder,
- pipeline = lunr.Pipeline.load(serializedIndex.pipeline)
- if (serializedIndex.version != lunr.version) {
- lunr.utils.warn("Version mismatch when loading serialised index. Current version of lunr '" + lunr.version + "' does not match serialized index '" + serializedIndex.version + "'")
- }
- for (var i = 0; i < serializedVectors.length; i++) {
- var tuple = serializedVectors[i],
- ref = tuple[0],
- elements = tuple[1]
- fieldVectors[ref] = new lunr.Vector(elements)
- }
- for (var i = 0; i < serializedInvertedIndex.length; i++) {
- var tuple = serializedInvertedIndex[i],
- term = tuple[0],
- posting = tuple[1]
- tokenSetBuilder.insert(term)
- invertedIndex[term] = posting
- }
- tokenSetBuilder.finish()
- attrs.fields = serializedIndex.fields
- attrs.fieldVectors = fieldVectors
- attrs.invertedIndex = invertedIndex
- attrs.tokenSet = tokenSetBuilder.root
- attrs.pipeline = pipeline
- return new lunr.Index(attrs)
- }
- lunr.Builder = function () {
- this._ref = "id"
- this._fields = Object.create(null)
- this._documents = Object.create(null)
- this.invertedIndex = Object.create(null)
- this.fieldTermFrequencies = {}
- this.fieldLengths = {}
- this.tokenizer = lunr.tokenizer
- this.pipeline = new lunr.Pipeline
- this.searchPipeline = new lunr.Pipeline
- this.documentCount = 0
- this._b = 0.75
- this._k1 = 1.2
- this.termIndex = 0
- this.metadataWhitelist = []
- }
- lunr.Builder.prototype.ref = function (ref) {
- this._ref = ref
- }
- lunr.Builder.prototype.field = function (fieldName, attributes) {
- if (/\//.test(fieldName)) {
- throw new RangeError ("Field '" + fieldName + "' contains illegal character '/'")
- }
- this._fields[fieldName] = attributes || {}
- }
- lunr.Builder.prototype.b = function (number) {
- if (number < 0) {
- this._b = 0
- } else if (number > 1) {
- this._b = 1
- } else {
- this._b = number
- }
- }
- lunr.Builder.prototype.k1 = function (number) {
- this._k1 = number
- }
- lunr.Builder.prototype.add = function (doc, attributes) {
- var docRef = doc[this._ref],
- fields = Object.keys(this._fields)
- this._documents[docRef] = attributes || {}
- this.documentCount += 1
- for (var i = 0; i < fields.length; i++) {
- var fieldName = fields[i],
- extractor = this._fields[fieldName].extractor,
- field = extractor ? extractor(doc) : doc[fieldName],
- tokens = this.tokenizer(field, {
- fields: [fieldName]
- }),
- terms = this.pipeline.run(tokens),
- fieldRef = new lunr.FieldRef (docRef, fieldName),
- fieldTerms = Object.create(null)
- this.fieldTermFrequencies[fieldRef] = fieldTerms
- this.fieldLengths[fieldRef] = 0
-
- this.fieldLengths[fieldRef] += terms.length
-
- for (var j = 0; j < terms.length; j++) {
- var term = terms[j]
- if (fieldTerms[term] == undefined) {
- fieldTerms[term] = 0
- }
- fieldTerms[term] += 1
-
-
- if (this.invertedIndex[term] == undefined) {
- var posting = Object.create(null)
- posting["_index"] = this.termIndex
- this.termIndex += 1
- for (var k = 0; k < fields.length; k++) {
- posting[fields[k]] = Object.create(null)
- }
- this.invertedIndex[term] = posting
- }
-
- if (this.invertedIndex[term][fieldName][docRef] == undefined) {
- this.invertedIndex[term][fieldName][docRef] = Object.create(null)
- }
-
-
- for (var l = 0; l < this.metadataWhitelist.length; l++) {
- var metadataKey = this.metadataWhitelist[l],
- metadata = term.metadata[metadataKey]
- if (this.invertedIndex[term][fieldName][docRef][metadataKey] == undefined) {
- this.invertedIndex[term][fieldName][docRef][metadataKey] = []
- }
- this.invertedIndex[term][fieldName][docRef][metadataKey].push(metadata)
- }
- }
- }
- }
- lunr.Builder.prototype.calculateAverageFieldLengths = function () {
- var fieldRefs = Object.keys(this.fieldLengths),
- numberOfFields = fieldRefs.length,
- accumulator = {},
- documentsWithField = {}
- for (var i = 0; i < numberOfFields; i++) {
- var fieldRef = lunr.FieldRef.fromString(fieldRefs[i]),
- field = fieldRef.fieldName
- documentsWithField[field] || (documentsWithField[field] = 0)
- documentsWithField[field] += 1
- accumulator[field] || (accumulator[field] = 0)
- accumulator[field] += this.fieldLengths[fieldRef]
- }
- var fields = Object.keys(this._fields)
- for (var i = 0; i < fields.length; i++) {
- var fieldName = fields[i]
- accumulator[fieldName] = accumulator[fieldName] / documentsWithField[fieldName]
- }
- this.averageFieldLength = accumulator
- }
- lunr.Builder.prototype.createFieldVectors = function () {
- var fieldVectors = {},
- fieldRefs = Object.keys(this.fieldTermFrequencies),
- fieldRefsLength = fieldRefs.length,
- termIdfCache = Object.create(null)
- for (var i = 0; i < fieldRefsLength; i++) {
- var fieldRef = lunr.FieldRef.fromString(fieldRefs[i]),
- fieldName = fieldRef.fieldName,
- fieldLength = this.fieldLengths[fieldRef],
- fieldVector = new lunr.Vector,
- termFrequencies = this.fieldTermFrequencies[fieldRef],
- terms = Object.keys(termFrequencies),
- termsLength = terms.length
- var fieldBoost = this._fields[fieldName].boost || 1,
- docBoost = this._documents[fieldRef.docRef].boost || 1
- for (var j = 0; j < termsLength; j++) {
- var term = terms[j],
- tf = termFrequencies[term],
- termIndex = this.invertedIndex[term]._index,
- idf, score, scoreWithPrecision
- if (termIdfCache[term] === undefined) {
- idf = lunr.idf(this.invertedIndex[term], this.documentCount)
- termIdfCache[term] = idf
- } else {
- idf = termIdfCache[term]
- }
- score = idf * ((this._k1 + 1) * tf) / (this._k1 * (1 - this._b + this._b * (fieldLength / this.averageFieldLength[fieldName])) + tf)
- score *= fieldBoost
- score *= docBoost
- scoreWithPrecision = Math.round(score * 1000) / 1000
-
-
-
-
-
-
- fieldVector.insert(termIndex, scoreWithPrecision)
- }
- fieldVectors[fieldRef] = fieldVector
- }
- this.fieldVectors = fieldVectors
- }
- lunr.Builder.prototype.createTokenSet = function () {
- this.tokenSet = lunr.TokenSet.fromArray(
- Object.keys(this.invertedIndex).sort()
- )
- }
- lunr.Builder.prototype.build = function () {
- this.calculateAverageFieldLengths()
- this.createFieldVectors()
- this.createTokenSet()
- return new lunr.Index({
- invertedIndex: this.invertedIndex,
- fieldVectors: this.fieldVectors,
- tokenSet: this.tokenSet,
- fields: Object.keys(this._fields),
- pipeline: this.searchPipeline
- })
- }
- lunr.Builder.prototype.use = function (fn) {
- var args = Array.prototype.slice.call(arguments, 1)
- args.unshift(this)
- fn.apply(this, args)
- }
- lunr.MatchData = function (term, field, metadata) {
- var clonedMetadata = Object.create(null),
- metadataKeys = Object.keys(metadata || {})
-
-
-
-
-
- for (var i = 0; i < metadataKeys.length; i++) {
- var key = metadataKeys[i]
- clonedMetadata[key] = metadata[key].slice()
- }
- this.metadata = Object.create(null)
- if (term !== undefined) {
- this.metadata[term] = Object.create(null)
- this.metadata[term][field] = clonedMetadata
- }
- }
- lunr.MatchData.prototype.combine = function (otherMatchData) {
- var terms = Object.keys(otherMatchData.metadata)
- for (var i = 0; i < terms.length; i++) {
- var term = terms[i],
- fields = Object.keys(otherMatchData.metadata[term])
- if (this.metadata[term] == undefined) {
- this.metadata[term] = Object.create(null)
- }
- for (var j = 0; j < fields.length; j++) {
- var field = fields[j],
- keys = Object.keys(otherMatchData.metadata[term][field])
- if (this.metadata[term][field] == undefined) {
- this.metadata[term][field] = Object.create(null)
- }
- for (var k = 0; k < keys.length; k++) {
- var key = keys[k]
- if (this.metadata[term][field][key] == undefined) {
- this.metadata[term][field][key] = otherMatchData.metadata[term][field][key]
- } else {
- this.metadata[term][field][key] = this.metadata[term][field][key].concat(otherMatchData.metadata[term][field][key])
- }
- }
- }
- }
- }
- lunr.MatchData.prototype.add = function (term, field, metadata) {
- if (!(term in this.metadata)) {
- this.metadata[term] = Object.create(null)
- this.metadata[term][field] = metadata
- return
- }
- if (!(field in this.metadata[term])) {
- this.metadata[term][field] = metadata
- return
- }
- var metadataKeys = Object.keys(metadata)
- for (var i = 0; i < metadataKeys.length; i++) {
- var key = metadataKeys[i]
- if (key in this.metadata[term][field]) {
- this.metadata[term][field][key] = this.metadata[term][field][key].concat(metadata[key])
- } else {
- this.metadata[term][field][key] = metadata[key]
- }
- }
- }
- lunr.Query = function (allFields) {
- this.clauses = []
- this.allFields = allFields
- }
- lunr.Query.wildcard = new String ("*")
- lunr.Query.wildcard.NONE = 0
- lunr.Query.wildcard.LEADING = 1
- lunr.Query.wildcard.TRAILING = 2
- lunr.Query.presence = {
-
- OPTIONAL: 1,
-
- REQUIRED: 2,
-
- PROHIBITED: 3
- }
- lunr.Query.prototype.clause = function (clause) {
- if (!('fields' in clause)) {
- clause.fields = this.allFields
- }
- if (!('boost' in clause)) {
- clause.boost = 1
- }
- if (!('usePipeline' in clause)) {
- clause.usePipeline = true
- }
- if (!('wildcard' in clause)) {
- clause.wildcard = lunr.Query.wildcard.NONE
- }
- if ((clause.wildcard & lunr.Query.wildcard.LEADING) && (clause.term.charAt(0) != lunr.Query.wildcard)) {
- clause.term = "*" + clause.term
- }
- if ((clause.wildcard & lunr.Query.wildcard.TRAILING) && (clause.term.slice(-1) != lunr.Query.wildcard)) {
- clause.term = "" + clause.term + "*"
- }
- if (!('presence' in clause)) {
- clause.presence = lunr.Query.presence.OPTIONAL
- }
- this.clauses.push(clause)
- return this
- }
- lunr.Query.prototype.isNegated = function () {
- for (var i = 0; i < this.clauses.length; i++) {
- if (this.clauses[i].presence != lunr.Query.presence.PROHIBITED) {
- return false
- }
- }
- return true
- }
- lunr.Query.prototype.term = function (term, options) {
- if (Array.isArray(term)) {
- term.forEach(function (t) { this.term(t, lunr.utils.clone(options)) }, this)
- return this
- }
- var clause = options || {}
- clause.term = term.toString()
- this.clause(clause)
- return this
- }
- lunr.QueryParseError = function (message, start, end) {
- this.name = "QueryParseError"
- this.message = message
- this.start = start
- this.end = end
- }
- lunr.QueryParseError.prototype = new Error
- lunr.QueryLexer = function (str) {
- this.lexemes = []
- this.str = str
- this.length = str.length
- this.pos = 0
- this.start = 0
- this.escapeCharPositions = []
- }
- lunr.QueryLexer.prototype.run = function () {
- var state = lunr.QueryLexer.lexText
- while (state) {
- state = state(this)
- }
- }
- lunr.QueryLexer.prototype.sliceString = function () {
- var subSlices = [],
- sliceStart = this.start,
- sliceEnd = this.pos
- for (var i = 0; i < this.escapeCharPositions.length; i++) {
- sliceEnd = this.escapeCharPositions[i]
- subSlices.push(this.str.slice(sliceStart, sliceEnd))
- sliceStart = sliceEnd + 1
- }
- subSlices.push(this.str.slice(sliceStart, this.pos))
- this.escapeCharPositions.length = 0
- return subSlices.join('')
- }
- lunr.QueryLexer.prototype.emit = function (type) {
- this.lexemes.push({
- type: type,
- str: this.sliceString(),
- start: this.start,
- end: this.pos
- })
- this.start = this.pos
- }
- lunr.QueryLexer.prototype.escapeCharacter = function () {
- this.escapeCharPositions.push(this.pos - 1)
- this.pos += 1
- }
- lunr.QueryLexer.prototype.next = function () {
- if (this.pos >= this.length) {
- return lunr.QueryLexer.EOS
- }
- var char = this.str.charAt(this.pos)
- this.pos += 1
- return char
- }
- lunr.QueryLexer.prototype.width = function () {
- return this.pos - this.start
- }
- lunr.QueryLexer.prototype.ignore = function () {
- if (this.start == this.pos) {
- this.pos += 1
- }
- this.start = this.pos
- }
- lunr.QueryLexer.prototype.backup = function () {
- this.pos -= 1
- }
- lunr.QueryLexer.prototype.acceptDigitRun = function () {
- var char, charCode
- do {
- char = this.next()
- charCode = char.charCodeAt(0)
- } while (charCode > 47 && charCode < 58)
- if (char != lunr.QueryLexer.EOS) {
- this.backup()
- }
- }
- lunr.QueryLexer.prototype.more = function () {
- return this.pos < this.length
- }
- lunr.QueryLexer.EOS = 'EOS'
- lunr.QueryLexer.FIELD = 'FIELD'
- lunr.QueryLexer.TERM = 'TERM'
- lunr.QueryLexer.EDIT_DISTANCE = 'EDIT_DISTANCE'
- lunr.QueryLexer.BOOST = 'BOOST'
- lunr.QueryLexer.PRESENCE = 'PRESENCE'
- lunr.QueryLexer.lexField = function (lexer) {
- lexer.backup()
- lexer.emit(lunr.QueryLexer.FIELD)
- lexer.ignore()
- return lunr.QueryLexer.lexText
- }
- lunr.QueryLexer.lexTerm = function (lexer) {
- if (lexer.width() > 1) {
- lexer.backup()
- lexer.emit(lunr.QueryLexer.TERM)
- }
- lexer.ignore()
- if (lexer.more()) {
- return lunr.QueryLexer.lexText
- }
- }
- lunr.QueryLexer.lexEditDistance = function (lexer) {
- lexer.ignore()
- lexer.acceptDigitRun()
- lexer.emit(lunr.QueryLexer.EDIT_DISTANCE)
- return lunr.QueryLexer.lexText
- }
- lunr.QueryLexer.lexBoost = function (lexer) {
- lexer.ignore()
- lexer.acceptDigitRun()
- lexer.emit(lunr.QueryLexer.BOOST)
- return lunr.QueryLexer.lexText
- }
- lunr.QueryLexer.lexEOS = function (lexer) {
- if (lexer.width() > 0) {
- lexer.emit(lunr.QueryLexer.TERM)
- }
- }
- lunr.QueryLexer.termSeparator = lunr.tokenizer.separator
- lunr.QueryLexer.lexText = function (lexer) {
- while (true) {
- var char = lexer.next()
- if (char == lunr.QueryLexer.EOS) {
- return lunr.QueryLexer.lexEOS
- }
-
- if (char.charCodeAt(0) == 92) {
- lexer.escapeCharacter()
- continue
- }
- if (char == ":") {
- return lunr.QueryLexer.lexField
- }
- if (char == "~") {
- lexer.backup()
- if (lexer.width() > 0) {
- lexer.emit(lunr.QueryLexer.TERM)
- }
- return lunr.QueryLexer.lexEditDistance
- }
- if (char == "^") {
- lexer.backup()
- if (lexer.width() > 0) {
- lexer.emit(lunr.QueryLexer.TERM)
- }
- return lunr.QueryLexer.lexBoost
- }
-
-
-
- if (char == "+" && lexer.width() === 1) {
- lexer.emit(lunr.QueryLexer.PRESENCE)
- return lunr.QueryLexer.lexText
- }
-
-
-
- if (char == "-" && lexer.width() === 1) {
- lexer.emit(lunr.QueryLexer.PRESENCE)
- return lunr.QueryLexer.lexText
- }
- if (char.match(lunr.QueryLexer.termSeparator)) {
- return lunr.QueryLexer.lexTerm
- }
- }
- }
- lunr.QueryParser = function (str, query) {
- this.lexer = new lunr.QueryLexer (str)
- this.query = query
- this.currentClause = {}
- this.lexemeIdx = 0
- }
- lunr.QueryParser.prototype.parse = function () {
- this.lexer.run()
- this.lexemes = this.lexer.lexemes
- var state = lunr.QueryParser.parseClause
- while (state) {
- state = state(this)
- }
- return this.query
- }
- lunr.QueryParser.prototype.peekLexeme = function () {
- return this.lexemes[this.lexemeIdx]
- }
- lunr.QueryParser.prototype.consumeLexeme = function () {
- var lexeme = this.peekLexeme()
- this.lexemeIdx += 1
- return lexeme
- }
- lunr.QueryParser.prototype.nextClause = function () {
- var completedClause = this.currentClause
- this.query.clause(completedClause)
- this.currentClause = {}
- }
- lunr.QueryParser.parseClause = function (parser) {
- var lexeme = parser.peekLexeme()
- if (lexeme == undefined) {
- return
- }
- switch (lexeme.type) {
- case lunr.QueryLexer.PRESENCE:
- return lunr.QueryParser.parsePresence
- case lunr.QueryLexer.FIELD:
- return lunr.QueryParser.parseField
- case lunr.QueryLexer.TERM:
- return lunr.QueryParser.parseTerm
- default:
- var errorMessage = "expected either a field or a term, found " + lexeme.type
- if (lexeme.str.length >= 1) {
- errorMessage += " with value '" + lexeme.str + "'"
- }
- throw new lunr.QueryParseError (errorMessage, lexeme.start, lexeme.end)
- }
- }
- lunr.QueryParser.parsePresence = function (parser) {
- var lexeme = parser.consumeLexeme()
- if (lexeme == undefined) {
- return
- }
- switch (lexeme.str) {
- case "-":
- parser.currentClause.presence = lunr.Query.presence.PROHIBITED
- break
- case "+":
- parser.currentClause.presence = lunr.Query.presence.REQUIRED
- break
- default:
- var errorMessage = "unrecognised presence operator'" + lexeme.str + "'"
- throw new lunr.QueryParseError (errorMessage, lexeme.start, lexeme.end)
- }
- var nextLexeme = parser.peekLexeme()
- if (nextLexeme == undefined) {
- var errorMessage = "expecting term or field, found nothing"
- throw new lunr.QueryParseError (errorMessage, lexeme.start, lexeme.end)
- }
- switch (nextLexeme.type) {
- case lunr.QueryLexer.FIELD:
- return lunr.QueryParser.parseField
- case lunr.QueryLexer.TERM:
- return lunr.QueryParser.parseTerm
- default:
- var errorMessage = "expecting term or field, found '" + nextLexeme.type + "'"
- throw new lunr.QueryParseError (errorMessage, nextLexeme.start, nextLexeme.end)
- }
- }
- lunr.QueryParser.parseField = function (parser) {
- var lexeme = parser.consumeLexeme()
- if (lexeme == undefined) {
- return
- }
- if (parser.query.allFields.indexOf(lexeme.str) == -1) {
- var possibleFields = parser.query.allFields.map(function (f) { return "'" + f + "'" }).join(', '),
- errorMessage = "unrecognised field '" + lexeme.str + "', possible fields: " + possibleFields
- throw new lunr.QueryParseError (errorMessage, lexeme.start, lexeme.end)
- }
- parser.currentClause.fields = [lexeme.str]
- var nextLexeme = parser.peekLexeme()
- if (nextLexeme == undefined) {
- var errorMessage = "expecting term, found nothing"
- throw new lunr.QueryParseError (errorMessage, lexeme.start, lexeme.end)
- }
- switch (nextLexeme.type) {
- case lunr.QueryLexer.TERM:
- return lunr.QueryParser.parseTerm
- default:
- var errorMessage = "expecting term, found '" + nextLexeme.type + "'"
- throw new lunr.QueryParseError (errorMessage, nextLexeme.start, nextLexeme.end)
- }
- }
- lunr.QueryParser.parseTerm = function (parser) {
- var lexeme = parser.consumeLexeme()
- if (lexeme == undefined) {
- return
- }
- parser.currentClause.term = lexeme.str.toLowerCase()
- if (lexeme.str.indexOf("*") != -1) {
- parser.currentClause.usePipeline = false
- }
- var nextLexeme = parser.peekLexeme()
- if (nextLexeme == undefined) {
- parser.nextClause()
- return
- }
- switch (nextLexeme.type) {
- case lunr.QueryLexer.TERM:
- parser.nextClause()
- return lunr.QueryParser.parseTerm
- case lunr.QueryLexer.FIELD:
- parser.nextClause()
- return lunr.QueryParser.parseField
- case lunr.QueryLexer.EDIT_DISTANCE:
- return lunr.QueryParser.parseEditDistance
- case lunr.QueryLexer.BOOST:
- return lunr.QueryParser.parseBoost
- case lunr.QueryLexer.PRESENCE:
- parser.nextClause()
- return lunr.QueryParser.parsePresence
- default:
- var errorMessage = "Unexpected lexeme type '" + nextLexeme.type + "'"
- throw new lunr.QueryParseError (errorMessage, nextLexeme.start, nextLexeme.end)
- }
- }
- lunr.QueryParser.parseEditDistance = function (parser) {
- var lexeme = parser.consumeLexeme()
- if (lexeme == undefined) {
- return
- }
- var editDistance = parseInt(lexeme.str, 10)
- if (isNaN(editDistance)) {
- var errorMessage = "edit distance must be numeric"
- throw new lunr.QueryParseError (errorMessage, lexeme.start, lexeme.end)
- }
- parser.currentClause.editDistance = editDistance
- var nextLexeme = parser.peekLexeme()
- if (nextLexeme == undefined) {
- parser.nextClause()
- return
- }
- switch (nextLexeme.type) {
- case lunr.QueryLexer.TERM:
- parser.nextClause()
- return lunr.QueryParser.parseTerm
- case lunr.QueryLexer.FIELD:
- parser.nextClause()
- return lunr.QueryParser.parseField
- case lunr.QueryLexer.EDIT_DISTANCE:
- return lunr.QueryParser.parseEditDistance
- case lunr.QueryLexer.BOOST:
- return lunr.QueryParser.parseBoost
- case lunr.QueryLexer.PRESENCE:
- parser.nextClause()
- return lunr.QueryParser.parsePresence
- default:
- var errorMessage = "Unexpected lexeme type '" + nextLexeme.type + "'"
- throw new lunr.QueryParseError (errorMessage, nextLexeme.start, nextLexeme.end)
- }
- }
- lunr.QueryParser.parseBoost = function (parser) {
- var lexeme = parser.consumeLexeme()
- if (lexeme == undefined) {
- return
- }
- var boost = parseInt(lexeme.str, 10)
- if (isNaN(boost)) {
- var errorMessage = "boost must be numeric"
- throw new lunr.QueryParseError (errorMessage, lexeme.start, lexeme.end)
- }
- parser.currentClause.boost = boost
- var nextLexeme = parser.peekLexeme()
- if (nextLexeme == undefined) {
- parser.nextClause()
- return
- }
- switch (nextLexeme.type) {
- case lunr.QueryLexer.TERM:
- parser.nextClause()
- return lunr.QueryParser.parseTerm
- case lunr.QueryLexer.FIELD:
- parser.nextClause()
- return lunr.QueryParser.parseField
- case lunr.QueryLexer.EDIT_DISTANCE:
- return lunr.QueryParser.parseEditDistance
- case lunr.QueryLexer.BOOST:
- return lunr.QueryParser.parseBoost
- case lunr.QueryLexer.PRESENCE:
- parser.nextClause()
- return lunr.QueryParser.parsePresence
- default:
- var errorMessage = "Unexpected lexeme type '" + nextLexeme.type + "'"
- throw new lunr.QueryParseError (errorMessage, nextLexeme.start, nextLexeme.end)
- }
- }
-
- ;(function (root, factory) {
- if (typeof define === 'function' && define.amd) {
-
- define(factory)
- } else if (typeof exports === 'object') {
-
- module.exports = factory()
- } else {
-
- root.lunr = factory()
- }
- }(this, function () {
-
- return lunr
- }))
- })();
|