jekyll-theme-paperwiki 0.1.21 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/_config.yml +119 -0
- data/_data/navigation.yml +1 -0
- data/_includes/collections_header.html +10 -0
- data/_includes/collections_sidebar.html +11 -7
- data/_includes/entry_tags.html +3 -1
- data/_includes/global_header.html +3 -0
- data/_includes/random_redirect.html +1 -0
- data/_includes/wiki_sidebar.html +29 -16
- data/_layouts/collections.html +1 -1
- data/_layouts/portal.html +15 -10
- data/_layouts/random.html +1 -1
- data/_layouts/reference_desk.html +26 -19
- data/_sass/partials/_base.scss +2 -1
- data/_sass/partials/_entries.scss +5 -0
- data/_sass/partials/_global.scss +4 -1
- data/assets/.DS_Store +0 -0
- data/assets/css/css.scss +1 -0
- data/assets/fonts/.DS_Store +0 -0
- data/assets/js/.DS_Store +0 -0
- data/assets/js/lunr.js +1753 -1754
- data/assets/js/search.js +21 -22
- data/assets/js/toc.js +9 -9
- metadata +7 -4
- data/assets/js/lunr.unicodeNormalizer.ts +0 -162
data/assets/js/lunr.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
/***
|
2
2
|
* lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 2.3.9
|
3
3
|
* Copyright (C) 2020 Oliver Nightingale
|
4
4
|
* @license MIT
|
@@ -38,20 +38,20 @@
|
|
38
38
|
* @namespace {function} lunr
|
39
39
|
*/
|
40
40
|
var lunr = function (config) {
|
41
|
-
|
41
|
+
var builder = new lunr.Builder
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
builder.pipeline.add(
|
44
|
+
lunr.trimmer,
|
45
|
+
lunr.stopWordFilter,
|
46
|
+
lunr.stemmer
|
47
|
+
)
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
builder.searchPipeline.add(
|
50
|
+
lunr.stemmer
|
51
|
+
)
|
52
52
|
|
53
|
-
|
54
|
-
|
53
|
+
config.call(builder, builder)
|
54
|
+
return builder.build()
|
55
55
|
}
|
56
56
|
|
57
57
|
lunr.version = "2.3.9"
|
@@ -74,13 +74,13 @@ lunr.utils = {}
|
|
74
74
|
* @function
|
75
75
|
*/
|
76
76
|
lunr.utils.warn = (function (global) {
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
77
|
+
/* eslint-disable no-console */
|
78
|
+
return function (message) {
|
79
|
+
if (global.console && console.warn) {
|
80
|
+
console.warn(message)
|
81
|
+
}
|
82
|
+
}
|
83
|
+
/* eslint-enable no-console */
|
84
84
|
})(this)
|
85
85
|
|
86
86
|
/**
|
@@ -95,11 +95,11 @@ lunr.utils.warn = (function (global) {
|
|
95
95
|
* @memberOf lunr.utils
|
96
96
|
*/
|
97
97
|
lunr.utils.asString = function (obj) {
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
98
|
+
if (obj === void 0 || obj === null) {
|
99
|
+
return ""
|
100
|
+
} else {
|
101
|
+
return obj.toString()
|
102
|
+
}
|
103
103
|
}
|
104
104
|
|
105
105
|
/**
|
@@ -119,61 +119,61 @@ lunr.utils.asString = function (obj) {
|
|
119
119
|
* @memberOf Utils
|
120
120
|
*/
|
121
121
|
lunr.utils.clone = function (obj) {
|
122
|
-
|
123
|
-
|
124
|
-
|
122
|
+
if (obj === null || obj === undefined) {
|
123
|
+
return obj
|
124
|
+
}
|
125
125
|
|
126
|
-
|
126
|
+
var clone = Object.create(null),
|
127
127
|
keys = Object.keys(obj)
|
128
128
|
|
129
|
-
|
130
|
-
|
131
|
-
|
129
|
+
for (var i = 0; i < keys.length; i++) {
|
130
|
+
var key = keys[i],
|
131
|
+
val = obj[key]
|
132
132
|
|
133
|
-
|
133
|
+
if (Array.isArray(val)) {
|
134
134
|
clone[key] = val.slice()
|
135
135
|
continue
|
136
|
-
|
136
|
+
}
|
137
137
|
|
138
|
-
|
139
|
-
|
140
|
-
|
138
|
+
if (typeof val === 'string' ||
|
139
|
+
typeof val === 'number' ||
|
140
|
+
typeof val === 'boolean') {
|
141
141
|
clone[key] = val
|
142
142
|
continue
|
143
|
-
|
143
|
+
}
|
144
144
|
|
145
|
-
|
146
|
-
|
145
|
+
throw new TypeError("clone is not deep and does not support nested objects")
|
146
|
+
}
|
147
147
|
|
148
|
-
|
148
|
+
return clone
|
149
149
|
}
|
150
150
|
lunr.FieldRef = function (docRef, fieldName, stringValue) {
|
151
|
-
|
152
|
-
|
153
|
-
|
151
|
+
this.docRef = docRef
|
152
|
+
this.fieldName = fieldName
|
153
|
+
this._stringValue = stringValue
|
154
154
|
}
|
155
155
|
|
156
156
|
lunr.FieldRef.joiner = "/"
|
157
157
|
|
158
158
|
lunr.FieldRef.fromString = function (s) {
|
159
|
-
|
159
|
+
var n = s.indexOf(lunr.FieldRef.joiner)
|
160
160
|
|
161
|
-
|
162
|
-
|
163
|
-
|
161
|
+
if (n === -1) {
|
162
|
+
throw "malformed field ref string"
|
163
|
+
}
|
164
164
|
|
165
|
-
|
165
|
+
var fieldRef = s.slice(0, n),
|
166
166
|
docRef = s.slice(n + 1)
|
167
167
|
|
168
|
-
|
168
|
+
return new lunr.FieldRef (docRef, fieldRef, s)
|
169
169
|
}
|
170
170
|
|
171
171
|
lunr.FieldRef.prototype.toString = function () {
|
172
|
-
|
173
|
-
|
174
|
-
|
172
|
+
if (this._stringValue == undefined) {
|
173
|
+
this._stringValue = this.fieldName + lunr.FieldRef.joiner + this.docRef
|
174
|
+
}
|
175
175
|
|
176
|
-
|
176
|
+
return this._stringValue
|
177
177
|
}
|
178
178
|
/*!
|
179
179
|
* lunr.Set
|
@@ -186,17 +186,17 @@ lunr.FieldRef.prototype.toString = function () {
|
|
186
186
|
* @constructor
|
187
187
|
*/
|
188
188
|
lunr.Set = function (elements) {
|
189
|
-
|
189
|
+
this.elements = Object.create(null)
|
190
190
|
|
191
|
-
|
192
|
-
|
191
|
+
if (elements) {
|
192
|
+
this.length = elements.length
|
193
193
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
194
|
+
for (var i = 0; i < this.length; i++) {
|
195
|
+
this.elements[elements[i]] = true
|
196
|
+
}
|
197
|
+
} else {
|
198
|
+
this.length = 0
|
199
|
+
}
|
200
200
|
}
|
201
201
|
|
202
202
|
/**
|
@@ -207,17 +207,17 @@ lunr.Set = function (elements) {
|
|
207
207
|
* @type {lunr.Set}
|
208
208
|
*/
|
209
209
|
lunr.Set.complete = {
|
210
|
-
|
211
|
-
|
212
|
-
|
210
|
+
intersect: function (other) {
|
211
|
+
return other
|
212
|
+
},
|
213
213
|
|
214
|
-
|
215
|
-
|
216
|
-
|
214
|
+
union: function () {
|
215
|
+
return this
|
216
|
+
},
|
217
217
|
|
218
|
-
|
219
|
-
|
220
|
-
|
218
|
+
contains: function () {
|
219
|
+
return true
|
220
|
+
}
|
221
221
|
}
|
222
222
|
|
223
223
|
/**
|
@@ -228,17 +228,17 @@ lunr.Set.complete = {
|
|
228
228
|
* @type {lunr.Set}
|
229
229
|
*/
|
230
230
|
lunr.Set.empty = {
|
231
|
-
|
232
|
-
|
233
|
-
|
231
|
+
intersect: function () {
|
232
|
+
return this
|
233
|
+
},
|
234
234
|
|
235
|
-
|
236
|
-
|
237
|
-
|
235
|
+
union: function (other) {
|
236
|
+
return other
|
237
|
+
},
|
238
238
|
|
239
|
-
|
240
|
-
|
241
|
-
|
239
|
+
contains: function () {
|
240
|
+
return false
|
241
|
+
}
|
242
242
|
}
|
243
243
|
|
244
244
|
/**
|
@@ -248,7 +248,7 @@ lunr.Set.empty = {
|
|
248
248
|
* @returns {boolean} - True if this set contains the specified object.
|
249
249
|
*/
|
250
250
|
lunr.Set.prototype.contains = function (object) {
|
251
|
-
|
251
|
+
return !!this.elements[object]
|
252
252
|
}
|
253
253
|
|
254
254
|
/**
|
@@ -260,34 +260,34 @@ lunr.Set.prototype.contains = function (object) {
|
|
260
260
|
*/
|
261
261
|
|
262
262
|
lunr.Set.prototype.intersect = function (other) {
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
263
|
+
var a, b, elements, intersection = []
|
264
|
+
|
265
|
+
if (other === lunr.Set.complete) {
|
266
|
+
return this
|
267
|
+
}
|
268
|
+
|
269
|
+
if (other === lunr.Set.empty) {
|
270
|
+
return other
|
271
|
+
}
|
272
|
+
|
273
|
+
if (this.length < other.length) {
|
274
|
+
a = this
|
275
|
+
b = other
|
276
|
+
} else {
|
277
|
+
a = other
|
278
|
+
b = this
|
279
|
+
}
|
280
|
+
|
281
|
+
elements = Object.keys(a.elements)
|
282
|
+
|
283
|
+
for (var i = 0; i < elements.length; i++) {
|
284
|
+
var element = elements[i]
|
285
|
+
if (element in b.elements) {
|
286
|
+
intersection.push(element)
|
287
|
+
}
|
288
|
+
}
|
289
289
|
|
290
|
-
|
290
|
+
return new lunr.Set (intersection)
|
291
291
|
}
|
292
292
|
|
293
293
|
/**
|
@@ -298,15 +298,15 @@ lunr.Set.prototype.intersect = function (other) {
|
|
298
298
|
*/
|
299
299
|
|
300
300
|
lunr.Set.prototype.union = function (other) {
|
301
|
-
|
302
|
-
|
303
|
-
|
301
|
+
if (other === lunr.Set.complete) {
|
302
|
+
return lunr.Set.complete
|
303
|
+
}
|
304
304
|
|
305
|
-
|
306
|
-
|
307
|
-
|
305
|
+
if (other === lunr.Set.empty) {
|
306
|
+
return this
|
307
|
+
}
|
308
308
|
|
309
|
-
|
309
|
+
return new lunr.Set(Object.keys(this.elements).concat(Object.keys(other.elements)))
|
310
310
|
}
|
311
311
|
/**
|
312
312
|
* A function to calculate the inverse document frequency for
|
@@ -317,16 +317,16 @@ lunr.Set.prototype.union = function (other) {
|
|
317
317
|
* @param {number} documentCount - The total number of documents.
|
318
318
|
*/
|
319
319
|
lunr.idf = function (posting, documentCount) {
|
320
|
-
|
320
|
+
var documentsWithTerm = 0
|
321
321
|
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
322
|
+
for (var fieldName in posting) {
|
323
|
+
if (fieldName == '_index') continue // Ignore the term index, its not a field
|
324
|
+
documentsWithTerm += Object.keys(posting[fieldName]).length
|
325
|
+
}
|
326
326
|
|
327
|
-
|
327
|
+
var x = (documentCount - documentsWithTerm + 0.5) / (documentsWithTerm + 0.5)
|
328
328
|
|
329
|
-
|
329
|
+
return Math.log(1 + Math.abs(x))
|
330
330
|
}
|
331
331
|
|
332
332
|
/**
|
@@ -338,8 +338,8 @@ lunr.idf = function (posting, documentCount) {
|
|
338
338
|
* @param {object} [metadata={}] - Metadata associated with this token.
|
339
339
|
*/
|
340
340
|
lunr.Token = function (str, metadata) {
|
341
|
-
|
342
|
-
|
341
|
+
this.str = str || ""
|
342
|
+
this.metadata = metadata || {}
|
343
343
|
}
|
344
344
|
|
345
345
|
/**
|
@@ -348,7 +348,7 @@ lunr.Token = function (str, metadata) {
|
|
348
348
|
* @returns {string}
|
349
349
|
*/
|
350
350
|
lunr.Token.prototype.toString = function () {
|
351
|
-
|
351
|
+
return this.str
|
352
352
|
}
|
353
353
|
|
354
354
|
/**
|
@@ -372,8 +372,8 @@ lunr.Token.prototype.toString = function () {
|
|
372
372
|
* @returns {lunr.Token}
|
373
373
|
*/
|
374
374
|
lunr.Token.prototype.update = function (fn) {
|
375
|
-
|
376
|
-
|
375
|
+
this.str = fn(this.str, this.metadata)
|
376
|
+
return this
|
377
377
|
}
|
378
378
|
|
379
379
|
/**
|
@@ -384,8 +384,8 @@ lunr.Token.prototype.update = function (fn) {
|
|
384
384
|
* @returns {lunr.Token}
|
385
385
|
*/
|
386
386
|
lunr.Token.prototype.clone = function (fn) {
|
387
|
-
|
388
|
-
|
387
|
+
fn = fn || function (s) { return s }
|
388
|
+
return new lunr.Token (fn(this.str, this.metadata), this.metadata)
|
389
389
|
}
|
390
390
|
/*!
|
391
391
|
* lunr.tokenizer
|
@@ -411,44 +411,44 @@ lunr.Token.prototype.clone = function (fn) {
|
|
411
411
|
* @see {@link lunr.Pipeline}
|
412
412
|
*/
|
413
413
|
lunr.tokenizer = function (obj, metadata) {
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
414
|
+
if (obj == null || obj == undefined) {
|
415
|
+
return []
|
416
|
+
}
|
417
|
+
|
418
|
+
if (Array.isArray(obj)) {
|
419
|
+
return obj.map(function (t) {
|
420
|
+
return new lunr.Token(
|
421
|
+
lunr.utils.asString(t).toLowerCase(),
|
422
|
+
lunr.utils.clone(metadata)
|
423
|
+
)
|
424
|
+
})
|
425
|
+
}
|
426
426
|
|
427
|
-
|
427
|
+
var str = obj.toString().toLowerCase(),
|
428
428
|
len = str.length,
|
429
429
|
tokens = []
|
430
430
|
|
431
|
-
|
432
|
-
|
433
|
-
|
431
|
+
for (var sliceEnd = 0, sliceStart = 0; sliceEnd <= len; sliceEnd++) {
|
432
|
+
var char = str.charAt(sliceEnd),
|
433
|
+
sliceLength = sliceEnd - sliceStart
|
434
434
|
|
435
|
-
|
435
|
+
if ((char.match(lunr.tokenizer.separator) || sliceEnd == len)) {
|
436
436
|
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
437
|
+
if (sliceLength > 0) {
|
438
|
+
var tokenMetadata = lunr.utils.clone(metadata) || {}
|
439
|
+
tokenMetadata["position"] = [sliceStart, sliceLength]
|
440
|
+
tokenMetadata["index"] = tokens.length
|
441
441
|
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
442
|
+
tokens.push(
|
443
|
+
new lunr.Token (
|
444
|
+
str.slice(sliceStart, sliceEnd),
|
445
|
+
tokenMetadata
|
446
|
+
)
|
447
|
+
)
|
448
|
+
}
|
449
449
|
|
450
|
-
|
451
|
-
|
450
|
+
sliceStart = sliceEnd + 1
|
451
|
+
}
|
452
452
|
|
453
453
|
}
|
454
454
|
|
@@ -498,7 +498,7 @@ lunr.tokenizer.separator = /[\s\-]+/
|
|
498
498
|
* @constructor
|
499
499
|
*/
|
500
500
|
lunr.Pipeline = function () {
|
501
|
-
|
501
|
+
this._stack = []
|
502
502
|
}
|
503
503
|
|
504
504
|
lunr.Pipeline.registeredFunctions = Object.create(null)
|
@@ -537,12 +537,12 @@ lunr.Pipeline.registeredFunctions = Object.create(null)
|
|
537
537
|
* @param {String} label - The label to register this function with
|
538
538
|
*/
|
539
539
|
lunr.Pipeline.registerFunction = function (fn, label) {
|
540
|
-
|
541
|
-
|
542
|
-
|
540
|
+
if (label in this.registeredFunctions) {
|
541
|
+
lunr.utils.warn('Overwriting existing registered function: ' + label)
|
542
|
+
}
|
543
543
|
|
544
|
-
|
545
|
-
|
544
|
+
fn.label = label
|
545
|
+
lunr.Pipeline.registeredFunctions[fn.label] = fn
|
546
546
|
}
|
547
547
|
|
548
548
|
/**
|
@@ -552,11 +552,11 @@ lunr.Pipeline.registerFunction = function (fn, label) {
|
|
552
552
|
* @private
|
553
553
|
*/
|
554
554
|
lunr.Pipeline.warnIfFunctionNotRegistered = function (fn) {
|
555
|
-
|
555
|
+
var isRegistered = fn.label && (fn.label in this.registeredFunctions)
|
556
556
|
|
557
|
-
|
558
|
-
|
559
|
-
|
557
|
+
if (!isRegistered) {
|
558
|
+
lunr.utils.warn('Function is not registered with pipeline. This may cause problems when serialising the index.\n', fn)
|
559
|
+
}
|
560
560
|
}
|
561
561
|
|
562
562
|
/**
|
@@ -570,17 +570,17 @@ lunr.Pipeline.warnIfFunctionNotRegistered = function (fn) {
|
|
570
570
|
* @returns {lunr.Pipeline}
|
571
571
|
*/
|
572
572
|
lunr.Pipeline.load = function (serialised) {
|
573
|
-
|
573
|
+
var pipeline = new lunr.Pipeline
|
574
574
|
|
575
|
-
|
576
|
-
|
575
|
+
serialised.forEach(function (fnName) {
|
576
|
+
var fn = lunr.Pipeline.registeredFunctions[fnName]
|
577
577
|
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
578
|
+
if (fn) {
|
579
|
+
pipeline.add(fn)
|
580
|
+
} else {
|
581
|
+
throw new Error('Cannot load unregistered function: ' + fnName)
|
582
|
+
}
|
583
|
+
})
|
584
584
|
|
585
585
|
return pipeline
|
586
586
|
}
|
@@ -593,12 +593,12 @@ lunr.Pipeline.load = function (serialised) {
|
|
593
593
|
* @param {lunr.PipelineFunction[]} functions - Any number of functions to add to the pipeline.
|
594
594
|
*/
|
595
595
|
lunr.Pipeline.prototype.add = function () {
|
596
|
-
|
596
|
+
var fns = Array.prototype.slice.call(arguments)
|
597
597
|
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
598
|
+
fns.forEach(function (fn) {
|
599
|
+
lunr.Pipeline.warnIfFunctionNotRegistered(fn)
|
600
|
+
this._stack.push(fn)
|
601
|
+
}, this)
|
602
602
|
}
|
603
603
|
|
604
604
|
/**
|
@@ -611,15 +611,15 @@ lunr.Pipeline.prototype.add = function () {
|
|
611
611
|
* @param {lunr.PipelineFunction} newFn - The new function to add to the pipeline.
|
612
612
|
*/
|
613
613
|
lunr.Pipeline.prototype.after = function (existingFn, newFn) {
|
614
|
-
|
614
|
+
lunr.Pipeline.warnIfFunctionNotRegistered(newFn)
|
615
615
|
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
616
|
+
var pos = this._stack.indexOf(existingFn)
|
617
|
+
if (pos == -1) {
|
618
|
+
throw new Error('Cannot find existingFn')
|
619
|
+
}
|
620
620
|
|
621
|
-
|
622
|
-
|
621
|
+
pos = pos + 1
|
622
|
+
this._stack.splice(pos, 0, newFn)
|
623
623
|
}
|
624
624
|
|
625
625
|
/**
|
@@ -632,14 +632,14 @@ lunr.Pipeline.prototype.after = function (existingFn, newFn) {
|
|
632
632
|
* @param {lunr.PipelineFunction} newFn - The new function to add to the pipeline.
|
633
633
|
*/
|
634
634
|
lunr.Pipeline.prototype.before = function (existingFn, newFn) {
|
635
|
-
|
635
|
+
lunr.Pipeline.warnIfFunctionNotRegistered(newFn)
|
636
636
|
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
637
|
+
var pos = this._stack.indexOf(existingFn)
|
638
|
+
if (pos == -1) {
|
639
|
+
throw new Error('Cannot find existingFn')
|
640
|
+
}
|
641
641
|
|
642
|
-
|
642
|
+
this._stack.splice(pos, 0, newFn)
|
643
643
|
}
|
644
644
|
|
645
645
|
/**
|
@@ -648,12 +648,12 @@ lunr.Pipeline.prototype.before = function (existingFn, newFn) {
|
|
648
648
|
* @param {lunr.PipelineFunction} fn The function to remove from the pipeline.
|
649
649
|
*/
|
650
650
|
lunr.Pipeline.prototype.remove = function (fn) {
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
651
|
+
var pos = this._stack.indexOf(fn)
|
652
|
+
if (pos == -1) {
|
653
|
+
return
|
654
|
+
}
|
655
655
|
|
656
|
-
|
656
|
+
this._stack.splice(pos, 1)
|
657
657
|
}
|
658
658
|
|
659
659
|
/**
|
@@ -664,30 +664,30 @@ lunr.Pipeline.prototype.remove = function (fn) {
|
|
664
664
|
* @returns {Array}
|
665
665
|
*/
|
666
666
|
lunr.Pipeline.prototype.run = function (tokens) {
|
667
|
-
|
667
|
+
var stackLength = this._stack.length
|
668
668
|
|
669
|
-
|
670
|
-
|
671
|
-
|
669
|
+
for (var i = 0; i < stackLength; i++) {
|
670
|
+
var fn = this._stack[i]
|
671
|
+
var memo = []
|
672
672
|
|
673
|
-
|
674
|
-
|
673
|
+
for (var j = 0; j < tokens.length; j++) {
|
674
|
+
var result = fn(tokens[j], j, tokens)
|
675
675
|
|
676
|
-
|
676
|
+
if (result === null || result === void 0 || result === '') continue
|
677
677
|
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
678
|
+
if (Array.isArray(result)) {
|
679
|
+
for (var k = 0; k < result.length; k++) {
|
680
|
+
memo.push(result[k])
|
681
|
+
}
|
682
|
+
} else {
|
683
|
+
memo.push(result)
|
684
|
+
}
|
684
685
|
}
|
685
|
-
}
|
686
686
|
|
687
|
-
|
688
|
-
|
687
|
+
tokens = memo
|
688
|
+
}
|
689
689
|
|
690
|
-
|
690
|
+
return tokens
|
691
691
|
}
|
692
692
|
|
693
693
|
/**
|
@@ -701,11 +701,11 @@ lunr.Pipeline.prototype.run = function (tokens) {
|
|
701
701
|
* @returns {string[]}
|
702
702
|
*/
|
703
703
|
lunr.Pipeline.prototype.runString = function (str, metadata) {
|
704
|
-
|
704
|
+
var token = new lunr.Token (str, metadata)
|
705
705
|
|
706
|
-
|
707
|
-
|
708
|
-
|
706
|
+
return this.run([token]).map(function (t) {
|
707
|
+
return t.toString()
|
708
|
+
})
|
709
709
|
}
|
710
710
|
|
711
711
|
/**
|
@@ -713,7 +713,7 @@ lunr.Pipeline.prototype.runString = function (str, metadata) {
|
|
713
713
|
*
|
714
714
|
*/
|
715
715
|
lunr.Pipeline.prototype.reset = function () {
|
716
|
-
|
716
|
+
this._stack = []
|
717
717
|
}
|
718
718
|
|
719
719
|
/**
|
@@ -724,11 +724,11 @@ lunr.Pipeline.prototype.reset = function () {
|
|
724
724
|
* @returns {Array}
|
725
725
|
*/
|
726
726
|
lunr.Pipeline.prototype.toJSON = function () {
|
727
|
-
|
728
|
-
|
727
|
+
return this._stack.map(function (fn) {
|
728
|
+
lunr.Pipeline.warnIfFunctionNotRegistered(fn)
|
729
729
|
|
730
|
-
|
731
|
-
|
730
|
+
return fn.label
|
731
|
+
})
|
732
732
|
}
|
733
733
|
/*!
|
734
734
|
* lunr.Vector
|
@@ -752,8 +752,8 @@ lunr.Pipeline.prototype.toJSON = function () {
|
|
752
752
|
* @param {Number[]} [elements] - The flat list of element index and element value pairs.
|
753
753
|
*/
|
754
754
|
lunr.Vector = function (elements) {
|
755
|
-
|
756
|
-
|
755
|
+
this._magnitude = 0
|
756
|
+
this.elements = elements || []
|
757
757
|
}
|
758
758
|
|
759
759
|
|
@@ -768,46 +768,46 @@ lunr.Vector = function (elements) {
|
|
768
768
|
* @returns {Number}
|
769
769
|
*/
|
770
770
|
lunr.Vector.prototype.positionForIndex = function (index) {
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
771
|
+
// For an empty vector the tuple can be inserted at the beginning
|
772
|
+
if (this.elements.length == 0) {
|
773
|
+
return 0
|
774
|
+
}
|
775
775
|
|
776
|
-
|
776
|
+
var start = 0,
|
777
777
|
end = this.elements.length / 2,
|
778
778
|
sliceLength = end - start,
|
779
779
|
pivotPoint = Math.floor(sliceLength / 2),
|
780
780
|
pivotIndex = this.elements[pivotPoint * 2]
|
781
781
|
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
782
|
+
while (sliceLength > 1) {
|
783
|
+
if (pivotIndex < index) {
|
784
|
+
start = pivotPoint
|
785
|
+
}
|
786
786
|
|
787
|
-
|
788
|
-
|
789
|
-
|
787
|
+
if (pivotIndex > index) {
|
788
|
+
end = pivotPoint
|
789
|
+
}
|
790
790
|
|
791
|
-
|
792
|
-
|
793
|
-
|
791
|
+
if (pivotIndex == index) {
|
792
|
+
break
|
793
|
+
}
|
794
794
|
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
795
|
+
sliceLength = end - start
|
796
|
+
pivotPoint = start + Math.floor(sliceLength / 2)
|
797
|
+
pivotIndex = this.elements[pivotPoint * 2]
|
798
|
+
}
|
799
799
|
|
800
|
-
|
801
|
-
|
802
|
-
|
800
|
+
if (pivotIndex == index) {
|
801
|
+
return pivotPoint * 2
|
802
|
+
}
|
803
803
|
|
804
|
-
|
805
|
-
|
806
|
-
|
804
|
+
if (pivotIndex > index) {
|
805
|
+
return pivotPoint * 2
|
806
|
+
}
|
807
807
|
|
808
|
-
|
809
|
-
|
810
|
-
|
808
|
+
if (pivotIndex < index) {
|
809
|
+
return (pivotPoint + 1) * 2
|
810
|
+
}
|
811
811
|
}
|
812
812
|
|
813
813
|
/**
|
@@ -820,9 +820,9 @@ lunr.Vector.prototype.positionForIndex = function (index) {
|
|
820
820
|
* @param {Number} val - The value to be inserted into the vector.
|
821
821
|
*/
|
822
822
|
lunr.Vector.prototype.insert = function (insertIdx, val) {
|
823
|
-
|
824
|
-
|
825
|
-
|
823
|
+
this.upsert(insertIdx, val, function () {
|
824
|
+
throw "duplicate index"
|
825
|
+
})
|
826
826
|
}
|
827
827
|
|
828
828
|
/**
|
@@ -834,14 +834,14 @@ lunr.Vector.prototype.insert = function (insertIdx, val) {
|
|
834
834
|
* requested value are passed as arguments
|
835
835
|
*/
|
836
836
|
lunr.Vector.prototype.upsert = function (insertIdx, val, fn) {
|
837
|
-
|
838
|
-
|
837
|
+
this._magnitude = 0
|
838
|
+
var position = this.positionForIndex(insertIdx)
|
839
839
|
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
840
|
+
if (this.elements[position] == insertIdx) {
|
841
|
+
this.elements[position + 1] = fn(this.elements[position + 1], val)
|
842
|
+
} else {
|
843
|
+
this.elements.splice(position, 0, insertIdx, val)
|
844
|
+
}
|
845
845
|
}
|
846
846
|
|
847
847
|
/**
|
@@ -850,17 +850,17 @@ lunr.Vector.prototype.upsert = function (insertIdx, val, fn) {
|
|
850
850
|
* @returns {Number}
|
851
851
|
*/
|
852
852
|
lunr.Vector.prototype.magnitude = function () {
|
853
|
-
|
853
|
+
if (this._magnitude) return this._magnitude
|
854
854
|
|
855
|
-
|
855
|
+
var sumOfSquares = 0,
|
856
856
|
elementsLength = this.elements.length
|
857
857
|
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
858
|
+
for (var i = 1; i < elementsLength; i += 2) {
|
859
|
+
var val = this.elements[i]
|
860
|
+
sumOfSquares += val * val
|
861
|
+
}
|
862
862
|
|
863
|
-
|
863
|
+
return this._magnitude = Math.sqrt(sumOfSquares)
|
864
864
|
}
|
865
865
|
|
866
866
|
/**
|
@@ -870,26 +870,26 @@ lunr.Vector.prototype.magnitude = function () {
|
|
870
870
|
* @returns {Number}
|
871
871
|
*/
|
872
872
|
lunr.Vector.prototype.dot = function (otherVector) {
|
873
|
-
|
873
|
+
var dotProduct = 0,
|
874
874
|
a = this.elements, b = otherVector.elements,
|
875
875
|
aLen = a.length, bLen = b.length,
|
876
876
|
aVal = 0, bVal = 0,
|
877
877
|
i = 0, j = 0
|
878
878
|
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
879
|
+
while (i < aLen && j < bLen) {
|
880
|
+
aVal = a[i], bVal = b[j]
|
881
|
+
if (aVal < bVal) {
|
882
|
+
i += 2
|
883
|
+
} else if (aVal > bVal) {
|
884
|
+
j += 2
|
885
|
+
} else if (aVal == bVal) {
|
886
|
+
dotProduct += a[i + 1] * b[j + 1]
|
887
|
+
i += 2
|
888
|
+
j += 2
|
889
|
+
}
|
890
|
+
}
|
891
891
|
|
892
|
-
|
892
|
+
return dotProduct
|
893
893
|
}
|
894
894
|
|
895
895
|
/**
|
@@ -900,7 +900,7 @@ lunr.Vector.prototype.dot = function (otherVector) {
|
|
900
900
|
* @returns {Number}
|
901
901
|
*/
|
902
902
|
lunr.Vector.prototype.similarity = function (otherVector) {
|
903
|
-
|
903
|
+
return this.dot(otherVector) / this.magnitude() || 0
|
904
904
|
}
|
905
905
|
|
906
906
|
/**
|
@@ -909,13 +909,13 @@ lunr.Vector.prototype.similarity = function (otherVector) {
|
|
909
909
|
* @returns {Number[]}
|
910
910
|
*/
|
911
911
|
lunr.Vector.prototype.toArray = function () {
|
912
|
-
|
912
|
+
var output = new Array (this.elements.length / 2)
|
913
913
|
|
914
|
-
|
915
|
-
|
916
|
-
|
914
|
+
for (var i = 1, j = 0; i < this.elements.length; i += 2, j++) {
|
915
|
+
output[j] = this.elements[i]
|
916
|
+
}
|
917
917
|
|
918
|
-
|
918
|
+
return output
|
919
919
|
}
|
920
920
|
|
921
921
|
/**
|
@@ -924,7 +924,7 @@ lunr.Vector.prototype.toArray = function () {
|
|
924
924
|
* @returns {Number[]}
|
925
925
|
*/
|
926
926
|
lunr.Vector.prototype.toJSON = function () {
|
927
|
-
|
927
|
+
return this.elements
|
928
928
|
}
|
929
929
|
/* eslint-disable */
|
930
930
|
/*!
|
@@ -945,7 +945,7 @@ lunr.Vector.prototype.toJSON = function () {
|
|
945
945
|
* @function
|
946
946
|
*/
|
947
947
|
lunr.stemmer = (function(){
|
948
|
-
|
948
|
+
var step2list = {
|
949
949
|
"ational" : "ate",
|
950
950
|
"tional" : "tion",
|
951
951
|
"enci" : "ence",
|
@@ -967,9 +967,9 @@ lunr.stemmer = (function(){
|
|
967
967
|
"iviti" : "ive",
|
968
968
|
"biliti" : "ble",
|
969
969
|
"logi" : "log"
|
970
|
-
|
970
|
+
},
|
971
971
|
|
972
|
-
|
972
|
+
step3list = {
|
973
973
|
"icate" : "ic",
|
974
974
|
"ative" : "",
|
975
975
|
"alize" : "al",
|
@@ -977,175 +977,174 @@ lunr.stemmer = (function(){
|
|
977
977
|
"ical" : "ic",
|
978
978
|
"ful" : "",
|
979
979
|
"ness" : ""
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
}
|
1033
|
-
|
1034
|
-
// Step 1a
|
1035
|
-
re = re_1a
|
1036
|
-
re2 = re2_1a;
|
1037
|
-
|
1038
|
-
if (re.test(w)) { w = w.replace(re,"$1$2"); }
|
1039
|
-
else if (re2.test(w)) { w = w.replace(re2,"$1$2"); }
|
1040
|
-
|
1041
|
-
// Step 1b
|
1042
|
-
re = re_1b;
|
1043
|
-
re2 = re2_1b;
|
1044
|
-
if (re.test(w)) {
|
1045
|
-
var fp = re.exec(w);
|
1046
|
-
re = re_mgr0;
|
1047
|
-
if (re.test(fp[1])) {
|
1048
|
-
re = re_1b_2;
|
1049
|
-
w = w.replace(re,"");
|
980
|
+
},
|
981
|
+
|
982
|
+
c = "[^aeiou]", // consonant
|
983
|
+
v = "[aeiouy]", // vowel
|
984
|
+
C = c + "[^aeiouy]*", // consonant sequence
|
985
|
+
V = v + "[aeiou]*", // vowel sequence
|
986
|
+
|
987
|
+
mgr0 = "^(" + C + ")?" + V + C, // [C]VC... is m>0
|
988
|
+
meq1 = "^(" + C + ")?" + V + C + "(" + V + ")?$", // [C]VC[V] is m=1
|
989
|
+
mgr1 = "^(" + C + ")?" + V + C + V + C, // [C]VCVC... is m>1
|
990
|
+
s_v = "^(" + C + ")?" + v; // vowel in stem
|
991
|
+
|
992
|
+
var re_mgr0 = new RegExp(mgr0);
|
993
|
+
var re_mgr1 = new RegExp(mgr1);
|
994
|
+
var re_meq1 = new RegExp(meq1);
|
995
|
+
var re_s_v = new RegExp(s_v);
|
996
|
+
|
997
|
+
var re_1a = /^(.+?)(ss|i)es$/;
|
998
|
+
var re2_1a = /^(.+?)([^s])s$/;
|
999
|
+
var re_1b = /^(.+?)eed$/;
|
1000
|
+
var re2_1b = /^(.+?)(ed|ing)$/;
|
1001
|
+
var re_1b_2 = /.$/;
|
1002
|
+
var re2_1b_2 = /(at|bl|iz)$/;
|
1003
|
+
var re3_1b_2 = new RegExp("([^aeiouylsz])\\1$");
|
1004
|
+
var re4_1b_2 = new RegExp("^" + C + v + "[^aeiouwxy]$");
|
1005
|
+
|
1006
|
+
var re_1c = /^(.+?[^aeiou])y$/;
|
1007
|
+
var re_2 = /^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/;
|
1008
|
+
|
1009
|
+
var re_3 = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/;
|
1010
|
+
|
1011
|
+
var re_4 = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/;
|
1012
|
+
var re2_4 = /^(.+?)(s|t)(ion)$/;
|
1013
|
+
|
1014
|
+
var re_5 = /^(.+?)e$/;
|
1015
|
+
var re_5_1 = /ll$/;
|
1016
|
+
var re3_5 = new RegExp("^" + C + v + "[^aeiouwxy]$");
|
1017
|
+
|
1018
|
+
var porterStemmer = function porterStemmer(w) {
|
1019
|
+
var stem,
|
1020
|
+
suffix,
|
1021
|
+
firstch,
|
1022
|
+
re,
|
1023
|
+
re2,
|
1024
|
+
re3,
|
1025
|
+
re4;
|
1026
|
+
|
1027
|
+
if (w.length < 3) { return w; }
|
1028
|
+
|
1029
|
+
firstch = w.substr(0,1);
|
1030
|
+
if (firstch == "y") {
|
1031
|
+
w = firstch.toUpperCase() + w.substr(1);
|
1050
1032
|
}
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
re2 =
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
w = stem + step2list[suffix];
|
1033
|
+
|
1034
|
+
// Step 1a
|
1035
|
+
re = re_1a
|
1036
|
+
re2 = re2_1a;
|
1037
|
+
|
1038
|
+
if (re.test(w)) { w = w.replace(re,"$1$2"); }
|
1039
|
+
else if (re2.test(w)) { w = w.replace(re2,"$1$2"); }
|
1040
|
+
|
1041
|
+
// Step 1b
|
1042
|
+
re = re_1b;
|
1043
|
+
re2 = re2_1b;
|
1044
|
+
if (re.test(w)) {
|
1045
|
+
var fp = re.exec(w);
|
1046
|
+
re = re_mgr0;
|
1047
|
+
if (re.test(fp[1])) {
|
1048
|
+
re = re_1b_2;
|
1049
|
+
w = w.replace(re,"");
|
1050
|
+
}
|
1051
|
+
} else if (re2.test(w)) {
|
1052
|
+
var fp = re2.exec(w);
|
1053
|
+
stem = fp[1];
|
1054
|
+
re2 = re_s_v;
|
1055
|
+
if (re2.test(stem)) {
|
1056
|
+
w = stem;
|
1057
|
+
re2 = re2_1b_2;
|
1058
|
+
re3 = re3_1b_2;
|
1059
|
+
re4 = re4_1b_2;
|
1060
|
+
if (re2.test(w)) { w = w + "e"; }
|
1061
|
+
else if (re3.test(w)) { re = re_1b_2; w = w.replace(re,""); }
|
1062
|
+
else if (re4.test(w)) { w = w + "e"; }
|
1063
|
+
}
|
1083
1064
|
}
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
suffix = fp[2];
|
1092
|
-
re = re_mgr0;
|
1093
|
-
if (re.test(stem)) {
|
1094
|
-
w = stem + step3list[suffix];
|
1065
|
+
|
1066
|
+
// Step 1c - replace suffix y or Y by i if preceded by a non-vowel which is not the first letter of the word (so cry -> cri, by -> by, say -> say)
|
1067
|
+
re = re_1c;
|
1068
|
+
if (re.test(w)) {
|
1069
|
+
var fp = re.exec(w);
|
1070
|
+
stem = fp[1];
|
1071
|
+
w = stem + "i";
|
1095
1072
|
}
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1073
|
+
|
1074
|
+
// Step 2
|
1075
|
+
re = re_2;
|
1076
|
+
if (re.test(w)) {
|
1077
|
+
var fp = re.exec(w);
|
1078
|
+
stem = fp[1];
|
1079
|
+
suffix = fp[2];
|
1080
|
+
re = re_mgr0;
|
1081
|
+
if (re.test(stem)) {
|
1082
|
+
w = stem + step2list[suffix];
|
1083
|
+
}
|
1107
1084
|
}
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1085
|
+
|
1086
|
+
// Step 3
|
1087
|
+
re = re_3;
|
1088
|
+
if (re.test(w)) {
|
1089
|
+
var fp = re.exec(w);
|
1090
|
+
stem = fp[1];
|
1091
|
+
suffix = fp[2];
|
1092
|
+
re = re_mgr0;
|
1093
|
+
if (re.test(stem)) {
|
1094
|
+
w = stem + step3list[suffix];
|
1095
|
+
}
|
1114
1096
|
}
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1097
|
+
|
1098
|
+
// Step 4
|
1099
|
+
re = re_4;
|
1100
|
+
re2 = re2_4;
|
1101
|
+
if (re.test(w)) {
|
1102
|
+
var fp = re.exec(w);
|
1103
|
+
stem = fp[1];
|
1104
|
+
re = re_mgr1;
|
1105
|
+
if (re.test(stem)) {
|
1106
|
+
w = stem;
|
1107
|
+
}
|
1108
|
+
} else if (re2.test(w)) {
|
1109
|
+
var fp = re2.exec(w);
|
1110
|
+
stem = fp[1] + fp[2];
|
1111
|
+
re2 = re_mgr1;
|
1112
|
+
if (re2.test(stem)) {
|
1113
|
+
w = stem;
|
1114
|
+
}
|
1127
1115
|
}
|
1128
|
-
}
|
1129
1116
|
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1117
|
+
// Step 5
|
1118
|
+
re = re_5;
|
1119
|
+
if (re.test(w)) {
|
1120
|
+
var fp = re.exec(w);
|
1121
|
+
stem = fp[1];
|
1122
|
+
re = re_mgr1;
|
1123
|
+
re2 = re_meq1;
|
1124
|
+
re3 = re3_5;
|
1125
|
+
if (re.test(stem) || (re2.test(stem) && !(re3.test(stem)))) {
|
1126
|
+
w = stem;
|
1127
|
+
}
|
1128
|
+
}
|
1136
1129
|
|
1137
|
-
|
1130
|
+
re = re_5_1;
|
1131
|
+
re2 = re_mgr1;
|
1132
|
+
if (re.test(w) && re2.test(w)) {
|
1133
|
+
re = re_1b_2;
|
1134
|
+
w = w.replace(re,"");
|
1135
|
+
}
|
1138
1136
|
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1137
|
+
// and turn initial Y back to y
|
1138
|
+
if (firstch == "y") {
|
1139
|
+
w = firstch.toLowerCase() + w.substr(1);
|
1140
|
+
}
|
1142
1141
|
|
1143
|
-
|
1144
|
-
|
1142
|
+
return w;
|
1143
|
+
};
|
1145
1144
|
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1145
|
+
return function (token) {
|
1146
|
+
return token.update(porterStemmer);
|
1147
|
+
}
|
1149
1148
|
})();
|
1150
1149
|
|
1151
1150
|
lunr.Pipeline.registerFunction(lunr.stemmer, 'stemmer')
|
@@ -1168,14 +1167,14 @@ lunr.Pipeline.registerFunction(lunr.stemmer, 'stemmer')
|
|
1168
1167
|
* @see lunr.stopWordFilter
|
1169
1168
|
*/
|
1170
1169
|
lunr.generateStopWordFilter = function (stopWords) {
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1170
|
+
var words = stopWords.reduce(function (memo, stopWord) {
|
1171
|
+
memo[stopWord] = stopWord
|
1172
|
+
return memo
|
1173
|
+
}, {})
|
1175
1174
|
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1175
|
+
return function (token) {
|
1176
|
+
if (token && words[token.toString()] !== token.toString()) return token
|
1177
|
+
}
|
1179
1178
|
}
|
1180
1179
|
|
1181
1180
|
/**
|
@@ -1192,125 +1191,125 @@ lunr.generateStopWordFilter = function (stopWords) {
|
|
1192
1191
|
* @see {@link lunr.Pipeline}
|
1193
1192
|
*/
|
1194
1193
|
lunr.stopWordFilter = lunr.generateStopWordFilter([
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1194
|
+
'a',
|
1195
|
+
'able',
|
1196
|
+
'about',
|
1197
|
+
'across',
|
1198
|
+
'after',
|
1199
|
+
'all',
|
1200
|
+
'almost',
|
1201
|
+
'also',
|
1202
|
+
'am',
|
1203
|
+
'among',
|
1204
|
+
'an',
|
1205
|
+
'and',
|
1206
|
+
'any',
|
1207
|
+
'are',
|
1208
|
+
'as',
|
1209
|
+
'at',
|
1210
|
+
'be',
|
1211
|
+
'because',
|
1212
|
+
'been',
|
1213
|
+
'but',
|
1214
|
+
'by',
|
1215
|
+
'can',
|
1216
|
+
'cannot',
|
1217
|
+
'could',
|
1218
|
+
'dear',
|
1219
|
+
'did',
|
1220
|
+
'do',
|
1221
|
+
'does',
|
1222
|
+
'either',
|
1223
|
+
'else',
|
1224
|
+
'ever',
|
1225
|
+
'every',
|
1226
|
+
'for',
|
1227
|
+
'from',
|
1228
|
+
'get',
|
1229
|
+
'got',
|
1230
|
+
'had',
|
1231
|
+
'has',
|
1232
|
+
'have',
|
1233
|
+
'he',
|
1234
|
+
'her',
|
1235
|
+
'hers',
|
1236
|
+
'him',
|
1237
|
+
'his',
|
1238
|
+
'how',
|
1239
|
+
'however',
|
1240
|
+
'i',
|
1241
|
+
'if',
|
1242
|
+
'in',
|
1243
|
+
'into',
|
1244
|
+
'is',
|
1245
|
+
'it',
|
1246
|
+
'its',
|
1247
|
+
'just',
|
1248
|
+
'least',
|
1249
|
+
'let',
|
1250
|
+
'like',
|
1251
|
+
'likely',
|
1252
|
+
'may',
|
1253
|
+
'me',
|
1254
|
+
'might',
|
1255
|
+
'most',
|
1256
|
+
'must',
|
1257
|
+
'my',
|
1258
|
+
'neither',
|
1259
|
+
'no',
|
1260
|
+
'nor',
|
1261
|
+
'not',
|
1262
|
+
'of',
|
1263
|
+
'off',
|
1264
|
+
'often',
|
1265
|
+
'on',
|
1266
|
+
'only',
|
1267
|
+
'or',
|
1268
|
+
'other',
|
1269
|
+
'our',
|
1270
|
+
'own',
|
1271
|
+
'rather',
|
1272
|
+
'said',
|
1273
|
+
'say',
|
1274
|
+
'says',
|
1275
|
+
'she',
|
1276
|
+
'should',
|
1277
|
+
'since',
|
1278
|
+
'so',
|
1279
|
+
'some',
|
1280
|
+
'than',
|
1281
|
+
'that',
|
1282
|
+
'the',
|
1283
|
+
'their',
|
1284
|
+
'them',
|
1285
|
+
'then',
|
1286
|
+
'there',
|
1287
|
+
'these',
|
1288
|
+
'they',
|
1289
|
+
'this',
|
1290
|
+
'tis',
|
1291
|
+
'to',
|
1292
|
+
'too',
|
1293
|
+
'twas',
|
1294
|
+
'us',
|
1295
|
+
'wants',
|
1296
|
+
'was',
|
1297
|
+
'we',
|
1298
|
+
'were',
|
1299
|
+
'what',
|
1300
|
+
'when',
|
1301
|
+
'where',
|
1302
|
+
'which',
|
1303
|
+
'while',
|
1304
|
+
'who',
|
1305
|
+
'whom',
|
1306
|
+
'why',
|
1307
|
+
'will',
|
1308
|
+
'with',
|
1309
|
+
'would',
|
1310
|
+
'yet',
|
1311
|
+
'you',
|
1312
|
+
'your'
|
1314
1313
|
])
|
1315
1314
|
|
1316
1315
|
lunr.Pipeline.registerFunction(lunr.stopWordFilter, 'stopWordFilter')
|
@@ -1335,9 +1334,9 @@ lunr.Pipeline.registerFunction(lunr.stopWordFilter, 'stopWordFilter')
|
|
1335
1334
|
* @see lunr.Pipeline
|
1336
1335
|
*/
|
1337
1336
|
lunr.trimmer = function (token) {
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1337
|
+
return token.update(function (s) {
|
1338
|
+
return s.replace(/^\W+/, '').replace(/\W+$/, '')
|
1339
|
+
})
|
1341
1340
|
}
|
1342
1341
|
|
1343
1342
|
lunr.Pipeline.registerFunction(lunr.trimmer, 'trimmer')
|
@@ -1368,10 +1367,10 @@ lunr.Pipeline.registerFunction(lunr.trimmer, 'trimmer')
|
|
1368
1367
|
* @constructor
|
1369
1368
|
*/
|
1370
1369
|
lunr.TokenSet = function () {
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1370
|
+
this.final = false
|
1371
|
+
this.edges = {}
|
1372
|
+
this.id = lunr.TokenSet._nextId
|
1373
|
+
lunr.TokenSet._nextId += 1
|
1375
1374
|
}
|
1376
1375
|
|
1377
1376
|
/**
|
@@ -1392,14 +1391,14 @@ lunr.TokenSet._nextId = 1
|
|
1392
1391
|
* @throws Will throw an error if the input array is not sorted.
|
1393
1392
|
*/
|
1394
1393
|
lunr.TokenSet.fromArray = function (arr) {
|
1395
|
-
|
1394
|
+
var builder = new lunr.TokenSet.Builder
|
1396
1395
|
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1396
|
+
for (var i = 0, len = arr.length; i < len; i++) {
|
1397
|
+
builder.insert(arr[i])
|
1398
|
+
}
|
1400
1399
|
|
1401
|
-
|
1402
|
-
|
1400
|
+
builder.finish()
|
1401
|
+
return builder.root
|
1403
1402
|
}
|
1404
1403
|
|
1405
1404
|
/**
|
@@ -1412,11 +1411,11 @@ lunr.TokenSet.fromArray = function (arr) {
|
|
1412
1411
|
* @returns {lunr.TokenSet}
|
1413
1412
|
*/
|
1414
1413
|
lunr.TokenSet.fromClause = function (clause) {
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1414
|
+
if ('editDistance' in clause) {
|
1415
|
+
return lunr.TokenSet.fromFuzzyString(clause.term, clause.editDistance)
|
1416
|
+
} else {
|
1417
|
+
return lunr.TokenSet.fromString(clause.term)
|
1418
|
+
}
|
1420
1419
|
}
|
1421
1420
|
|
1422
1421
|
/**
|
@@ -1435,129 +1434,129 @@ lunr.TokenSet.fromClause = function (clause) {
|
|
1435
1434
|
* @returns {lunr.Vector}
|
1436
1435
|
*/
|
1437
1436
|
lunr.TokenSet.fromFuzzyString = function (str, editDistance) {
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1437
|
+
var root = new lunr.TokenSet
|
1438
|
+
|
1439
|
+
var stack = [{
|
1440
|
+
node: root,
|
1441
|
+
editsRemaining: editDistance,
|
1442
|
+
str: str
|
1443
|
+
}]
|
1444
|
+
|
1445
|
+
while (stack.length) {
|
1446
|
+
var frame = stack.pop()
|
1447
|
+
|
1448
|
+
// no edit
|
1449
|
+
if (frame.str.length > 0) {
|
1450
|
+
var char = frame.str.charAt(0),
|
1451
|
+
noEditNode
|
1452
|
+
|
1453
|
+
if (char in frame.node.edges) {
|
1454
|
+
noEditNode = frame.node.edges[char]
|
1455
|
+
} else {
|
1456
|
+
noEditNode = new lunr.TokenSet
|
1457
|
+
frame.node.edges[char] = noEditNode
|
1458
|
+
}
|
1459
|
+
|
1460
|
+
if (frame.str.length == 1) {
|
1461
|
+
noEditNode.final = true
|
1462
|
+
}
|
1463
|
+
|
1464
|
+
stack.push({
|
1465
|
+
node: noEditNode,
|
1466
|
+
editsRemaining: frame.editsRemaining,
|
1467
|
+
str: frame.str.slice(1)
|
1468
|
+
})
|
1469
|
+
}
|
1448
1470
|
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
noEditNode
|
1471
|
+
if (frame.editsRemaining == 0) {
|
1472
|
+
continue
|
1473
|
+
}
|
1453
1474
|
|
1454
|
-
|
1455
|
-
|
1475
|
+
// insertion
|
1476
|
+
if ("*" in frame.node.edges) {
|
1477
|
+
var insertionNode = frame.node.edges["*"]
|
1456
1478
|
} else {
|
1457
|
-
|
1458
|
-
|
1479
|
+
var insertionNode = new lunr.TokenSet
|
1480
|
+
frame.node.edges["*"] = insertionNode
|
1459
1481
|
}
|
1460
1482
|
|
1461
|
-
if (frame.str.length ==
|
1462
|
-
|
1483
|
+
if (frame.str.length == 0) {
|
1484
|
+
insertionNode.final = true
|
1463
1485
|
}
|
1464
1486
|
|
1465
1487
|
stack.push({
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1488
|
+
node: insertionNode,
|
1489
|
+
editsRemaining: frame.editsRemaining - 1,
|
1490
|
+
str: frame.str
|
1469
1491
|
})
|
1470
|
-
}
|
1471
1492
|
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
frame.node.edges["*"] = insertionNode
|
1482
|
-
}
|
1483
|
-
|
1484
|
-
if (frame.str.length == 0) {
|
1485
|
-
insertionNode.final = true
|
1486
|
-
}
|
1487
|
-
|
1488
|
-
stack.push({
|
1489
|
-
node: insertionNode,
|
1490
|
-
editsRemaining: frame.editsRemaining - 1,
|
1491
|
-
str: frame.str
|
1492
|
-
})
|
1493
|
-
|
1494
|
-
// deletion
|
1495
|
-
// can only do a deletion if we have enough edits remaining
|
1496
|
-
// and if there are characters left to delete in the string
|
1497
|
-
if (frame.str.length > 1) {
|
1498
|
-
stack.push({
|
1499
|
-
node: frame.node,
|
1500
|
-
editsRemaining: frame.editsRemaining - 1,
|
1501
|
-
str: frame.str.slice(1)
|
1502
|
-
})
|
1503
|
-
}
|
1504
|
-
|
1505
|
-
// deletion
|
1506
|
-
// just removing the last character from the str
|
1507
|
-
if (frame.str.length == 1) {
|
1508
|
-
frame.node.final = true
|
1509
|
-
}
|
1510
|
-
|
1511
|
-
// substitution
|
1512
|
-
// can only do a substitution if we have enough edits remaining
|
1513
|
-
// and if there are characters left to substitute
|
1514
|
-
if (frame.str.length >= 1) {
|
1515
|
-
if ("*" in frame.node.edges) {
|
1516
|
-
var substitutionNode = frame.node.edges["*"]
|
1517
|
-
} else {
|
1518
|
-
var substitutionNode = new lunr.TokenSet
|
1519
|
-
frame.node.edges["*"] = substitutionNode
|
1493
|
+
// deletion
|
1494
|
+
// can only do a deletion if we have enough edits remaining
|
1495
|
+
// and if there are characters left to delete in the string
|
1496
|
+
if (frame.str.length > 1) {
|
1497
|
+
stack.push({
|
1498
|
+
node: frame.node,
|
1499
|
+
editsRemaining: frame.editsRemaining - 1,
|
1500
|
+
str: frame.str.slice(1)
|
1501
|
+
})
|
1520
1502
|
}
|
1521
1503
|
|
1504
|
+
// deletion
|
1505
|
+
// just removing the last character from the str
|
1522
1506
|
if (frame.str.length == 1) {
|
1523
|
-
|
1507
|
+
frame.node.final = true
|
1524
1508
|
}
|
1525
1509
|
|
1526
|
-
|
1527
|
-
|
1528
|
-
|
1529
|
-
|
1530
|
-
|
1531
|
-
|
1532
|
-
|
1533
|
-
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
1539
|
-
|
1540
|
-
|
1541
|
-
|
1542
|
-
|
1543
|
-
|
1544
|
-
|
1545
|
-
|
1510
|
+
// substitution
|
1511
|
+
// can only do a substitution if we have enough edits remaining
|
1512
|
+
// and if there are characters left to substitute
|
1513
|
+
if (frame.str.length >= 1) {
|
1514
|
+
if ("*" in frame.node.edges) {
|
1515
|
+
var substitutionNode = frame.node.edges["*"]
|
1516
|
+
} else {
|
1517
|
+
var substitutionNode = new lunr.TokenSet
|
1518
|
+
frame.node.edges["*"] = substitutionNode
|
1519
|
+
}
|
1520
|
+
|
1521
|
+
if (frame.str.length == 1) {
|
1522
|
+
substitutionNode.final = true
|
1523
|
+
}
|
1524
|
+
|
1525
|
+
stack.push({
|
1526
|
+
node: substitutionNode,
|
1527
|
+
editsRemaining: frame.editsRemaining - 1,
|
1528
|
+
str: frame.str.slice(1)
|
1529
|
+
})
|
1546
1530
|
}
|
1547
1531
|
|
1548
|
-
|
1549
|
-
|
1532
|
+
// transposition
|
1533
|
+
// can only do a transposition if there are edits remaining
|
1534
|
+
// and there are enough characters to transpose
|
1535
|
+
if (frame.str.length > 1) {
|
1536
|
+
var charA = frame.str.charAt(0),
|
1537
|
+
charB = frame.str.charAt(1),
|
1538
|
+
transposeNode
|
1539
|
+
|
1540
|
+
if (charB in frame.node.edges) {
|
1541
|
+
transposeNode = frame.node.edges[charB]
|
1542
|
+
} else {
|
1543
|
+
transposeNode = new lunr.TokenSet
|
1544
|
+
frame.node.edges[charB] = transposeNode
|
1545
|
+
}
|
1546
|
+
|
1547
|
+
if (frame.str.length == 1) {
|
1548
|
+
transposeNode.final = true
|
1549
|
+
}
|
1550
|
+
|
1551
|
+
stack.push({
|
1552
|
+
node: transposeNode,
|
1553
|
+
editsRemaining: frame.editsRemaining - 1,
|
1554
|
+
str: charA + frame.str.slice(2)
|
1555
|
+
})
|
1550
1556
|
}
|
1557
|
+
}
|
1551
1558
|
|
1552
|
-
|
1553
|
-
node: transposeNode,
|
1554
|
-
editsRemaining: frame.editsRemaining - 1,
|
1555
|
-
str: charA + frame.str.slice(2)
|
1556
|
-
})
|
1557
|
-
}
|
1558
|
-
}
|
1559
|
-
|
1560
|
-
return root
|
1559
|
+
return root
|
1561
1560
|
}
|
1562
1561
|
|
1563
1562
|
/**
|
@@ -1571,7 +1570,7 @@ lunr.TokenSet.fromFuzzyString = function (str, editDistance) {
|
|
1571
1570
|
* @returns {lunr.TokenSet}
|
1572
1571
|
*/
|
1573
1572
|
lunr.TokenSet.fromString = function (str) {
|
1574
|
-
|
1573
|
+
var node = new lunr.TokenSet,
|
1575
1574
|
root = node
|
1576
1575
|
|
1577
1576
|
/*
|
@@ -1582,24 +1581,24 @@ lunr.TokenSet.fromString = function (str) {
|
|
1582
1581
|
* referencing edge is introduced to continually match
|
1583
1582
|
* any number of any characters.
|
1584
1583
|
*/
|
1585
|
-
|
1586
|
-
|
1587
|
-
|
1584
|
+
for (var i = 0, len = str.length; i < len; i++) {
|
1585
|
+
var char = str[i],
|
1586
|
+
final = (i == len - 1)
|
1588
1587
|
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1588
|
+
if (char == "*") {
|
1589
|
+
node.edges[char] = node
|
1590
|
+
node.final = final
|
1592
1591
|
|
1593
|
-
|
1594
|
-
|
1595
|
-
|
1592
|
+
} else {
|
1593
|
+
var next = new lunr.TokenSet
|
1594
|
+
next.final = final
|
1596
1595
|
|
1597
|
-
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1596
|
+
node.edges[char] = next
|
1597
|
+
node = next
|
1598
|
+
}
|
1599
|
+
}
|
1601
1600
|
|
1602
|
-
|
1601
|
+
return root
|
1603
1602
|
}
|
1604
1603
|
|
1605
1604
|
/**
|
@@ -1613,38 +1612,38 @@ lunr.TokenSet.fromString = function (str) {
|
|
1613
1612
|
* @returns {string[]}
|
1614
1613
|
*/
|
1615
1614
|
lunr.TokenSet.prototype.toArray = function () {
|
1616
|
-
|
1617
|
-
|
1618
|
-
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
for (var i = 0; i < len; i++) {
|
1638
|
-
var edge = edges[i]
|
1615
|
+
var words = []
|
1616
|
+
|
1617
|
+
var stack = [{
|
1618
|
+
prefix: "",
|
1619
|
+
node: this
|
1620
|
+
}]
|
1621
|
+
|
1622
|
+
while (stack.length) {
|
1623
|
+
var frame = stack.pop(),
|
1624
|
+
edges = Object.keys(frame.node.edges),
|
1625
|
+
len = edges.length
|
1626
|
+
|
1627
|
+
if (frame.node.final) {
|
1628
|
+
/* In Safari, at this point the prefix is sometimes corrupted, see:
|
1629
|
+
* https://github.com/olivernn/lunr.js/issues/279 Calling any
|
1630
|
+
* String.prototype method forces Safari to "cast" this string to what
|
1631
|
+
* it's supposed to be, fixing the bug. */
|
1632
|
+
frame.prefix.charAt(0)
|
1633
|
+
words.push(frame.prefix)
|
1634
|
+
}
|
1639
1635
|
|
1640
|
-
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1636
|
+
for (var i = 0; i < len; i++) {
|
1637
|
+
var edge = edges[i]
|
1638
|
+
|
1639
|
+
stack.push({
|
1640
|
+
prefix: frame.prefix.concat(edge),
|
1641
|
+
node: frame.node.edges[edge]
|
1642
|
+
})
|
1643
|
+
}
|
1644
|
+
}
|
1646
1645
|
|
1647
|
-
|
1646
|
+
return words
|
1648
1647
|
}
|
1649
1648
|
|
1650
1649
|
/**
|
@@ -1666,22 +1665,22 @@ lunr.TokenSet.prototype.toString = function () {
|
|
1666
1665
|
// benchmarks the performance is comparable, but allowing
|
1667
1666
|
// V8 to optimize may mean easy performance wins in the future.
|
1668
1667
|
|
1669
|
-
|
1670
|
-
|
1671
|
-
|
1668
|
+
if (this._str) {
|
1669
|
+
return this._str
|
1670
|
+
}
|
1672
1671
|
|
1673
|
-
|
1672
|
+
var str = this.final ? '1' : '0',
|
1674
1673
|
labels = Object.keys(this.edges).sort(),
|
1675
1674
|
len = labels.length
|
1676
1675
|
|
1677
|
-
|
1678
|
-
|
1679
|
-
|
1676
|
+
for (var i = 0; i < len; i++) {
|
1677
|
+
var label = labels[i],
|
1678
|
+
node = this.edges[label]
|
1680
1679
|
|
1681
|
-
|
1682
|
-
|
1680
|
+
str = str + label + node.id
|
1681
|
+
}
|
1683
1682
|
|
1684
|
-
|
1683
|
+
return str
|
1685
1684
|
}
|
1686
1685
|
|
1687
1686
|
/**
|
@@ -1695,135 +1694,135 @@ lunr.TokenSet.prototype.toString = function () {
|
|
1695
1694
|
* @returns {lunr.TokenSet}
|
1696
1695
|
*/
|
1697
1696
|
lunr.TokenSet.prototype.intersect = function (b) {
|
1698
|
-
|
1697
|
+
var output = new lunr.TokenSet,
|
1699
1698
|
frame = undefined
|
1700
1699
|
|
1701
|
-
|
1702
|
-
|
1703
|
-
|
1704
|
-
|
1705
|
-
|
1706
|
-
|
1707
|
-
|
1708
|
-
|
1709
|
-
|
1710
|
-
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
1714
|
-
|
1715
|
-
|
1716
|
-
|
1717
|
-
|
1718
|
-
|
1719
|
-
|
1720
|
-
|
1721
|
-
|
1722
|
-
|
1723
|
-
|
1724
|
-
|
1725
|
-
|
1726
|
-
|
1727
|
-
|
1728
|
-
|
1729
|
-
|
1730
|
-
|
1731
|
-
|
1732
|
-
|
1733
|
-
|
1734
|
-
|
1735
|
-
|
1736
|
-
|
1737
|
-
|
1738
|
-
|
1739
|
-
|
1740
|
-
|
1741
|
-
|
1742
|
-
|
1743
|
-
|
1744
|
-
|
1745
|
-
|
1746
|
-
|
1747
|
-
|
1748
|
-
|
1749
|
-
|
1750
|
-
|
1751
|
-
|
1752
|
-
|
1700
|
+
var stack = [{
|
1701
|
+
qNode: b,
|
1702
|
+
output: output,
|
1703
|
+
node: this
|
1704
|
+
}]
|
1705
|
+
|
1706
|
+
while (stack.length) {
|
1707
|
+
frame = stack.pop()
|
1708
|
+
|
1709
|
+
// NOTE: As with the #toString method, we are using
|
1710
|
+
// Object.keys and a for loop instead of a for-in loop
|
1711
|
+
// as both of these objects enter 'hash' mode, causing
|
1712
|
+
// the function to be de-optimised in V8
|
1713
|
+
var qEdges = Object.keys(frame.qNode.edges),
|
1714
|
+
qLen = qEdges.length,
|
1715
|
+
nEdges = Object.keys(frame.node.edges),
|
1716
|
+
nLen = nEdges.length
|
1717
|
+
|
1718
|
+
for (var q = 0; q < qLen; q++) {
|
1719
|
+
var qEdge = qEdges[q]
|
1720
|
+
|
1721
|
+
for (var n = 0; n < nLen; n++) {
|
1722
|
+
var nEdge = nEdges[n]
|
1723
|
+
|
1724
|
+
if (nEdge == qEdge || qEdge == '*') {
|
1725
|
+
var node = frame.node.edges[nEdge],
|
1726
|
+
qNode = frame.qNode.edges[qEdge],
|
1727
|
+
final = node.final && qNode.final,
|
1728
|
+
next = undefined
|
1729
|
+
|
1730
|
+
if (nEdge in frame.output.edges) {
|
1731
|
+
// an edge already exists for this character
|
1732
|
+
// no need to create a new node, just set the finality
|
1733
|
+
// bit unless this node is already final
|
1734
|
+
next = frame.output.edges[nEdge]
|
1735
|
+
next.final = next.final || final
|
1736
|
+
|
1737
|
+
} else {
|
1738
|
+
// no edge exists yet, must create one
|
1739
|
+
// set the finality bit and insert it
|
1740
|
+
// into the output
|
1741
|
+
next = new lunr.TokenSet
|
1742
|
+
next.final = final
|
1743
|
+
frame.output.edges[nEdge] = next
|
1744
|
+
}
|
1745
|
+
|
1746
|
+
stack.push({
|
1747
|
+
qNode: qNode,
|
1748
|
+
output: next,
|
1749
|
+
node: node
|
1750
|
+
})
|
1751
|
+
}
|
1752
|
+
}
|
1753
1753
|
}
|
1754
|
-
|
1755
|
-
}
|
1754
|
+
}
|
1756
1755
|
|
1757
|
-
|
1756
|
+
return output
|
1758
1757
|
}
|
1759
1758
|
lunr.TokenSet.Builder = function () {
|
1760
|
-
|
1761
|
-
|
1762
|
-
|
1763
|
-
|
1759
|
+
this.previousWord = ""
|
1760
|
+
this.root = new lunr.TokenSet
|
1761
|
+
this.uncheckedNodes = []
|
1762
|
+
this.minimizedNodes = {}
|
1764
1763
|
}
|
1765
1764
|
|
1766
1765
|
lunr.TokenSet.Builder.prototype.insert = function (word) {
|
1767
|
-
|
1766
|
+
var node,
|
1768
1767
|
commonPrefix = 0
|
1769
1768
|
|
1770
|
-
|
1771
|
-
|
1772
|
-
|
1769
|
+
if (word < this.previousWord) {
|
1770
|
+
throw new Error ("Out of order word insertion")
|
1771
|
+
}
|
1773
1772
|
|
1774
|
-
|
1775
|
-
|
1776
|
-
|
1777
|
-
|
1773
|
+
for (var i = 0; i < word.length && i < this.previousWord.length; i++) {
|
1774
|
+
if (word[i] != this.previousWord[i]) break
|
1775
|
+
commonPrefix++
|
1776
|
+
}
|
1778
1777
|
|
1779
|
-
|
1778
|
+
this.minimize(commonPrefix)
|
1780
1779
|
|
1781
|
-
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
1785
|
-
|
1780
|
+
if (this.uncheckedNodes.length == 0) {
|
1781
|
+
node = this.root
|
1782
|
+
} else {
|
1783
|
+
node = this.uncheckedNodes[this.uncheckedNodes.length - 1].child
|
1784
|
+
}
|
1786
1785
|
|
1787
|
-
|
1788
|
-
|
1789
|
-
|
1786
|
+
for (var i = commonPrefix; i < word.length; i++) {
|
1787
|
+
var nextNode = new lunr.TokenSet,
|
1788
|
+
char = word[i]
|
1790
1789
|
|
1791
|
-
|
1790
|
+
node.edges[char] = nextNode
|
1792
1791
|
|
1793
|
-
|
1794
|
-
|
1795
|
-
|
1796
|
-
|
1797
|
-
|
1792
|
+
this.uncheckedNodes.push({
|
1793
|
+
parent: node,
|
1794
|
+
char: char,
|
1795
|
+
child: nextNode
|
1796
|
+
})
|
1798
1797
|
|
1799
|
-
|
1800
|
-
|
1798
|
+
node = nextNode
|
1799
|
+
}
|
1801
1800
|
|
1802
|
-
|
1803
|
-
|
1801
|
+
node.final = true
|
1802
|
+
this.previousWord = word
|
1804
1803
|
}
|
1805
1804
|
|
1806
1805
|
lunr.TokenSet.Builder.prototype.finish = function () {
|
1807
|
-
|
1806
|
+
this.minimize(0)
|
1808
1807
|
}
|
1809
1808
|
|
1810
1809
|
lunr.TokenSet.Builder.prototype.minimize = function (downTo) {
|
1811
|
-
|
1812
|
-
|
1813
|
-
|
1810
|
+
for (var i = this.uncheckedNodes.length - 1; i >= downTo; i--) {
|
1811
|
+
var node = this.uncheckedNodes[i],
|
1812
|
+
childKey = node.child.toString()
|
1814
1813
|
|
1815
|
-
|
1816
|
-
|
1817
|
-
|
1818
|
-
|
1819
|
-
|
1820
|
-
|
1814
|
+
if (childKey in this.minimizedNodes) {
|
1815
|
+
node.parent.edges[node.char] = this.minimizedNodes[childKey]
|
1816
|
+
} else {
|
1817
|
+
// Cache the key for this node since
|
1818
|
+
// we know it can't change anymore
|
1819
|
+
node.child._str = childKey
|
1821
1820
|
|
1822
|
-
|
1823
|
-
|
1821
|
+
this.minimizedNodes[childKey] = node.child
|
1822
|
+
}
|
1824
1823
|
|
1825
|
-
|
1826
|
-
|
1824
|
+
this.uncheckedNodes.pop()
|
1825
|
+
}
|
1827
1826
|
}
|
1828
1827
|
/*!
|
1829
1828
|
* lunr.Index
|
@@ -1847,11 +1846,11 @@ lunr.TokenSet.Builder.prototype.minimize = function (downTo) {
|
|
1847
1846
|
* @param {lunr.Pipeline} attrs.pipeline - The pipeline to use for search terms.
|
1848
1847
|
*/
|
1849
1848
|
lunr.Index = function (attrs) {
|
1850
|
-
|
1851
|
-
|
1852
|
-
|
1853
|
-
|
1854
|
-
|
1849
|
+
this.invertedIndex = attrs.invertedIndex
|
1850
|
+
this.fieldVectors = attrs.fieldVectors
|
1851
|
+
this.tokenSet = attrs.tokenSet
|
1852
|
+
this.fields = attrs.fields
|
1853
|
+
this.pipeline = attrs.pipeline
|
1855
1854
|
}
|
1856
1855
|
|
1857
1856
|
/**
|
@@ -1926,10 +1925,10 @@ lunr.Index = function (attrs) {
|
|
1926
1925
|
* @returns {lunr.Index~Result[]}
|
1927
1926
|
*/
|
1928
1927
|
lunr.Index.prototype.search = function (queryString) {
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1928
|
+
return this.query(function (query) {
|
1929
|
+
var parser = new lunr.QueryParser(queryString, query)
|
1930
|
+
parser.parse()
|
1931
|
+
})
|
1933
1932
|
}
|
1934
1933
|
|
1935
1934
|
/**
|
@@ -1965,280 +1964,280 @@ lunr.Index.prototype.query = function (fn) {
|
|
1965
1964
|
// * get document vectors
|
1966
1965
|
// * score documents
|
1967
1966
|
|
1968
|
-
|
1969
|
-
|
1970
|
-
|
1971
|
-
|
1972
|
-
|
1973
|
-
|
1967
|
+
var query = new lunr.Query(this.fields),
|
1968
|
+
matchingFields = Object.create(null),
|
1969
|
+
queryVectors = Object.create(null),
|
1970
|
+
termFieldCache = Object.create(null),
|
1971
|
+
requiredMatches = Object.create(null),
|
1972
|
+
prohibitedMatches = Object.create(null)
|
1974
1973
|
|
1975
1974
|
/*
|
1976
1975
|
* To support field level boosts a query vector is created per
|
1977
1976
|
* field. An empty vector is eagerly created to support negated
|
1978
1977
|
* queries.
|
1979
1978
|
*/
|
1980
|
-
|
1981
|
-
|
1982
|
-
|
1979
|
+
for (var i = 0; i < this.fields.length; i++) {
|
1980
|
+
queryVectors[this.fields[i]] = new lunr.Vector
|
1981
|
+
}
|
1983
1982
|
|
1984
|
-
|
1985
|
-
|
1986
|
-
for (var i = 0; i < query.clauses.length; i++) {
|
1987
|
-
/*
|
1988
|
-
* Unless the pipeline has been disabled for this term, which is
|
1989
|
-
* the case for terms with wildcards, we need to pass the clause
|
1990
|
-
* term through the search pipeline. A pipeline returns an array
|
1991
|
-
* of processed terms. Pipeline functions may expand the passed
|
1992
|
-
* term, which means we may end up performing multiple index lookups
|
1993
|
-
* for a single query term.
|
1994
|
-
*/
|
1995
|
-
var clause = query.clauses[i],
|
1996
|
-
terms = null,
|
1997
|
-
clauseMatches = lunr.Set.empty
|
1998
|
-
|
1999
|
-
if (clause.usePipeline) {
|
2000
|
-
terms = this.pipeline.runString(clause.term, {
|
2001
|
-
fields: clause.fields
|
2002
|
-
})
|
2003
|
-
} else {
|
2004
|
-
terms = [clause.term]
|
2005
|
-
}
|
2006
|
-
|
2007
|
-
for (var m = 0; m < terms.length; m++) {
|
2008
|
-
var term = terms[m]
|
2009
|
-
|
2010
|
-
/*
|
2011
|
-
* Each term returned from the pipeline needs to use the same query
|
2012
|
-
* clause object, e.g. the same boost and or edit distance. The
|
2013
|
-
* simplest way to do this is to re-use the clause object but mutate
|
2014
|
-
* its term property.
|
2015
|
-
*/
|
2016
|
-
clause.term = term
|
2017
|
-
|
2018
|
-
/*
|
2019
|
-
* From the term in the clause we create a token set which will then
|
2020
|
-
* be used to intersect the indexes token set to get a list of terms
|
2021
|
-
* to lookup in the inverted index
|
2022
|
-
*/
|
2023
|
-
var termTokenSet = lunr.TokenSet.fromClause(clause),
|
2024
|
-
expandedTerms = this.tokenSet.intersect(termTokenSet).toArray()
|
1983
|
+
fn.call(query, query)
|
2025
1984
|
|
1985
|
+
for (var i = 0; i < query.clauses.length; i++) {
|
2026
1986
|
/*
|
2027
|
-
*
|
2028
|
-
*
|
2029
|
-
*
|
2030
|
-
*
|
1987
|
+
* Unless the pipeline has been disabled for this term, which is
|
1988
|
+
* the case for terms with wildcards, we need to pass the clause
|
1989
|
+
* term through the search pipeline. A pipeline returns an array
|
1990
|
+
* of processed terms. Pipeline functions may expand the passed
|
1991
|
+
* term, which means we may end up performing multiple index lookups
|
1992
|
+
* for a single query term.
|
2031
1993
|
*/
|
2032
|
-
|
2033
|
-
|
2034
|
-
|
2035
|
-
|
2036
|
-
|
2037
|
-
|
2038
|
-
|
1994
|
+
var clause = query.clauses[i],
|
1995
|
+
terms = null,
|
1996
|
+
clauseMatches = lunr.Set.empty
|
1997
|
+
|
1998
|
+
if (clause.usePipeline) {
|
1999
|
+
terms = this.pipeline.runString(clause.term, {
|
2000
|
+
fields: clause.fields
|
2001
|
+
})
|
2002
|
+
} else {
|
2003
|
+
terms = [clause.term]
|
2039
2004
|
}
|
2040
2005
|
|
2041
|
-
for (var
|
2042
|
-
|
2043
|
-
|
2044
|
-
|
2045
|
-
|
2046
|
-
|
2047
|
-
|
2048
|
-
|
2049
|
-
|
2050
|
-
|
2051
|
-
|
2052
|
-
|
2053
|
-
|
2054
|
-
|
2055
|
-
|
2056
|
-
|
2057
|
-
|
2058
|
-
|
2059
|
-
|
2060
|
-
|
2061
|
-
|
2062
|
-
|
2063
|
-
|
2064
|
-
|
2065
|
-
|
2066
|
-
|
2067
|
-
|
2068
|
-
|
2069
|
-
|
2070
|
-
if (clause.presence == lunr.Query.presence.REQUIRED) {
|
2071
|
-
clauseMatches = clauseMatches.union(matchingDocumentsSet)
|
2072
|
-
|
2073
|
-
if (requiredMatches[field] === undefined) {
|
2074
|
-
requiredMatches[field] = lunr.Set.complete
|
2075
|
-
}
|
2076
|
-
}
|
2077
|
-
|
2078
|
-
/*
|
2079
|
-
* if the presence of this term is prohibited ensure that the matching
|
2080
|
-
* documents are added to the set of prohibited matches for this field,
|
2081
|
-
* creating that set if it does not yet exist.
|
2082
|
-
*/
|
2083
|
-
if (clause.presence == lunr.Query.presence.PROHIBITED) {
|
2084
|
-
if (prohibitedMatches[field] === undefined) {
|
2085
|
-
prohibitedMatches[field] = lunr.Set.empty
|
2006
|
+
for (var m = 0; m < terms.length; m++) {
|
2007
|
+
var term = terms[m]
|
2008
|
+
|
2009
|
+
/*
|
2010
|
+
* Each term returned from the pipeline needs to use the same query
|
2011
|
+
* clause object, e.g. the same boost and or edit distance. The
|
2012
|
+
* simplest way to do this is to re-use the clause object but mutate
|
2013
|
+
* its term property.
|
2014
|
+
*/
|
2015
|
+
clause.term = term
|
2016
|
+
|
2017
|
+
/*
|
2018
|
+
* From the term in the clause we create a token set which will then
|
2019
|
+
* be used to intersect the indexes token set to get a list of terms
|
2020
|
+
* to lookup in the inverted index
|
2021
|
+
*/
|
2022
|
+
var termTokenSet = lunr.TokenSet.fromClause(clause),
|
2023
|
+
expandedTerms = this.tokenSet.intersect(termTokenSet).toArray()
|
2024
|
+
|
2025
|
+
/*
|
2026
|
+
* If a term marked as required does not exist in the tokenSet it is
|
2027
|
+
* impossible for the search to return any matches. We set all the field
|
2028
|
+
* scoped required matches set to empty and stop examining any further
|
2029
|
+
* clauses.
|
2030
|
+
*/
|
2031
|
+
if (expandedTerms.length === 0 && clause.presence === lunr.Query.presence.REQUIRED) {
|
2032
|
+
for (var k = 0; k < clause.fields.length; k++) {
|
2033
|
+
var field = clause.fields[k]
|
2034
|
+
requiredMatches[field] = lunr.Set.empty
|
2086
2035
|
}
|
2087
2036
|
|
2088
|
-
|
2037
|
+
break
|
2038
|
+
}
|
2089
2039
|
|
2040
|
+
for (var j = 0; j < expandedTerms.length; j++) {
|
2090
2041
|
/*
|
2091
|
-
*
|
2092
|
-
*
|
2093
|
-
* to the next field
|
2094
|
-
*/
|
2095
|
-
continue
|
2096
|
-
}
|
2097
|
-
|
2098
|
-
/*
|
2099
|
-
* The query field vector is populated using the termIndex found for
|
2100
|
-
* the term and a unit value with the appropriate boost applied.
|
2101
|
-
* Using upsert because there could already be an entry in the vector
|
2102
|
-
* for the term we are working with. In that case we just add the scores
|
2103
|
-
* together.
|
2104
|
-
*/
|
2105
|
-
queryVectors[field].upsert(termIndex, clause.boost, function (a, b) { return a + b })
|
2106
|
-
|
2107
|
-
/**
|
2108
|
-
* If we've already seen this term, field combo then we've already collected
|
2109
|
-
* the matching documents and metadata, no need to go through all that again
|
2110
|
-
*/
|
2111
|
-
if (termFieldCache[termField]) {
|
2112
|
-
continue
|
2113
|
-
}
|
2114
|
-
|
2115
|
-
for (var l = 0; l < matchingDocumentRefs.length; l++) {
|
2116
|
-
/*
|
2117
|
-
* All metadata for this term/field/document triple
|
2118
|
-
* are then extracted and collected into an instance
|
2119
|
-
* of lunr.MatchData ready to be returned in the query
|
2120
|
-
* results
|
2042
|
+
* For each term get the posting and termIndex, this is required for
|
2043
|
+
* building the query vector.
|
2121
2044
|
*/
|
2122
|
-
var
|
2123
|
-
|
2124
|
-
|
2125
|
-
|
2126
|
-
|
2127
|
-
|
2128
|
-
|
2129
|
-
|
2130
|
-
|
2045
|
+
var expandedTerm = expandedTerms[j],
|
2046
|
+
posting = this.invertedIndex[expandedTerm],
|
2047
|
+
termIndex = posting._index
|
2048
|
+
|
2049
|
+
for (var k = 0; k < clause.fields.length; k++) {
|
2050
|
+
/*
|
2051
|
+
* For each field that this query term is scoped by (by default
|
2052
|
+
* all fields are in scope) we need to get all the document refs
|
2053
|
+
* that have this term in that field.
|
2054
|
+
*
|
2055
|
+
* The posting is the entry in the invertedIndex for the matching
|
2056
|
+
* term from above.
|
2057
|
+
*/
|
2058
|
+
var field = clause.fields[k],
|
2059
|
+
fieldPosting = posting[field],
|
2060
|
+
matchingDocumentRefs = Object.keys(fieldPosting),
|
2061
|
+
termField = expandedTerm + "/" + field,
|
2062
|
+
matchingDocumentsSet = new lunr.Set(matchingDocumentRefs)
|
2063
|
+
|
2064
|
+
/*
|
2065
|
+
* if the presence of this term is required ensure that the matching
|
2066
|
+
* documents are added to the set of required matches for this clause.
|
2067
|
+
*
|
2068
|
+
*/
|
2069
|
+
if (clause.presence == lunr.Query.presence.REQUIRED) {
|
2070
|
+
clauseMatches = clauseMatches.union(matchingDocumentsSet)
|
2071
|
+
|
2072
|
+
if (requiredMatches[field] === undefined) {
|
2073
|
+
requiredMatches[field] = lunr.Set.complete
|
2074
|
+
}
|
2075
|
+
}
|
2076
|
+
|
2077
|
+
/*
|
2078
|
+
* if the presence of this term is prohibited ensure that the matching
|
2079
|
+
* documents are added to the set of prohibited matches for this field,
|
2080
|
+
* creating that set if it does not yet exist.
|
2081
|
+
*/
|
2082
|
+
if (clause.presence == lunr.Query.presence.PROHIBITED) {
|
2083
|
+
if (prohibitedMatches[field] === undefined) {
|
2084
|
+
prohibitedMatches[field] = lunr.Set.empty
|
2085
|
+
}
|
2086
|
+
|
2087
|
+
prohibitedMatches[field] = prohibitedMatches[field].union(matchingDocumentsSet)
|
2088
|
+
|
2089
|
+
/*
|
2090
|
+
* Prohibited matches should not be part of the query vector used for
|
2091
|
+
* similarity scoring and no metadata should be extracted so we continue
|
2092
|
+
* to the next field
|
2093
|
+
*/
|
2094
|
+
continue
|
2095
|
+
}
|
2096
|
+
|
2097
|
+
/*
|
2098
|
+
* The query field vector is populated using the termIndex found for
|
2099
|
+
* the term and a unit value with the appropriate boost applied.
|
2100
|
+
* Using upsert because there could already be an entry in the vector
|
2101
|
+
* for the term we are working with. In that case we just add the scores
|
2102
|
+
* together.
|
2103
|
+
*/
|
2104
|
+
queryVectors[field].upsert(termIndex, clause.boost, function (a, b) { return a + b })
|
2105
|
+
|
2106
|
+
/**
|
2107
|
+
* If we've already seen this term, field combo then we've already collected
|
2108
|
+
* the matching documents and metadata, no need to go through all that again
|
2109
|
+
*/
|
2110
|
+
if (termFieldCache[termField]) {
|
2111
|
+
continue
|
2112
|
+
}
|
2113
|
+
|
2114
|
+
for (var l = 0; l < matchingDocumentRefs.length; l++) {
|
2115
|
+
/*
|
2116
|
+
* All metadata for this term/field/document triple
|
2117
|
+
* are then extracted and collected into an instance
|
2118
|
+
* of lunr.MatchData ready to be returned in the query
|
2119
|
+
* results
|
2120
|
+
*/
|
2121
|
+
var matchingDocumentRef = matchingDocumentRefs[l],
|
2122
|
+
matchingFieldRef = new lunr.FieldRef (matchingDocumentRef, field),
|
2123
|
+
metadata = fieldPosting[matchingDocumentRef],
|
2124
|
+
fieldMatch
|
2125
|
+
|
2126
|
+
if ((fieldMatch = matchingFields[matchingFieldRef]) === undefined) {
|
2127
|
+
matchingFields[matchingFieldRef] = new lunr.MatchData (expandedTerm, field, metadata)
|
2128
|
+
} else {
|
2129
|
+
fieldMatch.add(expandedTerm, field, metadata)
|
2130
|
+
}
|
2131
|
+
|
2132
|
+
}
|
2133
|
+
|
2134
|
+
termFieldCache[termField] = true
|
2131
2135
|
}
|
2132
|
-
|
2133
|
-
}
|
2134
|
-
|
2135
|
-
termFieldCache[termField] = true
|
2136
|
-
}
|
2136
|
+
}
|
2137
2137
|
}
|
2138
|
-
}
|
2139
|
-
|
2140
|
-
/**
|
2141
|
-
* If the presence was required we need to update the requiredMatches field sets.
|
2142
|
-
* We do this after all fields for the term have collected their matches because
|
2143
|
-
* the clause terms presence is required in _any_ of the fields not _all_ of the
|
2144
|
-
* fields.
|
2145
|
-
*/
|
2146
|
-
if (clause.presence === lunr.Query.presence.REQUIRED) {
|
2147
|
-
for (var k = 0; k < clause.fields.length; k++) {
|
2148
|
-
var field = clause.fields[k]
|
2149
|
-
requiredMatches[field] = requiredMatches[field].intersect(clauseMatches)
|
2150
|
-
}
|
2151
|
-
}
|
2152
|
-
}
|
2153
2138
|
|
2154
|
-
|
2155
|
-
|
2156
|
-
|
2157
|
-
|
2158
|
-
|
2159
|
-
|
2139
|
+
/**
|
2140
|
+
* If the presence was required we need to update the requiredMatches field sets.
|
2141
|
+
* We do this after all fields for the term have collected their matches because
|
2142
|
+
* the clause terms presence is required in _any_ of the fields not _all_ of the
|
2143
|
+
* fields.
|
2144
|
+
*/
|
2145
|
+
if (clause.presence === lunr.Query.presence.REQUIRED) {
|
2146
|
+
for (var k = 0; k < clause.fields.length; k++) {
|
2147
|
+
var field = clause.fields[k]
|
2148
|
+
requiredMatches[field] = requiredMatches[field].intersect(clauseMatches)
|
2149
|
+
}
|
2150
|
+
}
|
2151
|
+
}
|
2152
|
+
|
2153
|
+
/**
|
2154
|
+
* Need to combine the field scoped required and prohibited
|
2155
|
+
* matching documents into a global set of required and prohibited
|
2156
|
+
* matches
|
2157
|
+
*/
|
2158
|
+
var allRequiredMatches = lunr.Set.complete,
|
2160
2159
|
allProhibitedMatches = lunr.Set.empty
|
2161
2160
|
|
2162
|
-
|
2163
|
-
|
2161
|
+
for (var i = 0; i < this.fields.length; i++) {
|
2162
|
+
var field = this.fields[i]
|
2164
2163
|
|
2165
|
-
|
2166
|
-
|
2167
|
-
|
2164
|
+
if (requiredMatches[field]) {
|
2165
|
+
allRequiredMatches = allRequiredMatches.intersect(requiredMatches[field])
|
2166
|
+
}
|
2168
2167
|
|
2169
|
-
|
2170
|
-
|
2171
|
-
|
2172
|
-
|
2168
|
+
if (prohibitedMatches[field]) {
|
2169
|
+
allProhibitedMatches = allProhibitedMatches.union(prohibitedMatches[field])
|
2170
|
+
}
|
2171
|
+
}
|
2172
|
+
|
2173
|
+
var matchingFieldRefs = Object.keys(matchingFields),
|
2174
|
+
results = [],
|
2175
|
+
matches = Object.create(null)
|
2176
|
+
|
2177
|
+
/*
|
2178
|
+
* If the query is negated (contains only prohibited terms)
|
2179
|
+
* we need to get _all_ fieldRefs currently existing in the
|
2180
|
+
* index. This is only done when we know that the query is
|
2181
|
+
* entirely prohibited terms to avoid any cost of getting all
|
2182
|
+
* fieldRefs unnecessarily.
|
2183
|
+
*
|
2184
|
+
* Additionally, blank MatchData must be created to correctly
|
2185
|
+
* populate the results.
|
2186
|
+
*/
|
2187
|
+
if (query.isNegated()) {
|
2188
|
+
matchingFieldRefs = Object.keys(this.fieldVectors)
|
2189
|
+
|
2190
|
+
for (var i = 0; i < matchingFieldRefs.length; i++) {
|
2191
|
+
var matchingFieldRef = matchingFieldRefs[i]
|
2192
|
+
var fieldRef = lunr.FieldRef.fromString(matchingFieldRef)
|
2193
|
+
matchingFields[matchingFieldRef] = new lunr.MatchData
|
2194
|
+
}
|
2195
|
+
}
|
2173
2196
|
|
2174
|
-
|
2175
|
-
|
2176
|
-
|
2197
|
+
for (var i = 0; i < matchingFieldRefs.length; i++) {
|
2198
|
+
/*
|
2199
|
+
* Currently we have document fields that match the query, but we
|
2200
|
+
* need to return documents. The matchData and scores are combined
|
2201
|
+
* from multiple fields belonging to the same document.
|
2202
|
+
*
|
2203
|
+
* Scores are calculated by field, using the query vectors created
|
2204
|
+
* above, and combined into a final document score using addition.
|
2205
|
+
*/
|
2206
|
+
var fieldRef = lunr.FieldRef.fromString(matchingFieldRefs[i]),
|
2207
|
+
docRef = fieldRef.docRef
|
2177
2208
|
|
2178
|
-
|
2179
|
-
|
2180
|
-
|
2181
|
-
* index. This is only done when we know that the query is
|
2182
|
-
* entirely prohibited terms to avoid any cost of getting all
|
2183
|
-
* fieldRefs unnecessarily.
|
2184
|
-
*
|
2185
|
-
* Additionally, blank MatchData must be created to correctly
|
2186
|
-
* populate the results.
|
2187
|
-
*/
|
2188
|
-
if (query.isNegated()) {
|
2189
|
-
matchingFieldRefs = Object.keys(this.fieldVectors)
|
2190
|
-
|
2191
|
-
for (var i = 0; i < matchingFieldRefs.length; i++) {
|
2192
|
-
var matchingFieldRef = matchingFieldRefs[i]
|
2193
|
-
var fieldRef = lunr.FieldRef.fromString(matchingFieldRef)
|
2194
|
-
matchingFields[matchingFieldRef] = new lunr.MatchData
|
2195
|
-
}
|
2196
|
-
}
|
2209
|
+
if (!allRequiredMatches.contains(docRef)) {
|
2210
|
+
continue
|
2211
|
+
}
|
2197
2212
|
|
2198
|
-
|
2199
|
-
|
2200
|
-
|
2201
|
-
* need to return documents. The matchData and scores are combined
|
2202
|
-
* from multiple fields belonging to the same document.
|
2203
|
-
*
|
2204
|
-
* Scores are calculated by field, using the query vectors created
|
2205
|
-
* above, and combined into a final document score using addition.
|
2206
|
-
*/
|
2207
|
-
var fieldRef = lunr.FieldRef.fromString(matchingFieldRefs[i]),
|
2208
|
-
docRef = fieldRef.docRef
|
2209
|
-
|
2210
|
-
if (!allRequiredMatches.contains(docRef)) {
|
2211
|
-
continue
|
2212
|
-
}
|
2213
|
+
if (allProhibitedMatches.contains(docRef)) {
|
2214
|
+
continue
|
2215
|
+
}
|
2213
2216
|
|
2214
|
-
|
2215
|
-
|
2216
|
-
|
2217
|
-
|
2218
|
-
|
2219
|
-
|
2220
|
-
|
2221
|
-
|
2222
|
-
|
2223
|
-
|
2224
|
-
|
2225
|
-
|
2226
|
-
|
2227
|
-
|
2228
|
-
|
2229
|
-
matchData: matchingFields[fieldRef]
|
2217
|
+
var fieldVector = this.fieldVectors[fieldRef],
|
2218
|
+
score = queryVectors[fieldRef.fieldName].similarity(fieldVector),
|
2219
|
+
docMatch
|
2220
|
+
|
2221
|
+
if ((docMatch = matches[docRef]) !== undefined) {
|
2222
|
+
docMatch.score += score
|
2223
|
+
docMatch.matchData.combine(matchingFields[fieldRef])
|
2224
|
+
} else {
|
2225
|
+
var match = {
|
2226
|
+
ref: docRef,
|
2227
|
+
score: score,
|
2228
|
+
matchData: matchingFields[fieldRef]
|
2229
|
+
}
|
2230
|
+
matches[docRef] = match
|
2231
|
+
results.push(match)
|
2230
2232
|
}
|
2231
|
-
|
2232
|
-
results.push(match)
|
2233
|
-
}
|
2234
|
-
}
|
2233
|
+
}
|
2235
2234
|
|
2236
2235
|
/*
|
2237
2236
|
* Sort the results objects by score, highest first.
|
2238
2237
|
*/
|
2239
|
-
|
2240
|
-
|
2241
|
-
|
2238
|
+
return results.sort(function (a, b) {
|
2239
|
+
return b.score - a.score
|
2240
|
+
})
|
2242
2241
|
}
|
2243
2242
|
|
2244
2243
|
/**
|
@@ -2250,24 +2249,24 @@ lunr.Index.prototype.query = function (fn) {
|
|
2250
2249
|
* @returns {Object}
|
2251
2250
|
*/
|
2252
2251
|
lunr.Index.prototype.toJSON = function () {
|
2253
|
-
|
2254
|
-
|
2255
|
-
|
2256
|
-
|
2257
|
-
|
2258
|
-
|
2259
|
-
|
2260
|
-
|
2261
|
-
|
2262
|
-
|
2263
|
-
|
2264
|
-
|
2265
|
-
|
2266
|
-
|
2267
|
-
|
2268
|
-
|
2269
|
-
|
2270
|
-
|
2252
|
+
var invertedIndex = Object.keys(this.invertedIndex)
|
2253
|
+
.sort()
|
2254
|
+
.map(function (term) {
|
2255
|
+
return [term, this.invertedIndex[term]]
|
2256
|
+
}, this)
|
2257
|
+
|
2258
|
+
var fieldVectors = Object.keys(this.fieldVectors)
|
2259
|
+
.map(function (ref) {
|
2260
|
+
return [ref, this.fieldVectors[ref].toJSON()]
|
2261
|
+
}, this)
|
2262
|
+
|
2263
|
+
return {
|
2264
|
+
version: lunr.version,
|
2265
|
+
fields: this.fields,
|
2266
|
+
fieldVectors: fieldVectors,
|
2267
|
+
invertedIndex: invertedIndex,
|
2268
|
+
pipeline: this.pipeline.toJSON()
|
2269
|
+
}
|
2271
2270
|
}
|
2272
2271
|
|
2273
2272
|
/**
|
@@ -2277,7 +2276,7 @@ lunr.Index.prototype.toJSON = function () {
|
|
2277
2276
|
* @returns {lunr.Index}
|
2278
2277
|
*/
|
2279
2278
|
lunr.Index.load = function (serializedIndex) {
|
2280
|
-
|
2279
|
+
var attrs = {},
|
2281
2280
|
fieldVectors = {},
|
2282
2281
|
serializedVectors = serializedIndex.fieldVectors,
|
2283
2282
|
invertedIndex = Object.create(null),
|
@@ -2285,37 +2284,37 @@ lunr.Index.load = function (serializedIndex) {
|
|
2285
2284
|
tokenSetBuilder = new lunr.TokenSet.Builder,
|
2286
2285
|
pipeline = lunr.Pipeline.load(serializedIndex.pipeline)
|
2287
2286
|
|
2288
|
-
|
2289
|
-
|
2290
|
-
|
2287
|
+
if (serializedIndex.version != lunr.version) {
|
2288
|
+
lunr.utils.warn("Version mismatch when loading serialised index. Current version of lunr '" + lunr.version + "' does not match serialized index '" + serializedIndex.version + "'")
|
2289
|
+
}
|
2291
2290
|
|
2292
|
-
|
2293
|
-
|
2294
|
-
|
2295
|
-
|
2291
|
+
for (var i = 0; i < serializedVectors.length; i++) {
|
2292
|
+
var tuple = serializedVectors[i],
|
2293
|
+
ref = tuple[0],
|
2294
|
+
elements = tuple[1]
|
2296
2295
|
|
2297
|
-
|
2298
|
-
|
2296
|
+
fieldVectors[ref] = new lunr.Vector(elements)
|
2297
|
+
}
|
2299
2298
|
|
2300
|
-
|
2301
|
-
|
2302
|
-
|
2303
|
-
|
2299
|
+
for (var i = 0; i < serializedInvertedIndex.length; i++) {
|
2300
|
+
var tuple = serializedInvertedIndex[i],
|
2301
|
+
term = tuple[0],
|
2302
|
+
posting = tuple[1]
|
2304
2303
|
|
2305
|
-
|
2306
|
-
|
2307
|
-
|
2304
|
+
tokenSetBuilder.insert(term)
|
2305
|
+
invertedIndex[term] = posting
|
2306
|
+
}
|
2308
2307
|
|
2309
|
-
|
2308
|
+
tokenSetBuilder.finish()
|
2310
2309
|
|
2311
|
-
|
2310
|
+
attrs.fields = serializedIndex.fields
|
2312
2311
|
|
2313
|
-
|
2314
|
-
|
2315
|
-
|
2316
|
-
|
2312
|
+
attrs.fieldVectors = fieldVectors
|
2313
|
+
attrs.invertedIndex = invertedIndex
|
2314
|
+
attrs.tokenSet = tokenSetBuilder.root
|
2315
|
+
attrs.pipeline = pipeline
|
2317
2316
|
|
2318
|
-
|
2317
|
+
return new lunr.Index(attrs)
|
2319
2318
|
}
|
2320
2319
|
/*!
|
2321
2320
|
* lunr.Builder
|
@@ -2347,20 +2346,20 @@ lunr.Index.load = function (serializedIndex) {
|
|
2347
2346
|
* @property {array} metadataWhitelist - A list of metadata keys that have been whitelisted for entry in the index.
|
2348
2347
|
*/
|
2349
2348
|
lunr.Builder = function () {
|
2350
|
-
|
2351
|
-
|
2352
|
-
|
2353
|
-
|
2354
|
-
|
2355
|
-
|
2356
|
-
|
2357
|
-
|
2358
|
-
|
2359
|
-
|
2360
|
-
|
2361
|
-
|
2362
|
-
|
2363
|
-
|
2349
|
+
this._ref = "id"
|
2350
|
+
this._fields = Object.create(null)
|
2351
|
+
this._documents = Object.create(null)
|
2352
|
+
this.invertedIndex = Object.create(null)
|
2353
|
+
this.fieldTermFrequencies = {}
|
2354
|
+
this.fieldLengths = {}
|
2355
|
+
this.tokenizer = lunr.tokenizer
|
2356
|
+
this.pipeline = new lunr.Pipeline
|
2357
|
+
this.searchPipeline = new lunr.Pipeline
|
2358
|
+
this.documentCount = 0
|
2359
|
+
this._b = 0.75
|
2360
|
+
this._k1 = 1.2
|
2361
|
+
this.termIndex = 0
|
2362
|
+
this.metadataWhitelist = []
|
2364
2363
|
}
|
2365
2364
|
|
2366
2365
|
/**
|
@@ -2376,7 +2375,7 @@ lunr.Builder = function () {
|
|
2376
2375
|
* @param {string} ref - The name of the reference field in the document.
|
2377
2376
|
*/
|
2378
2377
|
lunr.Builder.prototype.ref = function (ref) {
|
2379
|
-
|
2378
|
+
this._ref = ref
|
2380
2379
|
}
|
2381
2380
|
|
2382
2381
|
/**
|
@@ -2412,11 +2411,11 @@ lunr.Builder.prototype.ref = function (ref) {
|
|
2412
2411
|
* @throws {RangeError} fieldName cannot contain unsupported characters '/'
|
2413
2412
|
*/
|
2414
2413
|
lunr.Builder.prototype.field = function (fieldName, attributes) {
|
2415
|
-
|
2416
|
-
|
2417
|
-
|
2414
|
+
if (/\//.test(fieldName)) {
|
2415
|
+
throw new RangeError ("Field '" + fieldName + "' contains illegal character '/'")
|
2416
|
+
}
|
2418
2417
|
|
2419
|
-
|
2418
|
+
this._fields[fieldName] = attributes || {}
|
2420
2419
|
}
|
2421
2420
|
|
2422
2421
|
/**
|
@@ -2428,13 +2427,13 @@ lunr.Builder.prototype.field = function (fieldName, attributes) {
|
|
2428
2427
|
* @param {number} number - The value to set for this tuning parameter.
|
2429
2428
|
*/
|
2430
2429
|
lunr.Builder.prototype.b = function (number) {
|
2431
|
-
|
2432
|
-
|
2433
|
-
|
2434
|
-
|
2435
|
-
|
2436
|
-
|
2437
|
-
|
2430
|
+
if (number < 0) {
|
2431
|
+
this._b = 0
|
2432
|
+
} else if (number > 1) {
|
2433
|
+
this._b = 1
|
2434
|
+
} else {
|
2435
|
+
this._b = number
|
2436
|
+
}
|
2438
2437
|
}
|
2439
2438
|
|
2440
2439
|
/**
|
@@ -2445,7 +2444,7 @@ lunr.Builder.prototype.b = function (number) {
|
|
2445
2444
|
* @param {number} number - The value to set for this tuning parameter.
|
2446
2445
|
*/
|
2447
2446
|
lunr.Builder.prototype.k1 = function (number) {
|
2448
|
-
|
2447
|
+
this._k1 = number
|
2449
2448
|
}
|
2450
2449
|
|
2451
2450
|
/**
|
@@ -2466,73 +2465,73 @@ lunr.Builder.prototype.k1 = function (number) {
|
|
2466
2465
|
* @param {number} [attributes.boost=1] - Boost applied to all terms within this document.
|
2467
2466
|
*/
|
2468
2467
|
lunr.Builder.prototype.add = function (doc, attributes) {
|
2469
|
-
|
2470
|
-
|
2471
|
-
|
2472
|
-
|
2473
|
-
|
2474
|
-
|
2475
|
-
|
2476
|
-
|
2477
|
-
|
2478
|
-
|
2479
|
-
|
2480
|
-
|
2481
|
-
|
2482
|
-
|
2483
|
-
|
2484
|
-
|
2485
|
-
|
2486
|
-
|
2487
|
-
|
2488
|
-
|
2489
|
-
|
2490
|
-
|
2491
|
-
|
2492
|
-
|
2493
|
-
|
2494
|
-
|
2495
|
-
|
2496
|
-
|
2497
|
-
|
2498
|
-
|
2499
|
-
|
2500
|
-
|
2501
|
-
|
2502
|
-
|
2503
|
-
|
2504
|
-
|
2505
|
-
|
2506
|
-
|
2507
|
-
|
2508
|
-
|
2509
|
-
|
2510
|
-
|
2511
|
-
|
2468
|
+
var docRef = doc[this._ref],
|
2469
|
+
fields = Object.keys(this._fields)
|
2470
|
+
|
2471
|
+
this._documents[docRef] = attributes || {}
|
2472
|
+
this.documentCount += 1
|
2473
|
+
|
2474
|
+
for (var i = 0; i < fields.length; i++) {
|
2475
|
+
var fieldName = fields[i],
|
2476
|
+
extractor = this._fields[fieldName].extractor,
|
2477
|
+
field = extractor ? extractor(doc) : doc[fieldName],
|
2478
|
+
tokens = this.tokenizer(field, {
|
2479
|
+
fields: [fieldName]
|
2480
|
+
}),
|
2481
|
+
terms = this.pipeline.run(tokens),
|
2482
|
+
fieldRef = new lunr.FieldRef (docRef, fieldName),
|
2483
|
+
fieldTerms = Object.create(null)
|
2484
|
+
|
2485
|
+
this.fieldTermFrequencies[fieldRef] = fieldTerms
|
2486
|
+
this.fieldLengths[fieldRef] = 0
|
2487
|
+
|
2488
|
+
// store the length of this field for this document
|
2489
|
+
this.fieldLengths[fieldRef] += terms.length
|
2490
|
+
|
2491
|
+
// calculate term frequencies for this field
|
2492
|
+
for (var j = 0; j < terms.length; j++) {
|
2493
|
+
var term = terms[j]
|
2494
|
+
|
2495
|
+
if (fieldTerms[term] == undefined) {
|
2496
|
+
fieldTerms[term] = 0
|
2497
|
+
}
|
2498
|
+
|
2499
|
+
fieldTerms[term] += 1
|
2500
|
+
|
2501
|
+
// add to inverted index
|
2502
|
+
// create an initial posting if one doesn't exist
|
2503
|
+
if (this.invertedIndex[term] == undefined) {
|
2504
|
+
var posting = Object.create(null)
|
2505
|
+
posting["_index"] = this.termIndex
|
2506
|
+
this.termIndex += 1
|
2507
|
+
|
2508
|
+
for (var k = 0; k < fields.length; k++) {
|
2509
|
+
posting[fields[k]] = Object.create(null)
|
2510
|
+
}
|
2512
2511
|
|
2513
|
-
|
2514
|
-
|
2512
|
+
this.invertedIndex[term] = posting
|
2513
|
+
}
|
2515
2514
|
|
2516
|
-
|
2517
|
-
|
2518
|
-
|
2519
|
-
|
2515
|
+
// add an entry for this term/fieldName/docRef to the invertedIndex
|
2516
|
+
if (this.invertedIndex[term][fieldName][docRef] == undefined) {
|
2517
|
+
this.invertedIndex[term][fieldName][docRef] = Object.create(null)
|
2518
|
+
}
|
2520
2519
|
|
2521
|
-
|
2522
|
-
|
2523
|
-
|
2524
|
-
|
2525
|
-
|
2520
|
+
// store all whitelisted metadata about this token in the
|
2521
|
+
// inverted index
|
2522
|
+
for (var l = 0; l < this.metadataWhitelist.length; l++) {
|
2523
|
+
var metadataKey = this.metadataWhitelist[l],
|
2524
|
+
metadata = term.metadata[metadataKey]
|
2526
2525
|
|
2527
|
-
|
2528
|
-
|
2529
|
-
|
2526
|
+
if (this.invertedIndex[term][fieldName][docRef][metadataKey] == undefined) {
|
2527
|
+
this.invertedIndex[term][fieldName][docRef][metadataKey] = []
|
2528
|
+
}
|
2530
2529
|
|
2531
|
-
|
2530
|
+
this.invertedIndex[term][fieldName][docRef][metadataKey].push(metadata)
|
2531
|
+
}
|
2532
2532
|
}
|
2533
|
-
}
|
2534
2533
|
|
2535
|
-
|
2534
|
+
}
|
2536
2535
|
}
|
2537
2536
|
|
2538
2537
|
/**
|
@@ -2542,30 +2541,30 @@ lunr.Builder.prototype.add = function (doc, attributes) {
|
|
2542
2541
|
*/
|
2543
2542
|
lunr.Builder.prototype.calculateAverageFieldLengths = function () {
|
2544
2543
|
|
2545
|
-
|
2546
|
-
|
2547
|
-
|
2548
|
-
|
2544
|
+
var fieldRefs = Object.keys(this.fieldLengths),
|
2545
|
+
numberOfFields = fieldRefs.length,
|
2546
|
+
accumulator = {},
|
2547
|
+
documentsWithField = {}
|
2549
2548
|
|
2550
|
-
|
2551
|
-
|
2552
|
-
|
2549
|
+
for (var i = 0; i < numberOfFields; i++) {
|
2550
|
+
var fieldRef = lunr.FieldRef.fromString(fieldRefs[i]),
|
2551
|
+
field = fieldRef.fieldName
|
2553
2552
|
|
2554
|
-
|
2555
|
-
|
2553
|
+
documentsWithField[field] || (documentsWithField[field] = 0)
|
2554
|
+
documentsWithField[field] += 1
|
2556
2555
|
|
2557
|
-
|
2558
|
-
|
2559
|
-
|
2556
|
+
accumulator[field] || (accumulator[field] = 0)
|
2557
|
+
accumulator[field] += this.fieldLengths[fieldRef]
|
2558
|
+
}
|
2560
2559
|
|
2561
|
-
|
2560
|
+
var fields = Object.keys(this._fields)
|
2562
2561
|
|
2563
|
-
|
2564
|
-
|
2565
|
-
|
2566
|
-
|
2562
|
+
for (var i = 0; i < fields.length; i++) {
|
2563
|
+
var fieldName = fields[i]
|
2564
|
+
accumulator[fieldName] = accumulator[fieldName] / documentsWithField[fieldName]
|
2565
|
+
}
|
2567
2566
|
|
2568
|
-
|
2567
|
+
this.averageFieldLength = accumulator
|
2569
2568
|
}
|
2570
2569
|
|
2571
2570
|
/**
|
@@ -2574,55 +2573,55 @@ lunr.Builder.prototype.calculateAverageFieldLengths = function () {
|
|
2574
2573
|
* @private
|
2575
2574
|
*/
|
2576
2575
|
lunr.Builder.prototype.createFieldVectors = function () {
|
2577
|
-
|
2578
|
-
|
2579
|
-
|
2580
|
-
|
2581
|
-
|
2582
|
-
|
2583
|
-
|
2584
|
-
|
2585
|
-
|
2586
|
-
|
2587
|
-
|
2588
|
-
|
2589
|
-
|
2590
|
-
|
2591
|
-
|
2592
|
-
|
2593
|
-
|
2594
|
-
|
2595
|
-
|
2596
|
-
|
2597
|
-
|
2598
|
-
|
2599
|
-
|
2600
|
-
|
2601
|
-
|
2602
|
-
|
2603
|
-
|
2604
|
-
|
2605
|
-
|
2576
|
+
var fieldVectors = {},
|
2577
|
+
fieldRefs = Object.keys(this.fieldTermFrequencies),
|
2578
|
+
fieldRefsLength = fieldRefs.length,
|
2579
|
+
termIdfCache = Object.create(null)
|
2580
|
+
|
2581
|
+
for (var i = 0; i < fieldRefsLength; i++) {
|
2582
|
+
var fieldRef = lunr.FieldRef.fromString(fieldRefs[i]),
|
2583
|
+
fieldName = fieldRef.fieldName,
|
2584
|
+
fieldLength = this.fieldLengths[fieldRef],
|
2585
|
+
fieldVector = new lunr.Vector,
|
2586
|
+
termFrequencies = this.fieldTermFrequencies[fieldRef],
|
2587
|
+
terms = Object.keys(termFrequencies),
|
2588
|
+
termsLength = terms.length
|
2589
|
+
|
2590
|
+
|
2591
|
+
var fieldBoost = this._fields[fieldName].boost || 1,
|
2592
|
+
docBoost = this._documents[fieldRef.docRef].boost || 1
|
2593
|
+
|
2594
|
+
for (var j = 0; j < termsLength; j++) {
|
2595
|
+
var term = terms[j],
|
2596
|
+
tf = termFrequencies[term],
|
2597
|
+
termIndex = this.invertedIndex[term]._index,
|
2598
|
+
idf, score, scoreWithPrecision
|
2599
|
+
|
2600
|
+
if (termIdfCache[term] === undefined) {
|
2601
|
+
idf = lunr.idf(this.invertedIndex[term], this.documentCount)
|
2602
|
+
termIdfCache[term] = idf
|
2603
|
+
} else {
|
2604
|
+
idf = termIdfCache[term]
|
2605
|
+
}
|
2606
|
+
|
2607
|
+
score = idf * ((this._k1 + 1) * tf) / (this._k1 * (1 - this._b + this._b * (fieldLength / this.averageFieldLength[fieldName])) + tf)
|
2608
|
+
score *= fieldBoost
|
2609
|
+
score *= docBoost
|
2610
|
+
scoreWithPrecision = Math.round(score * 1000) / 1000
|
2611
|
+
// Converts 1.23456789 to 1.234.
|
2612
|
+
// Reducing the precision so that the vectors take up less
|
2613
|
+
// space when serialised. Doing it now so that they behave
|
2614
|
+
// the same before and after serialisation. Also, this is
|
2615
|
+
// the fastest approach to reducing a number's precision in
|
2616
|
+
// JavaScript.
|
2617
|
+
|
2618
|
+
fieldVector.insert(termIndex, scoreWithPrecision)
|
2606
2619
|
}
|
2607
2620
|
|
2608
|
-
|
2609
|
-
|
2610
|
-
score *= docBoost
|
2611
|
-
scoreWithPrecision = Math.round(score * 1000) / 1000
|
2612
|
-
// Converts 1.23456789 to 1.234.
|
2613
|
-
// Reducing the precision so that the vectors take up less
|
2614
|
-
// space when serialised. Doing it now so that they behave
|
2615
|
-
// the same before and after serialisation. Also, this is
|
2616
|
-
// the fastest approach to reducing a number's precision in
|
2617
|
-
// JavaScript.
|
2618
|
-
|
2619
|
-
fieldVector.insert(termIndex, scoreWithPrecision)
|
2620
|
-
}
|
2621
|
-
|
2622
|
-
fieldVectors[fieldRef] = fieldVector
|
2623
|
-
}
|
2621
|
+
fieldVectors[fieldRef] = fieldVector
|
2622
|
+
}
|
2624
2623
|
|
2625
|
-
|
2624
|
+
this.fieldVectors = fieldVectors
|
2626
2625
|
}
|
2627
2626
|
|
2628
2627
|
/**
|
@@ -2631,9 +2630,9 @@ lunr.Builder.prototype.createFieldVectors = function () {
|
|
2631
2630
|
* @private
|
2632
2631
|
*/
|
2633
2632
|
lunr.Builder.prototype.createTokenSet = function () {
|
2634
|
-
|
2635
|
-
|
2636
|
-
|
2633
|
+
this.tokenSet = lunr.TokenSet.fromArray(
|
2634
|
+
Object.keys(this.invertedIndex).sort()
|
2635
|
+
)
|
2637
2636
|
}
|
2638
2637
|
|
2639
2638
|
/**
|
@@ -2645,17 +2644,17 @@ lunr.Builder.prototype.createTokenSet = function () {
|
|
2645
2644
|
* @returns {lunr.Index}
|
2646
2645
|
*/
|
2647
2646
|
lunr.Builder.prototype.build = function () {
|
2648
|
-
|
2649
|
-
|
2650
|
-
|
2647
|
+
this.calculateAverageFieldLengths()
|
2648
|
+
this.createFieldVectors()
|
2649
|
+
this.createTokenSet()
|
2651
2650
|
|
2652
|
-
|
2653
|
-
|
2654
|
-
|
2655
|
-
|
2656
|
-
|
2657
|
-
|
2658
|
-
|
2651
|
+
return new lunr.Index({
|
2652
|
+
invertedIndex: this.invertedIndex,
|
2653
|
+
fieldVectors: this.fieldVectors,
|
2654
|
+
tokenSet: this.tokenSet,
|
2655
|
+
fields: Object.keys(this._fields),
|
2656
|
+
pipeline: this.searchPipeline
|
2657
|
+
})
|
2659
2658
|
}
|
2660
2659
|
|
2661
2660
|
/**
|
@@ -2673,9 +2672,9 @@ lunr.Builder.prototype.build = function () {
|
|
2673
2672
|
* @param {Function} plugin The plugin to apply.
|
2674
2673
|
*/
|
2675
2674
|
lunr.Builder.prototype.use = function (fn) {
|
2676
|
-
|
2677
|
-
|
2678
|
-
|
2675
|
+
var args = Array.prototype.slice.call(arguments, 1)
|
2676
|
+
args.unshift(this)
|
2677
|
+
fn.apply(this, args)
|
2679
2678
|
}
|
2680
2679
|
/**
|
2681
2680
|
* Contains and collects metadata about a matching document.
|
@@ -2690,25 +2689,25 @@ lunr.Builder.prototype.use = function (fn) {
|
|
2690
2689
|
* @see {@link lunr.Index~Result}
|
2691
2690
|
*/
|
2692
2691
|
lunr.MatchData = function (term, field, metadata) {
|
2693
|
-
|
2694
|
-
|
2692
|
+
var clonedMetadata = Object.create(null),
|
2693
|
+
metadataKeys = Object.keys(metadata || {})
|
2695
2694
|
|
2696
2695
|
// Cloning the metadata to prevent the original
|
2697
2696
|
// being mutated during match data combination.
|
2698
2697
|
// Metadata is kept in an array within the inverted
|
2699
2698
|
// index so cloning the data can be done with
|
2700
2699
|
// Array#slice
|
2701
|
-
|
2702
|
-
|
2703
|
-
|
2704
|
-
|
2700
|
+
for (var i = 0; i < metadataKeys.length; i++) {
|
2701
|
+
var key = metadataKeys[i]
|
2702
|
+
clonedMetadata[key] = metadata[key].slice()
|
2703
|
+
}
|
2705
2704
|
|
2706
|
-
|
2705
|
+
this.metadata = Object.create(null)
|
2707
2706
|
|
2708
|
-
|
2709
|
-
|
2710
|
-
|
2711
|
-
|
2707
|
+
if (term !== undefined) {
|
2708
|
+
this.metadata[term] = Object.create(null)
|
2709
|
+
this.metadata[term][field] = clonedMetadata
|
2710
|
+
}
|
2712
2711
|
}
|
2713
2712
|
|
2714
2713
|
/**
|
@@ -2721,36 +2720,36 @@ lunr.MatchData = function (term, field, metadata) {
|
|
2721
2720
|
* @see {@link lunr.Index~Result}
|
2722
2721
|
*/
|
2723
2722
|
lunr.MatchData.prototype.combine = function (otherMatchData) {
|
2724
|
-
|
2723
|
+
var terms = Object.keys(otherMatchData.metadata)
|
2725
2724
|
|
2726
|
-
|
2727
|
-
|
2728
|
-
|
2725
|
+
for (var i = 0; i < terms.length; i++) {
|
2726
|
+
var term = terms[i],
|
2727
|
+
fields = Object.keys(otherMatchData.metadata[term])
|
2729
2728
|
|
2730
|
-
|
2731
|
-
|
2732
|
-
|
2729
|
+
if (this.metadata[term] == undefined) {
|
2730
|
+
this.metadata[term] = Object.create(null)
|
2731
|
+
}
|
2733
2732
|
|
2734
|
-
|
2735
|
-
|
2736
|
-
|
2733
|
+
for (var j = 0; j < fields.length; j++) {
|
2734
|
+
var field = fields[j],
|
2735
|
+
keys = Object.keys(otherMatchData.metadata[term][field])
|
2737
2736
|
|
2738
|
-
|
2739
|
-
|
2740
|
-
|
2737
|
+
if (this.metadata[term][field] == undefined) {
|
2738
|
+
this.metadata[term][field] = Object.create(null)
|
2739
|
+
}
|
2741
2740
|
|
2742
|
-
|
2743
|
-
|
2741
|
+
for (var k = 0; k < keys.length; k++) {
|
2742
|
+
var key = keys[k]
|
2744
2743
|
|
2745
|
-
|
2746
|
-
|
2747
|
-
|
2748
|
-
|
2749
|
-
|
2744
|
+
if (this.metadata[term][field][key] == undefined) {
|
2745
|
+
this.metadata[term][field][key] = otherMatchData.metadata[term][field][key]
|
2746
|
+
} else {
|
2747
|
+
this.metadata[term][field][key] = this.metadata[term][field][key].concat(otherMatchData.metadata[term][field][key])
|
2748
|
+
}
|
2750
2749
|
|
2750
|
+
}
|
2751
2751
|
}
|
2752
|
-
|
2753
|
-
}
|
2752
|
+
}
|
2754
2753
|
}
|
2755
2754
|
|
2756
2755
|
/**
|
@@ -2761,28 +2760,28 @@ lunr.MatchData.prototype.combine = function (otherMatchData) {
|
|
2761
2760
|
* @param {object} metadata - The metadata recorded about this term in this field
|
2762
2761
|
*/
|
2763
2762
|
lunr.MatchData.prototype.add = function (term, field, metadata) {
|
2764
|
-
|
2765
|
-
|
2766
|
-
|
2767
|
-
|
2768
|
-
|
2763
|
+
if (!(term in this.metadata)) {
|
2764
|
+
this.metadata[term] = Object.create(null)
|
2765
|
+
this.metadata[term][field] = metadata
|
2766
|
+
return
|
2767
|
+
}
|
2769
2768
|
|
2770
|
-
|
2771
|
-
|
2772
|
-
|
2773
|
-
|
2769
|
+
if (!(field in this.metadata[term])) {
|
2770
|
+
this.metadata[term][field] = metadata
|
2771
|
+
return
|
2772
|
+
}
|
2774
2773
|
|
2775
|
-
|
2774
|
+
var metadataKeys = Object.keys(metadata)
|
2776
2775
|
|
2777
|
-
|
2778
|
-
|
2776
|
+
for (var i = 0; i < metadataKeys.length; i++) {
|
2777
|
+
var key = metadataKeys[i]
|
2779
2778
|
|
2780
|
-
|
2781
|
-
|
2782
|
-
|
2783
|
-
|
2784
|
-
|
2785
|
-
|
2779
|
+
if (key in this.metadata[term][field]) {
|
2780
|
+
this.metadata[term][field][key] = this.metadata[term][field][key].concat(metadata[key])
|
2781
|
+
} else {
|
2782
|
+
this.metadata[term][field][key] = metadata[key]
|
2783
|
+
}
|
2784
|
+
}
|
2786
2785
|
}
|
2787
2786
|
/**
|
2788
2787
|
* A lunr.Query provides a programmatic way of defining queries to be performed
|
@@ -2796,8 +2795,8 @@ lunr.MatchData.prototype.add = function (term, field, metadata) {
|
|
2796
2795
|
* @property {string[]} allFields - An array of all available fields in a lunr.Index.
|
2797
2796
|
*/
|
2798
2797
|
lunr.Query = function (allFields) {
|
2799
|
-
|
2800
|
-
|
2798
|
+
this.clauses = []
|
2799
|
+
this.allFields = allFields
|
2801
2800
|
}
|
2802
2801
|
|
2803
2802
|
/**
|
@@ -2841,22 +2840,22 @@ lunr.Query.wildcard.TRAILING = 2
|
|
2841
2840
|
* query.term('foo', { presence: lunr.Query.presence.REQUIRED })
|
2842
2841
|
*/
|
2843
2842
|
lunr.Query.presence = {
|
2844
|
-
|
2845
|
-
|
2846
|
-
|
2847
|
-
|
2843
|
+
/**
|
2844
|
+
* Term's presence in a document is optional, this is the default value.
|
2845
|
+
*/
|
2846
|
+
OPTIONAL: 1,
|
2848
2847
|
|
2849
|
-
|
2850
|
-
|
2851
|
-
|
2852
|
-
|
2853
|
-
|
2848
|
+
/**
|
2849
|
+
* Term's presence in a document is required, documents that do not contain
|
2850
|
+
* this term will not be returned.
|
2851
|
+
*/
|
2852
|
+
REQUIRED: 2,
|
2854
2853
|
|
2855
|
-
|
2856
|
-
|
2857
|
-
|
2858
|
-
|
2859
|
-
|
2854
|
+
/**
|
2855
|
+
* Term's presence in a document is prohibited, documents that do contain
|
2856
|
+
* this term will not be returned.
|
2857
|
+
*/
|
2858
|
+
PROHIBITED: 3
|
2860
2859
|
}
|
2861
2860
|
|
2862
2861
|
/**
|
@@ -2883,37 +2882,37 @@ lunr.Query.presence = {
|
|
2883
2882
|
* @returns {lunr.Query}
|
2884
2883
|
*/
|
2885
2884
|
lunr.Query.prototype.clause = function (clause) {
|
2886
|
-
|
2887
|
-
|
2888
|
-
|
2885
|
+
if (!('fields' in clause)) {
|
2886
|
+
clause.fields = this.allFields
|
2887
|
+
}
|
2889
2888
|
|
2890
|
-
|
2891
|
-
|
2892
|
-
|
2889
|
+
if (!('boost' in clause)) {
|
2890
|
+
clause.boost = 1
|
2891
|
+
}
|
2893
2892
|
|
2894
|
-
|
2895
|
-
|
2896
|
-
|
2893
|
+
if (!('usePipeline' in clause)) {
|
2894
|
+
clause.usePipeline = true
|
2895
|
+
}
|
2897
2896
|
|
2898
|
-
|
2899
|
-
|
2900
|
-
|
2897
|
+
if (!('wildcard' in clause)) {
|
2898
|
+
clause.wildcard = lunr.Query.wildcard.NONE
|
2899
|
+
}
|
2901
2900
|
|
2902
|
-
|
2903
|
-
|
2904
|
-
|
2901
|
+
if ((clause.wildcard & lunr.Query.wildcard.LEADING) && (clause.term.charAt(0) != lunr.Query.wildcard)) {
|
2902
|
+
clause.term = "*" + clause.term
|
2903
|
+
}
|
2905
2904
|
|
2906
|
-
|
2907
|
-
|
2908
|
-
|
2905
|
+
if ((clause.wildcard & lunr.Query.wildcard.TRAILING) && (clause.term.slice(-1) != lunr.Query.wildcard)) {
|
2906
|
+
clause.term = "" + clause.term + "*"
|
2907
|
+
}
|
2909
2908
|
|
2910
|
-
|
2911
|
-
|
2912
|
-
|
2909
|
+
if (!('presence' in clause)) {
|
2910
|
+
clause.presence = lunr.Query.presence.OPTIONAL
|
2911
|
+
}
|
2913
2912
|
|
2914
|
-
|
2913
|
+
this.clauses.push(clause)
|
2915
2914
|
|
2916
|
-
|
2915
|
+
return this
|
2917
2916
|
}
|
2918
2917
|
|
2919
2918
|
/**
|
@@ -2924,13 +2923,13 @@ lunr.Query.prototype.clause = function (clause) {
|
|
2924
2923
|
* @returns boolean
|
2925
2924
|
*/
|
2926
2925
|
lunr.Query.prototype.isNegated = function () {
|
2927
|
-
|
2928
|
-
|
2929
|
-
|
2930
|
-
|
2931
|
-
|
2926
|
+
for (var i = 0; i < this.clauses.length; i++) {
|
2927
|
+
if (this.clauses[i].presence != lunr.Query.presence.PROHIBITED) {
|
2928
|
+
return false
|
2929
|
+
}
|
2930
|
+
}
|
2932
2931
|
|
2933
|
-
|
2932
|
+
return true
|
2934
2933
|
}
|
2935
2934
|
|
2936
2935
|
/**
|
@@ -2960,117 +2959,117 @@ lunr.Query.prototype.isNegated = function () {
|
|
2960
2959
|
* query.term(lunr.tokenizer("foo bar"))
|
2961
2960
|
*/
|
2962
2961
|
lunr.Query.prototype.term = function (term, options) {
|
2963
|
-
|
2964
|
-
|
2965
|
-
|
2966
|
-
|
2962
|
+
if (Array.isArray(term)) {
|
2963
|
+
term.forEach(function (t) { this.term(t, lunr.utils.clone(options)) }, this)
|
2964
|
+
return this
|
2965
|
+
}
|
2967
2966
|
|
2968
|
-
|
2969
|
-
|
2967
|
+
var clause = options || {}
|
2968
|
+
clause.term = term.toString()
|
2970
2969
|
|
2971
|
-
|
2970
|
+
this.clause(clause)
|
2972
2971
|
|
2973
|
-
|
2972
|
+
return this
|
2974
2973
|
}
|
2975
2974
|
lunr.QueryParseError = function (message, start, end) {
|
2976
|
-
|
2977
|
-
|
2978
|
-
|
2979
|
-
|
2975
|
+
this.name = "QueryParseError"
|
2976
|
+
this.message = message
|
2977
|
+
this.start = start
|
2978
|
+
this.end = end
|
2980
2979
|
}
|
2981
2980
|
|
2982
2981
|
lunr.QueryParseError.prototype = new Error
|
2983
2982
|
lunr.QueryLexer = function (str) {
|
2984
|
-
|
2985
|
-
|
2986
|
-
|
2987
|
-
|
2988
|
-
|
2989
|
-
|
2983
|
+
this.lexemes = []
|
2984
|
+
this.str = str
|
2985
|
+
this.length = str.length
|
2986
|
+
this.pos = 0
|
2987
|
+
this.start = 0
|
2988
|
+
this.escapeCharPositions = []
|
2990
2989
|
}
|
2991
2990
|
|
2992
2991
|
lunr.QueryLexer.prototype.run = function () {
|
2993
|
-
|
2992
|
+
var state = lunr.QueryLexer.lexText
|
2994
2993
|
|
2995
|
-
|
2996
|
-
|
2997
|
-
|
2994
|
+
while (state) {
|
2995
|
+
state = state(this)
|
2996
|
+
}
|
2998
2997
|
}
|
2999
2998
|
|
3000
2999
|
lunr.QueryLexer.prototype.sliceString = function () {
|
3001
|
-
|
3002
|
-
|
3003
|
-
|
3004
|
-
|
3005
|
-
|
3006
|
-
|
3007
|
-
|
3008
|
-
|
3009
|
-
|
3000
|
+
var subSlices = [],
|
3001
|
+
sliceStart = this.start,
|
3002
|
+
sliceEnd = this.pos
|
3003
|
+
|
3004
|
+
for (var i = 0; i < this.escapeCharPositions.length; i++) {
|
3005
|
+
sliceEnd = this.escapeCharPositions[i]
|
3006
|
+
subSlices.push(this.str.slice(sliceStart, sliceEnd))
|
3007
|
+
sliceStart = sliceEnd + 1
|
3008
|
+
}
|
3010
3009
|
|
3011
|
-
|
3012
|
-
|
3010
|
+
subSlices.push(this.str.slice(sliceStart, this.pos))
|
3011
|
+
this.escapeCharPositions.length = 0
|
3013
3012
|
|
3014
|
-
|
3013
|
+
return subSlices.join('')
|
3015
3014
|
}
|
3016
3015
|
|
3017
3016
|
lunr.QueryLexer.prototype.emit = function (type) {
|
3018
|
-
|
3019
|
-
|
3020
|
-
|
3021
|
-
|
3022
|
-
|
3023
|
-
|
3017
|
+
this.lexemes.push({
|
3018
|
+
type: type,
|
3019
|
+
str: this.sliceString(),
|
3020
|
+
start: this.start,
|
3021
|
+
end: this.pos
|
3022
|
+
})
|
3024
3023
|
|
3025
|
-
|
3024
|
+
this.start = this.pos
|
3026
3025
|
}
|
3027
3026
|
|
3028
3027
|
lunr.QueryLexer.prototype.escapeCharacter = function () {
|
3029
|
-
|
3030
|
-
|
3028
|
+
this.escapeCharPositions.push(this.pos - 1)
|
3029
|
+
this.pos += 1
|
3031
3030
|
}
|
3032
3031
|
|
3033
3032
|
lunr.QueryLexer.prototype.next = function () {
|
3034
|
-
|
3035
|
-
|
3036
|
-
|
3033
|
+
if (this.pos >= this.length) {
|
3034
|
+
return lunr.QueryLexer.EOS
|
3035
|
+
}
|
3037
3036
|
|
3038
|
-
|
3039
|
-
|
3040
|
-
|
3037
|
+
var char = this.str.charAt(this.pos)
|
3038
|
+
this.pos += 1
|
3039
|
+
return char
|
3041
3040
|
}
|
3042
3041
|
|
3043
3042
|
lunr.QueryLexer.prototype.width = function () {
|
3044
|
-
|
3043
|
+
return this.pos - this.start
|
3045
3044
|
}
|
3046
3045
|
|
3047
3046
|
lunr.QueryLexer.prototype.ignore = function () {
|
3048
|
-
|
3049
|
-
|
3050
|
-
|
3047
|
+
if (this.start == this.pos) {
|
3048
|
+
this.pos += 1
|
3049
|
+
}
|
3051
3050
|
|
3052
|
-
|
3051
|
+
this.start = this.pos
|
3053
3052
|
}
|
3054
3053
|
|
3055
3054
|
lunr.QueryLexer.prototype.backup = function () {
|
3056
|
-
|
3055
|
+
this.pos -= 1
|
3057
3056
|
}
|
3058
3057
|
|
3059
3058
|
lunr.QueryLexer.prototype.acceptDigitRun = function () {
|
3060
|
-
|
3059
|
+
var char, charCode
|
3061
3060
|
|
3062
|
-
|
3063
|
-
|
3064
|
-
|
3065
|
-
|
3061
|
+
do {
|
3062
|
+
char = this.next()
|
3063
|
+
charCode = char.charCodeAt(0)
|
3064
|
+
} while (charCode > 47 && charCode < 58)
|
3066
3065
|
|
3067
|
-
|
3068
|
-
|
3069
|
-
|
3066
|
+
if (char != lunr.QueryLexer.EOS) {
|
3067
|
+
this.backup()
|
3068
|
+
}
|
3070
3069
|
}
|
3071
3070
|
|
3072
3071
|
lunr.QueryLexer.prototype.more = function () {
|
3073
|
-
|
3072
|
+
return this.pos < this.length
|
3074
3073
|
}
|
3075
3074
|
|
3076
3075
|
lunr.QueryLexer.EOS = 'EOS'
|
@@ -3081,43 +3080,43 @@ lunr.QueryLexer.BOOST = 'BOOST'
|
|
3081
3080
|
lunr.QueryLexer.PRESENCE = 'PRESENCE'
|
3082
3081
|
|
3083
3082
|
lunr.QueryLexer.lexField = function (lexer) {
|
3084
|
-
|
3085
|
-
|
3086
|
-
|
3087
|
-
|
3083
|
+
lexer.backup()
|
3084
|
+
lexer.emit(lunr.QueryLexer.FIELD)
|
3085
|
+
lexer.ignore()
|
3086
|
+
return lunr.QueryLexer.lexText
|
3088
3087
|
}
|
3089
3088
|
|
3090
3089
|
lunr.QueryLexer.lexTerm = function (lexer) {
|
3091
|
-
|
3092
|
-
|
3093
|
-
|
3094
|
-
|
3090
|
+
if (lexer.width() > 1) {
|
3091
|
+
lexer.backup()
|
3092
|
+
lexer.emit(lunr.QueryLexer.TERM)
|
3093
|
+
}
|
3095
3094
|
|
3096
|
-
|
3095
|
+
lexer.ignore()
|
3097
3096
|
|
3098
|
-
|
3099
|
-
|
3100
|
-
|
3097
|
+
if (lexer.more()) {
|
3098
|
+
return lunr.QueryLexer.lexText
|
3099
|
+
}
|
3101
3100
|
}
|
3102
3101
|
|
3103
3102
|
lunr.QueryLexer.lexEditDistance = function (lexer) {
|
3104
|
-
|
3105
|
-
|
3106
|
-
|
3107
|
-
|
3103
|
+
lexer.ignore()
|
3104
|
+
lexer.acceptDigitRun()
|
3105
|
+
lexer.emit(lunr.QueryLexer.EDIT_DISTANCE)
|
3106
|
+
return lunr.QueryLexer.lexText
|
3108
3107
|
}
|
3109
3108
|
|
3110
3109
|
lunr.QueryLexer.lexBoost = function (lexer) {
|
3111
|
-
|
3112
|
-
|
3113
|
-
|
3114
|
-
|
3110
|
+
lexer.ignore()
|
3111
|
+
lexer.acceptDigitRun()
|
3112
|
+
lexer.emit(lunr.QueryLexer.BOOST)
|
3113
|
+
return lunr.QueryLexer.lexText
|
3115
3114
|
}
|
3116
3115
|
|
3117
3116
|
lunr.QueryLexer.lexEOS = function (lexer) {
|
3118
|
-
|
3119
|
-
|
3120
|
-
|
3117
|
+
if (lexer.width() > 0) {
|
3118
|
+
lexer.emit(lunr.QueryLexer.TERM)
|
3119
|
+
}
|
3121
3120
|
}
|
3122
3121
|
|
3123
3122
|
// This matches the separator used when tokenising fields
|
@@ -3134,342 +3133,342 @@ lunr.QueryLexer.lexEOS = function (lexer) {
|
|
3134
3133
|
lunr.QueryLexer.termSeparator = lunr.tokenizer.separator
|
3135
3134
|
|
3136
3135
|
lunr.QueryLexer.lexText = function (lexer) {
|
3137
|
-
|
3138
|
-
|
3136
|
+
while (true) {
|
3137
|
+
var char = lexer.next()
|
3139
3138
|
|
3140
|
-
|
3141
|
-
|
3142
|
-
|
3139
|
+
if (char == lunr.QueryLexer.EOS) {
|
3140
|
+
return lunr.QueryLexer.lexEOS
|
3141
|
+
}
|
3143
3142
|
|
3144
|
-
|
3145
|
-
|
3146
|
-
|
3147
|
-
|
3148
|
-
|
3143
|
+
// Escape character is '\'
|
3144
|
+
if (char.charCodeAt(0) == 92) {
|
3145
|
+
lexer.escapeCharacter()
|
3146
|
+
continue
|
3147
|
+
}
|
3149
3148
|
|
3150
|
-
|
3151
|
-
|
3152
|
-
|
3149
|
+
if (char == ":") {
|
3150
|
+
return lunr.QueryLexer.lexField
|
3151
|
+
}
|
3153
3152
|
|
3154
|
-
|
3155
|
-
|
3156
|
-
|
3157
|
-
|
3153
|
+
if (char == "~") {
|
3154
|
+
lexer.backup()
|
3155
|
+
if (lexer.width() > 0) {
|
3156
|
+
lexer.emit(lunr.QueryLexer.TERM)
|
3157
|
+
}
|
3158
|
+
return lunr.QueryLexer.lexEditDistance
|
3158
3159
|
}
|
3159
|
-
return lunr.QueryLexer.lexEditDistance
|
3160
|
-
}
|
3161
3160
|
|
3162
|
-
|
3163
|
-
|
3164
|
-
|
3165
|
-
|
3161
|
+
if (char == "^") {
|
3162
|
+
lexer.backup()
|
3163
|
+
if (lexer.width() > 0) {
|
3164
|
+
lexer.emit(lunr.QueryLexer.TERM)
|
3165
|
+
}
|
3166
|
+
return lunr.QueryLexer.lexBoost
|
3166
3167
|
}
|
3167
|
-
return lunr.QueryLexer.lexBoost
|
3168
|
-
}
|
3169
|
-
|
3170
|
-
// "+" indicates term presence is required
|
3171
|
-
// checking for length to ensure that only
|
3172
|
-
// leading "+" are considered
|
3173
|
-
if (char == "+" && lexer.width() === 1) {
|
3174
|
-
lexer.emit(lunr.QueryLexer.PRESENCE)
|
3175
|
-
return lunr.QueryLexer.lexText
|
3176
|
-
}
|
3177
3168
|
|
3178
|
-
|
3179
|
-
|
3180
|
-
|
3181
|
-
|
3182
|
-
|
3183
|
-
|
3184
|
-
|
3169
|
+
// "+" indicates term presence is required
|
3170
|
+
// checking for length to ensure that only
|
3171
|
+
// leading "+" are considered
|
3172
|
+
if (char == "+" && lexer.width() === 1) {
|
3173
|
+
lexer.emit(lunr.QueryLexer.PRESENCE)
|
3174
|
+
return lunr.QueryLexer.lexText
|
3175
|
+
}
|
3185
3176
|
|
3186
|
-
|
3187
|
-
|
3188
|
-
|
3189
|
-
|
3177
|
+
// "-" indicates term presence is prohibited
|
3178
|
+
// checking for length to ensure that only
|
3179
|
+
// leading "-" are considered
|
3180
|
+
if (char == "-" && lexer.width() === 1) {
|
3181
|
+
lexer.emit(lunr.QueryLexer.PRESENCE)
|
3182
|
+
return lunr.QueryLexer.lexText
|
3183
|
+
}
|
3184
|
+
|
3185
|
+
if (char.match(lunr.QueryLexer.termSeparator)) {
|
3186
|
+
return lunr.QueryLexer.lexTerm
|
3187
|
+
}
|
3188
|
+
}
|
3190
3189
|
}
|
3191
3190
|
|
3192
3191
|
lunr.QueryParser = function (str, query) {
|
3193
|
-
|
3194
|
-
|
3195
|
-
|
3196
|
-
|
3192
|
+
this.lexer = new lunr.QueryLexer (str)
|
3193
|
+
this.query = query
|
3194
|
+
this.currentClause = {}
|
3195
|
+
this.lexemeIdx = 0
|
3197
3196
|
}
|
3198
3197
|
|
3199
3198
|
lunr.QueryParser.prototype.parse = function () {
|
3200
|
-
|
3201
|
-
|
3199
|
+
this.lexer.run()
|
3200
|
+
this.lexemes = this.lexer.lexemes
|
3202
3201
|
|
3203
|
-
|
3202
|
+
var state = lunr.QueryParser.parseClause
|
3204
3203
|
|
3205
|
-
|
3206
|
-
|
3207
|
-
|
3204
|
+
while (state) {
|
3205
|
+
state = state(this)
|
3206
|
+
}
|
3208
3207
|
|
3209
|
-
|
3208
|
+
return this.query
|
3210
3209
|
}
|
3211
3210
|
|
3212
3211
|
lunr.QueryParser.prototype.peekLexeme = function () {
|
3213
|
-
|
3212
|
+
return this.lexemes[this.lexemeIdx]
|
3214
3213
|
}
|
3215
3214
|
|
3216
3215
|
lunr.QueryParser.prototype.consumeLexeme = function () {
|
3217
|
-
|
3218
|
-
|
3219
|
-
|
3216
|
+
var lexeme = this.peekLexeme()
|
3217
|
+
this.lexemeIdx += 1
|
3218
|
+
return lexeme
|
3220
3219
|
}
|
3221
3220
|
|
3222
3221
|
lunr.QueryParser.prototype.nextClause = function () {
|
3223
|
-
|
3224
|
-
|
3225
|
-
|
3222
|
+
var completedClause = this.currentClause
|
3223
|
+
this.query.clause(completedClause)
|
3224
|
+
this.currentClause = {}
|
3226
3225
|
}
|
3227
3226
|
|
3228
3227
|
lunr.QueryParser.parseClause = function (parser) {
|
3229
|
-
|
3228
|
+
var lexeme = parser.peekLexeme()
|
3230
3229
|
|
3231
|
-
|
3232
|
-
|
3233
|
-
|
3230
|
+
if (lexeme == undefined) {
|
3231
|
+
return
|
3232
|
+
}
|
3234
3233
|
|
3235
|
-
|
3236
|
-
|
3237
|
-
|
3238
|
-
|
3239
|
-
|
3240
|
-
|
3241
|
-
|
3242
|
-
|
3243
|
-
|
3244
|
-
|
3245
|
-
if (lexeme.str.length >= 1) {
|
3246
|
-
errorMessage += " with value '" + lexeme.str + "'"
|
3247
|
-
}
|
3234
|
+
switch (lexeme.type) {
|
3235
|
+
case lunr.QueryLexer.PRESENCE:
|
3236
|
+
return lunr.QueryParser.parsePresence
|
3237
|
+
case lunr.QueryLexer.FIELD:
|
3238
|
+
return lunr.QueryParser.parseField
|
3239
|
+
case lunr.QueryLexer.TERM:
|
3240
|
+
return lunr.QueryParser.parseTerm
|
3241
|
+
default:
|
3242
|
+
var errorMessage = "expected either a field or a term, found " + lexeme.type
|
3248
3243
|
|
3249
|
-
|
3250
|
-
|
3244
|
+
if (lexeme.str.length >= 1) {
|
3245
|
+
errorMessage += " with value '" + lexeme.str + "'"
|
3246
|
+
}
|
3247
|
+
|
3248
|
+
throw new lunr.QueryParseError (errorMessage, lexeme.start, lexeme.end)
|
3249
|
+
}
|
3251
3250
|
}
|
3252
3251
|
|
3253
3252
|
lunr.QueryParser.parsePresence = function (parser) {
|
3254
|
-
|
3255
|
-
|
3256
|
-
|
3257
|
-
|
3258
|
-
|
3259
|
-
|
3260
|
-
|
3261
|
-
|
3262
|
-
|
3263
|
-
|
3264
|
-
|
3265
|
-
|
3266
|
-
|
3267
|
-
|
3268
|
-
|
3253
|
+
var lexeme = parser.consumeLexeme()
|
3254
|
+
|
3255
|
+
if (lexeme == undefined) {
|
3256
|
+
return
|
3257
|
+
}
|
3258
|
+
|
3259
|
+
switch (lexeme.str) {
|
3260
|
+
case "-":
|
3261
|
+
parser.currentClause.presence = lunr.Query.presence.PROHIBITED
|
3262
|
+
break
|
3263
|
+
case "+":
|
3264
|
+
parser.currentClause.presence = lunr.Query.presence.REQUIRED
|
3265
|
+
break
|
3266
|
+
default:
|
3267
|
+
var errorMessage = "unrecognised presence operator'" + lexeme.str + "'"
|
3268
|
+
throw new lunr.QueryParseError (errorMessage, lexeme.start, lexeme.end)
|
3269
|
+
}
|
3270
|
+
|
3271
|
+
var nextLexeme = parser.peekLexeme()
|
3272
|
+
|
3273
|
+
if (nextLexeme == undefined) {
|
3274
|
+
var errorMessage = "expecting term or field, found nothing"
|
3269
3275
|
throw new lunr.QueryParseError (errorMessage, lexeme.start, lexeme.end)
|
3270
|
-
|
3271
|
-
|
3272
|
-
var nextLexeme = parser.peekLexeme()
|
3276
|
+
}
|
3273
3277
|
|
3274
|
-
|
3275
|
-
|
3276
|
-
|
3277
|
-
|
3278
|
-
|
3279
|
-
|
3280
|
-
|
3281
|
-
|
3282
|
-
|
3283
|
-
return lunr.QueryParser.parseTerm
|
3284
|
-
default:
|
3285
|
-
var errorMessage = "expecting term or field, found '" + nextLexeme.type + "'"
|
3286
|
-
throw new lunr.QueryParseError (errorMessage, nextLexeme.start, nextLexeme.end)
|
3287
|
-
}
|
3278
|
+
switch (nextLexeme.type) {
|
3279
|
+
case lunr.QueryLexer.FIELD:
|
3280
|
+
return lunr.QueryParser.parseField
|
3281
|
+
case lunr.QueryLexer.TERM:
|
3282
|
+
return lunr.QueryParser.parseTerm
|
3283
|
+
default:
|
3284
|
+
var errorMessage = "expecting term or field, found '" + nextLexeme.type + "'"
|
3285
|
+
throw new lunr.QueryParseError (errorMessage, nextLexeme.start, nextLexeme.end)
|
3286
|
+
}
|
3288
3287
|
}
|
3289
3288
|
|
3290
3289
|
lunr.QueryParser.parseField = function (parser) {
|
3291
|
-
|
3290
|
+
var lexeme = parser.consumeLexeme()
|
3292
3291
|
|
3293
|
-
|
3294
|
-
|
3295
|
-
|
3292
|
+
if (lexeme == undefined) {
|
3293
|
+
return
|
3294
|
+
}
|
3296
3295
|
|
3297
|
-
|
3298
|
-
|
3296
|
+
if (parser.query.allFields.indexOf(lexeme.str) == -1) {
|
3297
|
+
var possibleFields = parser.query.allFields.map(function (f) { return "'" + f + "'" }).join(', '),
|
3299
3298
|
errorMessage = "unrecognised field '" + lexeme.str + "', possible fields: " + possibleFields
|
3300
3299
|
|
3301
|
-
|
3302
|
-
|
3300
|
+
throw new lunr.QueryParseError (errorMessage, lexeme.start, lexeme.end)
|
3301
|
+
}
|
3303
3302
|
|
3304
|
-
|
3303
|
+
parser.currentClause.fields = [lexeme.str]
|
3305
3304
|
|
3306
|
-
|
3305
|
+
var nextLexeme = parser.peekLexeme()
|
3307
3306
|
|
3308
|
-
|
3309
|
-
|
3310
|
-
|
3311
|
-
|
3307
|
+
if (nextLexeme == undefined) {
|
3308
|
+
var errorMessage = "expecting term, found nothing"
|
3309
|
+
throw new lunr.QueryParseError (errorMessage, lexeme.start, lexeme.end)
|
3310
|
+
}
|
3312
3311
|
|
3313
|
-
|
3314
|
-
|
3315
|
-
|
3316
|
-
|
3317
|
-
|
3318
|
-
|
3319
|
-
|
3312
|
+
switch (nextLexeme.type) {
|
3313
|
+
case lunr.QueryLexer.TERM:
|
3314
|
+
return lunr.QueryParser.parseTerm
|
3315
|
+
default:
|
3316
|
+
var errorMessage = "expecting term, found '" + nextLexeme.type + "'"
|
3317
|
+
throw new lunr.QueryParseError (errorMessage, nextLexeme.start, nextLexeme.end)
|
3318
|
+
}
|
3320
3319
|
}
|
3321
3320
|
|
3322
3321
|
lunr.QueryParser.parseTerm = function (parser) {
|
3323
|
-
|
3322
|
+
var lexeme = parser.consumeLexeme()
|
3324
3323
|
|
3325
|
-
|
3326
|
-
|
3327
|
-
|
3328
|
-
|
3329
|
-
parser.currentClause.term = lexeme.str.toLowerCase()
|
3324
|
+
if (lexeme == undefined) {
|
3325
|
+
return
|
3326
|
+
}
|
3330
3327
|
|
3331
|
-
|
3332
|
-
parser.currentClause.usePipeline = false
|
3333
|
-
}
|
3328
|
+
parser.currentClause.term = lexeme.str.toLowerCase()
|
3334
3329
|
|
3335
|
-
|
3330
|
+
if (lexeme.str.indexOf("*") != -1) {
|
3331
|
+
parser.currentClause.usePipeline = false
|
3332
|
+
}
|
3336
3333
|
|
3337
|
-
|
3338
|
-
parser.nextClause()
|
3339
|
-
return
|
3340
|
-
}
|
3334
|
+
var nextLexeme = parser.peekLexeme()
|
3341
3335
|
|
3342
|
-
|
3343
|
-
case lunr.QueryLexer.TERM:
|
3336
|
+
if (nextLexeme == undefined) {
|
3344
3337
|
parser.nextClause()
|
3345
|
-
return
|
3346
|
-
|
3347
|
-
|
3348
|
-
|
3349
|
-
|
3350
|
-
|
3351
|
-
|
3352
|
-
|
3353
|
-
|
3354
|
-
|
3355
|
-
|
3356
|
-
|
3357
|
-
|
3358
|
-
|
3359
|
-
|
3338
|
+
return
|
3339
|
+
}
|
3340
|
+
|
3341
|
+
switch (nextLexeme.type) {
|
3342
|
+
case lunr.QueryLexer.TERM:
|
3343
|
+
parser.nextClause()
|
3344
|
+
return lunr.QueryParser.parseTerm
|
3345
|
+
case lunr.QueryLexer.FIELD:
|
3346
|
+
parser.nextClause()
|
3347
|
+
return lunr.QueryParser.parseField
|
3348
|
+
case lunr.QueryLexer.EDIT_DISTANCE:
|
3349
|
+
return lunr.QueryParser.parseEditDistance
|
3350
|
+
case lunr.QueryLexer.BOOST:
|
3351
|
+
return lunr.QueryParser.parseBoost
|
3352
|
+
case lunr.QueryLexer.PRESENCE:
|
3353
|
+
parser.nextClause()
|
3354
|
+
return lunr.QueryParser.parsePresence
|
3355
|
+
default:
|
3356
|
+
var errorMessage = "Unexpected lexeme type '" + nextLexeme.type + "'"
|
3357
|
+
throw new lunr.QueryParseError (errorMessage, nextLexeme.start, nextLexeme.end)
|
3358
|
+
}
|
3360
3359
|
}
|
3361
3360
|
|
3362
3361
|
lunr.QueryParser.parseEditDistance = function (parser) {
|
3363
|
-
|
3364
|
-
|
3365
|
-
if (lexeme == undefined) {
|
3366
|
-
return
|
3367
|
-
}
|
3362
|
+
var lexeme = parser.consumeLexeme()
|
3368
3363
|
|
3369
|
-
|
3364
|
+
if (lexeme == undefined) {
|
3365
|
+
return
|
3366
|
+
}
|
3370
3367
|
|
3371
|
-
|
3372
|
-
var errorMessage = "edit distance must be numeric"
|
3373
|
-
throw new lunr.QueryParseError (errorMessage, lexeme.start, lexeme.end)
|
3374
|
-
}
|
3368
|
+
var editDistance = parseInt(lexeme.str, 10)
|
3375
3369
|
|
3376
|
-
|
3370
|
+
if (isNaN(editDistance)) {
|
3371
|
+
var errorMessage = "edit distance must be numeric"
|
3372
|
+
throw new lunr.QueryParseError (errorMessage, lexeme.start, lexeme.end)
|
3373
|
+
}
|
3377
3374
|
|
3378
|
-
|
3375
|
+
parser.currentClause.editDistance = editDistance
|
3379
3376
|
|
3380
|
-
|
3381
|
-
parser.nextClause()
|
3382
|
-
return
|
3383
|
-
}
|
3377
|
+
var nextLexeme = parser.peekLexeme()
|
3384
3378
|
|
3385
|
-
|
3386
|
-
case lunr.QueryLexer.TERM:
|
3387
|
-
parser.nextClause()
|
3388
|
-
return lunr.QueryParser.parseTerm
|
3389
|
-
case lunr.QueryLexer.FIELD:
|
3379
|
+
if (nextLexeme == undefined) {
|
3390
3380
|
parser.nextClause()
|
3391
|
-
return
|
3392
|
-
|
3393
|
-
|
3394
|
-
|
3395
|
-
|
3396
|
-
|
3397
|
-
|
3398
|
-
|
3399
|
-
|
3400
|
-
|
3401
|
-
|
3402
|
-
|
3381
|
+
return
|
3382
|
+
}
|
3383
|
+
|
3384
|
+
switch (nextLexeme.type) {
|
3385
|
+
case lunr.QueryLexer.TERM:
|
3386
|
+
parser.nextClause()
|
3387
|
+
return lunr.QueryParser.parseTerm
|
3388
|
+
case lunr.QueryLexer.FIELD:
|
3389
|
+
parser.nextClause()
|
3390
|
+
return lunr.QueryParser.parseField
|
3391
|
+
case lunr.QueryLexer.EDIT_DISTANCE:
|
3392
|
+
return lunr.QueryParser.parseEditDistance
|
3393
|
+
case lunr.QueryLexer.BOOST:
|
3394
|
+
return lunr.QueryParser.parseBoost
|
3395
|
+
case lunr.QueryLexer.PRESENCE:
|
3396
|
+
parser.nextClause()
|
3397
|
+
return lunr.QueryParser.parsePresence
|
3398
|
+
default:
|
3399
|
+
var errorMessage = "Unexpected lexeme type '" + nextLexeme.type + "'"
|
3400
|
+
throw new lunr.QueryParseError (errorMessage, nextLexeme.start, nextLexeme.end)
|
3401
|
+
}
|
3403
3402
|
}
|
3404
3403
|
|
3405
3404
|
lunr.QueryParser.parseBoost = function (parser) {
|
3406
|
-
|
3405
|
+
var lexeme = parser.consumeLexeme()
|
3407
3406
|
|
3408
|
-
|
3409
|
-
|
3410
|
-
|
3407
|
+
if (lexeme == undefined) {
|
3408
|
+
return
|
3409
|
+
}
|
3411
3410
|
|
3412
|
-
|
3411
|
+
var boost = parseInt(lexeme.str, 10)
|
3413
3412
|
|
3414
|
-
|
3415
|
-
|
3416
|
-
|
3417
|
-
|
3418
|
-
|
3419
|
-
parser.currentClause.boost = boost
|
3413
|
+
if (isNaN(boost)) {
|
3414
|
+
var errorMessage = "boost must be numeric"
|
3415
|
+
throw new lunr.QueryParseError (errorMessage, lexeme.start, lexeme.end)
|
3416
|
+
}
|
3420
3417
|
|
3421
|
-
|
3418
|
+
parser.currentClause.boost = boost
|
3422
3419
|
|
3423
|
-
|
3424
|
-
parser.nextClause()
|
3425
|
-
return
|
3426
|
-
}
|
3420
|
+
var nextLexeme = parser.peekLexeme()
|
3427
3421
|
|
3428
|
-
|
3429
|
-
case lunr.QueryLexer.TERM:
|
3430
|
-
parser.nextClause()
|
3431
|
-
return lunr.QueryParser.parseTerm
|
3432
|
-
case lunr.QueryLexer.FIELD:
|
3422
|
+
if (nextLexeme == undefined) {
|
3433
3423
|
parser.nextClause()
|
3434
|
-
return
|
3435
|
-
|
3436
|
-
|
3437
|
-
|
3438
|
-
|
3439
|
-
|
3440
|
-
|
3441
|
-
|
3442
|
-
|
3443
|
-
|
3444
|
-
|
3445
|
-
|
3424
|
+
return
|
3425
|
+
}
|
3426
|
+
|
3427
|
+
switch (nextLexeme.type) {
|
3428
|
+
case lunr.QueryLexer.TERM:
|
3429
|
+
parser.nextClause()
|
3430
|
+
return lunr.QueryParser.parseTerm
|
3431
|
+
case lunr.QueryLexer.FIELD:
|
3432
|
+
parser.nextClause()
|
3433
|
+
return lunr.QueryParser.parseField
|
3434
|
+
case lunr.QueryLexer.EDIT_DISTANCE:
|
3435
|
+
return lunr.QueryParser.parseEditDistance
|
3436
|
+
case lunr.QueryLexer.BOOST:
|
3437
|
+
return lunr.QueryParser.parseBoost
|
3438
|
+
case lunr.QueryLexer.PRESENCE:
|
3439
|
+
parser.nextClause()
|
3440
|
+
return lunr.QueryParser.parsePresence
|
3441
|
+
default:
|
3442
|
+
var errorMessage = "Unexpected lexeme type '" + nextLexeme.type + "'"
|
3443
|
+
throw new lunr.QueryParseError (errorMessage, nextLexeme.start, nextLexeme.end)
|
3444
|
+
}
|
3446
3445
|
}
|
3447
3446
|
|
3448
3447
|
/**
|
3449
3448
|
* export the module via AMD, CommonJS or as a browser global
|
3450
3449
|
* Export code from https://github.com/umdjs/umd/blob/master/returnExports.js
|
3451
3450
|
*/
|
3452
|
-
|
3453
|
-
|
3454
|
-
|
3455
|
-
|
3456
|
-
|
3451
|
+
;(function (root, factory) {
|
3452
|
+
if (typeof define === 'function' && define.amd) {
|
3453
|
+
// AMD. Register as an anonymous module.
|
3454
|
+
define(factory)
|
3455
|
+
} else if (typeof exports === 'object') {
|
3456
|
+
/**
|
3457
|
+
* Node. Does not work with strict CommonJS, but
|
3458
|
+
* only CommonJS-like enviroments that support module.exports,
|
3459
|
+
* like Node.
|
3460
|
+
*/
|
3461
|
+
module.exports = factory()
|
3462
|
+
} else {
|
3463
|
+
// Browser globals (root is window)
|
3464
|
+
root.lunr = factory()
|
3465
|
+
}
|
3466
|
+
}(this, function () {
|
3457
3467
|
/**
|
3458
|
-
*
|
3459
|
-
*
|
3460
|
-
*
|
3468
|
+
* Just return a value to define the module export.
|
3469
|
+
* This example returns an object, but the module
|
3470
|
+
* can return a function as the exported value.
|
3461
3471
|
*/
|
3462
|
-
|
3463
|
-
|
3464
|
-
// Browser globals (root is window)
|
3465
|
-
root.lunr = factory()
|
3466
|
-
}
|
3467
|
-
}(this, function () {
|
3468
|
-
/**
|
3469
|
-
* Just return a value to define the module export.
|
3470
|
-
* This example returns an object, but the module
|
3471
|
-
* can return a function as the exported value.
|
3472
|
-
*/
|
3473
|
-
return lunr
|
3474
|
-
}))
|
3472
|
+
return lunr
|
3473
|
+
}))
|
3475
3474
|
})();
|