@startinblox/core 0.17.30 → 0.18.0-beta.1
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.
- package/dist/_snowpack/pkg/autolinker.js +3515 -3367
- package/dist/_snowpack/pkg/autolinker.js.map +1 -1
- package/dist/_snowpack/pkg/common/{_baseUnary-217dffb2.js → _baseUnary-c1edb653.js} +16 -40
- package/dist/_snowpack/pkg/common/{_baseUnary-217dffb2.js.map → _baseUnary-c1edb653.js.map} +1 -1
- package/dist/_snowpack/pkg/common/{_commonjsHelpers-8c19dec8.js → _commonjsHelpers-37fa8da4.js} +6 -2
- package/dist/_snowpack/pkg/common/_commonjsHelpers-37fa8da4.js.map +1 -0
- package/dist/_snowpack/pkg/common/{decode-a4c334cf.js → decode-26fbf385.js} +38 -69
- package/dist/_snowpack/pkg/common/decode-26fbf385.js.map +1 -0
- package/dist/_snowpack/pkg/common/lit-html-3647afce.js +1104 -0
- package/dist/_snowpack/pkg/common/lit-html-3647afce.js.map +1 -0
- package/dist/_snowpack/pkg/delta-markdown-for-quill.js +4767 -4246
- package/dist/_snowpack/pkg/delta-markdown-for-quill.js.map +1 -1
- package/dist/_snowpack/pkg/dialog-polyfill.js +107 -139
- package/dist/_snowpack/pkg/dialog-polyfill.js.map +1 -1
- package/dist/_snowpack/pkg/fusejs.js +411 -601
- package/dist/_snowpack/pkg/fusejs.js.map +1 -1
- package/dist/_snowpack/pkg/import-map.json +1 -0
- package/dist/_snowpack/pkg/jsonld-context-parser.js +718 -686
- package/dist/_snowpack/pkg/jsonld-context-parser.js.map +1 -1
- package/dist/_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.Default.css +59 -59
- package/dist/_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.Default.css.proxy.js +1 -1
- package/dist/_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.css +14 -14
- package/dist/_snowpack/pkg/leaflet.markercluster/dist/MarkerCluster.css.proxy.js +1 -1
- package/dist/_snowpack/pkg/lit-html/directives/if-defined.js +13 -14
- package/dist/_snowpack/pkg/lit-html/directives/if-defined.js.map +1 -1
- package/dist/_snowpack/pkg/lit-html/directives/unsafe-html.js +17 -15
- package/dist/_snowpack/pkg/lit-html/directives/unsafe-html.js.map +1 -1
- package/dist/_snowpack/pkg/lit-html/directives/until.js +45 -46
- package/dist/_snowpack/pkg/lit-html/directives/until.js.map +1 -1
- package/dist/_snowpack/pkg/lit-html.js +37 -35
- package/dist/_snowpack/pkg/lit-html.js.map +1 -1
- package/dist/_snowpack/pkg/markdown-it-link-attributes.js +68 -0
- package/dist/_snowpack/pkg/markdown-it-link-attributes.js.map +1 -0
- package/dist/_snowpack/pkg/markdown-it.js +1731 -2284
- package/dist/_snowpack/pkg/markdown-it.js.map +1 -1
- package/dist/_snowpack/pkg/quill-delta-to-markdown.js +236 -294
- package/dist/_snowpack/pkg/quill-delta-to-markdown.js.map +1 -1
- package/dist/_snowpack/pkg/quill.js +12077 -11017
- package/dist/_snowpack/pkg/quill.js.map +1 -1
- package/dist/_snowpack/pkg/slim-select.js +711 -1
- package/dist/_snowpack/pkg/slim-select.js.map +1 -1
- package/dist/_snowpack/pkg/tui-calendar/dist/tui-calendar.css +1 -16
- package/dist/_snowpack/pkg/tui-calendar/dist/tui-calendar.css.proxy.js +1 -1
- package/dist/_snowpack/pkg/tui-calendar.js +44297 -40075
- package/dist/_snowpack/pkg/tui-calendar.js.map +1 -1
- package/dist/components/solid-ac-checker.js +4 -17
- package/dist/components/solid-calendar.js +5 -26
- package/dist/components/solid-delete.js +9 -24
- package/dist/components/solid-display.js +15 -59
- package/dist/components/solid-form-search.js +27 -79
- package/dist/components/solid-form.js +48 -143
- package/dist/components/solid-lang.js +8 -19
- package/dist/components/solid-map.js +26 -64
- package/dist/components/solid-table.js +51 -133
- package/dist/components/solid-widget.js +2 -24
- package/dist/index.js +17 -11
- package/dist/libs/Component.js +4 -10
- package/dist/libs/ComponentFactory.js +6 -34
- package/dist/libs/Compositor.js +8 -15
- package/dist/libs/Sib.js +7 -21
- package/dist/libs/filter.js +184 -0
- package/dist/libs/helpers.js +19 -47
- package/dist/libs/interfaces.js +1 -1
- package/dist/libs/lit-helpers.js +7 -34
- package/dist/libs/polyfills.js +7 -10
- package/dist/libs/store/server-pagination.js +22 -0
- package/dist/libs/store/server-search.js +35 -0
- package/dist/libs/store/store.js +212 -227
- package/dist/mixins/attributeBinderMixin.js +17 -25
- package/dist/mixins/contextMixin.js +5 -7
- package/dist/mixins/counterMixin.js +2 -23
- package/dist/mixins/federationMixin.js +2 -14
- package/dist/mixins/filterMixin.js +60 -100
- package/dist/mixins/grouperMixin.js +11 -18
- package/dist/mixins/highlighterMixin.js +2 -8
- package/dist/mixins/interfaces.js +3 -5
- package/dist/mixins/listMixin.js +12 -43
- package/dist/mixins/nextMixin.js +1 -4
- package/dist/mixins/paginateMixin.js +17 -30
- package/dist/mixins/requiredMixin.js +1 -9
- package/dist/mixins/serverPaginationMixin.js +122 -0
- package/dist/mixins/sorterMixin.js +26 -44
- package/dist/mixins/storeMixin.js +28 -21
- package/dist/mixins/translationMixin.js +2 -12
- package/dist/mixins/validationMixin.js +28 -46
- package/dist/mixins/widgetMixin.js +58 -154
- package/dist/new-widgets/attributeMixins/actionMixin.js +1 -2
- package/dist/new-widgets/attributeMixins/blankMixin.js +1 -4
- package/dist/new-widgets/attributeMixins/booleanMixin.js +1 -4
- package/dist/new-widgets/attributeMixins/index.js +1 -2
- package/dist/new-widgets/attributeMixins/mailtoMixin.js +1 -4
- package/dist/new-widgets/attributeMixins/multipleMixin.js +1 -2
- package/dist/new-widgets/attributeMixins/numberMixin.js +1 -4
- package/dist/new-widgets/attributeMixins/placeholderMixin.js +1 -4
- package/dist/new-widgets/attributeMixins/telMixin.js +1 -4
- package/dist/new-widgets/baseWidgetMixin.js +5 -18
- package/dist/new-widgets/callbackMixins/autocompletionMixin.js +3 -11
- package/dist/new-widgets/callbackMixins/index.js +1 -2
- package/dist/new-widgets/callbackMixins/richtextMixin.js +1 -6
- package/dist/new-widgets/interfaces.js +1 -0
- package/dist/new-widgets/new-widget-factory.js +14 -19
- package/dist/new-widgets/templateAdditionMixins/addableMixin.js +6 -21
- package/dist/new-widgets/templateAdditionMixins/index.js +2 -3
- package/dist/new-widgets/templateAdditionMixins/labelLastMixin.js +5 -18
- package/dist/new-widgets/templateAdditionMixins/labelMixin.js +5 -18
- package/dist/new-widgets/templates/defaultTemplatesDirectory.js +21 -27
- package/dist/new-widgets/templates/displayTemplatesDirectory.js +35 -70
- package/dist/new-widgets/templates/formTemplatesDirectory.js +350 -315
- package/dist/new-widgets/templates/groupTemplatesDirectory.js +5 -15
- package/dist/new-widgets/templates/index.js +1 -2
- package/dist/new-widgets/templates/setTemplatesDirectory.js +4 -37
- package/dist/new-widgets/templatesDependencies/altMixin.js +1 -2
- package/dist/new-widgets/templatesDependencies/editableMixin.js +9 -26
- package/dist/new-widgets/templatesDependencies/filterRangeFormMixin.js +3 -7
- package/dist/new-widgets/templatesDependencies/formCheckboxMixin.js +1 -5
- package/dist/new-widgets/templatesDependencies/formCheckboxesMixin.js +1 -11
- package/dist/new-widgets/templatesDependencies/formDropdownMixin.js +3 -13
- package/dist/new-widgets/templatesDependencies/formFileMixin.js +1 -13
- package/dist/new-widgets/templatesDependencies/formLengthMixin.js +1 -2
- package/dist/new-widgets/templatesDependencies/formMinMaxMixin.js +1 -2
- package/dist/new-widgets/templatesDependencies/formMixin.js +4 -14
- package/dist/new-widgets/templatesDependencies/formNumberMixin.js +1 -5
- package/dist/new-widgets/templatesDependencies/formRadioMixin.js +1 -5
- package/dist/new-widgets/templatesDependencies/formStepMixin.js +1 -2
- package/dist/new-widgets/templatesDependencies/linkTextMixin.js +13 -0
- package/dist/new-widgets/templatesDependencies/multipleFormMixin.js +23 -18
- package/dist/new-widgets/templatesDependencies/multipleselectFormMixin.js +1 -10
- package/dist/new-widgets/templatesDependencies/patternMixin.js +1 -2
- package/dist/new-widgets/templatesDependencies/rangeMixin.js +5 -15
- package/dist/new-widgets/templatesDependencies/setMixin.js +1 -4
- package/dist/new-widgets/templatesDependencies/valueRichtextMixin.js +1 -4
- package/dist/new-widgets/valueTransformationMixins/autolinkMixin.js +1 -5
- package/dist/new-widgets/valueTransformationMixins/dateMixin.js +5 -11
- package/dist/new-widgets/valueTransformationMixins/dateTimeMixin.js +1 -5
- package/dist/new-widgets/valueTransformationMixins/index.js +1 -2
- package/dist/new-widgets/valueTransformationMixins/markdownMixin.js +10 -8
- package/dist/new-widgets/valueTransformationMixins/multilineMixin.js +1 -5
- package/dist/new-widgets/valueTransformationMixins/oembedMixin.js +1 -7
- package/dist/solid-template-element.js +24 -44
- package/dist/widgets/baseWidget.js +21 -85
- package/dist/widgets/widget-factory.js +4 -6
- package/package.json +9 -6
- package/dist/_snowpack/env.js +0 -3
- package/dist/_snowpack/pkg/autolinker.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/common/_baseUnary-217dffb2.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/common/_commonjsHelpers-8c19dec8.js.map +0 -1
- package/dist/_snowpack/pkg/common/_commonjsHelpers-8c19dec8.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/common/decode-a4c334cf.js.map +0 -1
- package/dist/_snowpack/pkg/common/decode-a4c334cf.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/common/lit-html-babd44cd.js +0 -1119
- package/dist/_snowpack/pkg/common/lit-html-babd44cd.js.map +0 -1
- package/dist/_snowpack/pkg/common/lit-html-babd44cd.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/delta-markdown-for-quill.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/dialog-polyfill.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/fusejs.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/jsonld-context-parser.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/lit-html/directives/if-defined.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/lit-html/directives/unsafe-html.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/lit-html/directives/until.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/lit-html.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/markdown-it.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/quill-delta-to-markdown.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/quill.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/slim-select.js.map.proxy.js +0 -1
- package/dist/_snowpack/pkg/tui-calendar.js.map.proxy.js +0 -1
- package/dist/components/solid-ac-checker.js.map +0 -1
- package/dist/components/solid-calendar.js.map +0 -1
- package/dist/components/solid-delete.js.map +0 -1
- package/dist/components/solid-display.js.map +0 -1
- package/dist/components/solid-form-search.js.map +0 -1
- package/dist/components/solid-form.js.map +0 -1
- package/dist/components/solid-lang.js.map +0 -1
- package/dist/components/solid-map.js.map +0 -1
- package/dist/components/solid-table.js.map +0 -1
- package/dist/components/solid-widget.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/libs/Component.js.map +0 -1
- package/dist/libs/ComponentFactory.js.map +0 -1
- package/dist/libs/Compositor.js.map +0 -1
- package/dist/libs/Sib.js.map +0 -1
- package/dist/libs/helpers.js.map +0 -1
- package/dist/libs/interfaces.js.map +0 -1
- package/dist/libs/lit-helpers.js.map +0 -1
- package/dist/libs/polyfills.js.map +0 -1
- package/dist/libs/store/store.js.map +0 -1
- package/dist/mixins/attributeBinderMixin.js.map +0 -1
- package/dist/mixins/contextMixin.js.map +0 -1
- package/dist/mixins/counterMixin.js.map +0 -1
- package/dist/mixins/federationMixin.js.map +0 -1
- package/dist/mixins/filterMixin.js.map +0 -1
- package/dist/mixins/grouperMixin.js.map +0 -1
- package/dist/mixins/highlighterMixin.js.map +0 -1
- package/dist/mixins/interfaces.js.map +0 -1
- package/dist/mixins/listMixin.js.map +0 -1
- package/dist/mixins/nextMixin.js.map +0 -1
- package/dist/mixins/paginateMixin.js.map +0 -1
- package/dist/mixins/requiredMixin.js.map +0 -1
- package/dist/mixins/sorterMixin.js.map +0 -1
- package/dist/mixins/storeMixin.js.map +0 -1
- package/dist/mixins/translationMixin.js.map +0 -1
- package/dist/mixins/validationMixin.js.map +0 -1
- package/dist/mixins/widgetMixin.js.map +0 -1
- package/dist/new-widgets/attributeMixins/actionMixin.js.map +0 -1
- package/dist/new-widgets/attributeMixins/blankMixin.js.map +0 -1
- package/dist/new-widgets/attributeMixins/booleanMixin.js.map +0 -1
- package/dist/new-widgets/attributeMixins/index.js.map +0 -1
- package/dist/new-widgets/attributeMixins/mailtoMixin.js.map +0 -1
- package/dist/new-widgets/attributeMixins/multipleMixin.js.map +0 -1
- package/dist/new-widgets/attributeMixins/numberMixin.js.map +0 -1
- package/dist/new-widgets/attributeMixins/placeholderMixin.js.map +0 -1
- package/dist/new-widgets/attributeMixins/telMixin.js.map +0 -1
- package/dist/new-widgets/baseWidgetMixin.js.map +0 -1
- package/dist/new-widgets/callbackMixins/autocompletionMixin.js.map +0 -1
- package/dist/new-widgets/callbackMixins/index.js.map +0 -1
- package/dist/new-widgets/callbackMixins/richtextMixin.js.map +0 -1
- package/dist/new-widgets/new-widget-factory.js.map +0 -1
- package/dist/new-widgets/templateAdditionMixins/addableMixin.js.map +0 -1
- package/dist/new-widgets/templateAdditionMixins/index.js.map +0 -1
- package/dist/new-widgets/templateAdditionMixins/labelLastMixin.js.map +0 -1
- package/dist/new-widgets/templateAdditionMixins/labelMixin.js.map +0 -1
- package/dist/new-widgets/templates/defaultTemplatesDirectory.js.map +0 -1
- package/dist/new-widgets/templates/displayTemplatesDirectory.js.map +0 -1
- package/dist/new-widgets/templates/formTemplatesDirectory.js.map +0 -1
- package/dist/new-widgets/templates/groupTemplatesDirectory.js.map +0 -1
- package/dist/new-widgets/templates/index.js.map +0 -1
- package/dist/new-widgets/templates/setTemplatesDirectory.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/altMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/editableMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/filterRangeFormMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/formCheckboxMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/formCheckboxesMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/formDropdownMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/formFileMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/formLengthMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/formMinMaxMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/formMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/formNumberMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/formRadioMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/formStepMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/multipleFormMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/multipleselectFormMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/patternMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/rangeMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/setMixin.js.map +0 -1
- package/dist/new-widgets/templatesDependencies/valueRichtextMixin.js.map +0 -1
- package/dist/new-widgets/valueTransformationMixins/autolinkMixin.js.map +0 -1
- package/dist/new-widgets/valueTransformationMixins/dateMixin.js.map +0 -1
- package/dist/new-widgets/valueTransformationMixins/dateTimeMixin.js.map +0 -1
- package/dist/new-widgets/valueTransformationMixins/index.js.map +0 -1
- package/dist/new-widgets/valueTransformationMixins/markdownMixin.js.map +0 -1
- package/dist/new-widgets/valueTransformationMixins/multilineMixin.js.map +0 -1
- package/dist/new-widgets/valueTransformationMixins/oembedMixin.js.map +0 -1
- package/dist/solid-template-element.js.map +0 -1
- package/dist/widgets/baseWidget.js.map +0 -1
- package/dist/widgets/widget-factory.js.map +0 -1
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Fuse.js v6.
|
|
2
|
+
* Fuse.js v6.6.2 - Lightweight fuzzy-search (http://fusejs.io)
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2022 Kiro Risk (http://kiro.me)
|
|
5
5
|
* All Rights Reserved. Apache Software License 2.0
|
|
6
6
|
*
|
|
7
7
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
function isArray(value) {
|
|
11
|
-
return !Array.isArray
|
|
12
|
-
? getTag(value) === '[object Array]'
|
|
13
|
-
: Array.isArray(value)
|
|
11
|
+
return !Array.isArray ? getTag(value) === '[object Array]' : Array.isArray(value);
|
|
14
12
|
}
|
|
15
13
|
|
|
16
14
|
// Adapted from: https://github.com/lodash/lodash/blob/master/.internal/baseToString.js
|
|
@@ -18,178 +16,140 @@ const INFINITY = 1 / 0;
|
|
|
18
16
|
function baseToString(value) {
|
|
19
17
|
// Exit early for strings to avoid a performance hit in some environments.
|
|
20
18
|
if (typeof value == 'string') {
|
|
21
|
-
return value
|
|
19
|
+
return value;
|
|
22
20
|
}
|
|
23
21
|
let result = value + '';
|
|
24
|
-
return result == '0' && 1 / value == -INFINITY ? '-0' : result
|
|
22
|
+
return result == '0' && 1 / value == -INFINITY ? '-0' : result;
|
|
25
23
|
}
|
|
26
|
-
|
|
27
24
|
function toString(value) {
|
|
28
|
-
return value == null ? '' : baseToString(value)
|
|
25
|
+
return value == null ? '' : baseToString(value);
|
|
29
26
|
}
|
|
30
|
-
|
|
31
27
|
function isString(value) {
|
|
32
|
-
return typeof value === 'string'
|
|
28
|
+
return typeof value === 'string';
|
|
33
29
|
}
|
|
34
|
-
|
|
35
30
|
function isNumber(value) {
|
|
36
|
-
return typeof value === 'number'
|
|
31
|
+
return typeof value === 'number';
|
|
37
32
|
}
|
|
38
33
|
|
|
39
34
|
// Adapted from: https://github.com/lodash/lodash/blob/master/isBoolean.js
|
|
40
35
|
function isBoolean(value) {
|
|
41
|
-
return (
|
|
42
|
-
value === true ||
|
|
43
|
-
value === false ||
|
|
44
|
-
(isObjectLike(value) && getTag(value) == '[object Boolean]')
|
|
45
|
-
)
|
|
36
|
+
return value === true || value === false || isObjectLike(value) && getTag(value) == '[object Boolean]';
|
|
46
37
|
}
|
|
47
|
-
|
|
48
38
|
function isObject(value) {
|
|
49
|
-
return typeof value === 'object'
|
|
39
|
+
return typeof value === 'object';
|
|
50
40
|
}
|
|
51
41
|
|
|
52
42
|
// Checks if `value` is object-like.
|
|
53
43
|
function isObjectLike(value) {
|
|
54
|
-
return isObject(value) && value !== null
|
|
44
|
+
return isObject(value) && value !== null;
|
|
55
45
|
}
|
|
56
|
-
|
|
57
46
|
function isDefined(value) {
|
|
58
|
-
return value !== undefined && value !== null
|
|
47
|
+
return value !== undefined && value !== null;
|
|
59
48
|
}
|
|
60
|
-
|
|
61
49
|
function isBlank(value) {
|
|
62
|
-
return !value.trim().length
|
|
50
|
+
return !value.trim().length;
|
|
63
51
|
}
|
|
64
52
|
|
|
65
53
|
// Gets the `toStringTag` of `value`.
|
|
66
54
|
// Adapted from: https://github.com/lodash/lodash/blob/master/.internal/getTag.js
|
|
67
55
|
function getTag(value) {
|
|
68
|
-
return value == null
|
|
69
|
-
? value === undefined
|
|
70
|
-
? '[object Undefined]'
|
|
71
|
-
: '[object Null]'
|
|
72
|
-
: Object.prototype.toString.call(value)
|
|
56
|
+
return value == null ? value === undefined ? '[object Undefined]' : '[object Null]' : Object.prototype.toString.call(value);
|
|
73
57
|
}
|
|
74
|
-
|
|
75
58
|
const EXTENDED_SEARCH_UNAVAILABLE = 'Extended search is not available';
|
|
76
|
-
|
|
77
59
|
const INCORRECT_INDEX_TYPE = "Incorrect 'index' type";
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const PATTERN_LENGTH_TOO_LARGE = (max) =>
|
|
83
|
-
`Pattern length exceeds max of ${max}.`;
|
|
84
|
-
|
|
85
|
-
const MISSING_KEY_PROPERTY = (name) => `Missing ${name} property in key`;
|
|
86
|
-
|
|
87
|
-
const INVALID_KEY_WEIGHT_VALUE = (key) =>
|
|
88
|
-
`Property 'weight' in key '${key}' must be a positive integer`;
|
|
89
|
-
|
|
60
|
+
const LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = key => `Invalid value for key ${key}`;
|
|
61
|
+
const PATTERN_LENGTH_TOO_LARGE = max => `Pattern length exceeds max of ${max}.`;
|
|
62
|
+
const MISSING_KEY_PROPERTY = name => `Missing ${name} property in key`;
|
|
63
|
+
const INVALID_KEY_WEIGHT_VALUE = key => `Property 'weight' in key '${key}' must be a positive integer`;
|
|
90
64
|
const hasOwn = Object.prototype.hasOwnProperty;
|
|
91
|
-
|
|
92
65
|
class KeyStore {
|
|
93
66
|
constructor(keys) {
|
|
94
67
|
this._keys = [];
|
|
95
68
|
this._keyMap = {};
|
|
96
|
-
|
|
97
69
|
let totalWeight = 0;
|
|
98
|
-
|
|
99
|
-
keys.forEach((key) => {
|
|
70
|
+
keys.forEach(key => {
|
|
100
71
|
let obj = createKey(key);
|
|
101
|
-
|
|
102
72
|
totalWeight += obj.weight;
|
|
103
|
-
|
|
104
73
|
this._keys.push(obj);
|
|
105
74
|
this._keyMap[obj.id] = obj;
|
|
106
|
-
|
|
107
75
|
totalWeight += obj.weight;
|
|
108
76
|
});
|
|
109
77
|
|
|
110
78
|
// Normalize weights so that their sum is equal to 1
|
|
111
|
-
this._keys.forEach(
|
|
79
|
+
this._keys.forEach(key => {
|
|
112
80
|
key.weight /= totalWeight;
|
|
113
81
|
});
|
|
114
82
|
}
|
|
115
83
|
get(keyId) {
|
|
116
|
-
return this._keyMap[keyId]
|
|
84
|
+
return this._keyMap[keyId];
|
|
117
85
|
}
|
|
118
86
|
keys() {
|
|
119
|
-
return this._keys
|
|
87
|
+
return this._keys;
|
|
120
88
|
}
|
|
121
89
|
toJSON() {
|
|
122
|
-
return JSON.stringify(this._keys)
|
|
90
|
+
return JSON.stringify(this._keys);
|
|
123
91
|
}
|
|
124
92
|
}
|
|
125
|
-
|
|
126
93
|
function createKey(key) {
|
|
127
94
|
let path = null;
|
|
128
95
|
let id = null;
|
|
129
96
|
let src = null;
|
|
130
97
|
let weight = 1;
|
|
131
|
-
|
|
98
|
+
let getFn = null;
|
|
132
99
|
if (isString(key) || isArray(key)) {
|
|
133
100
|
src = key;
|
|
134
101
|
path = createKeyPath(key);
|
|
135
102
|
id = createKeyId(key);
|
|
136
103
|
} else {
|
|
137
104
|
if (!hasOwn.call(key, 'name')) {
|
|
138
|
-
throw new Error(MISSING_KEY_PROPERTY('name'))
|
|
105
|
+
throw new Error(MISSING_KEY_PROPERTY('name'));
|
|
139
106
|
}
|
|
140
|
-
|
|
141
107
|
const name = key.name;
|
|
142
108
|
src = name;
|
|
143
|
-
|
|
144
109
|
if (hasOwn.call(key, 'weight')) {
|
|
145
110
|
weight = key.weight;
|
|
146
|
-
|
|
147
111
|
if (weight <= 0) {
|
|
148
|
-
throw new Error(INVALID_KEY_WEIGHT_VALUE(name))
|
|
112
|
+
throw new Error(INVALID_KEY_WEIGHT_VALUE(name));
|
|
149
113
|
}
|
|
150
114
|
}
|
|
151
|
-
|
|
152
115
|
path = createKeyPath(name);
|
|
153
116
|
id = createKeyId(name);
|
|
117
|
+
getFn = key.getFn;
|
|
154
118
|
}
|
|
155
|
-
|
|
156
|
-
|
|
119
|
+
return {
|
|
120
|
+
path,
|
|
121
|
+
id,
|
|
122
|
+
weight,
|
|
123
|
+
src,
|
|
124
|
+
getFn
|
|
125
|
+
};
|
|
157
126
|
}
|
|
158
|
-
|
|
159
127
|
function createKeyPath(key) {
|
|
160
|
-
return isArray(key) ? key : key.split('.')
|
|
128
|
+
return isArray(key) ? key : key.split('.');
|
|
161
129
|
}
|
|
162
|
-
|
|
163
130
|
function createKeyId(key) {
|
|
164
|
-
return isArray(key) ? key.join('.') : key
|
|
131
|
+
return isArray(key) ? key.join('.') : key;
|
|
165
132
|
}
|
|
166
|
-
|
|
167
133
|
function get(obj, path) {
|
|
168
134
|
let list = [];
|
|
169
135
|
let arr = false;
|
|
170
|
-
|
|
171
136
|
const deepGet = (obj, path, index) => {
|
|
172
137
|
if (!isDefined(obj)) {
|
|
173
|
-
return
|
|
138
|
+
return;
|
|
174
139
|
}
|
|
175
140
|
if (!path[index]) {
|
|
176
141
|
// If there's no path left, we've arrived at the object we care about.
|
|
177
142
|
list.push(obj);
|
|
178
143
|
} else {
|
|
179
144
|
let key = path[index];
|
|
180
|
-
|
|
181
145
|
const value = obj[key];
|
|
182
|
-
|
|
183
146
|
if (!isDefined(value)) {
|
|
184
|
-
return
|
|
147
|
+
return;
|
|
185
148
|
}
|
|
186
149
|
|
|
187
150
|
// If we're at the last value in the path, and if it's a string/number/bool,
|
|
188
151
|
// add it to the list
|
|
189
|
-
if (
|
|
190
|
-
index === path.length - 1 &&
|
|
191
|
-
(isString(value) || isNumber(value) || isBoolean(value))
|
|
192
|
-
) {
|
|
152
|
+
if (index === path.length - 1 && (isString(value) || isNumber(value) || isBoolean(value))) {
|
|
193
153
|
list.push(toString(value));
|
|
194
154
|
} else if (isArray(value)) {
|
|
195
155
|
arr = true;
|
|
@@ -206,10 +166,8 @@ function get(obj, path) {
|
|
|
206
166
|
|
|
207
167
|
// Backwards compatibility (since path used to be a string)
|
|
208
168
|
deepGet(obj, isString(path) ? path.split('.') : path, 0);
|
|
209
|
-
|
|
210
|
-
return arr ? list : list[0]
|
|
169
|
+
return arr ? list : list[0];
|
|
211
170
|
}
|
|
212
|
-
|
|
213
171
|
const MatchOptions = {
|
|
214
172
|
// Whether the matches should be included in the result set. When `true`, each record in the result
|
|
215
173
|
// set will include the indices of the matched characters.
|
|
@@ -221,7 +179,6 @@ const MatchOptions = {
|
|
|
221
179
|
// Minimum number of characters that must be matched before a result is considered a match
|
|
222
180
|
minMatchCharLength: 1
|
|
223
181
|
};
|
|
224
|
-
|
|
225
182
|
const BasicOptions = {
|
|
226
183
|
// When `true`, the algorithm continues searching to the end of the input even if a perfect
|
|
227
184
|
// match is found before the end of the same input.
|
|
@@ -233,10 +190,8 @@ const BasicOptions = {
|
|
|
233
190
|
// Whether to sort the result list, by score
|
|
234
191
|
shouldSort: true,
|
|
235
192
|
// Default sort function: sort by ascending score, ascending index
|
|
236
|
-
sortFn: (a, b) =>
|
|
237
|
-
a.score === b.score ? (a.idx < b.idx ? -1 : 1) : a.score < b.score ? -1 : 1
|
|
193
|
+
sortFn: (a, b) => a.score === b.score ? a.idx < b.idx ? -1 : 1 : a.score < b.score ? -1 : 1
|
|
238
194
|
};
|
|
239
|
-
|
|
240
195
|
const FuzzyOptions = {
|
|
241
196
|
// Approximately where in the text is the pattern expected to be found?
|
|
242
197
|
location: 0,
|
|
@@ -250,7 +205,6 @@ const FuzzyOptions = {
|
|
|
250
205
|
// to be within 800 characters of the fuzzy location to be found using a 0.8 threshold.
|
|
251
206
|
distance: 100
|
|
252
207
|
};
|
|
253
|
-
|
|
254
208
|
const AdvancedOptions = {
|
|
255
209
|
// When `true`, it enables the use of unix-like search commands
|
|
256
210
|
useExtendedSearch: false,
|
|
@@ -264,53 +218,51 @@ const AdvancedOptions = {
|
|
|
264
218
|
// When `true`, the calculation for the relevance score (used for sorting) will
|
|
265
219
|
// ignore the field-length norm.
|
|
266
220
|
// More info: https://fusejs.io/concepts/scoring-theory.html#field-length-norm
|
|
267
|
-
ignoreFieldNorm: false
|
|
221
|
+
ignoreFieldNorm: false,
|
|
222
|
+
// The weight to determine how much field length norm effects scoring.
|
|
223
|
+
fieldNormWeight: 1
|
|
268
224
|
};
|
|
269
|
-
|
|
270
225
|
var Config = {
|
|
271
226
|
...BasicOptions,
|
|
272
227
|
...MatchOptions,
|
|
273
228
|
...FuzzyOptions,
|
|
274
229
|
...AdvancedOptions
|
|
275
230
|
};
|
|
276
|
-
|
|
277
231
|
const SPACE = /[^ ]+/g;
|
|
278
232
|
|
|
279
233
|
// Field-length norm: the shorter the field, the higher the weight.
|
|
280
234
|
// Set to 3 decimals to reduce index size.
|
|
281
|
-
function norm(mantissa = 3) {
|
|
235
|
+
function norm(weight = 1, mantissa = 3) {
|
|
282
236
|
const cache = new Map();
|
|
283
237
|
const m = Math.pow(10, mantissa);
|
|
284
|
-
|
|
285
238
|
return {
|
|
286
239
|
get(value) {
|
|
287
240
|
const numTokens = value.match(SPACE).length;
|
|
288
|
-
|
|
289
241
|
if (cache.has(numTokens)) {
|
|
290
|
-
return cache.get(numTokens)
|
|
242
|
+
return cache.get(numTokens);
|
|
291
243
|
}
|
|
292
244
|
|
|
293
|
-
|
|
245
|
+
// Default function is 1/sqrt(x), weight makes that variable
|
|
246
|
+
const norm = 1 / Math.pow(numTokens, 0.5 * weight);
|
|
294
247
|
|
|
295
248
|
// In place of `toFixed(mantissa)`, for faster computation
|
|
296
249
|
const n = parseFloat(Math.round(norm * m) / m);
|
|
297
|
-
|
|
298
250
|
cache.set(numTokens, n);
|
|
299
|
-
|
|
300
|
-
return n
|
|
251
|
+
return n;
|
|
301
252
|
},
|
|
302
253
|
clear() {
|
|
303
254
|
cache.clear();
|
|
304
255
|
}
|
|
305
|
-
}
|
|
256
|
+
};
|
|
306
257
|
}
|
|
307
|
-
|
|
308
258
|
class FuseIndex {
|
|
309
|
-
constructor({
|
|
310
|
-
|
|
259
|
+
constructor({
|
|
260
|
+
getFn = Config.getFn,
|
|
261
|
+
fieldNormWeight = Config.fieldNormWeight
|
|
262
|
+
} = {}) {
|
|
263
|
+
this.norm = norm(fieldNormWeight, 3);
|
|
311
264
|
this.getFn = getFn;
|
|
312
265
|
this.isCreated = false;
|
|
313
|
-
|
|
314
266
|
this.setIndexRecords();
|
|
315
267
|
}
|
|
316
268
|
setSources(docs = []) {
|
|
@@ -328,9 +280,8 @@ class FuseIndex {
|
|
|
328
280
|
}
|
|
329
281
|
create() {
|
|
330
282
|
if (this.isCreated || !this.docs.length) {
|
|
331
|
-
return
|
|
283
|
+
return;
|
|
332
284
|
}
|
|
333
|
-
|
|
334
285
|
this.isCreated = true;
|
|
335
286
|
|
|
336
287
|
// List is Array<String>
|
|
@@ -344,13 +295,11 @@ class FuseIndex {
|
|
|
344
295
|
this._addObject(doc, docIndex);
|
|
345
296
|
});
|
|
346
297
|
}
|
|
347
|
-
|
|
348
298
|
this.norm.clear();
|
|
349
299
|
}
|
|
350
300
|
// Adds a doc to the end of the index
|
|
351
301
|
add(doc) {
|
|
352
302
|
const idx = this.size();
|
|
353
|
-
|
|
354
303
|
if (isString(doc)) {
|
|
355
304
|
this._addString(doc, idx);
|
|
356
305
|
} else {
|
|
@@ -367,54 +316,54 @@ class FuseIndex {
|
|
|
367
316
|
}
|
|
368
317
|
}
|
|
369
318
|
getValueForItemAtKeyId(item, keyId) {
|
|
370
|
-
return item[this._keysMap[keyId]]
|
|
319
|
+
return item[this._keysMap[keyId]];
|
|
371
320
|
}
|
|
372
321
|
size() {
|
|
373
|
-
return this.records.length
|
|
322
|
+
return this.records.length;
|
|
374
323
|
}
|
|
375
324
|
_addString(doc, docIndex) {
|
|
376
325
|
if (!isDefined(doc) || isBlank(doc)) {
|
|
377
|
-
return
|
|
326
|
+
return;
|
|
378
327
|
}
|
|
379
|
-
|
|
380
328
|
let record = {
|
|
381
329
|
v: doc,
|
|
382
330
|
i: docIndex,
|
|
383
331
|
n: this.norm.get(doc)
|
|
384
332
|
};
|
|
385
|
-
|
|
386
333
|
this.records.push(record);
|
|
387
334
|
}
|
|
388
335
|
_addObject(doc, docIndex) {
|
|
389
|
-
let record = {
|
|
336
|
+
let record = {
|
|
337
|
+
i: docIndex,
|
|
338
|
+
$: {}
|
|
339
|
+
};
|
|
390
340
|
|
|
391
341
|
// Iterate over every key (i.e, path), and fetch the value at that key
|
|
392
342
|
this.keys.forEach((key, keyIndex) => {
|
|
393
|
-
|
|
394
|
-
let value = this.getFn(doc, key.path);
|
|
395
|
-
|
|
343
|
+
let value = key.getFn ? key.getFn(doc) : this.getFn(doc, key.path);
|
|
396
344
|
if (!isDefined(value)) {
|
|
397
|
-
return
|
|
345
|
+
return;
|
|
398
346
|
}
|
|
399
|
-
|
|
400
347
|
if (isArray(value)) {
|
|
401
348
|
let subRecords = [];
|
|
402
|
-
const stack = [{
|
|
403
|
-
|
|
349
|
+
const stack = [{
|
|
350
|
+
nestedArrIndex: -1,
|
|
351
|
+
value
|
|
352
|
+
}];
|
|
404
353
|
while (stack.length) {
|
|
405
|
-
const {
|
|
406
|
-
|
|
354
|
+
const {
|
|
355
|
+
nestedArrIndex,
|
|
356
|
+
value
|
|
357
|
+
} = stack.pop();
|
|
407
358
|
if (!isDefined(value)) {
|
|
408
|
-
continue
|
|
359
|
+
continue;
|
|
409
360
|
}
|
|
410
|
-
|
|
411
361
|
if (isString(value) && !isBlank(value)) {
|
|
412
362
|
let subRecord = {
|
|
413
363
|
v: value,
|
|
414
364
|
i: nestedArrIndex,
|
|
415
365
|
n: this.norm.get(value)
|
|
416
366
|
};
|
|
417
|
-
|
|
418
367
|
subRecords.push(subRecord);
|
|
419
368
|
} else if (isArray(value)) {
|
|
420
369
|
value.forEach((item, k) => {
|
|
@@ -423,80 +372,78 @@ class FuseIndex {
|
|
|
423
372
|
value: item
|
|
424
373
|
});
|
|
425
374
|
});
|
|
426
|
-
}
|
|
375
|
+
} else ;
|
|
427
376
|
}
|
|
428
377
|
record.$[keyIndex] = subRecords;
|
|
429
|
-
} else if (!isBlank(value)) {
|
|
378
|
+
} else if (isString(value) && !isBlank(value)) {
|
|
430
379
|
let subRecord = {
|
|
431
380
|
v: value,
|
|
432
381
|
n: this.norm.get(value)
|
|
433
382
|
};
|
|
434
|
-
|
|
435
383
|
record.$[keyIndex] = subRecord;
|
|
436
384
|
}
|
|
437
385
|
});
|
|
438
|
-
|
|
439
386
|
this.records.push(record);
|
|
440
387
|
}
|
|
441
388
|
toJSON() {
|
|
442
389
|
return {
|
|
443
390
|
keys: this.keys,
|
|
444
391
|
records: this.records
|
|
445
|
-
}
|
|
392
|
+
};
|
|
446
393
|
}
|
|
447
394
|
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
395
|
+
function createIndex(keys, docs, {
|
|
396
|
+
getFn = Config.getFn,
|
|
397
|
+
fieldNormWeight = Config.fieldNormWeight
|
|
398
|
+
} = {}) {
|
|
399
|
+
const myIndex = new FuseIndex({
|
|
400
|
+
getFn,
|
|
401
|
+
fieldNormWeight
|
|
402
|
+
});
|
|
451
403
|
myIndex.setKeys(keys.map(createKey));
|
|
452
404
|
myIndex.setSources(docs);
|
|
453
405
|
myIndex.create();
|
|
454
|
-
return myIndex
|
|
406
|
+
return myIndex;
|
|
455
407
|
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
408
|
+
function parseIndex(data, {
|
|
409
|
+
getFn = Config.getFn,
|
|
410
|
+
fieldNormWeight = Config.fieldNormWeight
|
|
411
|
+
} = {}) {
|
|
412
|
+
const {
|
|
413
|
+
keys,
|
|
414
|
+
records
|
|
415
|
+
} = data;
|
|
416
|
+
const myIndex = new FuseIndex({
|
|
417
|
+
getFn,
|
|
418
|
+
fieldNormWeight
|
|
419
|
+
});
|
|
460
420
|
myIndex.setKeys(keys);
|
|
461
421
|
myIndex.setIndexRecords(records);
|
|
462
|
-
return myIndex
|
|
422
|
+
return myIndex;
|
|
463
423
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
distance = Config.distance,
|
|
472
|
-
ignoreLocation = Config.ignoreLocation
|
|
473
|
-
} = {}
|
|
474
|
-
) {
|
|
424
|
+
function computeScore$1(pattern, {
|
|
425
|
+
errors = 0,
|
|
426
|
+
currentLocation = 0,
|
|
427
|
+
expectedLocation = 0,
|
|
428
|
+
distance = Config.distance,
|
|
429
|
+
ignoreLocation = Config.ignoreLocation
|
|
430
|
+
} = {}) {
|
|
475
431
|
const accuracy = errors / pattern.length;
|
|
476
|
-
|
|
477
432
|
if (ignoreLocation) {
|
|
478
|
-
return accuracy
|
|
433
|
+
return accuracy;
|
|
479
434
|
}
|
|
480
|
-
|
|
481
435
|
const proximity = Math.abs(expectedLocation - currentLocation);
|
|
482
|
-
|
|
483
436
|
if (!distance) {
|
|
484
437
|
// Dodge divide by zero error.
|
|
485
|
-
return proximity ? 1.0 : accuracy
|
|
438
|
+
return proximity ? 1.0 : accuracy;
|
|
486
439
|
}
|
|
487
|
-
|
|
488
|
-
return accuracy + proximity / distance
|
|
440
|
+
return accuracy + proximity / distance;
|
|
489
441
|
}
|
|
490
|
-
|
|
491
|
-
function convertMaskToIndices(
|
|
492
|
-
matchmask = [],
|
|
493
|
-
minMatchCharLength = Config.minMatchCharLength
|
|
494
|
-
) {
|
|
442
|
+
function convertMaskToIndices(matchmask = [], minMatchCharLength = Config.minMatchCharLength) {
|
|
495
443
|
let indices = [];
|
|
496
444
|
let start = -1;
|
|
497
445
|
let end = -1;
|
|
498
446
|
let i = 0;
|
|
499
|
-
|
|
500
447
|
for (let len = matchmask.length; i < len; i += 1) {
|
|
501
448
|
let match = matchmask[i];
|
|
502
449
|
if (match && start === -1) {
|
|
@@ -514,31 +461,23 @@ function convertMaskToIndices(
|
|
|
514
461
|
if (matchmask[i - 1] && i - start >= minMatchCharLength) {
|
|
515
462
|
indices.push([start, i - 1]);
|
|
516
463
|
}
|
|
517
|
-
|
|
518
|
-
return indices
|
|
464
|
+
return indices;
|
|
519
465
|
}
|
|
520
466
|
|
|
521
467
|
// Machine word size
|
|
522
468
|
const MAX_BITS = 32;
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
findAllMatches = Config.findAllMatches,
|
|
533
|
-
minMatchCharLength = Config.minMatchCharLength,
|
|
534
|
-
includeMatches = Config.includeMatches,
|
|
535
|
-
ignoreLocation = Config.ignoreLocation
|
|
536
|
-
} = {}
|
|
537
|
-
) {
|
|
469
|
+
function search(text, pattern, patternAlphabet, {
|
|
470
|
+
location = Config.location,
|
|
471
|
+
distance = Config.distance,
|
|
472
|
+
threshold = Config.threshold,
|
|
473
|
+
findAllMatches = Config.findAllMatches,
|
|
474
|
+
minMatchCharLength = Config.minMatchCharLength,
|
|
475
|
+
includeMatches = Config.includeMatches,
|
|
476
|
+
ignoreLocation = Config.ignoreLocation
|
|
477
|
+
} = {}) {
|
|
538
478
|
if (pattern.length > MAX_BITS) {
|
|
539
|
-
throw new Error(PATTERN_LENGTH_TOO_LARGE(MAX_BITS))
|
|
479
|
+
throw new Error(PATTERN_LENGTH_TOO_LARGE(MAX_BITS));
|
|
540
480
|
}
|
|
541
|
-
|
|
542
481
|
const patternLen = pattern.length;
|
|
543
482
|
// Set starting location at beginning text and initialize the alphabet.
|
|
544
483
|
const textLen = text.length;
|
|
@@ -554,21 +493,18 @@ function search(
|
|
|
554
493
|
const computeMatches = minMatchCharLength > 1 || includeMatches;
|
|
555
494
|
// A mask of the matches, used for building the indices
|
|
556
495
|
const matchMask = computeMatches ? Array(textLen) : [];
|
|
557
|
-
|
|
558
496
|
let index;
|
|
559
497
|
|
|
560
498
|
// Get all exact matches, here for speed up
|
|
561
499
|
while ((index = text.indexOf(pattern, bestLocation)) > -1) {
|
|
562
|
-
let score = computeScore(pattern, {
|
|
500
|
+
let score = computeScore$1(pattern, {
|
|
563
501
|
currentLocation: index,
|
|
564
502
|
expectedLocation,
|
|
565
503
|
distance,
|
|
566
504
|
ignoreLocation
|
|
567
505
|
});
|
|
568
|
-
|
|
569
506
|
currentThreshold = Math.min(score, currentThreshold);
|
|
570
507
|
bestLocation = index + patternLen;
|
|
571
|
-
|
|
572
508
|
if (computeMatches) {
|
|
573
509
|
let i = 0;
|
|
574
510
|
while (i < patternLen) {
|
|
@@ -580,71 +516,57 @@ function search(
|
|
|
580
516
|
|
|
581
517
|
// Reset the best location
|
|
582
518
|
bestLocation = -1;
|
|
583
|
-
|
|
584
519
|
let lastBitArr = [];
|
|
585
520
|
let finalScore = 1;
|
|
586
521
|
let binMax = patternLen + textLen;
|
|
587
|
-
|
|
588
|
-
const mask = 1 << (patternLen - 1);
|
|
589
|
-
|
|
522
|
+
const mask = 1 << patternLen - 1;
|
|
590
523
|
for (let i = 0; i < patternLen; i += 1) {
|
|
591
524
|
// Scan for the best match; each iteration allows for one more error.
|
|
592
525
|
// Run a binary search to determine how far from the match location we can stray
|
|
593
526
|
// at this error level.
|
|
594
527
|
let binMin = 0;
|
|
595
528
|
let binMid = binMax;
|
|
596
|
-
|
|
597
529
|
while (binMin < binMid) {
|
|
598
|
-
const score = computeScore(pattern, {
|
|
530
|
+
const score = computeScore$1(pattern, {
|
|
599
531
|
errors: i,
|
|
600
532
|
currentLocation: expectedLocation + binMid,
|
|
601
533
|
expectedLocation,
|
|
602
534
|
distance,
|
|
603
535
|
ignoreLocation
|
|
604
536
|
});
|
|
605
|
-
|
|
606
537
|
if (score <= currentThreshold) {
|
|
607
538
|
binMin = binMid;
|
|
608
539
|
} else {
|
|
609
540
|
binMax = binMid;
|
|
610
541
|
}
|
|
611
|
-
|
|
612
542
|
binMid = Math.floor((binMax - binMin) / 2 + binMin);
|
|
613
543
|
}
|
|
614
544
|
|
|
615
545
|
// Use the result from this iteration as the maximum for the next.
|
|
616
546
|
binMax = binMid;
|
|
617
|
-
|
|
618
547
|
let start = Math.max(1, expectedLocation - binMid + 1);
|
|
619
|
-
let finish = findAllMatches
|
|
620
|
-
? textLen
|
|
621
|
-
: Math.min(expectedLocation + binMid, textLen) + patternLen;
|
|
548
|
+
let finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen;
|
|
622
549
|
|
|
623
550
|
// Initialize the bit array
|
|
624
551
|
let bitArr = Array(finish + 2);
|
|
625
|
-
|
|
626
552
|
bitArr[finish + 1] = (1 << i) - 1;
|
|
627
|
-
|
|
628
553
|
for (let j = finish; j >= start; j -= 1) {
|
|
629
554
|
let currentLocation = j - 1;
|
|
630
555
|
let charMatch = patternAlphabet[text.charAt(currentLocation)];
|
|
631
|
-
|
|
632
556
|
if (computeMatches) {
|
|
633
557
|
// Speed up: quick bool to int conversion (i.e, `charMatch ? 1 : 0`)
|
|
634
558
|
matchMask[currentLocation] = +!!charMatch;
|
|
635
559
|
}
|
|
636
560
|
|
|
637
561
|
// First pass: exact match
|
|
638
|
-
bitArr[j] = (
|
|
562
|
+
bitArr[j] = (bitArr[j + 1] << 1 | 1) & charMatch;
|
|
639
563
|
|
|
640
564
|
// Subsequent passes: fuzzy match
|
|
641
565
|
if (i) {
|
|
642
|
-
bitArr[j] |=
|
|
643
|
-
((lastBitArr[j + 1] | lastBitArr[j]) << 1) | 1 | lastBitArr[j + 1];
|
|
566
|
+
bitArr[j] |= (lastBitArr[j + 1] | lastBitArr[j]) << 1 | 1 | lastBitArr[j + 1];
|
|
644
567
|
}
|
|
645
|
-
|
|
646
568
|
if (bitArr[j] & mask) {
|
|
647
|
-
finalScore = computeScore(pattern, {
|
|
569
|
+
finalScore = computeScore$1(pattern, {
|
|
648
570
|
errors: i,
|
|
649
571
|
currentLocation,
|
|
650
572
|
expectedLocation,
|
|
@@ -661,7 +583,7 @@ function search(
|
|
|
661
583
|
|
|
662
584
|
// Already passed `loc`, downhill from here on in.
|
|
663
585
|
if (bestLocation <= expectedLocation) {
|
|
664
|
-
break
|
|
586
|
+
break;
|
|
665
587
|
}
|
|
666
588
|
|
|
667
589
|
// When passing `bestLocation`, don't exceed our current distance from `expectedLocation`.
|
|
@@ -671,27 +593,23 @@ function search(
|
|
|
671
593
|
}
|
|
672
594
|
|
|
673
595
|
// No hope for a (better) match at greater error levels.
|
|
674
|
-
const score = computeScore(pattern, {
|
|
596
|
+
const score = computeScore$1(pattern, {
|
|
675
597
|
errors: i + 1,
|
|
676
598
|
currentLocation: expectedLocation,
|
|
677
599
|
expectedLocation,
|
|
678
600
|
distance,
|
|
679
601
|
ignoreLocation
|
|
680
602
|
});
|
|
681
|
-
|
|
682
603
|
if (score > currentThreshold) {
|
|
683
|
-
break
|
|
604
|
+
break;
|
|
684
605
|
}
|
|
685
|
-
|
|
686
606
|
lastBitArr = bitArr;
|
|
687
607
|
}
|
|
688
|
-
|
|
689
608
|
const result = {
|
|
690
609
|
isMatch: bestLocation >= 0,
|
|
691
610
|
// Count exact matches (those with a score of 0) to be "almost" exact
|
|
692
611
|
score: Math.max(0.001, finalScore)
|
|
693
612
|
};
|
|
694
|
-
|
|
695
613
|
if (computeMatches) {
|
|
696
614
|
const indices = convertMaskToIndices(matchMask, minMatchCharLength);
|
|
697
615
|
if (!indices.length) {
|
|
@@ -700,35 +618,27 @@ function search(
|
|
|
700
618
|
result.indices = indices;
|
|
701
619
|
}
|
|
702
620
|
}
|
|
703
|
-
|
|
704
|
-
return result
|
|
621
|
+
return result;
|
|
705
622
|
}
|
|
706
|
-
|
|
707
623
|
function createPatternAlphabet(pattern) {
|
|
708
624
|
let mask = {};
|
|
709
|
-
|
|
710
625
|
for (let i = 0, len = pattern.length; i < len; i += 1) {
|
|
711
626
|
const char = pattern.charAt(i);
|
|
712
|
-
mask[char] = (mask[char] || 0) |
|
|
627
|
+
mask[char] = (mask[char] || 0) | 1 << len - i - 1;
|
|
713
628
|
}
|
|
714
|
-
|
|
715
|
-
return mask
|
|
629
|
+
return mask;
|
|
716
630
|
}
|
|
717
|
-
|
|
718
631
|
class BitapSearch {
|
|
719
|
-
constructor(
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
ignoreLocation = Config.ignoreLocation
|
|
730
|
-
} = {}
|
|
731
|
-
) {
|
|
632
|
+
constructor(pattern, {
|
|
633
|
+
location = Config.location,
|
|
634
|
+
threshold = Config.threshold,
|
|
635
|
+
distance = Config.distance,
|
|
636
|
+
includeMatches = Config.includeMatches,
|
|
637
|
+
findAllMatches = Config.findAllMatches,
|
|
638
|
+
minMatchCharLength = Config.minMatchCharLength,
|
|
639
|
+
isCaseSensitive = Config.isCaseSensitive,
|
|
640
|
+
ignoreLocation = Config.ignoreLocation
|
|
641
|
+
} = {}) {
|
|
732
642
|
this.options = {
|
|
733
643
|
location,
|
|
734
644
|
threshold,
|
|
@@ -739,15 +649,11 @@ class BitapSearch {
|
|
|
739
649
|
isCaseSensitive,
|
|
740
650
|
ignoreLocation
|
|
741
651
|
};
|
|
742
|
-
|
|
743
652
|
this.pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
|
|
744
|
-
|
|
745
653
|
this.chunks = [];
|
|
746
|
-
|
|
747
654
|
if (!this.pattern.length) {
|
|
748
|
-
return
|
|
655
|
+
return;
|
|
749
656
|
}
|
|
750
|
-
|
|
751
657
|
const addChunk = (pattern, startIndex) => {
|
|
752
658
|
this.chunks.push({
|
|
753
659
|
pattern,
|
|
@@ -755,19 +661,15 @@ class BitapSearch {
|
|
|
755
661
|
startIndex
|
|
756
662
|
});
|
|
757
663
|
};
|
|
758
|
-
|
|
759
664
|
const len = this.pattern.length;
|
|
760
|
-
|
|
761
665
|
if (len > MAX_BITS) {
|
|
762
666
|
let i = 0;
|
|
763
667
|
const remainder = len % MAX_BITS;
|
|
764
668
|
const end = len - remainder;
|
|
765
|
-
|
|
766
669
|
while (i < end) {
|
|
767
670
|
addChunk(this.pattern.substr(i, MAX_BITS), i);
|
|
768
671
|
i += MAX_BITS;
|
|
769
672
|
}
|
|
770
|
-
|
|
771
673
|
if (remainder) {
|
|
772
674
|
const startIndex = len - MAX_BITS;
|
|
773
675
|
addChunk(this.pattern.substr(startIndex), startIndex);
|
|
@@ -776,10 +678,11 @@ class BitapSearch {
|
|
|
776
678
|
addChunk(this.pattern, 0);
|
|
777
679
|
}
|
|
778
680
|
}
|
|
779
|
-
|
|
780
681
|
searchIn(text) {
|
|
781
|
-
const {
|
|
782
|
-
|
|
682
|
+
const {
|
|
683
|
+
isCaseSensitive,
|
|
684
|
+
includeMatches
|
|
685
|
+
} = this.options;
|
|
783
686
|
if (!isCaseSensitive) {
|
|
784
687
|
text = text.toLowerCase();
|
|
785
688
|
}
|
|
@@ -790,12 +693,10 @@ class BitapSearch {
|
|
|
790
693
|
isMatch: true,
|
|
791
694
|
score: 0
|
|
792
695
|
};
|
|
793
|
-
|
|
794
696
|
if (includeMatches) {
|
|
795
697
|
result.indices = [[0, text.length - 1]];
|
|
796
698
|
}
|
|
797
|
-
|
|
798
|
-
return result
|
|
699
|
+
return result;
|
|
799
700
|
}
|
|
800
701
|
|
|
801
702
|
// Otherwise, use Bitap algorithm
|
|
@@ -807,13 +708,19 @@ class BitapSearch {
|
|
|
807
708
|
minMatchCharLength,
|
|
808
709
|
ignoreLocation
|
|
809
710
|
} = this.options;
|
|
810
|
-
|
|
811
711
|
let allIndices = [];
|
|
812
712
|
let totalScore = 0;
|
|
813
713
|
let hasMatches = false;
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
714
|
+
this.chunks.forEach(({
|
|
715
|
+
pattern,
|
|
716
|
+
alphabet,
|
|
717
|
+
startIndex
|
|
718
|
+
}) => {
|
|
719
|
+
const {
|
|
720
|
+
isMatch,
|
|
721
|
+
score,
|
|
722
|
+
indices
|
|
723
|
+
} = search(text, pattern, alphabet, {
|
|
817
724
|
location: location + startIndex,
|
|
818
725
|
distance,
|
|
819
726
|
threshold,
|
|
@@ -822,47 +729,39 @@ class BitapSearch {
|
|
|
822
729
|
includeMatches,
|
|
823
730
|
ignoreLocation
|
|
824
731
|
});
|
|
825
|
-
|
|
826
732
|
if (isMatch) {
|
|
827
733
|
hasMatches = true;
|
|
828
734
|
}
|
|
829
|
-
|
|
830
735
|
totalScore += score;
|
|
831
|
-
|
|
832
736
|
if (isMatch && indices) {
|
|
833
737
|
allIndices = [...allIndices, ...indices];
|
|
834
738
|
}
|
|
835
739
|
});
|
|
836
|
-
|
|
837
740
|
let result = {
|
|
838
741
|
isMatch: hasMatches,
|
|
839
742
|
score: hasMatches ? totalScore / this.chunks.length : 1
|
|
840
743
|
};
|
|
841
|
-
|
|
842
744
|
if (hasMatches && includeMatches) {
|
|
843
745
|
result.indices = allIndices;
|
|
844
746
|
}
|
|
845
|
-
|
|
846
|
-
return result
|
|
747
|
+
return result;
|
|
847
748
|
}
|
|
848
749
|
}
|
|
849
|
-
|
|
850
750
|
class BaseMatch {
|
|
851
751
|
constructor(pattern) {
|
|
852
752
|
this.pattern = pattern;
|
|
853
753
|
}
|
|
854
754
|
static isMultiMatch(pattern) {
|
|
855
|
-
return getMatch(pattern, this.multiRegex)
|
|
755
|
+
return getMatch(pattern, this.multiRegex);
|
|
856
756
|
}
|
|
857
757
|
static isSingleMatch(pattern) {
|
|
858
|
-
return getMatch(pattern, this.singleRegex)
|
|
758
|
+
return getMatch(pattern, this.singleRegex);
|
|
859
759
|
}
|
|
860
|
-
search(/*text*/) {}
|
|
760
|
+
search( /*text*/) {}
|
|
861
761
|
}
|
|
862
|
-
|
|
863
762
|
function getMatch(pattern, exp) {
|
|
864
763
|
const matches = pattern.match(exp);
|
|
865
|
-
return matches ? matches[1] : null
|
|
764
|
+
return matches ? matches[1] : null;
|
|
866
765
|
}
|
|
867
766
|
|
|
868
767
|
// Token: 'file
|
|
@@ -872,22 +771,21 @@ class ExactMatch extends BaseMatch {
|
|
|
872
771
|
super(pattern);
|
|
873
772
|
}
|
|
874
773
|
static get type() {
|
|
875
|
-
return 'exact'
|
|
774
|
+
return 'exact';
|
|
876
775
|
}
|
|
877
776
|
static get multiRegex() {
|
|
878
|
-
return /^="(.*)"
|
|
777
|
+
return /^="(.*)"$/;
|
|
879
778
|
}
|
|
880
779
|
static get singleRegex() {
|
|
881
|
-
return /^=(.*)
|
|
780
|
+
return /^=(.*)$/;
|
|
882
781
|
}
|
|
883
782
|
search(text) {
|
|
884
783
|
const isMatch = text === this.pattern;
|
|
885
|
-
|
|
886
784
|
return {
|
|
887
785
|
isMatch,
|
|
888
786
|
score: isMatch ? 0 : 1,
|
|
889
787
|
indices: [0, this.pattern.length - 1]
|
|
890
|
-
}
|
|
788
|
+
};
|
|
891
789
|
}
|
|
892
790
|
}
|
|
893
791
|
|
|
@@ -898,23 +796,22 @@ class InverseExactMatch extends BaseMatch {
|
|
|
898
796
|
super(pattern);
|
|
899
797
|
}
|
|
900
798
|
static get type() {
|
|
901
|
-
return 'inverse-exact'
|
|
799
|
+
return 'inverse-exact';
|
|
902
800
|
}
|
|
903
801
|
static get multiRegex() {
|
|
904
|
-
return /^!"(.*)"
|
|
802
|
+
return /^!"(.*)"$/;
|
|
905
803
|
}
|
|
906
804
|
static get singleRegex() {
|
|
907
|
-
return /^!(.*)
|
|
805
|
+
return /^!(.*)$/;
|
|
908
806
|
}
|
|
909
807
|
search(text) {
|
|
910
808
|
const index = text.indexOf(this.pattern);
|
|
911
809
|
const isMatch = index === -1;
|
|
912
|
-
|
|
913
810
|
return {
|
|
914
811
|
isMatch,
|
|
915
812
|
score: isMatch ? 0 : 1,
|
|
916
813
|
indices: [0, text.length - 1]
|
|
917
|
-
}
|
|
814
|
+
};
|
|
918
815
|
}
|
|
919
816
|
}
|
|
920
817
|
|
|
@@ -925,22 +822,21 @@ class PrefixExactMatch extends BaseMatch {
|
|
|
925
822
|
super(pattern);
|
|
926
823
|
}
|
|
927
824
|
static get type() {
|
|
928
|
-
return 'prefix-exact'
|
|
825
|
+
return 'prefix-exact';
|
|
929
826
|
}
|
|
930
827
|
static get multiRegex() {
|
|
931
|
-
return /^\^"(.*)"
|
|
828
|
+
return /^\^"(.*)"$/;
|
|
932
829
|
}
|
|
933
830
|
static get singleRegex() {
|
|
934
|
-
return /^\^(.*)
|
|
831
|
+
return /^\^(.*)$/;
|
|
935
832
|
}
|
|
936
833
|
search(text) {
|
|
937
834
|
const isMatch = text.startsWith(this.pattern);
|
|
938
|
-
|
|
939
835
|
return {
|
|
940
836
|
isMatch,
|
|
941
837
|
score: isMatch ? 0 : 1,
|
|
942
838
|
indices: [0, this.pattern.length - 1]
|
|
943
|
-
}
|
|
839
|
+
};
|
|
944
840
|
}
|
|
945
841
|
}
|
|
946
842
|
|
|
@@ -951,22 +847,21 @@ class InversePrefixExactMatch extends BaseMatch {
|
|
|
951
847
|
super(pattern);
|
|
952
848
|
}
|
|
953
849
|
static get type() {
|
|
954
|
-
return 'inverse-prefix-exact'
|
|
850
|
+
return 'inverse-prefix-exact';
|
|
955
851
|
}
|
|
956
852
|
static get multiRegex() {
|
|
957
|
-
return /^!\^"(.*)"
|
|
853
|
+
return /^!\^"(.*)"$/;
|
|
958
854
|
}
|
|
959
855
|
static get singleRegex() {
|
|
960
|
-
return /^!\^(.*)
|
|
856
|
+
return /^!\^(.*)$/;
|
|
961
857
|
}
|
|
962
858
|
search(text) {
|
|
963
859
|
const isMatch = !text.startsWith(this.pattern);
|
|
964
|
-
|
|
965
860
|
return {
|
|
966
861
|
isMatch,
|
|
967
862
|
score: isMatch ? 0 : 1,
|
|
968
863
|
indices: [0, text.length - 1]
|
|
969
|
-
}
|
|
864
|
+
};
|
|
970
865
|
}
|
|
971
866
|
}
|
|
972
867
|
|
|
@@ -977,22 +872,21 @@ class SuffixExactMatch extends BaseMatch {
|
|
|
977
872
|
super(pattern);
|
|
978
873
|
}
|
|
979
874
|
static get type() {
|
|
980
|
-
return 'suffix-exact'
|
|
875
|
+
return 'suffix-exact';
|
|
981
876
|
}
|
|
982
877
|
static get multiRegex() {
|
|
983
|
-
return /^"(.*)"
|
|
878
|
+
return /^"(.*)"\$$/;
|
|
984
879
|
}
|
|
985
880
|
static get singleRegex() {
|
|
986
|
-
return /^(.*)
|
|
881
|
+
return /^(.*)\$$/;
|
|
987
882
|
}
|
|
988
883
|
search(text) {
|
|
989
884
|
const isMatch = text.endsWith(this.pattern);
|
|
990
|
-
|
|
991
885
|
return {
|
|
992
886
|
isMatch,
|
|
993
887
|
score: isMatch ? 0 : 1,
|
|
994
888
|
indices: [text.length - this.pattern.length, text.length - 1]
|
|
995
|
-
}
|
|
889
|
+
};
|
|
996
890
|
}
|
|
997
891
|
}
|
|
998
892
|
|
|
@@ -1003,13 +897,13 @@ class InverseSuffixExactMatch extends BaseMatch {
|
|
|
1003
897
|
super(pattern);
|
|
1004
898
|
}
|
|
1005
899
|
static get type() {
|
|
1006
|
-
return 'inverse-suffix-exact'
|
|
900
|
+
return 'inverse-suffix-exact';
|
|
1007
901
|
}
|
|
1008
902
|
static get multiRegex() {
|
|
1009
|
-
return /^!"(.*)"
|
|
903
|
+
return /^!"(.*)"\$$/;
|
|
1010
904
|
}
|
|
1011
905
|
static get singleRegex() {
|
|
1012
|
-
return /^!(.*)
|
|
906
|
+
return /^!(.*)\$$/;
|
|
1013
907
|
}
|
|
1014
908
|
search(text) {
|
|
1015
909
|
const isMatch = !text.endsWith(this.pattern);
|
|
@@ -1017,24 +911,20 @@ class InverseSuffixExactMatch extends BaseMatch {
|
|
|
1017
911
|
isMatch,
|
|
1018
912
|
score: isMatch ? 0 : 1,
|
|
1019
913
|
indices: [0, text.length - 1]
|
|
1020
|
-
}
|
|
914
|
+
};
|
|
1021
915
|
}
|
|
1022
916
|
}
|
|
1023
|
-
|
|
1024
917
|
class FuzzyMatch extends BaseMatch {
|
|
1025
|
-
constructor(
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
ignoreLocation = Config.ignoreLocation
|
|
1036
|
-
} = {}
|
|
1037
|
-
) {
|
|
918
|
+
constructor(pattern, {
|
|
919
|
+
location = Config.location,
|
|
920
|
+
threshold = Config.threshold,
|
|
921
|
+
distance = Config.distance,
|
|
922
|
+
includeMatches = Config.includeMatches,
|
|
923
|
+
findAllMatches = Config.findAllMatches,
|
|
924
|
+
minMatchCharLength = Config.minMatchCharLength,
|
|
925
|
+
isCaseSensitive = Config.isCaseSensitive,
|
|
926
|
+
ignoreLocation = Config.ignoreLocation
|
|
927
|
+
} = {}) {
|
|
1038
928
|
super(pattern);
|
|
1039
929
|
this._bitapSearch = new BitapSearch(pattern, {
|
|
1040
930
|
location,
|
|
@@ -1048,16 +938,16 @@ class FuzzyMatch extends BaseMatch {
|
|
|
1048
938
|
});
|
|
1049
939
|
}
|
|
1050
940
|
static get type() {
|
|
1051
|
-
return 'fuzzy'
|
|
941
|
+
return 'fuzzy';
|
|
1052
942
|
}
|
|
1053
943
|
static get multiRegex() {
|
|
1054
|
-
return /^"(.*)"
|
|
944
|
+
return /^"(.*)"$/;
|
|
1055
945
|
}
|
|
1056
946
|
static get singleRegex() {
|
|
1057
|
-
return /^(.*)
|
|
947
|
+
return /^(.*)$/;
|
|
1058
948
|
}
|
|
1059
949
|
search(text) {
|
|
1060
|
-
return this._bitapSearch.searchIn(text)
|
|
950
|
+
return this._bitapSearch.searchIn(text);
|
|
1061
951
|
}
|
|
1062
952
|
}
|
|
1063
953
|
|
|
@@ -1068,18 +958,17 @@ class IncludeMatch extends BaseMatch {
|
|
|
1068
958
|
super(pattern);
|
|
1069
959
|
}
|
|
1070
960
|
static get type() {
|
|
1071
|
-
return 'include'
|
|
961
|
+
return 'include';
|
|
1072
962
|
}
|
|
1073
963
|
static get multiRegex() {
|
|
1074
|
-
return /^'"(.*)"
|
|
964
|
+
return /^'"(.*)"$/;
|
|
1075
965
|
}
|
|
1076
966
|
static get singleRegex() {
|
|
1077
|
-
return /^'(.*)
|
|
967
|
+
return /^'(.*)$/;
|
|
1078
968
|
}
|
|
1079
969
|
search(text) {
|
|
1080
970
|
let location = 0;
|
|
1081
971
|
let index;
|
|
1082
|
-
|
|
1083
972
|
const indices = [];
|
|
1084
973
|
const patternLen = this.pattern.length;
|
|
1085
974
|
|
|
@@ -1088,45 +977,29 @@ class IncludeMatch extends BaseMatch {
|
|
|
1088
977
|
location = index + patternLen;
|
|
1089
978
|
indices.push([index, location - 1]);
|
|
1090
979
|
}
|
|
1091
|
-
|
|
1092
980
|
const isMatch = !!indices.length;
|
|
1093
|
-
|
|
1094
981
|
return {
|
|
1095
982
|
isMatch,
|
|
1096
983
|
score: isMatch ? 0 : 1,
|
|
1097
984
|
indices
|
|
1098
|
-
}
|
|
985
|
+
};
|
|
1099
986
|
}
|
|
1100
987
|
}
|
|
1101
988
|
|
|
1102
989
|
// ❗Order is important. DO NOT CHANGE.
|
|
1103
|
-
const searchers = [
|
|
1104
|
-
ExactMatch,
|
|
1105
|
-
IncludeMatch,
|
|
1106
|
-
PrefixExactMatch,
|
|
1107
|
-
InversePrefixExactMatch,
|
|
1108
|
-
InverseSuffixExactMatch,
|
|
1109
|
-
SuffixExactMatch,
|
|
1110
|
-
InverseExactMatch,
|
|
1111
|
-
FuzzyMatch
|
|
1112
|
-
];
|
|
1113
|
-
|
|
990
|
+
const searchers = [ExactMatch, IncludeMatch, PrefixExactMatch, InversePrefixExactMatch, InverseSuffixExactMatch, SuffixExactMatch, InverseExactMatch, FuzzyMatch];
|
|
1114
991
|
const searchersLen = searchers.length;
|
|
1115
992
|
|
|
1116
993
|
// Regex to split by spaces, but keep anything in quotes together
|
|
1117
|
-
const SPACE_RE = / +(?=([^\"]*\"[^\"]*\")*[^\"]*$)/;
|
|
994
|
+
const SPACE_RE = / +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/;
|
|
1118
995
|
const OR_TOKEN = '|';
|
|
1119
996
|
|
|
1120
997
|
// Return a 2D array representation of the query, for simpler parsing.
|
|
1121
998
|
// Example:
|
|
1122
999
|
// "^core go$ | rb$ | py$ xy$" => [["^core", "go$"], ["rb$"], ["py$", "xy$"]]
|
|
1123
1000
|
function parseQuery(pattern, options = {}) {
|
|
1124
|
-
return pattern.split(OR_TOKEN).map(
|
|
1125
|
-
let query = item
|
|
1126
|
-
.trim()
|
|
1127
|
-
.split(SPACE_RE)
|
|
1128
|
-
.filter((item) => item && !!item.trim());
|
|
1129
|
-
|
|
1001
|
+
return pattern.split(OR_TOKEN).map(item => {
|
|
1002
|
+
let query = item.trim().split(SPACE_RE).filter(item => item && !!item.trim());
|
|
1130
1003
|
let results = [];
|
|
1131
1004
|
for (let i = 0, len = query.length; i < len; i += 1) {
|
|
1132
1005
|
const queryItem = query[i];
|
|
@@ -1142,9 +1015,8 @@ function parseQuery(pattern, options = {}) {
|
|
|
1142
1015
|
found = true;
|
|
1143
1016
|
}
|
|
1144
1017
|
}
|
|
1145
|
-
|
|
1146
1018
|
if (found) {
|
|
1147
|
-
continue
|
|
1019
|
+
continue;
|
|
1148
1020
|
}
|
|
1149
1021
|
|
|
1150
1022
|
// 2. Handle single query matches (i.e, once that are *not* quoted)
|
|
@@ -1154,13 +1026,12 @@ function parseQuery(pattern, options = {}) {
|
|
|
1154
1026
|
let token = searcher.isSingleMatch(queryItem);
|
|
1155
1027
|
if (token) {
|
|
1156
1028
|
results.push(new searcher(token, options));
|
|
1157
|
-
break
|
|
1029
|
+
break;
|
|
1158
1030
|
}
|
|
1159
1031
|
}
|
|
1160
1032
|
}
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
})
|
|
1033
|
+
return results;
|
|
1034
|
+
});
|
|
1164
1035
|
}
|
|
1165
1036
|
|
|
1166
1037
|
// These extended matchers can return an array of matches, as opposed
|
|
@@ -1196,19 +1067,16 @@ const MultiMatchSet = new Set([FuzzyMatch.type, IncludeMatch.type]);
|
|
|
1196
1067
|
* ```
|
|
1197
1068
|
*/
|
|
1198
1069
|
class ExtendedSearch {
|
|
1199
|
-
constructor(
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
distance = Config.distance
|
|
1210
|
-
} = {}
|
|
1211
|
-
) {
|
|
1070
|
+
constructor(pattern, {
|
|
1071
|
+
isCaseSensitive = Config.isCaseSensitive,
|
|
1072
|
+
includeMatches = Config.includeMatches,
|
|
1073
|
+
minMatchCharLength = Config.minMatchCharLength,
|
|
1074
|
+
ignoreLocation = Config.ignoreLocation,
|
|
1075
|
+
findAllMatches = Config.findAllMatches,
|
|
1076
|
+
location = Config.location,
|
|
1077
|
+
threshold = Config.threshold,
|
|
1078
|
+
distance = Config.distance
|
|
1079
|
+
} = {}) {
|
|
1212
1080
|
this.query = null;
|
|
1213
1081
|
this.options = {
|
|
1214
1082
|
isCaseSensitive,
|
|
@@ -1220,29 +1088,25 @@ class ExtendedSearch {
|
|
|
1220
1088
|
threshold,
|
|
1221
1089
|
distance
|
|
1222
1090
|
};
|
|
1223
|
-
|
|
1224
1091
|
this.pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
|
|
1225
1092
|
this.query = parseQuery(this.pattern, this.options);
|
|
1226
1093
|
}
|
|
1227
|
-
|
|
1228
1094
|
static condition(_, options) {
|
|
1229
|
-
return options.useExtendedSearch
|
|
1095
|
+
return options.useExtendedSearch;
|
|
1230
1096
|
}
|
|
1231
|
-
|
|
1232
1097
|
searchIn(text) {
|
|
1233
1098
|
const query = this.query;
|
|
1234
|
-
|
|
1235
1099
|
if (!query) {
|
|
1236
1100
|
return {
|
|
1237
1101
|
isMatch: false,
|
|
1238
1102
|
score: 1
|
|
1239
|
-
}
|
|
1103
|
+
};
|
|
1240
1104
|
}
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1105
|
+
const {
|
|
1106
|
+
includeMatches,
|
|
1107
|
+
isCaseSensitive
|
|
1108
|
+
} = this.options;
|
|
1244
1109
|
text = isCaseSensitive ? text : text.toLowerCase();
|
|
1245
|
-
|
|
1246
1110
|
let numMatches = 0;
|
|
1247
1111
|
let allIndices = [];
|
|
1248
1112
|
let totalScore = 0;
|
|
@@ -1258,8 +1122,11 @@ class ExtendedSearch {
|
|
|
1258
1122
|
// ANDs
|
|
1259
1123
|
for (let j = 0, pLen = searchers.length; j < pLen; j += 1) {
|
|
1260
1124
|
const searcher = searchers[j];
|
|
1261
|
-
const {
|
|
1262
|
-
|
|
1125
|
+
const {
|
|
1126
|
+
isMatch,
|
|
1127
|
+
indices,
|
|
1128
|
+
score
|
|
1129
|
+
} = searcher.search(text);
|
|
1263
1130
|
if (isMatch) {
|
|
1264
1131
|
numMatches += 1;
|
|
1265
1132
|
totalScore += score;
|
|
@@ -1275,7 +1142,7 @@ class ExtendedSearch {
|
|
|
1275
1142
|
totalScore = 0;
|
|
1276
1143
|
numMatches = 0;
|
|
1277
1144
|
allIndices.length = 0;
|
|
1278
|
-
break
|
|
1145
|
+
break;
|
|
1279
1146
|
}
|
|
1280
1147
|
}
|
|
1281
1148
|
|
|
@@ -1285,12 +1152,10 @@ class ExtendedSearch {
|
|
|
1285
1152
|
isMatch: true,
|
|
1286
1153
|
score: totalScore / numMatches
|
|
1287
1154
|
};
|
|
1288
|
-
|
|
1289
1155
|
if (includeMatches) {
|
|
1290
1156
|
result.indices = allIndices;
|
|
1291
1157
|
}
|
|
1292
|
-
|
|
1293
|
-
return result
|
|
1158
|
+
return result;
|
|
1294
1159
|
}
|
|
1295
1160
|
}
|
|
1296
1161
|
|
|
@@ -1298,263 +1163,207 @@ class ExtendedSearch {
|
|
|
1298
1163
|
return {
|
|
1299
1164
|
isMatch: false,
|
|
1300
1165
|
score: 1
|
|
1301
|
-
}
|
|
1166
|
+
};
|
|
1302
1167
|
}
|
|
1303
1168
|
}
|
|
1304
|
-
|
|
1305
1169
|
const registeredSearchers = [];
|
|
1306
|
-
|
|
1307
1170
|
function register(...args) {
|
|
1308
1171
|
registeredSearchers.push(...args);
|
|
1309
1172
|
}
|
|
1310
|
-
|
|
1311
1173
|
function createSearcher(pattern, options) {
|
|
1312
1174
|
for (let i = 0, len = registeredSearchers.length; i < len; i += 1) {
|
|
1313
1175
|
let searcherClass = registeredSearchers[i];
|
|
1314
1176
|
if (searcherClass.condition(pattern, options)) {
|
|
1315
|
-
return new searcherClass(pattern, options)
|
|
1177
|
+
return new searcherClass(pattern, options);
|
|
1316
1178
|
}
|
|
1317
1179
|
}
|
|
1318
|
-
|
|
1319
|
-
return new BitapSearch(pattern, options)
|
|
1180
|
+
return new BitapSearch(pattern, options);
|
|
1320
1181
|
}
|
|
1321
|
-
|
|
1322
1182
|
const LogicalOperator = {
|
|
1323
1183
|
AND: '$and',
|
|
1324
1184
|
OR: '$or'
|
|
1325
1185
|
};
|
|
1326
|
-
|
|
1327
1186
|
const KeyType = {
|
|
1328
1187
|
PATH: '$path',
|
|
1329
1188
|
PATTERN: '$val'
|
|
1330
1189
|
};
|
|
1331
|
-
|
|
1332
|
-
const
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
const isLeaf = (query) =>
|
|
1338
|
-
!isArray(query) && isObject(query) && !isExpression(query);
|
|
1339
|
-
|
|
1340
|
-
const convertToExplicit = (query) => ({
|
|
1341
|
-
[LogicalOperator.AND]: Object.keys(query).map((key) => ({
|
|
1190
|
+
const isExpression = query => !!(query[LogicalOperator.AND] || query[LogicalOperator.OR]);
|
|
1191
|
+
const isPath = query => !!query[KeyType.PATH];
|
|
1192
|
+
const isLeaf = query => !isArray(query) && isObject(query) && !isExpression(query);
|
|
1193
|
+
const convertToExplicit = query => ({
|
|
1194
|
+
[LogicalOperator.AND]: Object.keys(query).map(key => ({
|
|
1342
1195
|
[key]: query[key]
|
|
1343
1196
|
}))
|
|
1344
1197
|
});
|
|
1345
1198
|
|
|
1346
1199
|
// When `auto` is `true`, the parse function will infer and initialize and add
|
|
1347
1200
|
// the appropriate `Searcher` instance
|
|
1348
|
-
function parse(query, options, {
|
|
1349
|
-
|
|
1201
|
+
function parse(query, options, {
|
|
1202
|
+
auto = true
|
|
1203
|
+
} = {}) {
|
|
1204
|
+
const next = query => {
|
|
1350
1205
|
let keys = Object.keys(query);
|
|
1351
|
-
|
|
1352
1206
|
const isQueryPath = isPath(query);
|
|
1353
|
-
|
|
1354
1207
|
if (!isQueryPath && keys.length > 1 && !isExpression(query)) {
|
|
1355
|
-
return next(convertToExplicit(query))
|
|
1208
|
+
return next(convertToExplicit(query));
|
|
1356
1209
|
}
|
|
1357
|
-
|
|
1358
1210
|
if (isLeaf(query)) {
|
|
1359
1211
|
const key = isQueryPath ? query[KeyType.PATH] : keys[0];
|
|
1360
|
-
|
|
1361
1212
|
const pattern = isQueryPath ? query[KeyType.PATTERN] : query[key];
|
|
1362
|
-
|
|
1363
1213
|
if (!isString(pattern)) {
|
|
1364
|
-
throw new Error(LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key))
|
|
1214
|
+
throw new Error(LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key));
|
|
1365
1215
|
}
|
|
1366
|
-
|
|
1367
1216
|
const obj = {
|
|
1368
1217
|
keyId: createKeyId(key),
|
|
1369
1218
|
pattern
|
|
1370
1219
|
};
|
|
1371
|
-
|
|
1372
1220
|
if (auto) {
|
|
1373
1221
|
obj.searcher = createSearcher(pattern, options);
|
|
1374
1222
|
}
|
|
1375
|
-
|
|
1376
|
-
return obj
|
|
1223
|
+
return obj;
|
|
1377
1224
|
}
|
|
1378
|
-
|
|
1379
1225
|
let node = {
|
|
1380
1226
|
children: [],
|
|
1381
1227
|
operator: keys[0]
|
|
1382
1228
|
};
|
|
1383
|
-
|
|
1384
|
-
keys.forEach((key) => {
|
|
1229
|
+
keys.forEach(key => {
|
|
1385
1230
|
const value = query[key];
|
|
1386
|
-
|
|
1387
1231
|
if (isArray(value)) {
|
|
1388
|
-
value.forEach(
|
|
1232
|
+
value.forEach(item => {
|
|
1389
1233
|
node.children.push(next(item));
|
|
1390
1234
|
});
|
|
1391
1235
|
}
|
|
1392
1236
|
});
|
|
1393
|
-
|
|
1394
|
-
return node
|
|
1237
|
+
return node;
|
|
1395
1238
|
};
|
|
1396
|
-
|
|
1397
1239
|
if (!isExpression(query)) {
|
|
1398
1240
|
query = convertToExplicit(query);
|
|
1399
1241
|
}
|
|
1400
|
-
|
|
1401
|
-
return next(query)
|
|
1242
|
+
return next(query);
|
|
1402
1243
|
}
|
|
1403
1244
|
|
|
1404
1245
|
// Practical scoring function
|
|
1405
|
-
function computeScore
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
results.forEach((result) => {
|
|
1246
|
+
function computeScore(results, {
|
|
1247
|
+
ignoreFieldNorm = Config.ignoreFieldNorm
|
|
1248
|
+
}) {
|
|
1249
|
+
results.forEach(result => {
|
|
1410
1250
|
let totalScore = 1;
|
|
1411
|
-
|
|
1412
|
-
|
|
1251
|
+
result.matches.forEach(({
|
|
1252
|
+
key,
|
|
1253
|
+
norm,
|
|
1254
|
+
score
|
|
1255
|
+
}) => {
|
|
1413
1256
|
const weight = key ? key.weight : null;
|
|
1414
|
-
|
|
1415
|
-
totalScore *= Math.pow(
|
|
1416
|
-
score === 0 && weight ? Number.EPSILON : score,
|
|
1417
|
-
(weight || 1) * (ignoreFieldNorm ? 1 : norm)
|
|
1418
|
-
);
|
|
1257
|
+
totalScore *= Math.pow(score === 0 && weight ? Number.EPSILON : score, (weight || 1) * (ignoreFieldNorm ? 1 : norm));
|
|
1419
1258
|
});
|
|
1420
|
-
|
|
1421
1259
|
result.score = totalScore;
|
|
1422
1260
|
});
|
|
1423
1261
|
}
|
|
1424
|
-
|
|
1425
1262
|
function transformMatches(result, data) {
|
|
1426
1263
|
const matches = result.matches;
|
|
1427
1264
|
data.matches = [];
|
|
1428
|
-
|
|
1429
1265
|
if (!isDefined(matches)) {
|
|
1430
|
-
return
|
|
1266
|
+
return;
|
|
1431
1267
|
}
|
|
1432
|
-
|
|
1433
|
-
matches.forEach((match) => {
|
|
1268
|
+
matches.forEach(match => {
|
|
1434
1269
|
if (!isDefined(match.indices) || !match.indices.length) {
|
|
1435
|
-
return
|
|
1270
|
+
return;
|
|
1436
1271
|
}
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1272
|
+
const {
|
|
1273
|
+
indices,
|
|
1274
|
+
value
|
|
1275
|
+
} = match;
|
|
1440
1276
|
let obj = {
|
|
1441
1277
|
indices,
|
|
1442
1278
|
value
|
|
1443
1279
|
};
|
|
1444
|
-
|
|
1445
1280
|
if (match.key) {
|
|
1446
1281
|
obj.key = match.key.src;
|
|
1447
1282
|
}
|
|
1448
|
-
|
|
1449
1283
|
if (match.idx > -1) {
|
|
1450
1284
|
obj.refIndex = match.idx;
|
|
1451
1285
|
}
|
|
1452
|
-
|
|
1453
1286
|
data.matches.push(obj);
|
|
1454
1287
|
});
|
|
1455
1288
|
}
|
|
1456
|
-
|
|
1457
1289
|
function transformScore(result, data) {
|
|
1458
1290
|
data.score = result.score;
|
|
1459
1291
|
}
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
{
|
|
1465
|
-
includeMatches = Config.includeMatches,
|
|
1466
|
-
includeScore = Config.includeScore
|
|
1467
|
-
} = {}
|
|
1468
|
-
) {
|
|
1292
|
+
function format(results, docs, {
|
|
1293
|
+
includeMatches = Config.includeMatches,
|
|
1294
|
+
includeScore = Config.includeScore
|
|
1295
|
+
} = {}) {
|
|
1469
1296
|
const transformers = [];
|
|
1470
|
-
|
|
1471
1297
|
if (includeMatches) transformers.push(transformMatches);
|
|
1472
1298
|
if (includeScore) transformers.push(transformScore);
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1299
|
+
return results.map(result => {
|
|
1300
|
+
const {
|
|
1301
|
+
idx
|
|
1302
|
+
} = result;
|
|
1477
1303
|
const data = {
|
|
1478
1304
|
item: docs[idx],
|
|
1479
1305
|
refIndex: idx
|
|
1480
1306
|
};
|
|
1481
|
-
|
|
1482
1307
|
if (transformers.length) {
|
|
1483
|
-
transformers.forEach(
|
|
1308
|
+
transformers.forEach(transformer => {
|
|
1484
1309
|
transformer(result, data);
|
|
1485
1310
|
});
|
|
1486
1311
|
}
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
})
|
|
1312
|
+
return data;
|
|
1313
|
+
});
|
|
1490
1314
|
}
|
|
1491
|
-
|
|
1492
1315
|
class Fuse {
|
|
1493
1316
|
constructor(docs, options = {}, index) {
|
|
1494
|
-
this.options = {
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
throw new Error(EXTENDED_SEARCH_UNAVAILABLE)
|
|
1317
|
+
this.options = {
|
|
1318
|
+
...Config,
|
|
1319
|
+
...options
|
|
1320
|
+
};
|
|
1321
|
+
if (this.options.useExtendedSearch && !true) {
|
|
1322
|
+
throw new Error(EXTENDED_SEARCH_UNAVAILABLE);
|
|
1501
1323
|
}
|
|
1502
|
-
|
|
1503
1324
|
this._keyStore = new KeyStore(this.options.keys);
|
|
1504
|
-
|
|
1505
1325
|
this.setCollection(docs, index);
|
|
1506
1326
|
}
|
|
1507
|
-
|
|
1508
1327
|
setCollection(docs, index) {
|
|
1509
1328
|
this._docs = docs;
|
|
1510
|
-
|
|
1511
1329
|
if (index && !(index instanceof FuseIndex)) {
|
|
1512
|
-
throw new Error(INCORRECT_INDEX_TYPE)
|
|
1330
|
+
throw new Error(INCORRECT_INDEX_TYPE);
|
|
1513
1331
|
}
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
getFn: this.options.getFn
|
|
1519
|
-
});
|
|
1332
|
+
this._myIndex = index || createIndex(this.options.keys, this._docs, {
|
|
1333
|
+
getFn: this.options.getFn,
|
|
1334
|
+
fieldNormWeight: this.options.fieldNormWeight
|
|
1335
|
+
});
|
|
1520
1336
|
}
|
|
1521
|
-
|
|
1522
1337
|
add(doc) {
|
|
1523
1338
|
if (!isDefined(doc)) {
|
|
1524
|
-
return
|
|
1339
|
+
return;
|
|
1525
1340
|
}
|
|
1526
|
-
|
|
1527
1341
|
this._docs.push(doc);
|
|
1528
1342
|
this._myIndex.add(doc);
|
|
1529
1343
|
}
|
|
1530
|
-
|
|
1531
|
-
remove(predicate = (/* doc, idx */) => false) {
|
|
1344
|
+
remove(predicate = ( /* doc, idx */) => false) {
|
|
1532
1345
|
const results = [];
|
|
1533
|
-
|
|
1534
1346
|
for (let i = 0, len = this._docs.length; i < len; i += 1) {
|
|
1535
1347
|
const doc = this._docs[i];
|
|
1536
1348
|
if (predicate(doc, i)) {
|
|
1537
1349
|
this.removeAt(i);
|
|
1538
1350
|
i -= 1;
|
|
1539
1351
|
len -= 1;
|
|
1540
|
-
|
|
1541
1352
|
results.push(doc);
|
|
1542
1353
|
}
|
|
1543
1354
|
}
|
|
1544
|
-
|
|
1545
|
-
return results
|
|
1355
|
+
return results;
|
|
1546
1356
|
}
|
|
1547
|
-
|
|
1548
1357
|
removeAt(idx) {
|
|
1549
1358
|
this._docs.splice(idx, 1);
|
|
1550
1359
|
this._myIndex.removeAt(idx);
|
|
1551
1360
|
}
|
|
1552
|
-
|
|
1553
1361
|
getIndex() {
|
|
1554
|
-
return this._myIndex
|
|
1362
|
+
return this._myIndex;
|
|
1555
1363
|
}
|
|
1556
|
-
|
|
1557
|
-
|
|
1364
|
+
search(query, {
|
|
1365
|
+
limit = -1
|
|
1366
|
+
} = {}) {
|
|
1558
1367
|
const {
|
|
1559
1368
|
includeMatches,
|
|
1560
1369
|
includeScore,
|
|
@@ -1562,159 +1371,146 @@ class Fuse {
|
|
|
1562
1371
|
sortFn,
|
|
1563
1372
|
ignoreFieldNorm
|
|
1564
1373
|
} = this.options;
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
: this._searchObjectList(query)
|
|
1570
|
-
: this._searchLogical(query);
|
|
1571
|
-
|
|
1572
|
-
computeScore$1(results, { ignoreFieldNorm });
|
|
1573
|
-
|
|
1374
|
+
let results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query);
|
|
1375
|
+
computeScore(results, {
|
|
1376
|
+
ignoreFieldNorm
|
|
1377
|
+
});
|
|
1574
1378
|
if (shouldSort) {
|
|
1575
1379
|
results.sort(sortFn);
|
|
1576
1380
|
}
|
|
1577
|
-
|
|
1578
1381
|
if (isNumber(limit) && limit > -1) {
|
|
1579
1382
|
results = results.slice(0, limit);
|
|
1580
1383
|
}
|
|
1581
|
-
|
|
1582
1384
|
return format(results, this._docs, {
|
|
1583
1385
|
includeMatches,
|
|
1584
1386
|
includeScore
|
|
1585
|
-
})
|
|
1387
|
+
});
|
|
1586
1388
|
}
|
|
1587
|
-
|
|
1588
1389
|
_searchStringList(query) {
|
|
1589
1390
|
const searcher = createSearcher(query, this.options);
|
|
1590
|
-
const {
|
|
1391
|
+
const {
|
|
1392
|
+
records
|
|
1393
|
+
} = this._myIndex;
|
|
1591
1394
|
const results = [];
|
|
1592
1395
|
|
|
1593
1396
|
// Iterate over every string in the index
|
|
1594
|
-
records.forEach(({
|
|
1397
|
+
records.forEach(({
|
|
1398
|
+
v: text,
|
|
1399
|
+
i: idx,
|
|
1400
|
+
n: norm
|
|
1401
|
+
}) => {
|
|
1595
1402
|
if (!isDefined(text)) {
|
|
1596
|
-
return
|
|
1403
|
+
return;
|
|
1597
1404
|
}
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1405
|
+
const {
|
|
1406
|
+
isMatch,
|
|
1407
|
+
score,
|
|
1408
|
+
indices
|
|
1409
|
+
} = searcher.searchIn(text);
|
|
1601
1410
|
if (isMatch) {
|
|
1602
1411
|
results.push({
|
|
1603
1412
|
item: text,
|
|
1604
1413
|
idx,
|
|
1605
|
-
matches: [{
|
|
1414
|
+
matches: [{
|
|
1415
|
+
score,
|
|
1416
|
+
value: text,
|
|
1417
|
+
norm,
|
|
1418
|
+
indices
|
|
1419
|
+
}]
|
|
1606
1420
|
});
|
|
1607
1421
|
}
|
|
1608
1422
|
});
|
|
1609
|
-
|
|
1610
|
-
return results
|
|
1423
|
+
return results;
|
|
1611
1424
|
}
|
|
1612
|
-
|
|
1613
1425
|
_searchLogical(query) {
|
|
1614
|
-
|
|
1615
1426
|
const expression = parse(query, this.options);
|
|
1616
|
-
|
|
1617
1427
|
const evaluate = (node, item, idx) => {
|
|
1618
1428
|
if (!node.children) {
|
|
1619
|
-
const {
|
|
1620
|
-
|
|
1429
|
+
const {
|
|
1430
|
+
keyId,
|
|
1431
|
+
searcher
|
|
1432
|
+
} = node;
|
|
1621
1433
|
const matches = this._findMatches({
|
|
1622
1434
|
key: this._keyStore.get(keyId),
|
|
1623
1435
|
value: this._myIndex.getValueForItemAtKeyId(item, keyId),
|
|
1624
1436
|
searcher
|
|
1625
1437
|
});
|
|
1626
|
-
|
|
1627
1438
|
if (matches && matches.length) {
|
|
1628
|
-
return [
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
}
|
|
1634
|
-
]
|
|
1439
|
+
return [{
|
|
1440
|
+
idx,
|
|
1441
|
+
item,
|
|
1442
|
+
matches
|
|
1443
|
+
}];
|
|
1635
1444
|
}
|
|
1636
|
-
|
|
1637
|
-
return []
|
|
1445
|
+
return [];
|
|
1638
1446
|
}
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
if (result.length) {
|
|
1648
|
-
res.push(...result);
|
|
1649
|
-
} else {
|
|
1650
|
-
return []
|
|
1651
|
-
}
|
|
1652
|
-
}
|
|
1653
|
-
return res
|
|
1654
|
-
}
|
|
1655
|
-
case LogicalOperator.OR: {
|
|
1656
|
-
const res = [];
|
|
1657
|
-
for (let i = 0, len = node.children.length; i < len; i += 1) {
|
|
1658
|
-
const child = node.children[i];
|
|
1659
|
-
const result = evaluate(child, item, idx);
|
|
1660
|
-
if (result.length) {
|
|
1661
|
-
res.push(...result);
|
|
1662
|
-
break
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
return res
|
|
1447
|
+
const res = [];
|
|
1448
|
+
for (let i = 0, len = node.children.length; i < len; i += 1) {
|
|
1449
|
+
const child = node.children[i];
|
|
1450
|
+
const result = evaluate(child, item, idx);
|
|
1451
|
+
if (result.length) {
|
|
1452
|
+
res.push(...result);
|
|
1453
|
+
} else if (node.operator === LogicalOperator.AND) {
|
|
1454
|
+
return [];
|
|
1666
1455
|
}
|
|
1667
1456
|
}
|
|
1457
|
+
return res;
|
|
1668
1458
|
};
|
|
1669
|
-
|
|
1670
1459
|
const records = this._myIndex.records;
|
|
1671
1460
|
const resultMap = {};
|
|
1672
1461
|
const results = [];
|
|
1673
|
-
|
|
1674
|
-
|
|
1462
|
+
records.forEach(({
|
|
1463
|
+
$: item,
|
|
1464
|
+
i: idx
|
|
1465
|
+
}) => {
|
|
1675
1466
|
if (isDefined(item)) {
|
|
1676
1467
|
let expResults = evaluate(expression, item, idx);
|
|
1677
|
-
|
|
1678
1468
|
if (expResults.length) {
|
|
1679
1469
|
// Dedupe when adding
|
|
1680
1470
|
if (!resultMap[idx]) {
|
|
1681
|
-
resultMap[idx] = {
|
|
1471
|
+
resultMap[idx] = {
|
|
1472
|
+
idx,
|
|
1473
|
+
item,
|
|
1474
|
+
matches: []
|
|
1475
|
+
};
|
|
1682
1476
|
results.push(resultMap[idx]);
|
|
1683
1477
|
}
|
|
1684
|
-
expResults.forEach(({
|
|
1478
|
+
expResults.forEach(({
|
|
1479
|
+
matches
|
|
1480
|
+
}) => {
|
|
1685
1481
|
resultMap[idx].matches.push(...matches);
|
|
1686
1482
|
});
|
|
1687
1483
|
}
|
|
1688
1484
|
}
|
|
1689
1485
|
});
|
|
1690
|
-
|
|
1691
|
-
return results
|
|
1486
|
+
return results;
|
|
1692
1487
|
}
|
|
1693
|
-
|
|
1694
1488
|
_searchObjectList(query) {
|
|
1695
1489
|
const searcher = createSearcher(query, this.options);
|
|
1696
|
-
const {
|
|
1490
|
+
const {
|
|
1491
|
+
keys,
|
|
1492
|
+
records
|
|
1493
|
+
} = this._myIndex;
|
|
1697
1494
|
const results = [];
|
|
1698
1495
|
|
|
1699
1496
|
// List is Array<Object>
|
|
1700
|
-
records.forEach(({
|
|
1497
|
+
records.forEach(({
|
|
1498
|
+
$: item,
|
|
1499
|
+
i: idx
|
|
1500
|
+
}) => {
|
|
1701
1501
|
if (!isDefined(item)) {
|
|
1702
|
-
return
|
|
1502
|
+
return;
|
|
1703
1503
|
}
|
|
1704
|
-
|
|
1705
1504
|
let matches = [];
|
|
1706
1505
|
|
|
1707
1506
|
// Iterate over every key (i.e, path), and fetch the value at that key
|
|
1708
1507
|
keys.forEach((key, keyIndex) => {
|
|
1709
|
-
matches.push(
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
})
|
|
1715
|
-
);
|
|
1508
|
+
matches.push(...this._findMatches({
|
|
1509
|
+
key,
|
|
1510
|
+
value: item[keyIndex],
|
|
1511
|
+
searcher
|
|
1512
|
+
}));
|
|
1716
1513
|
});
|
|
1717
|
-
|
|
1718
1514
|
if (matches.length) {
|
|
1719
1515
|
results.push({
|
|
1720
1516
|
idx,
|
|
@@ -1723,24 +1519,31 @@ class Fuse {
|
|
|
1723
1519
|
});
|
|
1724
1520
|
}
|
|
1725
1521
|
});
|
|
1726
|
-
|
|
1727
|
-
return results
|
|
1522
|
+
return results;
|
|
1728
1523
|
}
|
|
1729
|
-
_findMatches({
|
|
1524
|
+
_findMatches({
|
|
1525
|
+
key,
|
|
1526
|
+
value,
|
|
1527
|
+
searcher
|
|
1528
|
+
}) {
|
|
1730
1529
|
if (!isDefined(value)) {
|
|
1731
|
-
return []
|
|
1530
|
+
return [];
|
|
1732
1531
|
}
|
|
1733
|
-
|
|
1734
1532
|
let matches = [];
|
|
1735
|
-
|
|
1736
1533
|
if (isArray(value)) {
|
|
1737
|
-
value.forEach(({
|
|
1534
|
+
value.forEach(({
|
|
1535
|
+
v: text,
|
|
1536
|
+
i: idx,
|
|
1537
|
+
n: norm
|
|
1538
|
+
}) => {
|
|
1738
1539
|
if (!isDefined(text)) {
|
|
1739
|
-
return
|
|
1540
|
+
return;
|
|
1740
1541
|
}
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1542
|
+
const {
|
|
1543
|
+
isMatch,
|
|
1544
|
+
score,
|
|
1545
|
+
indices
|
|
1546
|
+
} = searcher.searchIn(text);
|
|
1744
1547
|
if (isMatch) {
|
|
1745
1548
|
matches.push({
|
|
1746
1549
|
score,
|
|
@@ -1753,28 +1556,35 @@ class Fuse {
|
|
|
1753
1556
|
}
|
|
1754
1557
|
});
|
|
1755
1558
|
} else {
|
|
1756
|
-
const {
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1559
|
+
const {
|
|
1560
|
+
v: text,
|
|
1561
|
+
n: norm
|
|
1562
|
+
} = value;
|
|
1563
|
+
const {
|
|
1564
|
+
isMatch,
|
|
1565
|
+
score,
|
|
1566
|
+
indices
|
|
1567
|
+
} = searcher.searchIn(text);
|
|
1760
1568
|
if (isMatch) {
|
|
1761
|
-
matches.push({
|
|
1569
|
+
matches.push({
|
|
1570
|
+
score,
|
|
1571
|
+
key,
|
|
1572
|
+
value: text,
|
|
1573
|
+
norm,
|
|
1574
|
+
indices
|
|
1575
|
+
});
|
|
1762
1576
|
}
|
|
1763
1577
|
}
|
|
1764
|
-
|
|
1765
|
-
return matches
|
|
1578
|
+
return matches;
|
|
1766
1579
|
}
|
|
1767
1580
|
}
|
|
1768
|
-
|
|
1769
|
-
Fuse.version = '6.4.6';
|
|
1581
|
+
Fuse.version = '6.6.2';
|
|
1770
1582
|
Fuse.createIndex = createIndex;
|
|
1771
1583
|
Fuse.parseIndex = parseIndex;
|
|
1772
1584
|
Fuse.config = Config;
|
|
1773
|
-
|
|
1774
1585
|
{
|
|
1775
1586
|
Fuse.parseQuery = parse;
|
|
1776
1587
|
}
|
|
1777
|
-
|
|
1778
1588
|
{
|
|
1779
1589
|
register(ExtendedSearch);
|
|
1780
1590
|
}
|