@inseefr/lunatic 0.3.0-experimental → 0.3.0-prisme
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/LICENSE +21 -21
- package/README.md +25 -23
- package/lib/index.esm.js +3539 -0
- package/lib/index.esm.js.map +1 -0
- package/lib/index.js +240 -282
- package/lib/index.js.map +1 -1
- package/package.json +179 -173
- package/src/components/breadcrumb/breadcrumb.scss +22 -22
- package/src/components/checkbox/boolean.js +172 -172
- package/src/components/checkbox/checkbox.scss +73 -73
- package/src/components/checkbox/group.js +231 -231
- package/src/components/checkbox/one.js +11 -11
- package/src/components/component-wrapper/controls/component.js +70 -70
- package/src/components/component-wrapper/controls/controls.scss +6 -6
- package/src/components/component-wrapper/controls/index.js +1 -1
- package/src/components/component-wrapper/controls/validators/datepicker.js +44 -33
- package/src/components/component-wrapper/controls/validators/index.js +16 -16
- package/src/components/component-wrapper/controls/validators/input-number.js +23 -23
- package/src/components/component-wrapper/index.js +1 -1
- package/src/components/component-wrapper/missing/component.js +200 -180
- package/src/components/component-wrapper/missing/index.js +1 -1
- package/src/components/component-wrapper/missing/missing.scss +32 -32
- package/src/components/component-wrapper/wrapper.js +23 -23
- package/src/components/components.js +19 -19
- package/src/components/datepicker/component.js +26 -30
- package/src/components/declarations/component.js +46 -46
- package/src/components/declarations/declarations.scss +40 -40
- package/src/components/declarations/wrappers/input-declarations-wrapper.js +328 -302
- package/src/components/declarations/wrappers/simple-declarations-wrapper.js +54 -54
- package/src/components/dropdown/commons/actions.js +65 -65
- package/src/components/dropdown/commons/children-to-option.js +9 -9
- package/src/components/dropdown/commons/cleaner-callbacks.js +58 -58
- package/src/components/dropdown/commons/components/dropdown-container.js +29 -29
- package/src/components/dropdown/commons/components/dropdown.js +204 -183
- package/src/components/dropdown/commons/components/panel.js +78 -78
- package/src/components/dropdown/commons/event-callbacks/on-mousedown-callback.js +15 -15
- package/src/components/dropdown/commons/reducer.js +152 -152
- package/src/components/dropdown/commons/tools/index.js +17 -17
- package/src/components/dropdown/component.js +135 -135
- package/src/components/dropdown/dropdown-edit/dropdown-edit.js +194 -191
- package/src/components/dropdown/dropdown-edit/index.js +11 -11
- package/src/components/dropdown/dropdown-simple/dropdown.js +173 -171
- package/src/components/dropdown/dropdown-simple/index.js +20 -20
- package/src/components/dropdown/dropdown.scss +178 -178
- package/src/components/icon/icon.scss +15 -15
- package/src/components/index.js +2 -0
- package/src/components/index.scss +177 -177
- package/src/components/input/input-number.js +30 -28
- package/src/components/input/input.js +11 -11
- package/src/components/input/input.scss +31 -31
- package/src/components/loop/component.js +170 -170
- package/src/components/loop/loop.scss +13 -13
- package/src/components/loop/wrapper.js +15 -15
- package/src/components/loop-constructor/block/block.scss +10 -10
- package/src/components/loop-constructor/block/component.js +9 -9
- package/src/components/loop-constructor/roster/component.js +8 -8
- package/src/components/loop-constructor/wrapper/body-component.js +146 -131
- package/src/components/loop-constructor/wrapper/component.js +190 -190
- package/src/components/modal/component.js +36 -36
- package/src/components/modal/index.js +1 -1
- package/src/components/modal/modal.scss +33 -33
- package/src/components/progress-bar/progress-bar.scss +54 -54
- package/src/components/radio/component.js +9 -9
- package/src/components/radio/radio.scss +59 -59
- package/src/components/sequence/component.js +50 -50
- package/src/components/sequence/sequence.scss +10 -10
- package/src/components/subsequence/component.js +49 -49
- package/src/components/suggester/check-store.js +2 -4
- package/src/components/suggester/components/panel/default-option-renderer.js +27 -27
- package/src/components/suggester/components/panel/option-container.js +61 -61
- package/src/components/suggester/components/panel/panel.js +47 -47
- package/src/components/suggester/components/selection/default-label-renderer.js +31 -31
- package/src/components/suggester/components/selection/label.js +35 -35
- package/src/components/suggester/components/selection/selection.js +50 -50
- package/src/components/suggester/components/suggester-content.js +2 -2
- package/src/components/suggester/components/suggester.js +128 -88
- package/src/components/suggester/components/suggester.scss +101 -101
- package/src/components/suggester/default-style.scss +125 -125
- package/src/components/suggester/find-best-label/find-best-label.js +51 -51
- package/src/components/suggester/find-best-label/index.js +1 -1
- package/src/components/suggester/idb-suggester.js +73 -67
- package/src/components/suggester/lunatic-suggester.js +140 -139
- package/src/components/suggester/searching/create-searching.js +49 -49
- package/src/components/suggester/searching/index.js +1 -1
- package/src/components/suggester/state-management/actions.js +38 -38
- package/src/components/suggester/state-management/reducer/reduce-on-delete-search.js +11 -11
- package/src/components/suggester/state-management/reducer/reduce-on-init.js +29 -29
- package/src/components/suggester/state-management/reducer/reducer.js +38 -38
- package/src/components/suggester/suggester-wrapper.js +127 -121
- package/src/components/suggester-loader-widget/loader.js +67 -67
- package/src/components/suggester-loader-widget/widget.js +123 -123
- package/src/components/table/table.js +173 -171
- package/src/components/table/table.scss +26 -26
- package/src/components/textarea/component.js +11 -11
- package/src/components/textarea/textarea.scss +8 -8
- package/src/components/tooltip/tooltip.scss +30 -30
- package/src/stories/breadcrumb/breadcrumb.stories.js +21 -21
- package/src/stories/checkbox-boolean/data.json +78 -78
- package/src/stories/datepicker/data.json +45 -45
- package/src/stories/declarations/declarations.stories.js +116 -116
- package/src/stories/dropdown/README.md +44 -44
- package/src/stories/dropdown/data.json +98 -98
- package/src/stories/dropdown/dropdown.stories.js +89 -89
- package/src/stories/progress-bar/progress-bar.stories.js +24 -24
- package/src/stories/questionnaire/arithmetic-management.json +47 -0
- package/src/stories/questionnaire/arithmetic.json +247 -247
- package/src/stories/questionnaire/calc-var.json +187 -187
- package/src/stories/questionnaire/data-logement.json +2691 -2691
- package/src/stories/questionnaire/kish.json +275 -0
- package/src/stories/questionnaire/logement-queen.json +23390 -22706
- package/src/stories/questionnaire/logement-s2.json +46028 -44537
- package/src/stories/questionnaire/logement-sequence.json +26741 -26741
- package/src/stories/questionnaire/logement.json +21072 -21072
- package/src/stories/questionnaire/loop-and-controls.json +481 -0
- package/src/stories/questionnaire/questionnaire.stories.js +236 -172
- package/src/stories/questionnaire/update-external/data.json +1 -0
- package/src/stories/questionnaire/update-external/questionnaire.json +75 -0
- package/src/stories/sequence/sequence.stories.js +32 -32
- package/src/stories/subsequence/subsequence.stories.js +32 -32
- package/src/stories/suggester/README.md +46 -46
- package/src/stories/suggester/bailleurs-sociaux/fetch-bailleurs.js +15 -15
- package/src/stories/suggester/bailleurs-sociaux/index.js +2 -2
- package/src/stories/suggester/bailleurs-sociaux/option-bailleur-renderer.js +58 -58
- package/src/stories/suggester/bailleurs-sociaux/preloader.svg +51 -51
- package/src/stories/suggester/bailleurs-sociaux/theme.scss +22 -22
- package/src/stories/suggester/bailleurs-sociaux-2021/fetch-bailleurs.js +12 -0
- package/src/stories/suggester/bailleurs-sociaux-2021/index.js +1 -0
- package/src/stories/suggester/cog-communes/fetch-cog.js +15 -15
- package/src/stories/suggester/data-auto.json +232 -232
- package/src/stories/suggester/data-vtl.json +82 -82
- package/src/stories/suggester/data.json +169 -136
- package/src/stories/suggester/naf-rev2/index.js +2 -2
- package/src/stories/suggester/naf-rev2/option-naf-renderer.js +17 -17
- package/src/stories/suggester/suggester-workers.stories.js +226 -179
- package/src/stories/suggester/suggester.stories.js +138 -133
- package/src/stories/utils/orchestrator-split.js +119 -0
- package/src/stories/utils/orchestrator.js +119 -110
- package/src/tests/components/input-number.spec.js +188 -188
- package/src/tests/components/loops/roster-loop.json +71 -71
- package/src/tests/components/missing-wrapper.spec.js +32 -32
- package/src/tests/utils/lib/table/roster.spec.js +25 -25
- package/src/tests/utils/to-expose/handler/results/res-input-edited.json +1 -1
- package/src/tests/utils/to-expose/init-questionnaire/questionnaire.json +148 -148
- package/src/tests/utils/to-expose/init-questionnaire/result.json +181 -181
- package/src/utils/components/dragger/dragger.scss +7 -7
- package/src/utils/idb-tools/create-db-opener.js +43 -43
- package/src/utils/idb-tools/create-open-db.js +25 -25
- package/src/utils/idb-tools/idb-bulk-insert.js +96 -96
- package/src/utils/idb-tools/index.js +10 -10
- package/src/utils/idb-tools/insert-entity.js +15 -15
- package/src/utils/idb-tools/open-db.js +13 -13
- package/src/utils/idb-tools/open-or-create-db.js +34 -34
- package/src/utils/lib/controls/index.js +1 -1
- package/src/utils/lib/controls/utils.js +152 -146
- package/src/utils/lib/decorator/title-decorator.js +16 -16
- package/src/utils/lib/env.js +2 -2
- package/src/utils/lib/index.js +21 -20
- package/src/utils/lib/input-number.js +1 -1
- package/src/utils/lib/options-positioning.js +9 -9
- package/src/utils/lib/pagination/navigation/shared.js +256 -256
- package/src/utils/lib/prop-types/lines.js +6 -6
- package/src/utils/lib/responses.js +11 -11
- package/src/utils/lib/splitting.js +142 -0
- package/src/utils/lib/style.js +10 -10
- package/src/utils/store-tools/auto-load.js +74 -74
- package/src/utils/suggester-workers/append-to-index/append.js +25 -25
- package/src/utils/suggester-workers/append-to-index/append.worker.js +16 -16
- package/src/utils/suggester-workers/append-to-index/create-append-task.js +45 -45
- package/src/utils/suggester-workers/append-to-index/index.js +2 -2
- package/src/utils/suggester-workers/append-to-index/prepare-entities.js +61 -61
- package/src/utils/suggester-workers/append-to-index/store-messages.js +21 -21
- package/src/utils/suggester-workers/commons-tokenizer/create-entity-tokenizer.js +56 -54
- package/src/utils/suggester-workers/commons-tokenizer/create-fields-tokenizer.js +56 -52
- package/src/utils/suggester-workers/commons-tokenizer/create-filter-stop-words.js +17 -17
- package/src/utils/suggester-workers/commons-tokenizer/filters/compose-filters.js +10 -10
- package/src/utils/suggester-workers/commons-tokenizer/filters/create-filter-stop-words.js +17 -17
- package/src/utils/suggester-workers/commons-tokenizer/filters/create-filter-stop-words.spec.js +14 -14
- package/src/utils/suggester-workers/commons-tokenizer/filters/{filter-accents-to-lower.js → filter-accents.js} +12 -12
- package/src/utils/suggester-workers/commons-tokenizer/filters/{filter-accents-to-lower.spec.js → filter-accents.spec.js} +12 -12
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-double.js +12 -12
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-double.spec.js +20 -20
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-length.js +7 -7
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-length.spec.js +18 -18
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-stemmer.js +13 -13
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-stemmer.spec.js +12 -12
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-synonyms.js +36 -10
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-synonyms.spec.js +12 -12
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-to-lower.js +10 -0
- package/src/utils/suggester-workers/commons-tokenizer/filters/filter-to-lower.spec.js +12 -0
- package/src/utils/suggester-workers/commons-tokenizer/filters/index.js +2 -2
- package/src/utils/suggester-workers/commons-tokenizer/filters/stop-words.js +118 -118
- package/src/utils/suggester-workers/commons-tokenizer/get-regexp-from-pattern.js +8 -8
- package/src/utils/suggester-workers/commons-tokenizer/get-stemmer.js +18 -18
- package/src/utils/suggester-workers/commons-tokenizer/index.js +9 -8
- package/src/utils/suggester-workers/commons-tokenizer/prepare-string-indexation.js +13 -13
- package/src/utils/suggester-workers/commons-tokenizer/soft-tokenizer.js +7 -7
- package/src/utils/suggester-workers/create-worker.js +56 -56
- package/src/utils/suggester-workers/find-best-label/find-best-label.js +39 -39
- package/src/utils/suggester-workers/find-best-label/find-best-label.worker.js +40 -40
- package/src/utils/suggester-workers/find-best-label/tokenize.js +30 -30
- package/src/utils/suggester-workers/find-best-label/tokenize.spec.js +19 -19
- package/src/utils/suggester-workers/searching/compute-score.js +33 -33
- package/src/utils/suggester-workers/searching/get-db.js +18 -18
- package/src/utils/suggester-workers/searching/index.js +1 -1
- package/src/utils/suggester-workers/searching/order/create-alphanumeric-orderer.js +20 -20
- package/src/utils/suggester-workers/searching/order/index.js +19 -19
- package/src/utils/suggester-workers/searching/query-parser/index.js +2 -2
- package/src/utils/suggester-workers/searching/query-parser/query-parser-soft.js +7 -7
- package/src/utils/suggester-workers/searching/query-parser/query-parser-soft.spec.js +24 -24
- package/src/utils/suggester-workers/searching/query-parser/query-parser-tokenized.js +34 -28
- package/src/utils/suggester-workers/searching/resolve-query-parser.js +27 -27
- package/src/utils/suggester-workers/searching/search-in-index.js +17 -17
- package/src/utils/suggester-workers/searching/searching.js +70 -70
- package/src/utils/suggester-workers/searching/searching.worker.js +11 -11
- package/src/utils/to-expose/calculated-variables.js +113 -113
- package/src/utils/to-expose/handler.js +149 -112
- package/src/utils/to-expose/hooks/filter-components.js +27 -12
- package/src/utils/to-expose/hooks/index.js +2 -1
- package/src/utils/to-expose/hooks/lunatic-split.js +428 -0
- package/src/utils/to-expose/hooks/lunatic.js +284 -235
- package/src/utils/to-expose/index.js +1 -1
- package/src/utils/to-expose/init-questionnaire.js +164 -164
- package/src/utils/to-expose/interpret/vtl.js +18 -18
- package/src/utils/to-expose/state.js +66 -58
- package/src/tests/utils/to-expose/hooks/use-lunatic.spec.js +0 -46
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import tokenizer from 'string-tokenizer';
|
|
2
|
-
|
|
3
|
-
function toArray(tokens) {
|
|
4
|
-
if (Array.isArray(tokens)) {
|
|
5
|
-
return tokens;
|
|
6
|
-
}
|
|
7
|
-
return [tokens];
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function tokenize(object, pattern = /[\w]+/) {
|
|
11
|
-
if (typeof object === 'object') {
|
|
12
|
-
const map = {};
|
|
13
|
-
Object.entries(object).forEach(function ([key, string]) {
|
|
14
|
-
if (string.length) {
|
|
15
|
-
const { tokens } = tokenizer()
|
|
16
|
-
.input(string)
|
|
17
|
-
.tokens({ tokens: pattern })
|
|
18
|
-
.resolve();
|
|
19
|
-
map[key] = toArray(tokens);
|
|
20
|
-
} else {
|
|
21
|
-
map[key] = [];
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
return map;
|
|
26
|
-
}
|
|
27
|
-
return {};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export default tokenize;
|
|
1
|
+
import tokenizer from 'string-tokenizer';
|
|
2
|
+
|
|
3
|
+
function toArray(tokens) {
|
|
4
|
+
if (Array.isArray(tokens)) {
|
|
5
|
+
return tokens;
|
|
6
|
+
}
|
|
7
|
+
return [tokens];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function tokenize(object, pattern = /[\w]+/) {
|
|
11
|
+
if (typeof object === 'object') {
|
|
12
|
+
const map = {};
|
|
13
|
+
Object.entries(object).forEach(function ([key, string]) {
|
|
14
|
+
if (string.length) {
|
|
15
|
+
const { tokens } = tokenizer()
|
|
16
|
+
.input(string)
|
|
17
|
+
.tokens({ tokens: pattern })
|
|
18
|
+
.resolve();
|
|
19
|
+
map[key] = toArray(tokens);
|
|
20
|
+
} else {
|
|
21
|
+
map[key] = [];
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return map;
|
|
26
|
+
}
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default tokenize;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import tokenize from './tokenize';
|
|
2
|
-
|
|
3
|
-
describe('tokenize', function () {
|
|
4
|
-
it('simple', function () {
|
|
5
|
-
const results = tokenize({ hello: 'hello world!' });
|
|
6
|
-
const { hello } = results;
|
|
7
|
-
expect(Array.isArray(hello)).toEqual(true);
|
|
8
|
-
expect(hello.length).toEqual(2);
|
|
9
|
-
expect(hello[0]).toEqual('hello');
|
|
10
|
-
expect(hello[1]).toEqual('world');
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('undefined', function () {
|
|
14
|
-
const results = tokenize({ hello: '' });
|
|
15
|
-
const { hello } = results;
|
|
16
|
-
expect(Array.isArray(hello)).toEqual(true);
|
|
17
|
-
expect(hello.length).toEqual(0);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
1
|
+
import tokenize from './tokenize';
|
|
2
|
+
|
|
3
|
+
describe('tokenize', function () {
|
|
4
|
+
it('simple', function () {
|
|
5
|
+
const results = tokenize({ hello: 'hello world!' });
|
|
6
|
+
const { hello } = results;
|
|
7
|
+
expect(Array.isArray(hello)).toEqual(true);
|
|
8
|
+
expect(hello.length).toEqual(2);
|
|
9
|
+
expect(hello[0]).toEqual('hello');
|
|
10
|
+
expect(hello[1]).toEqual('world');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('undefined', function () {
|
|
14
|
+
const results = tokenize({ hello: '' });
|
|
15
|
+
const { hello } = results;
|
|
16
|
+
expect(Array.isArray(hello)).toEqual(true);
|
|
17
|
+
expect(hello.length).toEqual(0);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
function finalize(withScore, max = 30) {
|
|
2
|
-
return withScore
|
|
3
|
-
.sort(function (a, b) {
|
|
4
|
-
if (a.score > b.score) {
|
|
5
|
-
return -1;
|
|
6
|
-
}
|
|
7
|
-
if (a.score < b.score) {
|
|
8
|
-
return 1;
|
|
9
|
-
}
|
|
10
|
-
return 0;
|
|
11
|
-
})
|
|
12
|
-
.slice(0, max);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function compute(results) {
|
|
16
|
-
const listOfDocs = Object.values(results);
|
|
17
|
-
const mapResults = {};
|
|
18
|
-
|
|
19
|
-
listOfDocs.forEach(function (docs, i) {
|
|
20
|
-
docs.forEach(function (doc) {
|
|
21
|
-
const { id } = doc;
|
|
22
|
-
if (id in mapResults) {
|
|
23
|
-
mapResults[id].score++;
|
|
24
|
-
mapResults[id].step = [i, ...mapResults[id].step];
|
|
25
|
-
} else {
|
|
26
|
-
mapResults[id] = { ...doc, score: 1, step: [i] };
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
return finalize(Object.values(mapResults));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export default compute;
|
|
1
|
+
function finalize(withScore, max = 30) {
|
|
2
|
+
return withScore
|
|
3
|
+
.sort(function (a, b) {
|
|
4
|
+
if (a.score > b.score) {
|
|
5
|
+
return -1;
|
|
6
|
+
}
|
|
7
|
+
if (a.score < b.score) {
|
|
8
|
+
return 1;
|
|
9
|
+
}
|
|
10
|
+
return 0;
|
|
11
|
+
})
|
|
12
|
+
.slice(0, max);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function compute(results) {
|
|
16
|
+
const listOfDocs = Object.values(results);
|
|
17
|
+
const mapResults = {};
|
|
18
|
+
|
|
19
|
+
listOfDocs.forEach(function (docs, i) {
|
|
20
|
+
docs.forEach(function (doc) {
|
|
21
|
+
const { id } = doc;
|
|
22
|
+
if (id in mapResults) {
|
|
23
|
+
mapResults[id].score++;
|
|
24
|
+
mapResults[id].step = [i, ...mapResults[id].step];
|
|
25
|
+
} else {
|
|
26
|
+
mapResults[id] = { ...doc, score: 1, step: [i] };
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
return finalize(Object.values(mapResults));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default compute;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { openDb } from '../../idb-tools';
|
|
2
|
-
|
|
3
|
-
let STORES = {};
|
|
4
|
-
|
|
5
|
-
async function getDb(name, version) {
|
|
6
|
-
if (name in STORES) {
|
|
7
|
-
return STORES[name];
|
|
8
|
-
}
|
|
9
|
-
try {
|
|
10
|
-
const store = await openDb(name, version);
|
|
11
|
-
STORES[name] = store;
|
|
12
|
-
return store;
|
|
13
|
-
} catch (e) {
|
|
14
|
-
throw new Error(`Can't open store ${name} ${version}`);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export default getDb;
|
|
1
|
+
import { openDb } from '../../idb-tools';
|
|
2
|
+
|
|
3
|
+
let STORES = {};
|
|
4
|
+
|
|
5
|
+
async function getDb(name, version) {
|
|
6
|
+
if (name in STORES) {
|
|
7
|
+
return STORES[name];
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
const store = await openDb(name, version);
|
|
11
|
+
STORES[name] = store;
|
|
12
|
+
return store;
|
|
13
|
+
} catch (e) {
|
|
14
|
+
throw new Error(`Can't open store ${name} ${version}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default getDb;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from './searching';
|
|
1
|
+
export { default } from './searching';
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
function createAlphanumericOrderer(descending = false) {
|
|
2
|
-
return function ascending(response, order = {}) {
|
|
3
|
-
const { field } = order;
|
|
4
|
-
|
|
5
|
-
if (field && Array.isArray(response)) {
|
|
6
|
-
return response.sort(function (a, b) {
|
|
7
|
-
if (field in a.suggestion && field in b.suggestion) {
|
|
8
|
-
if (a.suggestion[field] > b.suggestion[field]) {
|
|
9
|
-
return descending ? -1 : 1;
|
|
10
|
-
} else if (a.suggestion[field] < b.suggestion[field]) {
|
|
11
|
-
return descending ? 1 : -1;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return 0;
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return response;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
export default createAlphanumericOrderer;
|
|
1
|
+
function createAlphanumericOrderer(descending = false) {
|
|
2
|
+
return function ascending(response, order = {}) {
|
|
3
|
+
const { field } = order;
|
|
4
|
+
|
|
5
|
+
if (field && Array.isArray(response)) {
|
|
6
|
+
return response.sort(function (a, b) {
|
|
7
|
+
if (field in a.suggestion && field in b.suggestion) {
|
|
8
|
+
if (a.suggestion[field] > b.suggestion[field]) {
|
|
9
|
+
return descending ? -1 : 1;
|
|
10
|
+
} else if (a.suggestion[field] < b.suggestion[field]) {
|
|
11
|
+
return descending ? 1 : -1;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return 0;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return response;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export default createAlphanumericOrderer;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import createAlphanumericOrderer from './create-alphanumeric-orderer';
|
|
2
|
-
|
|
3
|
-
function identity(response) {
|
|
4
|
-
return response;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
function getOrderingFunction(order = {}) {
|
|
8
|
-
const { type } = order;
|
|
9
|
-
switch (type) {
|
|
10
|
-
case 'ascending':
|
|
11
|
-
return createAlphanumericOrderer(false);
|
|
12
|
-
case 'descending':
|
|
13
|
-
return createAlphanumericOrderer(true);
|
|
14
|
-
default:
|
|
15
|
-
return identity;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export default getOrderingFunction;
|
|
1
|
+
import createAlphanumericOrderer from './create-alphanumeric-orderer';
|
|
2
|
+
|
|
3
|
+
function identity(response) {
|
|
4
|
+
return response;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function getOrderingFunction(order = {}) {
|
|
8
|
+
const { type } = order;
|
|
9
|
+
switch (type) {
|
|
10
|
+
case 'ascending':
|
|
11
|
+
return createAlphanumericOrderer(false);
|
|
12
|
+
case 'descending':
|
|
13
|
+
return createAlphanumericOrderer(true);
|
|
14
|
+
default:
|
|
15
|
+
return identity;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default getOrderingFunction;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default as queryParserTokenized } from './query-parser-tokenized';
|
|
2
|
-
export { default as queryParserSoft } from './query-parser-soft';
|
|
1
|
+
export { default as queryParserTokenized } from './query-parser-tokenized';
|
|
2
|
+
export { default as queryParserSoft } from './query-parser-soft';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { prepareStringIndexation } from '../../commons-tokenizer';
|
|
2
|
-
|
|
3
|
-
function queryParserSoft(string) {
|
|
4
|
-
return [prepareStringIndexation(string, '-')];
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export default queryParserSoft;
|
|
1
|
+
import { prepareStringIndexation } from '../../commons-tokenizer';
|
|
2
|
+
|
|
3
|
+
function queryParserSoft(string) {
|
|
4
|
+
return [prepareStringIndexation(string, '-')];
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export default queryParserSoft;
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import queryParserSoft from './query-parser-soft';
|
|
2
|
-
|
|
3
|
-
describe('query-parser-soft', function () {
|
|
4
|
-
it('empty query', function () {
|
|
5
|
-
const result = queryParserSoft('');
|
|
6
|
-
expect(result.length).toBe(1);
|
|
7
|
-
expect(result).toContain('');
|
|
8
|
-
});
|
|
9
|
-
it('to lower case', function () {
|
|
10
|
-
const result = queryParserSoft('HELLO');
|
|
11
|
-
expect(result.length).toBe(1);
|
|
12
|
-
expect(result).toContain('hello');
|
|
13
|
-
});
|
|
14
|
-
it('trim accent', function () {
|
|
15
|
-
const result = queryParserSoft('ïéèû');
|
|
16
|
-
expect(result.length).toBe(1);
|
|
17
|
-
expect(result).toContain('ieeu');
|
|
18
|
-
});
|
|
19
|
-
it('white spaces', function () {
|
|
20
|
-
const result = queryParserSoft('HELLO WORLD!');
|
|
21
|
-
expect(result.length).toBe(1);
|
|
22
|
-
expect(result).toContain('hello-world!');
|
|
23
|
-
});
|
|
24
|
-
});
|
|
1
|
+
import queryParserSoft from './query-parser-soft';
|
|
2
|
+
|
|
3
|
+
describe('query-parser-soft', function () {
|
|
4
|
+
it('empty query', function () {
|
|
5
|
+
const result = queryParserSoft('');
|
|
6
|
+
expect(result.length).toBe(1);
|
|
7
|
+
expect(result).toContain('');
|
|
8
|
+
});
|
|
9
|
+
it('to lower case', function () {
|
|
10
|
+
const result = queryParserSoft('HELLO');
|
|
11
|
+
expect(result.length).toBe(1);
|
|
12
|
+
expect(result).toContain('hello');
|
|
13
|
+
});
|
|
14
|
+
it('trim accent', function () {
|
|
15
|
+
const result = queryParserSoft('ïéèû');
|
|
16
|
+
expect(result.length).toBe(1);
|
|
17
|
+
expect(result).toContain('ieeu');
|
|
18
|
+
});
|
|
19
|
+
it('white spaces', function () {
|
|
20
|
+
const result = queryParserSoft('HELLO WORLD!');
|
|
21
|
+
expect(result.length).toBe(1);
|
|
22
|
+
expect(result).toContain('hello-world!');
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -1,28 +1,34 @@
|
|
|
1
|
-
import tokenizer from 'string-tokenizer';
|
|
2
|
-
import {
|
|
3
|
-
filterStemmer,
|
|
4
|
-
filterLength,
|
|
5
|
-
filterDouble,
|
|
6
|
-
getRegExpFromPattern,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
import tokenizer from 'string-tokenizer';
|
|
2
|
+
import {
|
|
3
|
+
filterStemmer,
|
|
4
|
+
filterLength,
|
|
5
|
+
filterDouble,
|
|
6
|
+
getRegExpFromPattern,
|
|
7
|
+
filterToLower,
|
|
8
|
+
} from '../../commons-tokenizer';
|
|
9
|
+
import { composeFilters } from '../../commons-tokenizer/filters';
|
|
10
|
+
|
|
11
|
+
const filterTokens = composeFilters(
|
|
12
|
+
filterDouble,
|
|
13
|
+
filterStemmer,
|
|
14
|
+
filterToLower,
|
|
15
|
+
filterLength
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
function toArray(tokens) {
|
|
19
|
+
if (tokens) {
|
|
20
|
+
return Array.isArray(tokens) ? tokens : [tokens];
|
|
21
|
+
}
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function queryParserTokenized(query = '', { pattern, ...args } = {}) {
|
|
26
|
+
const patternForTokens = { tokens: getRegExpFromPattern(pattern) };
|
|
27
|
+
const { tokens } = tokenizer()
|
|
28
|
+
.input(query)
|
|
29
|
+
.tokens(patternForTokens)
|
|
30
|
+
.resolve();
|
|
31
|
+
return filterTokens(toArray(tokens), args);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default queryParserTokenized;
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { queryParserTokenized, queryParserSoft } from './query-parser';
|
|
2
|
-
|
|
3
|
-
async function resolve(queryParser) {
|
|
4
|
-
try {
|
|
5
|
-
const { type } = queryParser;
|
|
6
|
-
switch (type) {
|
|
7
|
-
case 'tokenized':
|
|
8
|
-
const { params } = queryParser;
|
|
9
|
-
const { language, pattern, min, stemmer } = params;
|
|
10
|
-
return (query) =>
|
|
11
|
-
queryParserTokenized(query, {
|
|
12
|
-
language,
|
|
13
|
-
pattern,
|
|
14
|
-
min,
|
|
15
|
-
stemmer,
|
|
16
|
-
});
|
|
17
|
-
case 'soft':
|
|
18
|
-
return queryParserSoft;
|
|
19
|
-
default:
|
|
20
|
-
throw new Error(`Unknown parser type ${type}`);
|
|
21
|
-
}
|
|
22
|
-
} catch (e) {
|
|
23
|
-
throw new Error(e);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export default resolve;
|
|
1
|
+
import { queryParserTokenized, queryParserSoft } from './query-parser';
|
|
2
|
+
|
|
3
|
+
async function resolve(queryParser) {
|
|
4
|
+
try {
|
|
5
|
+
const { type } = queryParser;
|
|
6
|
+
switch (type) {
|
|
7
|
+
case 'tokenized':
|
|
8
|
+
const { params } = queryParser;
|
|
9
|
+
const { language, pattern, min, stemmer } = params;
|
|
10
|
+
return (query) =>
|
|
11
|
+
queryParserTokenized(query, {
|
|
12
|
+
language,
|
|
13
|
+
pattern,
|
|
14
|
+
min,
|
|
15
|
+
stemmer,
|
|
16
|
+
});
|
|
17
|
+
case 'soft':
|
|
18
|
+
return queryParserSoft;
|
|
19
|
+
default:
|
|
20
|
+
throw new Error(`Unknown parser type ${type}`);
|
|
21
|
+
}
|
|
22
|
+
} catch (e) {
|
|
23
|
+
throw new Error(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default resolve;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { CONSTANTES } from '../../store-tools';
|
|
2
|
-
|
|
3
|
-
function search(token, index) {
|
|
4
|
-
const range = IDBKeyRange.bound(token, `${token}${CONSTANTES.MAX_STRING}`);
|
|
5
|
-
return new Promise(function (resolve, reject) {
|
|
6
|
-
try {
|
|
7
|
-
index.getAll(range).onsuccess = function (req) {
|
|
8
|
-
const results = req.target.result;
|
|
9
|
-
resolve(results);
|
|
10
|
-
};
|
|
11
|
-
} catch (e) {
|
|
12
|
-
reject(e);
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default search;
|
|
1
|
+
import { CONSTANTES } from '../../store-tools';
|
|
2
|
+
|
|
3
|
+
function search(token, index) {
|
|
4
|
+
const range = IDBKeyRange.bound(token, `${token}${CONSTANTES.MAX_STRING}`);
|
|
5
|
+
return new Promise(function (resolve, reject) {
|
|
6
|
+
try {
|
|
7
|
+
index.getAll(range).onsuccess = function (req) {
|
|
8
|
+
const results = req.target.result;
|
|
9
|
+
resolve(results);
|
|
10
|
+
};
|
|
11
|
+
} catch (e) {
|
|
12
|
+
reject(e);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default search;
|
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import getDb from './get-db';
|
|
2
|
-
import { CONSTANTES } from '../../store-tools';
|
|
3
|
-
import { getEntity } from '../../idb-tools';
|
|
4
|
-
import searchInIndex from './search-in-index';
|
|
5
|
-
import resolveQueryParser from './resolve-query-parser';
|
|
6
|
-
import computeScore from './compute-score';
|
|
7
|
-
import getOrderingFunction from './order';
|
|
8
|
-
|
|
9
|
-
function prepare(response) {
|
|
10
|
-
return response.map(({ suggestion, tokensMap }) => ({
|
|
11
|
-
...suggestion,
|
|
12
|
-
tokensMap,
|
|
13
|
-
}));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async function searchTokens(tokens, index) {
|
|
17
|
-
const results = await Promise.all(
|
|
18
|
-
tokens.map((token) => searchInIndex(token, index))
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
return results.reduce(function (a, step, i) {
|
|
22
|
-
return { ...a, [tokens[i]]: step };
|
|
23
|
-
}, {});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function isValideSearch(search) {
|
|
27
|
-
if (typeof search === 'string' && search.trim().length) {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function filterSize(response, max) {
|
|
34
|
-
if (max && max < response.length) {
|
|
35
|
-
return response.slice(0, max);
|
|
36
|
-
}
|
|
37
|
-
return response;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async function searching(search, { name, version = '1' }) {
|
|
41
|
-
try {
|
|
42
|
-
if (isValideSearch(search)) {
|
|
43
|
-
const db = await getDb(name, version);
|
|
44
|
-
const info = await getEntity(db, CONSTANTES.STORE_INFO_NAME, name);
|
|
45
|
-
const { queryParser, max, order } = info;
|
|
46
|
-
const parser = await resolveQueryParser(queryParser);
|
|
47
|
-
const transaction = db.transaction(
|
|
48
|
-
CONSTANTES.STORE_DATA_NAME,
|
|
49
|
-
'readonly'
|
|
50
|
-
);
|
|
51
|
-
const store = transaction.objectStore(CONSTANTES.STORE_DATA_NAME);
|
|
52
|
-
const index = store.index(CONSTANTES.STORE_INDEX_NAME);
|
|
53
|
-
const tokens = parser(search);
|
|
54
|
-
const tokensSuggestions = await searchTokens(tokens, index);
|
|
55
|
-
const response = computeScore(tokensSuggestions);
|
|
56
|
-
return {
|
|
57
|
-
results: prepare(
|
|
58
|
-
getOrderingFunction(order)(filterSize(response, max), order)
|
|
59
|
-
),
|
|
60
|
-
search,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
return { results: [], search };
|
|
64
|
-
} catch (e) {
|
|
65
|
-
console.error(e);
|
|
66
|
-
throw e;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export default searching;
|
|
1
|
+
import getDb from './get-db';
|
|
2
|
+
import { CONSTANTES } from '../../store-tools';
|
|
3
|
+
import { getEntity } from '../../idb-tools';
|
|
4
|
+
import searchInIndex from './search-in-index';
|
|
5
|
+
import resolveQueryParser from './resolve-query-parser';
|
|
6
|
+
import computeScore from './compute-score';
|
|
7
|
+
import getOrderingFunction from './order';
|
|
8
|
+
|
|
9
|
+
function prepare(response) {
|
|
10
|
+
return response.map(({ suggestion, tokensMap }) => ({
|
|
11
|
+
...suggestion,
|
|
12
|
+
tokensMap,
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function searchTokens(tokens, index) {
|
|
17
|
+
const results = await Promise.all(
|
|
18
|
+
tokens.map((token) => searchInIndex(token, index))
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
return results.reduce(function (a, step, i) {
|
|
22
|
+
return { ...a, [tokens[i]]: step };
|
|
23
|
+
}, {});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function isValideSearch(search) {
|
|
27
|
+
if (typeof search === 'string' && search.trim().length) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function filterSize(response, max) {
|
|
34
|
+
if (max && max < response.length) {
|
|
35
|
+
return response.slice(0, max);
|
|
36
|
+
}
|
|
37
|
+
return response;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function searching(search, { name, version = '1' }) {
|
|
41
|
+
try {
|
|
42
|
+
if (isValideSearch(search)) {
|
|
43
|
+
const db = await getDb(name, version);
|
|
44
|
+
const info = await getEntity(db, CONSTANTES.STORE_INFO_NAME, name);
|
|
45
|
+
const { queryParser, max, order } = info;
|
|
46
|
+
const parser = await resolveQueryParser(queryParser);
|
|
47
|
+
const transaction = db.transaction(
|
|
48
|
+
CONSTANTES.STORE_DATA_NAME,
|
|
49
|
+
'readonly'
|
|
50
|
+
);
|
|
51
|
+
const store = transaction.objectStore(CONSTANTES.STORE_DATA_NAME);
|
|
52
|
+
const index = store.index(CONSTANTES.STORE_INDEX_NAME);
|
|
53
|
+
const tokens = parser(search);
|
|
54
|
+
const tokensSuggestions = await searchTokens(tokens, index);
|
|
55
|
+
const response = computeScore(tokensSuggestions);
|
|
56
|
+
return {
|
|
57
|
+
results: prepare(
|
|
58
|
+
getOrderingFunction(order)(filterSize(response, max), order)
|
|
59
|
+
),
|
|
60
|
+
search,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return { results: [], search };
|
|
64
|
+
} catch (e) {
|
|
65
|
+
console.error(e);
|
|
66
|
+
throw e;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default searching;
|