venue-js 1.4.0-next.4 → 1.4.0-next.6
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/index.d.mts +26 -7
- package/dist/index.d.ts +26 -7
- package/dist/index.js +1383 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1390 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -535,8 +535,8 @@ var createPopulator = ({
|
|
|
535
535
|
anchor_id,
|
|
536
536
|
venue_id,
|
|
537
537
|
local_category_ids,
|
|
538
|
-
promotion_ids,
|
|
539
|
-
privilege_ids,
|
|
538
|
+
promotion_ids = [],
|
|
539
|
+
privilege_ids = [],
|
|
540
540
|
kiosk_id,
|
|
541
541
|
unit_id,
|
|
542
542
|
kiosk_ids = [],
|
|
@@ -661,8 +661,1373 @@ var createPopulator = ({
|
|
|
661
661
|
};
|
|
662
662
|
};
|
|
663
663
|
|
|
664
|
+
// ../../node_modules/fuse.js/dist/fuse.mjs
|
|
665
|
+
function isArray(value) {
|
|
666
|
+
return !Array.isArray ? getTag(value) === "[object Array]" : Array.isArray(value);
|
|
667
|
+
}
|
|
668
|
+
var INFINITY = 1 / 0;
|
|
669
|
+
function baseToString(value) {
|
|
670
|
+
if (typeof value == "string") {
|
|
671
|
+
return value;
|
|
672
|
+
}
|
|
673
|
+
let result = value + "";
|
|
674
|
+
return result == "0" && 1 / value == -INFINITY ? "-0" : result;
|
|
675
|
+
}
|
|
676
|
+
function toString(value) {
|
|
677
|
+
return value == null ? "" : baseToString(value);
|
|
678
|
+
}
|
|
679
|
+
function isString(value) {
|
|
680
|
+
return typeof value === "string";
|
|
681
|
+
}
|
|
682
|
+
function isNumber(value) {
|
|
683
|
+
return typeof value === "number";
|
|
684
|
+
}
|
|
685
|
+
function isBoolean(value) {
|
|
686
|
+
return value === true || value === false || isObjectLike(value) && getTag(value) == "[object Boolean]";
|
|
687
|
+
}
|
|
688
|
+
function isObject(value) {
|
|
689
|
+
return typeof value === "object";
|
|
690
|
+
}
|
|
691
|
+
function isObjectLike(value) {
|
|
692
|
+
return isObject(value) && value !== null;
|
|
693
|
+
}
|
|
694
|
+
function isDefined(value) {
|
|
695
|
+
return value !== void 0 && value !== null;
|
|
696
|
+
}
|
|
697
|
+
function isBlank(value) {
|
|
698
|
+
return !value.trim().length;
|
|
699
|
+
}
|
|
700
|
+
function getTag(value) {
|
|
701
|
+
return value == null ? value === void 0 ? "[object Undefined]" : "[object Null]" : Object.prototype.toString.call(value);
|
|
702
|
+
}
|
|
703
|
+
var INCORRECT_INDEX_TYPE = "Incorrect 'index' type";
|
|
704
|
+
var LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY = (key) => `Invalid value for key ${key}`;
|
|
705
|
+
var PATTERN_LENGTH_TOO_LARGE = (max2) => `Pattern length exceeds max of ${max2}.`;
|
|
706
|
+
var MISSING_KEY_PROPERTY = (name) => `Missing ${name} property in key`;
|
|
707
|
+
var INVALID_KEY_WEIGHT_VALUE = (key) => `Property 'weight' in key '${key}' must be a positive integer`;
|
|
708
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
709
|
+
var KeyStore = class {
|
|
710
|
+
constructor(keys) {
|
|
711
|
+
this._keys = [];
|
|
712
|
+
this._keyMap = {};
|
|
713
|
+
let totalWeight = 0;
|
|
714
|
+
keys.forEach((key) => {
|
|
715
|
+
let obj = createKey(key);
|
|
716
|
+
this._keys.push(obj);
|
|
717
|
+
this._keyMap[obj.id] = obj;
|
|
718
|
+
totalWeight += obj.weight;
|
|
719
|
+
});
|
|
720
|
+
this._keys.forEach((key) => {
|
|
721
|
+
key.weight /= totalWeight;
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
get(keyId) {
|
|
725
|
+
return this._keyMap[keyId];
|
|
726
|
+
}
|
|
727
|
+
keys() {
|
|
728
|
+
return this._keys;
|
|
729
|
+
}
|
|
730
|
+
toJSON() {
|
|
731
|
+
return JSON.stringify(this._keys);
|
|
732
|
+
}
|
|
733
|
+
};
|
|
734
|
+
function createKey(key) {
|
|
735
|
+
let path = null;
|
|
736
|
+
let id = null;
|
|
737
|
+
let src = null;
|
|
738
|
+
let weight = 1;
|
|
739
|
+
let getFn = null;
|
|
740
|
+
if (isString(key) || isArray(key)) {
|
|
741
|
+
src = key;
|
|
742
|
+
path = createKeyPath(key);
|
|
743
|
+
id = createKeyId(key);
|
|
744
|
+
} else {
|
|
745
|
+
if (!hasOwn.call(key, "name")) {
|
|
746
|
+
throw new Error(MISSING_KEY_PROPERTY("name"));
|
|
747
|
+
}
|
|
748
|
+
const name = key.name;
|
|
749
|
+
src = name;
|
|
750
|
+
if (hasOwn.call(key, "weight")) {
|
|
751
|
+
weight = key.weight;
|
|
752
|
+
if (weight <= 0) {
|
|
753
|
+
throw new Error(INVALID_KEY_WEIGHT_VALUE(name));
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
path = createKeyPath(name);
|
|
757
|
+
id = createKeyId(name);
|
|
758
|
+
getFn = key.getFn;
|
|
759
|
+
}
|
|
760
|
+
return { path, id, weight, src, getFn };
|
|
761
|
+
}
|
|
762
|
+
function createKeyPath(key) {
|
|
763
|
+
return isArray(key) ? key : key.split(".");
|
|
764
|
+
}
|
|
765
|
+
function createKeyId(key) {
|
|
766
|
+
return isArray(key) ? key.join(".") : key;
|
|
767
|
+
}
|
|
768
|
+
function get(obj, path) {
|
|
769
|
+
let list = [];
|
|
770
|
+
let arr = false;
|
|
771
|
+
const deepGet = (obj2, path2, index) => {
|
|
772
|
+
if (!isDefined(obj2)) {
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
if (!path2[index]) {
|
|
776
|
+
list.push(obj2);
|
|
777
|
+
} else {
|
|
778
|
+
let key = path2[index];
|
|
779
|
+
const value = obj2[key];
|
|
780
|
+
if (!isDefined(value)) {
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
if (index === path2.length - 1 && (isString(value) || isNumber(value) || isBoolean(value))) {
|
|
784
|
+
list.push(toString(value));
|
|
785
|
+
} else if (isArray(value)) {
|
|
786
|
+
arr = true;
|
|
787
|
+
for (let i = 0, len = value.length; i < len; i += 1) {
|
|
788
|
+
deepGet(value[i], path2, index + 1);
|
|
789
|
+
}
|
|
790
|
+
} else if (path2.length) {
|
|
791
|
+
deepGet(value, path2, index + 1);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
deepGet(obj, isString(path) ? path.split(".") : path, 0);
|
|
796
|
+
return arr ? list : list[0];
|
|
797
|
+
}
|
|
798
|
+
var MatchOptions = {
|
|
799
|
+
// Whether the matches should be included in the result set. When `true`, each record in the result
|
|
800
|
+
// set will include the indices of the matched characters.
|
|
801
|
+
// These can consequently be used for highlighting purposes.
|
|
802
|
+
includeMatches: false,
|
|
803
|
+
// When `true`, the matching function will continue to the end of a search pattern even if
|
|
804
|
+
// a perfect match has already been located in the string.
|
|
805
|
+
findAllMatches: false,
|
|
806
|
+
// Minimum number of characters that must be matched before a result is considered a match
|
|
807
|
+
minMatchCharLength: 1
|
|
808
|
+
};
|
|
809
|
+
var BasicOptions = {
|
|
810
|
+
// When `true`, the algorithm continues searching to the end of the input even if a perfect
|
|
811
|
+
// match is found before the end of the same input.
|
|
812
|
+
isCaseSensitive: false,
|
|
813
|
+
// When `true`, the algorithm will ignore diacritics (accents) in comparisons
|
|
814
|
+
ignoreDiacritics: false,
|
|
815
|
+
// When true, the matching function will continue to the end of a search pattern even if
|
|
816
|
+
includeScore: false,
|
|
817
|
+
// List of properties that will be searched. This also supports nested properties.
|
|
818
|
+
keys: [],
|
|
819
|
+
// Whether to sort the result list, by score
|
|
820
|
+
shouldSort: true,
|
|
821
|
+
// Default sort function: sort by ascending score, ascending index
|
|
822
|
+
sortFn: (a, b) => a.score === b.score ? a.idx < b.idx ? -1 : 1 : a.score < b.score ? -1 : 1
|
|
823
|
+
};
|
|
824
|
+
var FuzzyOptions = {
|
|
825
|
+
// Approximately where in the text is the pattern expected to be found?
|
|
826
|
+
location: 0,
|
|
827
|
+
// At what point does the match algorithm give up. A threshold of '0.0' requires a perfect match
|
|
828
|
+
// (of both letters and location), a threshold of '1.0' would match anything.
|
|
829
|
+
threshold: 0.6,
|
|
830
|
+
// Determines how close the match must be to the fuzzy location (specified above).
|
|
831
|
+
// An exact letter match which is 'distance' characters away from the fuzzy location
|
|
832
|
+
// would score as a complete mismatch. A distance of '0' requires the match be at
|
|
833
|
+
// the exact location specified, a threshold of '1000' would require a perfect match
|
|
834
|
+
// to be within 800 characters of the fuzzy location to be found using a 0.8 threshold.
|
|
835
|
+
distance: 100
|
|
836
|
+
};
|
|
837
|
+
var AdvancedOptions = {
|
|
838
|
+
// When `true`, it enables the use of unix-like search commands
|
|
839
|
+
useExtendedSearch: false,
|
|
840
|
+
// The get function to use when fetching an object's properties.
|
|
841
|
+
// The default will search nested paths *ie foo.bar.baz*
|
|
842
|
+
getFn: get,
|
|
843
|
+
// When `true`, search will ignore `location` and `distance`, so it won't matter
|
|
844
|
+
// where in the string the pattern appears.
|
|
845
|
+
// More info: https://fusejs.io/concepts/scoring-theory.html#fuzziness-score
|
|
846
|
+
ignoreLocation: false,
|
|
847
|
+
// When `true`, the calculation for the relevance score (used for sorting) will
|
|
848
|
+
// ignore the field-length norm.
|
|
849
|
+
// More info: https://fusejs.io/concepts/scoring-theory.html#field-length-norm
|
|
850
|
+
ignoreFieldNorm: false,
|
|
851
|
+
// The weight to determine how much field length norm effects scoring.
|
|
852
|
+
fieldNormWeight: 1
|
|
853
|
+
};
|
|
854
|
+
var Config = {
|
|
855
|
+
...BasicOptions,
|
|
856
|
+
...MatchOptions,
|
|
857
|
+
...FuzzyOptions,
|
|
858
|
+
...AdvancedOptions
|
|
859
|
+
};
|
|
860
|
+
var SPACE = /[^ ]+/g;
|
|
861
|
+
function norm(weight = 1, mantissa = 3) {
|
|
862
|
+
const cache = /* @__PURE__ */ new Map();
|
|
863
|
+
const m = Math.pow(10, mantissa);
|
|
864
|
+
return {
|
|
865
|
+
get(value) {
|
|
866
|
+
const numTokens = value.match(SPACE).length;
|
|
867
|
+
if (cache.has(numTokens)) {
|
|
868
|
+
return cache.get(numTokens);
|
|
869
|
+
}
|
|
870
|
+
const norm2 = 1 / Math.pow(numTokens, 0.5 * weight);
|
|
871
|
+
const n = parseFloat(Math.round(norm2 * m) / m);
|
|
872
|
+
cache.set(numTokens, n);
|
|
873
|
+
return n;
|
|
874
|
+
},
|
|
875
|
+
clear() {
|
|
876
|
+
cache.clear();
|
|
877
|
+
}
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
var FuseIndex = class {
|
|
881
|
+
constructor({
|
|
882
|
+
getFn = Config.getFn,
|
|
883
|
+
fieldNormWeight = Config.fieldNormWeight
|
|
884
|
+
} = {}) {
|
|
885
|
+
this.norm = norm(fieldNormWeight, 3);
|
|
886
|
+
this.getFn = getFn;
|
|
887
|
+
this.isCreated = false;
|
|
888
|
+
this.setIndexRecords();
|
|
889
|
+
}
|
|
890
|
+
setSources(docs = []) {
|
|
891
|
+
this.docs = docs;
|
|
892
|
+
}
|
|
893
|
+
setIndexRecords(records = []) {
|
|
894
|
+
this.records = records;
|
|
895
|
+
}
|
|
896
|
+
setKeys(keys = []) {
|
|
897
|
+
this.keys = keys;
|
|
898
|
+
this._keysMap = {};
|
|
899
|
+
keys.forEach((key, idx) => {
|
|
900
|
+
this._keysMap[key.id] = idx;
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
create() {
|
|
904
|
+
if (this.isCreated || !this.docs.length) {
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
this.isCreated = true;
|
|
908
|
+
if (isString(this.docs[0])) {
|
|
909
|
+
this.docs.forEach((doc, docIndex) => {
|
|
910
|
+
this._addString(doc, docIndex);
|
|
911
|
+
});
|
|
912
|
+
} else {
|
|
913
|
+
this.docs.forEach((doc, docIndex) => {
|
|
914
|
+
this._addObject(doc, docIndex);
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
this.norm.clear();
|
|
918
|
+
}
|
|
919
|
+
// Adds a doc to the end of the index
|
|
920
|
+
add(doc) {
|
|
921
|
+
const idx = this.size();
|
|
922
|
+
if (isString(doc)) {
|
|
923
|
+
this._addString(doc, idx);
|
|
924
|
+
} else {
|
|
925
|
+
this._addObject(doc, idx);
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
// Removes the doc at the specified index of the index
|
|
929
|
+
removeAt(idx) {
|
|
930
|
+
this.records.splice(idx, 1);
|
|
931
|
+
for (let i = idx, len = this.size(); i < len; i += 1) {
|
|
932
|
+
this.records[i].i -= 1;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
getValueForItemAtKeyId(item, keyId) {
|
|
936
|
+
return item[this._keysMap[keyId]];
|
|
937
|
+
}
|
|
938
|
+
size() {
|
|
939
|
+
return this.records.length;
|
|
940
|
+
}
|
|
941
|
+
_addString(doc, docIndex) {
|
|
942
|
+
if (!isDefined(doc) || isBlank(doc)) {
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
let record = {
|
|
946
|
+
v: doc,
|
|
947
|
+
i: docIndex,
|
|
948
|
+
n: this.norm.get(doc)
|
|
949
|
+
};
|
|
950
|
+
this.records.push(record);
|
|
951
|
+
}
|
|
952
|
+
_addObject(doc, docIndex) {
|
|
953
|
+
let record = { i: docIndex, $: {} };
|
|
954
|
+
this.keys.forEach((key, keyIndex) => {
|
|
955
|
+
let value = key.getFn ? key.getFn(doc) : this.getFn(doc, key.path);
|
|
956
|
+
if (!isDefined(value)) {
|
|
957
|
+
return;
|
|
958
|
+
}
|
|
959
|
+
if (isArray(value)) {
|
|
960
|
+
let subRecords = [];
|
|
961
|
+
const stack = [{ nestedArrIndex: -1, value }];
|
|
962
|
+
while (stack.length) {
|
|
963
|
+
const { nestedArrIndex, value: value2 } = stack.pop();
|
|
964
|
+
if (!isDefined(value2)) {
|
|
965
|
+
continue;
|
|
966
|
+
}
|
|
967
|
+
if (isString(value2) && !isBlank(value2)) {
|
|
968
|
+
let subRecord = {
|
|
969
|
+
v: value2,
|
|
970
|
+
i: nestedArrIndex,
|
|
971
|
+
n: this.norm.get(value2)
|
|
972
|
+
};
|
|
973
|
+
subRecords.push(subRecord);
|
|
974
|
+
} else if (isArray(value2)) {
|
|
975
|
+
value2.forEach((item, k) => {
|
|
976
|
+
stack.push({
|
|
977
|
+
nestedArrIndex: k,
|
|
978
|
+
value: item
|
|
979
|
+
});
|
|
980
|
+
});
|
|
981
|
+
} else ;
|
|
982
|
+
}
|
|
983
|
+
record.$[keyIndex] = subRecords;
|
|
984
|
+
} else if (isString(value) && !isBlank(value)) {
|
|
985
|
+
let subRecord = {
|
|
986
|
+
v: value,
|
|
987
|
+
n: this.norm.get(value)
|
|
988
|
+
};
|
|
989
|
+
record.$[keyIndex] = subRecord;
|
|
990
|
+
}
|
|
991
|
+
});
|
|
992
|
+
this.records.push(record);
|
|
993
|
+
}
|
|
994
|
+
toJSON() {
|
|
995
|
+
return {
|
|
996
|
+
keys: this.keys,
|
|
997
|
+
records: this.records
|
|
998
|
+
};
|
|
999
|
+
}
|
|
1000
|
+
};
|
|
1001
|
+
function createIndex(keys, docs, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
|
|
1002
|
+
const myIndex = new FuseIndex({ getFn, fieldNormWeight });
|
|
1003
|
+
myIndex.setKeys(keys.map(createKey));
|
|
1004
|
+
myIndex.setSources(docs);
|
|
1005
|
+
myIndex.create();
|
|
1006
|
+
return myIndex;
|
|
1007
|
+
}
|
|
1008
|
+
function parseIndex(data, { getFn = Config.getFn, fieldNormWeight = Config.fieldNormWeight } = {}) {
|
|
1009
|
+
const { keys, records } = data;
|
|
1010
|
+
const myIndex = new FuseIndex({ getFn, fieldNormWeight });
|
|
1011
|
+
myIndex.setKeys(keys);
|
|
1012
|
+
myIndex.setIndexRecords(records);
|
|
1013
|
+
return myIndex;
|
|
1014
|
+
}
|
|
1015
|
+
function computeScore$1(pattern, {
|
|
1016
|
+
errors = 0,
|
|
1017
|
+
currentLocation = 0,
|
|
1018
|
+
expectedLocation = 0,
|
|
1019
|
+
distance = Config.distance,
|
|
1020
|
+
ignoreLocation = Config.ignoreLocation
|
|
1021
|
+
} = {}) {
|
|
1022
|
+
const accuracy = errors / pattern.length;
|
|
1023
|
+
if (ignoreLocation) {
|
|
1024
|
+
return accuracy;
|
|
1025
|
+
}
|
|
1026
|
+
const proximity = Math.abs(expectedLocation - currentLocation);
|
|
1027
|
+
if (!distance) {
|
|
1028
|
+
return proximity ? 1 : accuracy;
|
|
1029
|
+
}
|
|
1030
|
+
return accuracy + proximity / distance;
|
|
1031
|
+
}
|
|
1032
|
+
function convertMaskToIndices(matchmask = [], minMatchCharLength = Config.minMatchCharLength) {
|
|
1033
|
+
let indices = [];
|
|
1034
|
+
let start = -1;
|
|
1035
|
+
let end = -1;
|
|
1036
|
+
let i = 0;
|
|
1037
|
+
for (let len = matchmask.length; i < len; i += 1) {
|
|
1038
|
+
let match = matchmask[i];
|
|
1039
|
+
if (match && start === -1) {
|
|
1040
|
+
start = i;
|
|
1041
|
+
} else if (!match && start !== -1) {
|
|
1042
|
+
end = i - 1;
|
|
1043
|
+
if (end - start + 1 >= minMatchCharLength) {
|
|
1044
|
+
indices.push([start, end]);
|
|
1045
|
+
}
|
|
1046
|
+
start = -1;
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
if (matchmask[i - 1] && i - start >= minMatchCharLength) {
|
|
1050
|
+
indices.push([start, i - 1]);
|
|
1051
|
+
}
|
|
1052
|
+
return indices;
|
|
1053
|
+
}
|
|
1054
|
+
var MAX_BITS = 32;
|
|
1055
|
+
function search(text, pattern, patternAlphabet, {
|
|
1056
|
+
location = Config.location,
|
|
1057
|
+
distance = Config.distance,
|
|
1058
|
+
threshold = Config.threshold,
|
|
1059
|
+
findAllMatches = Config.findAllMatches,
|
|
1060
|
+
minMatchCharLength = Config.minMatchCharLength,
|
|
1061
|
+
includeMatches = Config.includeMatches,
|
|
1062
|
+
ignoreLocation = Config.ignoreLocation
|
|
1063
|
+
} = {}) {
|
|
1064
|
+
if (pattern.length > MAX_BITS) {
|
|
1065
|
+
throw new Error(PATTERN_LENGTH_TOO_LARGE(MAX_BITS));
|
|
1066
|
+
}
|
|
1067
|
+
const patternLen = pattern.length;
|
|
1068
|
+
const textLen = text.length;
|
|
1069
|
+
const expectedLocation = Math.max(0, Math.min(location, textLen));
|
|
1070
|
+
let currentThreshold = threshold;
|
|
1071
|
+
let bestLocation = expectedLocation;
|
|
1072
|
+
const computeMatches = minMatchCharLength > 1 || includeMatches;
|
|
1073
|
+
const matchMask = computeMatches ? Array(textLen) : [];
|
|
1074
|
+
let index;
|
|
1075
|
+
while ((index = text.indexOf(pattern, bestLocation)) > -1) {
|
|
1076
|
+
let score = computeScore$1(pattern, {
|
|
1077
|
+
currentLocation: index,
|
|
1078
|
+
expectedLocation,
|
|
1079
|
+
distance,
|
|
1080
|
+
ignoreLocation
|
|
1081
|
+
});
|
|
1082
|
+
currentThreshold = Math.min(score, currentThreshold);
|
|
1083
|
+
bestLocation = index + patternLen;
|
|
1084
|
+
if (computeMatches) {
|
|
1085
|
+
let i = 0;
|
|
1086
|
+
while (i < patternLen) {
|
|
1087
|
+
matchMask[index + i] = 1;
|
|
1088
|
+
i += 1;
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
bestLocation = -1;
|
|
1093
|
+
let lastBitArr = [];
|
|
1094
|
+
let finalScore = 1;
|
|
1095
|
+
let binMax = patternLen + textLen;
|
|
1096
|
+
const mask = 1 << patternLen - 1;
|
|
1097
|
+
for (let i = 0; i < patternLen; i += 1) {
|
|
1098
|
+
let binMin = 0;
|
|
1099
|
+
let binMid = binMax;
|
|
1100
|
+
while (binMin < binMid) {
|
|
1101
|
+
const score2 = computeScore$1(pattern, {
|
|
1102
|
+
errors: i,
|
|
1103
|
+
currentLocation: expectedLocation + binMid,
|
|
1104
|
+
expectedLocation,
|
|
1105
|
+
distance,
|
|
1106
|
+
ignoreLocation
|
|
1107
|
+
});
|
|
1108
|
+
if (score2 <= currentThreshold) {
|
|
1109
|
+
binMin = binMid;
|
|
1110
|
+
} else {
|
|
1111
|
+
binMax = binMid;
|
|
1112
|
+
}
|
|
1113
|
+
binMid = Math.floor((binMax - binMin) / 2 + binMin);
|
|
1114
|
+
}
|
|
1115
|
+
binMax = binMid;
|
|
1116
|
+
let start = Math.max(1, expectedLocation - binMid + 1);
|
|
1117
|
+
let finish = findAllMatches ? textLen : Math.min(expectedLocation + binMid, textLen) + patternLen;
|
|
1118
|
+
let bitArr = Array(finish + 2);
|
|
1119
|
+
bitArr[finish + 1] = (1 << i) - 1;
|
|
1120
|
+
for (let j = finish; j >= start; j -= 1) {
|
|
1121
|
+
let currentLocation = j - 1;
|
|
1122
|
+
let charMatch = patternAlphabet[text.charAt(currentLocation)];
|
|
1123
|
+
if (computeMatches) {
|
|
1124
|
+
matchMask[currentLocation] = +!!charMatch;
|
|
1125
|
+
}
|
|
1126
|
+
bitArr[j] = (bitArr[j + 1] << 1 | 1) & charMatch;
|
|
1127
|
+
if (i) {
|
|
1128
|
+
bitArr[j] |= (lastBitArr[j + 1] | lastBitArr[j]) << 1 | 1 | lastBitArr[j + 1];
|
|
1129
|
+
}
|
|
1130
|
+
if (bitArr[j] & mask) {
|
|
1131
|
+
finalScore = computeScore$1(pattern, {
|
|
1132
|
+
errors: i,
|
|
1133
|
+
currentLocation,
|
|
1134
|
+
expectedLocation,
|
|
1135
|
+
distance,
|
|
1136
|
+
ignoreLocation
|
|
1137
|
+
});
|
|
1138
|
+
if (finalScore <= currentThreshold) {
|
|
1139
|
+
currentThreshold = finalScore;
|
|
1140
|
+
bestLocation = currentLocation;
|
|
1141
|
+
if (bestLocation <= expectedLocation) {
|
|
1142
|
+
break;
|
|
1143
|
+
}
|
|
1144
|
+
start = Math.max(1, 2 * expectedLocation - bestLocation);
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
const score = computeScore$1(pattern, {
|
|
1149
|
+
errors: i + 1,
|
|
1150
|
+
currentLocation: expectedLocation,
|
|
1151
|
+
expectedLocation,
|
|
1152
|
+
distance,
|
|
1153
|
+
ignoreLocation
|
|
1154
|
+
});
|
|
1155
|
+
if (score > currentThreshold) {
|
|
1156
|
+
break;
|
|
1157
|
+
}
|
|
1158
|
+
lastBitArr = bitArr;
|
|
1159
|
+
}
|
|
1160
|
+
const result = {
|
|
1161
|
+
isMatch: bestLocation >= 0,
|
|
1162
|
+
// Count exact matches (those with a score of 0) to be "almost" exact
|
|
1163
|
+
score: Math.max(1e-3, finalScore)
|
|
1164
|
+
};
|
|
1165
|
+
if (computeMatches) {
|
|
1166
|
+
const indices = convertMaskToIndices(matchMask, minMatchCharLength);
|
|
1167
|
+
if (!indices.length) {
|
|
1168
|
+
result.isMatch = false;
|
|
1169
|
+
} else if (includeMatches) {
|
|
1170
|
+
result.indices = indices;
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
return result;
|
|
1174
|
+
}
|
|
1175
|
+
function createPatternAlphabet(pattern) {
|
|
1176
|
+
let mask = {};
|
|
1177
|
+
for (let i = 0, len = pattern.length; i < len; i += 1) {
|
|
1178
|
+
const char = pattern.charAt(i);
|
|
1179
|
+
mask[char] = (mask[char] || 0) | 1 << len - i - 1;
|
|
1180
|
+
}
|
|
1181
|
+
return mask;
|
|
1182
|
+
}
|
|
1183
|
+
var stripDiacritics = String.prototype.normalize ? ((str) => str.normalize("NFD").replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g, "")) : ((str) => str);
|
|
1184
|
+
var BitapSearch = class {
|
|
1185
|
+
constructor(pattern, {
|
|
1186
|
+
location = Config.location,
|
|
1187
|
+
threshold = Config.threshold,
|
|
1188
|
+
distance = Config.distance,
|
|
1189
|
+
includeMatches = Config.includeMatches,
|
|
1190
|
+
findAllMatches = Config.findAllMatches,
|
|
1191
|
+
minMatchCharLength = Config.minMatchCharLength,
|
|
1192
|
+
isCaseSensitive = Config.isCaseSensitive,
|
|
1193
|
+
ignoreDiacritics = Config.ignoreDiacritics,
|
|
1194
|
+
ignoreLocation = Config.ignoreLocation
|
|
1195
|
+
} = {}) {
|
|
1196
|
+
this.options = {
|
|
1197
|
+
location,
|
|
1198
|
+
threshold,
|
|
1199
|
+
distance,
|
|
1200
|
+
includeMatches,
|
|
1201
|
+
findAllMatches,
|
|
1202
|
+
minMatchCharLength,
|
|
1203
|
+
isCaseSensitive,
|
|
1204
|
+
ignoreDiacritics,
|
|
1205
|
+
ignoreLocation
|
|
1206
|
+
};
|
|
1207
|
+
pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
|
|
1208
|
+
pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
|
|
1209
|
+
this.pattern = pattern;
|
|
1210
|
+
this.chunks = [];
|
|
1211
|
+
if (!this.pattern.length) {
|
|
1212
|
+
return;
|
|
1213
|
+
}
|
|
1214
|
+
const addChunk = (pattern2, startIndex) => {
|
|
1215
|
+
this.chunks.push({
|
|
1216
|
+
pattern: pattern2,
|
|
1217
|
+
alphabet: createPatternAlphabet(pattern2),
|
|
1218
|
+
startIndex
|
|
1219
|
+
});
|
|
1220
|
+
};
|
|
1221
|
+
const len = this.pattern.length;
|
|
1222
|
+
if (len > MAX_BITS) {
|
|
1223
|
+
let i = 0;
|
|
1224
|
+
const remainder = len % MAX_BITS;
|
|
1225
|
+
const end = len - remainder;
|
|
1226
|
+
while (i < end) {
|
|
1227
|
+
addChunk(this.pattern.substr(i, MAX_BITS), i);
|
|
1228
|
+
i += MAX_BITS;
|
|
1229
|
+
}
|
|
1230
|
+
if (remainder) {
|
|
1231
|
+
const startIndex = len - MAX_BITS;
|
|
1232
|
+
addChunk(this.pattern.substr(startIndex), startIndex);
|
|
1233
|
+
}
|
|
1234
|
+
} else {
|
|
1235
|
+
addChunk(this.pattern, 0);
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
searchIn(text) {
|
|
1239
|
+
const { isCaseSensitive, ignoreDiacritics, includeMatches } = this.options;
|
|
1240
|
+
text = isCaseSensitive ? text : text.toLowerCase();
|
|
1241
|
+
text = ignoreDiacritics ? stripDiacritics(text) : text;
|
|
1242
|
+
if (this.pattern === text) {
|
|
1243
|
+
let result2 = {
|
|
1244
|
+
isMatch: true,
|
|
1245
|
+
score: 0
|
|
1246
|
+
};
|
|
1247
|
+
if (includeMatches) {
|
|
1248
|
+
result2.indices = [[0, text.length - 1]];
|
|
1249
|
+
}
|
|
1250
|
+
return result2;
|
|
1251
|
+
}
|
|
1252
|
+
const {
|
|
1253
|
+
location,
|
|
1254
|
+
distance,
|
|
1255
|
+
threshold,
|
|
1256
|
+
findAllMatches,
|
|
1257
|
+
minMatchCharLength,
|
|
1258
|
+
ignoreLocation
|
|
1259
|
+
} = this.options;
|
|
1260
|
+
let allIndices = [];
|
|
1261
|
+
let totalScore = 0;
|
|
1262
|
+
let hasMatches = false;
|
|
1263
|
+
this.chunks.forEach(({ pattern, alphabet, startIndex }) => {
|
|
1264
|
+
const { isMatch, score, indices } = search(text, pattern, alphabet, {
|
|
1265
|
+
location: location + startIndex,
|
|
1266
|
+
distance,
|
|
1267
|
+
threshold,
|
|
1268
|
+
findAllMatches,
|
|
1269
|
+
minMatchCharLength,
|
|
1270
|
+
includeMatches,
|
|
1271
|
+
ignoreLocation
|
|
1272
|
+
});
|
|
1273
|
+
if (isMatch) {
|
|
1274
|
+
hasMatches = true;
|
|
1275
|
+
}
|
|
1276
|
+
totalScore += score;
|
|
1277
|
+
if (isMatch && indices) {
|
|
1278
|
+
allIndices = [...allIndices, ...indices];
|
|
1279
|
+
}
|
|
1280
|
+
});
|
|
1281
|
+
let result = {
|
|
1282
|
+
isMatch: hasMatches,
|
|
1283
|
+
score: hasMatches ? totalScore / this.chunks.length : 1
|
|
1284
|
+
};
|
|
1285
|
+
if (hasMatches && includeMatches) {
|
|
1286
|
+
result.indices = allIndices;
|
|
1287
|
+
}
|
|
1288
|
+
return result;
|
|
1289
|
+
}
|
|
1290
|
+
};
|
|
1291
|
+
var BaseMatch = class {
|
|
1292
|
+
constructor(pattern) {
|
|
1293
|
+
this.pattern = pattern;
|
|
1294
|
+
}
|
|
1295
|
+
static isMultiMatch(pattern) {
|
|
1296
|
+
return getMatch(pattern, this.multiRegex);
|
|
1297
|
+
}
|
|
1298
|
+
static isSingleMatch(pattern) {
|
|
1299
|
+
return getMatch(pattern, this.singleRegex);
|
|
1300
|
+
}
|
|
1301
|
+
search() {
|
|
1302
|
+
}
|
|
1303
|
+
};
|
|
1304
|
+
function getMatch(pattern, exp) {
|
|
1305
|
+
const matches = pattern.match(exp);
|
|
1306
|
+
return matches ? matches[1] : null;
|
|
1307
|
+
}
|
|
1308
|
+
var ExactMatch = class extends BaseMatch {
|
|
1309
|
+
constructor(pattern) {
|
|
1310
|
+
super(pattern);
|
|
1311
|
+
}
|
|
1312
|
+
static get type() {
|
|
1313
|
+
return "exact";
|
|
1314
|
+
}
|
|
1315
|
+
static get multiRegex() {
|
|
1316
|
+
return /^="(.*)"$/;
|
|
1317
|
+
}
|
|
1318
|
+
static get singleRegex() {
|
|
1319
|
+
return /^=(.*)$/;
|
|
1320
|
+
}
|
|
1321
|
+
search(text) {
|
|
1322
|
+
const isMatch = text === this.pattern;
|
|
1323
|
+
return {
|
|
1324
|
+
isMatch,
|
|
1325
|
+
score: isMatch ? 0 : 1,
|
|
1326
|
+
indices: [0, this.pattern.length - 1]
|
|
1327
|
+
};
|
|
1328
|
+
}
|
|
1329
|
+
};
|
|
1330
|
+
var InverseExactMatch = class extends BaseMatch {
|
|
1331
|
+
constructor(pattern) {
|
|
1332
|
+
super(pattern);
|
|
1333
|
+
}
|
|
1334
|
+
static get type() {
|
|
1335
|
+
return "inverse-exact";
|
|
1336
|
+
}
|
|
1337
|
+
static get multiRegex() {
|
|
1338
|
+
return /^!"(.*)"$/;
|
|
1339
|
+
}
|
|
1340
|
+
static get singleRegex() {
|
|
1341
|
+
return /^!(.*)$/;
|
|
1342
|
+
}
|
|
1343
|
+
search(text) {
|
|
1344
|
+
const index = text.indexOf(this.pattern);
|
|
1345
|
+
const isMatch = index === -1;
|
|
1346
|
+
return {
|
|
1347
|
+
isMatch,
|
|
1348
|
+
score: isMatch ? 0 : 1,
|
|
1349
|
+
indices: [0, text.length - 1]
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1352
|
+
};
|
|
1353
|
+
var PrefixExactMatch = class extends BaseMatch {
|
|
1354
|
+
constructor(pattern) {
|
|
1355
|
+
super(pattern);
|
|
1356
|
+
}
|
|
1357
|
+
static get type() {
|
|
1358
|
+
return "prefix-exact";
|
|
1359
|
+
}
|
|
1360
|
+
static get multiRegex() {
|
|
1361
|
+
return /^\^"(.*)"$/;
|
|
1362
|
+
}
|
|
1363
|
+
static get singleRegex() {
|
|
1364
|
+
return /^\^(.*)$/;
|
|
1365
|
+
}
|
|
1366
|
+
search(text) {
|
|
1367
|
+
const isMatch = text.startsWith(this.pattern);
|
|
1368
|
+
return {
|
|
1369
|
+
isMatch,
|
|
1370
|
+
score: isMatch ? 0 : 1,
|
|
1371
|
+
indices: [0, this.pattern.length - 1]
|
|
1372
|
+
};
|
|
1373
|
+
}
|
|
1374
|
+
};
|
|
1375
|
+
var InversePrefixExactMatch = class extends BaseMatch {
|
|
1376
|
+
constructor(pattern) {
|
|
1377
|
+
super(pattern);
|
|
1378
|
+
}
|
|
1379
|
+
static get type() {
|
|
1380
|
+
return "inverse-prefix-exact";
|
|
1381
|
+
}
|
|
1382
|
+
static get multiRegex() {
|
|
1383
|
+
return /^!\^"(.*)"$/;
|
|
1384
|
+
}
|
|
1385
|
+
static get singleRegex() {
|
|
1386
|
+
return /^!\^(.*)$/;
|
|
1387
|
+
}
|
|
1388
|
+
search(text) {
|
|
1389
|
+
const isMatch = !text.startsWith(this.pattern);
|
|
1390
|
+
return {
|
|
1391
|
+
isMatch,
|
|
1392
|
+
score: isMatch ? 0 : 1,
|
|
1393
|
+
indices: [0, text.length - 1]
|
|
1394
|
+
};
|
|
1395
|
+
}
|
|
1396
|
+
};
|
|
1397
|
+
var SuffixExactMatch = class extends BaseMatch {
|
|
1398
|
+
constructor(pattern) {
|
|
1399
|
+
super(pattern);
|
|
1400
|
+
}
|
|
1401
|
+
static get type() {
|
|
1402
|
+
return "suffix-exact";
|
|
1403
|
+
}
|
|
1404
|
+
static get multiRegex() {
|
|
1405
|
+
return /^"(.*)"\$$/;
|
|
1406
|
+
}
|
|
1407
|
+
static get singleRegex() {
|
|
1408
|
+
return /^(.*)\$$/;
|
|
1409
|
+
}
|
|
1410
|
+
search(text) {
|
|
1411
|
+
const isMatch = text.endsWith(this.pattern);
|
|
1412
|
+
return {
|
|
1413
|
+
isMatch,
|
|
1414
|
+
score: isMatch ? 0 : 1,
|
|
1415
|
+
indices: [text.length - this.pattern.length, text.length - 1]
|
|
1416
|
+
};
|
|
1417
|
+
}
|
|
1418
|
+
};
|
|
1419
|
+
var InverseSuffixExactMatch = class extends BaseMatch {
|
|
1420
|
+
constructor(pattern) {
|
|
1421
|
+
super(pattern);
|
|
1422
|
+
}
|
|
1423
|
+
static get type() {
|
|
1424
|
+
return "inverse-suffix-exact";
|
|
1425
|
+
}
|
|
1426
|
+
static get multiRegex() {
|
|
1427
|
+
return /^!"(.*)"\$$/;
|
|
1428
|
+
}
|
|
1429
|
+
static get singleRegex() {
|
|
1430
|
+
return /^!(.*)\$$/;
|
|
1431
|
+
}
|
|
1432
|
+
search(text) {
|
|
1433
|
+
const isMatch = !text.endsWith(this.pattern);
|
|
1434
|
+
return {
|
|
1435
|
+
isMatch,
|
|
1436
|
+
score: isMatch ? 0 : 1,
|
|
1437
|
+
indices: [0, text.length - 1]
|
|
1438
|
+
};
|
|
1439
|
+
}
|
|
1440
|
+
};
|
|
1441
|
+
var FuzzyMatch = class extends BaseMatch {
|
|
1442
|
+
constructor(pattern, {
|
|
1443
|
+
location = Config.location,
|
|
1444
|
+
threshold = Config.threshold,
|
|
1445
|
+
distance = Config.distance,
|
|
1446
|
+
includeMatches = Config.includeMatches,
|
|
1447
|
+
findAllMatches = Config.findAllMatches,
|
|
1448
|
+
minMatchCharLength = Config.minMatchCharLength,
|
|
1449
|
+
isCaseSensitive = Config.isCaseSensitive,
|
|
1450
|
+
ignoreDiacritics = Config.ignoreDiacritics,
|
|
1451
|
+
ignoreLocation = Config.ignoreLocation
|
|
1452
|
+
} = {}) {
|
|
1453
|
+
super(pattern);
|
|
1454
|
+
this._bitapSearch = new BitapSearch(pattern, {
|
|
1455
|
+
location,
|
|
1456
|
+
threshold,
|
|
1457
|
+
distance,
|
|
1458
|
+
includeMatches,
|
|
1459
|
+
findAllMatches,
|
|
1460
|
+
minMatchCharLength,
|
|
1461
|
+
isCaseSensitive,
|
|
1462
|
+
ignoreDiacritics,
|
|
1463
|
+
ignoreLocation
|
|
1464
|
+
});
|
|
1465
|
+
}
|
|
1466
|
+
static get type() {
|
|
1467
|
+
return "fuzzy";
|
|
1468
|
+
}
|
|
1469
|
+
static get multiRegex() {
|
|
1470
|
+
return /^"(.*)"$/;
|
|
1471
|
+
}
|
|
1472
|
+
static get singleRegex() {
|
|
1473
|
+
return /^(.*)$/;
|
|
1474
|
+
}
|
|
1475
|
+
search(text) {
|
|
1476
|
+
return this._bitapSearch.searchIn(text);
|
|
1477
|
+
}
|
|
1478
|
+
};
|
|
1479
|
+
var IncludeMatch = class extends BaseMatch {
|
|
1480
|
+
constructor(pattern) {
|
|
1481
|
+
super(pattern);
|
|
1482
|
+
}
|
|
1483
|
+
static get type() {
|
|
1484
|
+
return "include";
|
|
1485
|
+
}
|
|
1486
|
+
static get multiRegex() {
|
|
1487
|
+
return /^'"(.*)"$/;
|
|
1488
|
+
}
|
|
1489
|
+
static get singleRegex() {
|
|
1490
|
+
return /^'(.*)$/;
|
|
1491
|
+
}
|
|
1492
|
+
search(text) {
|
|
1493
|
+
let location = 0;
|
|
1494
|
+
let index;
|
|
1495
|
+
const indices = [];
|
|
1496
|
+
const patternLen = this.pattern.length;
|
|
1497
|
+
while ((index = text.indexOf(this.pattern, location)) > -1) {
|
|
1498
|
+
location = index + patternLen;
|
|
1499
|
+
indices.push([index, location - 1]);
|
|
1500
|
+
}
|
|
1501
|
+
const isMatch = !!indices.length;
|
|
1502
|
+
return {
|
|
1503
|
+
isMatch,
|
|
1504
|
+
score: isMatch ? 0 : 1,
|
|
1505
|
+
indices
|
|
1506
|
+
};
|
|
1507
|
+
}
|
|
1508
|
+
};
|
|
1509
|
+
var searchers = [
|
|
1510
|
+
ExactMatch,
|
|
1511
|
+
IncludeMatch,
|
|
1512
|
+
PrefixExactMatch,
|
|
1513
|
+
InversePrefixExactMatch,
|
|
1514
|
+
InverseSuffixExactMatch,
|
|
1515
|
+
SuffixExactMatch,
|
|
1516
|
+
InverseExactMatch,
|
|
1517
|
+
FuzzyMatch
|
|
1518
|
+
];
|
|
1519
|
+
var searchersLen = searchers.length;
|
|
1520
|
+
var SPACE_RE = / +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/;
|
|
1521
|
+
var OR_TOKEN = "|";
|
|
1522
|
+
function parseQuery(pattern, options = {}) {
|
|
1523
|
+
return pattern.split(OR_TOKEN).map((item) => {
|
|
1524
|
+
let query = item.trim().split(SPACE_RE).filter((item2) => item2 && !!item2.trim());
|
|
1525
|
+
let results = [];
|
|
1526
|
+
for (let i = 0, len = query.length; i < len; i += 1) {
|
|
1527
|
+
const queryItem = query[i];
|
|
1528
|
+
let found = false;
|
|
1529
|
+
let idx = -1;
|
|
1530
|
+
while (!found && ++idx < searchersLen) {
|
|
1531
|
+
const searcher = searchers[idx];
|
|
1532
|
+
let token = searcher.isMultiMatch(queryItem);
|
|
1533
|
+
if (token) {
|
|
1534
|
+
results.push(new searcher(token, options));
|
|
1535
|
+
found = true;
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
if (found) {
|
|
1539
|
+
continue;
|
|
1540
|
+
}
|
|
1541
|
+
idx = -1;
|
|
1542
|
+
while (++idx < searchersLen) {
|
|
1543
|
+
const searcher = searchers[idx];
|
|
1544
|
+
let token = searcher.isSingleMatch(queryItem);
|
|
1545
|
+
if (token) {
|
|
1546
|
+
results.push(new searcher(token, options));
|
|
1547
|
+
break;
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
return results;
|
|
1552
|
+
});
|
|
1553
|
+
}
|
|
1554
|
+
var MultiMatchSet = /* @__PURE__ */ new Set([FuzzyMatch.type, IncludeMatch.type]);
|
|
1555
|
+
var ExtendedSearch = class {
|
|
1556
|
+
constructor(pattern, {
|
|
1557
|
+
isCaseSensitive = Config.isCaseSensitive,
|
|
1558
|
+
ignoreDiacritics = Config.ignoreDiacritics,
|
|
1559
|
+
includeMatches = Config.includeMatches,
|
|
1560
|
+
minMatchCharLength = Config.minMatchCharLength,
|
|
1561
|
+
ignoreLocation = Config.ignoreLocation,
|
|
1562
|
+
findAllMatches = Config.findAllMatches,
|
|
1563
|
+
location = Config.location,
|
|
1564
|
+
threshold = Config.threshold,
|
|
1565
|
+
distance = Config.distance
|
|
1566
|
+
} = {}) {
|
|
1567
|
+
this.query = null;
|
|
1568
|
+
this.options = {
|
|
1569
|
+
isCaseSensitive,
|
|
1570
|
+
ignoreDiacritics,
|
|
1571
|
+
includeMatches,
|
|
1572
|
+
minMatchCharLength,
|
|
1573
|
+
findAllMatches,
|
|
1574
|
+
ignoreLocation,
|
|
1575
|
+
location,
|
|
1576
|
+
threshold,
|
|
1577
|
+
distance
|
|
1578
|
+
};
|
|
1579
|
+
pattern = isCaseSensitive ? pattern : pattern.toLowerCase();
|
|
1580
|
+
pattern = ignoreDiacritics ? stripDiacritics(pattern) : pattern;
|
|
1581
|
+
this.pattern = pattern;
|
|
1582
|
+
this.query = parseQuery(this.pattern, this.options);
|
|
1583
|
+
}
|
|
1584
|
+
static condition(_6, options) {
|
|
1585
|
+
return options.useExtendedSearch;
|
|
1586
|
+
}
|
|
1587
|
+
searchIn(text) {
|
|
1588
|
+
const query = this.query;
|
|
1589
|
+
if (!query) {
|
|
1590
|
+
return {
|
|
1591
|
+
isMatch: false,
|
|
1592
|
+
score: 1
|
|
1593
|
+
};
|
|
1594
|
+
}
|
|
1595
|
+
const { includeMatches, isCaseSensitive, ignoreDiacritics } = this.options;
|
|
1596
|
+
text = isCaseSensitive ? text : text.toLowerCase();
|
|
1597
|
+
text = ignoreDiacritics ? stripDiacritics(text) : text;
|
|
1598
|
+
let numMatches = 0;
|
|
1599
|
+
let allIndices = [];
|
|
1600
|
+
let totalScore = 0;
|
|
1601
|
+
for (let i = 0, qLen = query.length; i < qLen; i += 1) {
|
|
1602
|
+
const searchers2 = query[i];
|
|
1603
|
+
allIndices.length = 0;
|
|
1604
|
+
numMatches = 0;
|
|
1605
|
+
for (let j = 0, pLen = searchers2.length; j < pLen; j += 1) {
|
|
1606
|
+
const searcher = searchers2[j];
|
|
1607
|
+
const { isMatch, indices, score } = searcher.search(text);
|
|
1608
|
+
if (isMatch) {
|
|
1609
|
+
numMatches += 1;
|
|
1610
|
+
totalScore += score;
|
|
1611
|
+
if (includeMatches) {
|
|
1612
|
+
const type = searcher.constructor.type;
|
|
1613
|
+
if (MultiMatchSet.has(type)) {
|
|
1614
|
+
allIndices = [...allIndices, ...indices];
|
|
1615
|
+
} else {
|
|
1616
|
+
allIndices.push(indices);
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
} else {
|
|
1620
|
+
totalScore = 0;
|
|
1621
|
+
numMatches = 0;
|
|
1622
|
+
allIndices.length = 0;
|
|
1623
|
+
break;
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
if (numMatches) {
|
|
1627
|
+
let result = {
|
|
1628
|
+
isMatch: true,
|
|
1629
|
+
score: totalScore / numMatches
|
|
1630
|
+
};
|
|
1631
|
+
if (includeMatches) {
|
|
1632
|
+
result.indices = allIndices;
|
|
1633
|
+
}
|
|
1634
|
+
return result;
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
return {
|
|
1638
|
+
isMatch: false,
|
|
1639
|
+
score: 1
|
|
1640
|
+
};
|
|
1641
|
+
}
|
|
1642
|
+
};
|
|
1643
|
+
var registeredSearchers = [];
|
|
1644
|
+
function register(...args) {
|
|
1645
|
+
registeredSearchers.push(...args);
|
|
1646
|
+
}
|
|
1647
|
+
function createSearcher(pattern, options) {
|
|
1648
|
+
for (let i = 0, len = registeredSearchers.length; i < len; i += 1) {
|
|
1649
|
+
let searcherClass = registeredSearchers[i];
|
|
1650
|
+
if (searcherClass.condition(pattern, options)) {
|
|
1651
|
+
return new searcherClass(pattern, options);
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
return new BitapSearch(pattern, options);
|
|
1655
|
+
}
|
|
1656
|
+
var LogicalOperator = {
|
|
1657
|
+
AND: "$and",
|
|
1658
|
+
OR: "$or"
|
|
1659
|
+
};
|
|
1660
|
+
var KeyType = {
|
|
1661
|
+
PATH: "$path",
|
|
1662
|
+
PATTERN: "$val"
|
|
1663
|
+
};
|
|
1664
|
+
var isExpression = (query) => !!(query[LogicalOperator.AND] || query[LogicalOperator.OR]);
|
|
1665
|
+
var isPath = (query) => !!query[KeyType.PATH];
|
|
1666
|
+
var isLeaf = (query) => !isArray(query) && isObject(query) && !isExpression(query);
|
|
1667
|
+
var convertToExplicit = (query) => ({
|
|
1668
|
+
[LogicalOperator.AND]: Object.keys(query).map((key) => ({
|
|
1669
|
+
[key]: query[key]
|
|
1670
|
+
}))
|
|
1671
|
+
});
|
|
1672
|
+
function parse(query, options, { auto = true } = {}) {
|
|
1673
|
+
const next = (query2) => {
|
|
1674
|
+
let keys = Object.keys(query2);
|
|
1675
|
+
const isQueryPath = isPath(query2);
|
|
1676
|
+
if (!isQueryPath && keys.length > 1 && !isExpression(query2)) {
|
|
1677
|
+
return next(convertToExplicit(query2));
|
|
1678
|
+
}
|
|
1679
|
+
if (isLeaf(query2)) {
|
|
1680
|
+
const key = isQueryPath ? query2[KeyType.PATH] : keys[0];
|
|
1681
|
+
const pattern = isQueryPath ? query2[KeyType.PATTERN] : query2[key];
|
|
1682
|
+
if (!isString(pattern)) {
|
|
1683
|
+
throw new Error(LOGICAL_SEARCH_INVALID_QUERY_FOR_KEY(key));
|
|
1684
|
+
}
|
|
1685
|
+
const obj = {
|
|
1686
|
+
keyId: createKeyId(key),
|
|
1687
|
+
pattern
|
|
1688
|
+
};
|
|
1689
|
+
if (auto) {
|
|
1690
|
+
obj.searcher = createSearcher(pattern, options);
|
|
1691
|
+
}
|
|
1692
|
+
return obj;
|
|
1693
|
+
}
|
|
1694
|
+
let node = {
|
|
1695
|
+
children: [],
|
|
1696
|
+
operator: keys[0]
|
|
1697
|
+
};
|
|
1698
|
+
keys.forEach((key) => {
|
|
1699
|
+
const value = query2[key];
|
|
1700
|
+
if (isArray(value)) {
|
|
1701
|
+
value.forEach((item) => {
|
|
1702
|
+
node.children.push(next(item));
|
|
1703
|
+
});
|
|
1704
|
+
}
|
|
1705
|
+
});
|
|
1706
|
+
return node;
|
|
1707
|
+
};
|
|
1708
|
+
if (!isExpression(query)) {
|
|
1709
|
+
query = convertToExplicit(query);
|
|
1710
|
+
}
|
|
1711
|
+
return next(query);
|
|
1712
|
+
}
|
|
1713
|
+
function computeScore(results, { ignoreFieldNorm = Config.ignoreFieldNorm }) {
|
|
1714
|
+
results.forEach((result) => {
|
|
1715
|
+
let totalScore = 1;
|
|
1716
|
+
result.matches.forEach(({ key, norm: norm2, score }) => {
|
|
1717
|
+
const weight = key ? key.weight : null;
|
|
1718
|
+
totalScore *= Math.pow(
|
|
1719
|
+
score === 0 && weight ? Number.EPSILON : score,
|
|
1720
|
+
(weight || 1) * (ignoreFieldNorm ? 1 : norm2)
|
|
1721
|
+
);
|
|
1722
|
+
});
|
|
1723
|
+
result.score = totalScore;
|
|
1724
|
+
});
|
|
1725
|
+
}
|
|
1726
|
+
function transformMatches(result, data) {
|
|
1727
|
+
const matches = result.matches;
|
|
1728
|
+
data.matches = [];
|
|
1729
|
+
if (!isDefined(matches)) {
|
|
1730
|
+
return;
|
|
1731
|
+
}
|
|
1732
|
+
matches.forEach((match) => {
|
|
1733
|
+
if (!isDefined(match.indices) || !match.indices.length) {
|
|
1734
|
+
return;
|
|
1735
|
+
}
|
|
1736
|
+
const { indices, value } = match;
|
|
1737
|
+
let obj = {
|
|
1738
|
+
indices,
|
|
1739
|
+
value
|
|
1740
|
+
};
|
|
1741
|
+
if (match.key) {
|
|
1742
|
+
obj.key = match.key.src;
|
|
1743
|
+
}
|
|
1744
|
+
if (match.idx > -1) {
|
|
1745
|
+
obj.refIndex = match.idx;
|
|
1746
|
+
}
|
|
1747
|
+
data.matches.push(obj);
|
|
1748
|
+
});
|
|
1749
|
+
}
|
|
1750
|
+
function transformScore(result, data) {
|
|
1751
|
+
data.score = result.score;
|
|
1752
|
+
}
|
|
1753
|
+
function format(results, docs, {
|
|
1754
|
+
includeMatches = Config.includeMatches,
|
|
1755
|
+
includeScore = Config.includeScore
|
|
1756
|
+
} = {}) {
|
|
1757
|
+
const transformers = [];
|
|
1758
|
+
if (includeMatches) transformers.push(transformMatches);
|
|
1759
|
+
if (includeScore) transformers.push(transformScore);
|
|
1760
|
+
return results.map((result) => {
|
|
1761
|
+
const { idx } = result;
|
|
1762
|
+
const data = {
|
|
1763
|
+
item: docs[idx],
|
|
1764
|
+
refIndex: idx
|
|
1765
|
+
};
|
|
1766
|
+
if (transformers.length) {
|
|
1767
|
+
transformers.forEach((transformer) => {
|
|
1768
|
+
transformer(result, data);
|
|
1769
|
+
});
|
|
1770
|
+
}
|
|
1771
|
+
return data;
|
|
1772
|
+
});
|
|
1773
|
+
}
|
|
1774
|
+
var Fuse = class {
|
|
1775
|
+
constructor(docs, options = {}, index) {
|
|
1776
|
+
this.options = { ...Config, ...options };
|
|
1777
|
+
if (this.options.useExtendedSearch && false) {
|
|
1778
|
+
throw new Error(EXTENDED_SEARCH_UNAVAILABLE);
|
|
1779
|
+
}
|
|
1780
|
+
this._keyStore = new KeyStore(this.options.keys);
|
|
1781
|
+
this.setCollection(docs, index);
|
|
1782
|
+
}
|
|
1783
|
+
setCollection(docs, index) {
|
|
1784
|
+
this._docs = docs;
|
|
1785
|
+
if (index && !(index instanceof FuseIndex)) {
|
|
1786
|
+
throw new Error(INCORRECT_INDEX_TYPE);
|
|
1787
|
+
}
|
|
1788
|
+
this._myIndex = index || createIndex(this.options.keys, this._docs, {
|
|
1789
|
+
getFn: this.options.getFn,
|
|
1790
|
+
fieldNormWeight: this.options.fieldNormWeight
|
|
1791
|
+
});
|
|
1792
|
+
}
|
|
1793
|
+
add(doc) {
|
|
1794
|
+
if (!isDefined(doc)) {
|
|
1795
|
+
return;
|
|
1796
|
+
}
|
|
1797
|
+
this._docs.push(doc);
|
|
1798
|
+
this._myIndex.add(doc);
|
|
1799
|
+
}
|
|
1800
|
+
remove(predicate = () => false) {
|
|
1801
|
+
const results = [];
|
|
1802
|
+
for (let i = 0, len = this._docs.length; i < len; i += 1) {
|
|
1803
|
+
const doc = this._docs[i];
|
|
1804
|
+
if (predicate(doc, i)) {
|
|
1805
|
+
this.removeAt(i);
|
|
1806
|
+
i -= 1;
|
|
1807
|
+
len -= 1;
|
|
1808
|
+
results.push(doc);
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
return results;
|
|
1812
|
+
}
|
|
1813
|
+
removeAt(idx) {
|
|
1814
|
+
this._docs.splice(idx, 1);
|
|
1815
|
+
this._myIndex.removeAt(idx);
|
|
1816
|
+
}
|
|
1817
|
+
getIndex() {
|
|
1818
|
+
return this._myIndex;
|
|
1819
|
+
}
|
|
1820
|
+
search(query, { limit = -1 } = {}) {
|
|
1821
|
+
const {
|
|
1822
|
+
includeMatches,
|
|
1823
|
+
includeScore,
|
|
1824
|
+
shouldSort,
|
|
1825
|
+
sortFn,
|
|
1826
|
+
ignoreFieldNorm
|
|
1827
|
+
} = this.options;
|
|
1828
|
+
let results = isString(query) ? isString(this._docs[0]) ? this._searchStringList(query) : this._searchObjectList(query) : this._searchLogical(query);
|
|
1829
|
+
computeScore(results, { ignoreFieldNorm });
|
|
1830
|
+
if (shouldSort) {
|
|
1831
|
+
results.sort(sortFn);
|
|
1832
|
+
}
|
|
1833
|
+
if (isNumber(limit) && limit > -1) {
|
|
1834
|
+
results = results.slice(0, limit);
|
|
1835
|
+
}
|
|
1836
|
+
return format(results, this._docs, {
|
|
1837
|
+
includeMatches,
|
|
1838
|
+
includeScore
|
|
1839
|
+
});
|
|
1840
|
+
}
|
|
1841
|
+
_searchStringList(query) {
|
|
1842
|
+
const searcher = createSearcher(query, this.options);
|
|
1843
|
+
const { records } = this._myIndex;
|
|
1844
|
+
const results = [];
|
|
1845
|
+
records.forEach(({ v: text, i: idx, n: norm2 }) => {
|
|
1846
|
+
if (!isDefined(text)) {
|
|
1847
|
+
return;
|
|
1848
|
+
}
|
|
1849
|
+
const { isMatch, score, indices } = searcher.searchIn(text);
|
|
1850
|
+
if (isMatch) {
|
|
1851
|
+
results.push({
|
|
1852
|
+
item: text,
|
|
1853
|
+
idx,
|
|
1854
|
+
matches: [{ score, value: text, norm: norm2, indices }]
|
|
1855
|
+
});
|
|
1856
|
+
}
|
|
1857
|
+
});
|
|
1858
|
+
return results;
|
|
1859
|
+
}
|
|
1860
|
+
_searchLogical(query) {
|
|
1861
|
+
const expression = parse(query, this.options);
|
|
1862
|
+
const evaluate = (node, item, idx) => {
|
|
1863
|
+
if (!node.children) {
|
|
1864
|
+
const { keyId, searcher } = node;
|
|
1865
|
+
const matches = this._findMatches({
|
|
1866
|
+
key: this._keyStore.get(keyId),
|
|
1867
|
+
value: this._myIndex.getValueForItemAtKeyId(item, keyId),
|
|
1868
|
+
searcher
|
|
1869
|
+
});
|
|
1870
|
+
if (matches && matches.length) {
|
|
1871
|
+
return [
|
|
1872
|
+
{
|
|
1873
|
+
idx,
|
|
1874
|
+
item,
|
|
1875
|
+
matches
|
|
1876
|
+
}
|
|
1877
|
+
];
|
|
1878
|
+
}
|
|
1879
|
+
return [];
|
|
1880
|
+
}
|
|
1881
|
+
const res = [];
|
|
1882
|
+
for (let i = 0, len = node.children.length; i < len; i += 1) {
|
|
1883
|
+
const child = node.children[i];
|
|
1884
|
+
const result = evaluate(child, item, idx);
|
|
1885
|
+
if (result.length) {
|
|
1886
|
+
res.push(...result);
|
|
1887
|
+
} else if (node.operator === LogicalOperator.AND) {
|
|
1888
|
+
return [];
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
return res;
|
|
1892
|
+
};
|
|
1893
|
+
const records = this._myIndex.records;
|
|
1894
|
+
const resultMap = {};
|
|
1895
|
+
const results = [];
|
|
1896
|
+
records.forEach(({ $: item, i: idx }) => {
|
|
1897
|
+
if (isDefined(item)) {
|
|
1898
|
+
let expResults = evaluate(expression, item, idx);
|
|
1899
|
+
if (expResults.length) {
|
|
1900
|
+
if (!resultMap[idx]) {
|
|
1901
|
+
resultMap[idx] = { idx, item, matches: [] };
|
|
1902
|
+
results.push(resultMap[idx]);
|
|
1903
|
+
}
|
|
1904
|
+
expResults.forEach(({ matches }) => {
|
|
1905
|
+
resultMap[idx].matches.push(...matches);
|
|
1906
|
+
});
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
});
|
|
1910
|
+
return results;
|
|
1911
|
+
}
|
|
1912
|
+
_searchObjectList(query) {
|
|
1913
|
+
const searcher = createSearcher(query, this.options);
|
|
1914
|
+
const { keys, records } = this._myIndex;
|
|
1915
|
+
const results = [];
|
|
1916
|
+
records.forEach(({ $: item, i: idx }) => {
|
|
1917
|
+
if (!isDefined(item)) {
|
|
1918
|
+
return;
|
|
1919
|
+
}
|
|
1920
|
+
let matches = [];
|
|
1921
|
+
keys.forEach((key, keyIndex) => {
|
|
1922
|
+
matches.push(
|
|
1923
|
+
...this._findMatches({
|
|
1924
|
+
key,
|
|
1925
|
+
value: item[keyIndex],
|
|
1926
|
+
searcher
|
|
1927
|
+
})
|
|
1928
|
+
);
|
|
1929
|
+
});
|
|
1930
|
+
if (matches.length) {
|
|
1931
|
+
results.push({
|
|
1932
|
+
idx,
|
|
1933
|
+
item,
|
|
1934
|
+
matches
|
|
1935
|
+
});
|
|
1936
|
+
}
|
|
1937
|
+
});
|
|
1938
|
+
return results;
|
|
1939
|
+
}
|
|
1940
|
+
_findMatches({ key, value, searcher }) {
|
|
1941
|
+
if (!isDefined(value)) {
|
|
1942
|
+
return [];
|
|
1943
|
+
}
|
|
1944
|
+
let matches = [];
|
|
1945
|
+
if (isArray(value)) {
|
|
1946
|
+
value.forEach(({ v: text, i: idx, n: norm2 }) => {
|
|
1947
|
+
if (!isDefined(text)) {
|
|
1948
|
+
return;
|
|
1949
|
+
}
|
|
1950
|
+
const { isMatch, score, indices } = searcher.searchIn(text);
|
|
1951
|
+
if (isMatch) {
|
|
1952
|
+
matches.push({
|
|
1953
|
+
score,
|
|
1954
|
+
key,
|
|
1955
|
+
value: text,
|
|
1956
|
+
idx,
|
|
1957
|
+
norm: norm2,
|
|
1958
|
+
indices
|
|
1959
|
+
});
|
|
1960
|
+
}
|
|
1961
|
+
});
|
|
1962
|
+
} else {
|
|
1963
|
+
const { v: text, n: norm2 } = value;
|
|
1964
|
+
const { isMatch, score, indices } = searcher.searchIn(text);
|
|
1965
|
+
if (isMatch) {
|
|
1966
|
+
matches.push({ score, key, value: text, norm: norm2, indices });
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
return matches;
|
|
1970
|
+
}
|
|
1971
|
+
};
|
|
1972
|
+
Fuse.version = "7.1.0";
|
|
1973
|
+
Fuse.createIndex = createIndex;
|
|
1974
|
+
Fuse.parseIndex = parseIndex;
|
|
1975
|
+
Fuse.config = Config;
|
|
1976
|
+
{
|
|
1977
|
+
Fuse.parseQuery = parse;
|
|
1978
|
+
}
|
|
1979
|
+
{
|
|
1980
|
+
register(ExtendedSearch);
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1983
|
+
// src/data/search/utils/sanitizeInput.ts
|
|
1984
|
+
var sanitizeInput = (str) => str.replace(/[\u200E\u200F\u202A-\u202E\u2066-\u2069]/g, "").replace(/[\-–—_./()]+/g, "").normalize("NFC").trim();
|
|
1985
|
+
|
|
1986
|
+
// src/data/search/getSearchClient.ts
|
|
1987
|
+
var getSearchClient = ({ occupants, amenities }) => {
|
|
1988
|
+
const fuseAmenities = new Fuse(amenities, { threshold: 0.2 });
|
|
1989
|
+
const fuseOccupants = new Fuse(occupants, {
|
|
1990
|
+
threshold: 0.3,
|
|
1991
|
+
// 0.2 is too strict (can't find Mo-Mo Paradise with "momo" search string)
|
|
1992
|
+
includeScore: true,
|
|
1993
|
+
keys: [
|
|
1994
|
+
{ name: "properties.name", "weight": 4, getFn: (obj) => Object.values(obj.properties.name) },
|
|
1995
|
+
{ name: "properties.category", "weight": 0.25 },
|
|
1996
|
+
{
|
|
1997
|
+
name: "properties.local_categories",
|
|
1998
|
+
"weight": 0.25,
|
|
1999
|
+
getFn: (occ) => occ.properties.local_categories.map((cat3) => Object.values(cat3.properties.name)).flat()
|
|
2000
|
+
},
|
|
2001
|
+
{ name: "properties.keywords", "weight": 0.25 },
|
|
2002
|
+
{ name: "properties.description", "weight": 0.25, getFn: (occ) => Object.values(occ.properties.description || {}) },
|
|
2003
|
+
{ name: "properties.unit.properties.name", "weight": 0.25, getFn: (obj) => Object.values(obj.properties.unit?.properties.name || {}) },
|
|
2004
|
+
{ name: "properties.kiosk.properties.name", "weight": 0.25, getFn: (obj) => Object.values(obj.properties.kiosk?.properties.name || {}) }
|
|
2005
|
+
]
|
|
2006
|
+
});
|
|
2007
|
+
const fuseFuzzyAmenities = new Fuse(amenities, {
|
|
2008
|
+
threshold: 0.2,
|
|
2009
|
+
keys: [
|
|
2010
|
+
{ name: "properties.category", weight: 4 }
|
|
2011
|
+
]
|
|
2012
|
+
});
|
|
2013
|
+
const search2 = (value) => {
|
|
2014
|
+
const sanitizedValue = sanitizeInput(value);
|
|
2015
|
+
const matchedAmenities = fuseAmenities.search(sanitizedValue);
|
|
2016
|
+
if (matchedAmenities.length > 0) return matchedAmenities;
|
|
2017
|
+
const matchedOccupants = fuseOccupants.search(sanitizedValue);
|
|
2018
|
+
if (matchedOccupants.length > 0) return matchedOccupants;
|
|
2019
|
+
const matchedFuzzyAmenities = fuseFuzzyAmenities.search(sanitizedValue);
|
|
2020
|
+
if (matchedFuzzyAmenities.length > 0) return matchedFuzzyAmenities;
|
|
2021
|
+
return [];
|
|
2022
|
+
};
|
|
2023
|
+
return {
|
|
2024
|
+
search: search2
|
|
2025
|
+
};
|
|
2026
|
+
};
|
|
2027
|
+
|
|
664
2028
|
// src/data/getDataClient.ts
|
|
665
2029
|
var getDataClient = (options) => {
|
|
2030
|
+
let searchClient;
|
|
666
2031
|
const observers = /* @__PURE__ */ new Map();
|
|
667
2032
|
const queryClient = options.queryClient ?? new import_query_core.QueryClient();
|
|
668
2033
|
const { mode = "delivery", projectId, apiKey, baseUrl, previewToken } = options;
|
|
@@ -691,7 +2056,7 @@ var getDataClient = (options) => {
|
|
|
691
2056
|
}
|
|
692
2057
|
};
|
|
693
2058
|
const internalFindById = async (id) => {
|
|
694
|
-
if (id === null) return null;
|
|
2059
|
+
if (id === null || id === void 0) return null;
|
|
695
2060
|
const featureType = id.slice(0, id.lastIndexOf("-"));
|
|
696
2061
|
const feature2 = await queryClient.ensureQueryData({
|
|
697
2062
|
queryKey: ["_deliveryapi", featureType, id],
|
|
@@ -774,6 +2139,17 @@ var getDataClient = (options) => {
|
|
|
774
2139
|
const feature2 = await queryClient.ensureQueryData(findQueryOptions);
|
|
775
2140
|
return feature2;
|
|
776
2141
|
}
|
|
2142
|
+
const searchFn = async (txt) => {
|
|
2143
|
+
if (!searchClient) {
|
|
2144
|
+
const [occupants, amenities] = await Promise.all([
|
|
2145
|
+
filterByType("occupant", { populate: true }),
|
|
2146
|
+
filterByType("amenity")
|
|
2147
|
+
]);
|
|
2148
|
+
const haystack = { occupants, amenities };
|
|
2149
|
+
searchClient = getSearchClient(haystack);
|
|
2150
|
+
}
|
|
2151
|
+
return searchClient.search(txt);
|
|
2152
|
+
};
|
|
777
2153
|
return {
|
|
778
2154
|
projectId,
|
|
779
2155
|
queryClient,
|
|
@@ -783,7 +2159,8 @@ var getDataClient = (options) => {
|
|
|
783
2159
|
createFilterByTypeQueryOptions,
|
|
784
2160
|
createFindByIdQueryOptions,
|
|
785
2161
|
filterByType,
|
|
786
|
-
findById
|
|
2162
|
+
findById,
|
|
2163
|
+
search: searchFn
|
|
787
2164
|
};
|
|
788
2165
|
};
|
|
789
2166
|
|
|
@@ -834,7 +2211,7 @@ function point(coordinates, properties, options = {}) {
|
|
|
834
2211
|
if (coordinates.length < 2) {
|
|
835
2212
|
throw new Error("coordinates must be at least 2 numbers long");
|
|
836
2213
|
}
|
|
837
|
-
if (!
|
|
2214
|
+
if (!isNumber2(coordinates[0]) || !isNumber2(coordinates[1])) {
|
|
838
2215
|
throw new Error("coordinates must contain numbers");
|
|
839
2216
|
}
|
|
840
2217
|
const geom = {
|
|
@@ -893,7 +2270,7 @@ function multiPoint(coordinates, properties, options = {}) {
|
|
|
893
2270
|
};
|
|
894
2271
|
return feature(geom, properties, options);
|
|
895
2272
|
}
|
|
896
|
-
function
|
|
2273
|
+
function isNumber2(num) {
|
|
897
2274
|
return !isNaN(num) && num !== null && !Array.isArray(num);
|
|
898
2275
|
}
|
|
899
2276
|
|