diff --git a/dist/db/indexeddb/index.cjs b/dist/db/indexeddb/index.cjs index 3874bf2..7e75d57 100644 --- a/dist/db/indexeddb/index.cjs +++ b/dist/db/indexeddb/index.cjs @@ -1,3 +1,11 @@ +/** @define {string} */ + +/** @define {boolean} */ +const SUPPORT_PERSISTENT = true; + +/** @define {boolean} */ +const SUPPORT_KEYSTORE = true; + /** * @param {*} value * @param {*} default_value @@ -5,6 +13,92 @@ * @return {*} */ +function parse_option(value, default_value, merge_value){ + + const type_merge = typeof merge_value; + const type_value = typeof value; + + if(type_merge !== "undefined"){ + if(type_value !== "undefined"){ + + if(merge_value){ + if(type_value === "function" && + type_merge === type_value){ + return function(str){ + return /** @type Function */ (value)( + /** @type Function */ (merge_value)(str) + ); + } + } + + const constructor_value = value.constructor; + const constructor_merge = merge_value.constructor; + + if(constructor_value === constructor_merge){ + + if(constructor_value === Array){ + return merge_value.concat(value); + } + + if(constructor_value === Map){ + const map = new Map(/** @type !Map */ (merge_value)); + for(const item of /** @type !Map */ (value)){ + const key = item[0]; + const val = item[1]; + map.set(key, val); + } + return map; + } + + if(constructor_value === Set){ + const set = new Set(/** @type !Set */ (merge_value)); + for(const val of /** @type !Set */ (value).values()){ + set.add(val); + } + return set; + } + } + } + + return value; + } + else { + return merge_value; + } + } + + return type_value === "undefined" + ? default_value + : value; +} + +function create_object(){ + return Object.create(null); +} + +function concat(arrays){ + return [].concat.apply([], arrays); +} + +function sort_by_length_down(a, b){ + return b.length - a.length; +} + +function is_array(val){ + return val.constructor === Array; +} + +function is_string(val){ + return typeof val === "string"; +} + +function is_object(val){ + return typeof val === "object"; +} + +function is_function(val){ + return typeof val === "function"; +} /** * @param {Map|Set} val @@ -20,6 +114,6285 @@ function toArray(val, stringify){ return result; } +// TODO support generic function created from string when tree depth > 1 +function parse_simple(obj, tree){ + + if(is_string(tree)){ + obj = obj[tree]; + } + else for(let i = 0; obj && (i < tree.length); i++){ + obj = obj[tree[i]]; + } + + return obj; +} + +function get_max_len(arr){ + let len = 0; + for(let i = 0, res; i < arr.length; i++){ + if((res = arr[i])){ + if(len < res.length){ + len = res.length; + } + } + } + return len; +} + +var normalize_polyfill = [ + + // Charset Normalization + + ["ª","a"], + ["²","2"], + ["³","3"], + ["¹","1"], + ["º","o"], + ["¼","1⁄4"], + ["½","1⁄2"], + ["¾","3⁄4"], + ["à","a"], + ["á","a"], + ["â","a"], + ["ã","a"], + ["ä","a"], + ["å","a"], + ["ç","c"], + ["è","e"], + ["é","e"], + ["ê","e"], + ["ë","e"], + ["ì","i"], + ["í","i"], + ["î","i"], + ["ï","i"], + ["ñ","n"], + ["ò","o"], + ["ó","o"], + ["ô","o"], + ["õ","o"], + ["ö","o"], + ["ù","u"], + ["ú","u"], + ["û","u"], + ["ü","u"], + ["ý","y"], + ["ÿ","y"], + ["ā","a"], + ["ă","a"], + ["ą","a"], + ["ć","c"], + ["ĉ","c"], + ["ċ","c"], + ["č","c"], + ["ď","d"], + ["ē","e"], + ["ĕ","e"], + ["ė","e"], + ["ę","e"], + ["ě","e"], + ["ĝ","g"], + ["ğ","g"], + ["ġ","g"], + ["ģ","g"], + ["ĥ","h"], + ["ĩ","i"], + ["ī","i"], + ["ĭ","i"], + ["į","i"], + ["ij","ij"], + ["ĵ","j"], + ["ķ","k"], + ["ĺ","l"], + ["ļ","l"], + ["ľ","l"], + ["ŀ","l"], + ["ń","n"], + ["ņ","n"], + ["ň","n"], + ["ʼn","n"], + ["ō","o"], + ["ŏ","o"], + ["ő","o"], + ["ŕ","r"], + ["ŗ","r"], + ["ř","r"], + ["ś","s"], + ["ŝ","s"], + ["ş","s"], + ["š","s"], + ["ţ","t"], + ["ť","t"], + ["ũ","u"], + ["ū","u"], + ["ŭ","u"], + ["ů","u"], + ["ű","u"], + ["ų","u"], + ["ŵ","w"], + ["ŷ","y"], + ["ź","z"], + ["ż","z"], + ["ž","z"], + ["ſ","s"], + ["ơ","o"], + ["ư","u"], + ["dž","dz"], + ["lj","lj"], + ["nj","nj"], + ["ǎ","a"], + ["ǐ","i"], + ["ǒ","o"], + ["ǔ","u"], + ["ǖ","u"], + ["ǘ","u"], + ["ǚ","u"], + ["ǜ","u"], + ["ǟ","a"], + ["ǡ","a"], + ["ǣ","ae"], + ["æ","ae"], + ["ǽ","ae"], + ["ǧ","g"], + ["ǩ","k"], + ["ǫ","o"], + ["ǭ","o"], + ["ǯ","ʒ"], + ["ǰ","j"], + ["dz","dz"], + ["ǵ","g"], + ["ǹ","n"], + ["ǻ","a"], + ["ǿ","ø"], + ["ȁ","a"], + ["ȃ","a"], + ["ȅ","e"], + ["ȇ","e"], + ["ȉ","i"], + ["ȋ","i"], + ["ȍ","o"], + ["ȏ","o"], + ["ȑ","r"], + ["ȓ","r"], + ["ȕ","u"], + ["ȗ","u"], + ["ș","s"], + ["ț","t"], + ["ȟ","h"], + ["ȧ","a"], + ["ȩ","e"], + ["ȫ","o"], + ["ȭ","o"], + ["ȯ","o"], + ["ȱ","o"], + ["ȳ","y"], + ["ʰ","h"], + ["ʱ","h"], + ["ɦ","h"], + ["ʲ","j"], + ["ʳ","r"], + ["ʴ","ɹ"], + ["ʵ","ɻ"], + ["ʶ","ʁ"], + ["ʷ","w"], + ["ʸ","y"], + ["ˠ","ɣ"], + ["ˡ","l"], + ["ˢ","s"], + ["ˣ","x"], + ["ˤ","ʕ"], + ["ΐ","ι"], + ["ά","α"], + ["έ","ε"], + ["ή","η"], + ["ί","ι"], + ["ΰ","υ"], + ["ϊ","ι"], + ["ϋ","υ"], + ["ό","ο"], + ["ύ","υ"], + ["ώ","ω"], + ["ϐ","β"], + ["ϑ","θ"], + ["ϒ","Υ"], + ["ϓ","Υ"], + ["ϔ","Υ"], + ["ϕ","φ"], + ["ϖ","π"], + ["ϰ","κ"], + ["ϱ","ρ"], + ["ϲ","ς"], + ["ϵ","ε"], + ["й","и"], + ["ѐ","е"], + ["ё","е"], + ["ѓ","г"], + ["ї","і"], + ["ќ","к"], + ["ѝ","и"], + ["ў","у"], + ["ѷ","ѵ"], + ["ӂ","ж"], + ["ӑ","а"], + ["ӓ","а"], + ["ӗ","е"], + ["ӛ","ә"], + ["ӝ","ж"], + ["ӟ","з"], + ["ӣ","и"], + ["ӥ","и"], + ["ӧ","о"], + ["ӫ","ө"], + ["ӭ","э"], + ["ӯ","у"], + ["ӱ","у"], + ["ӳ","у"], + ["ӵ","ч"] + + // Term Separators + + // ["'", ""], // it's -> its + // ["´", ""], + // ["`", ""], + // ["’", ""], + // ["ʼ", ""], + + // Numeric-Separators Chars Removal + + // [",", ""], + // [".", ""] + + // Non-Whitespace Separators + + // already was split by default via p{P} + // ["-", " "], + // [":", " "], + // ["_", " "], + // ["|", " "], + // ["/", " "], + // ["\\", " "] +]; + +// COMPILER BLOCK --> + +/* + +Custom Encoder +---------------- + +// Split a passed string into an Array of words: +function englishEncoder(string){ + return string.toLowerCase().split(/[^a-z]+/) +} + +// For CJK split a passed string into an Array of chars: +function chineseEncoder(string){ + return string.replace(/\s+/, "").split("") +} + +// Alternatively do not split the input: +function fixedEncoder(string){ + return [string] +} + +Built-in Encoder (Workflow) +---------------------------- +Pipeline: + 1. apply this.normalize: charset normalization: + applied on the whole input string e.g. lowercase, + will also apply on: filter, matcher, stemmer, mapper + 2. apply this.split: split input into terms (includes/excludes) + 3. apply this.filter (pre-filter) + 4. apply this.matcher (replace terms) + 5. apply this.stemmer (replace term endings) + 6. apply this.filter (post-filter) + 7. apply this.mapper (replace chars) + 8. apply this.replacer (custom regex) + 9. apply this.dedupe (letter deduplication) + 10. apply this.finalize +*/ + +const whitespace = /[^\p{L}\p{N}]+/u; // /[\p{Z}\p{S}\p{P}\p{C}]+/u; +//const numeric_split = /(\d{3})/g; +const numeric_split_length = /(\d{3})/g; +const numeric_split_prev_char = /(\D)(\d{3})/g; +const numeric_split_next_char = /(\d{3})(\D)/g; +//.replace(/(\d{3})/g, "$1 ") +//.replace(/([^\d])([\d])/g, "$1 $2") +//.replace(/([\d])([^\d])/g, "$1 $2") +const normalize = "".normalize && /[\u0300-\u036f]/g; // '´`’ʼ., +//const normalize_mapper = SUPPORT_CHARSET && !normalize && normalize_polyfill; + +/** + * @param {EncoderOptions=} options + * @constructor + */ + +function Encoder(options){ + + if(!this){ + return new Encoder(...arguments); + } + + for(let i = 0; i < arguments.length; i++){ + this.assign(arguments[i]); + } +} +/** + * @param {!EncoderOptions} options + */ +Encoder.prototype.assign = function(options){ + + /** + * pre-processing string input + * @type {Function|boolean} + */ + this.normalize = /** @type {Function|boolean} */ ( + parse_option(options.normalize, true, this.normalize) + ); + + // { + // letter: true, + // number: true, + // whitespace: true, + // symbol: true, + // punctuation: true, + // control: true, + // char: "" + // } + + let include = options.include; + let tmp = include || options.exclude || options.split; + + if(typeof tmp === "object"){ + let numeric = !include; + let regex = ""; + // split on whitespace by default + options.include || ( + regex += "\\p{Z}" + ); + if(tmp.letter){ + regex += "\\p{L}"; + } + if(tmp.number){ + regex += "\\p{N}"; + numeric = !!include; + } + if(tmp.symbol){ + regex += "\\p{S}"; + } + if(tmp.punctuation){ + regex += "\\p{P}"; + } + if(tmp.control){ + regex += "\\p{C}"; + } + if((tmp = tmp.char)){ + regex += typeof tmp === "object" ? tmp.join("") : tmp; + } + + try{ + // https://github.com/nextapps-de/flexsearch/issues/410 + /** + * split string input into terms + * @type {string|RegExp|boolean|null} + */ + this.split = new RegExp("[" + (include ? "^" : "") + regex + "]+", "u"); + } + catch(e){ + // fallback to a simple whitespace splitter + this.split = /\s+/; + } + this.numeric = numeric; + } + else { + try{ + // https://github.com/nextapps-de/flexsearch/issues/410 + this.split = /** @type {string|RegExp|boolean} */ (parse_option(tmp, whitespace, this.split)); + } + catch(e){ + // fallback to a simple whitespace splitter + this.split = /\s+/; + } + this.numeric = parse_option(this.numeric, true); + } + + /** + * post-processing terms + * @type {Function|null} + */ + this.prepare = /** @type {Function|null} */ ( + parse_option(options.prepare, null, this.prepare) + ); + /** + * final processing + * @type {Function|null} + */ + this.finalize = /** @type {Function|null} */ ( + parse_option(options.finalize, null, this.finalize) + ); + + // assign the normalization fallback to the mapper + if(!normalize){ + this.mapper = new Map( + /** @type {Array>} */ ( + normalize_polyfill + ) + ); + } + + // options + + this.rtl = options.rtl || false; + this.dedupe = parse_option(options.dedupe, true, this.dedupe); + this.filter = parse_option((tmp = options.filter) && new Set(tmp), null, this.filter); + this.matcher = parse_option((tmp = options.matcher) && new Map(tmp), null, this.matcher); + this.mapper = parse_option((tmp = options.mapper) && new Map(tmp), null, this.mapper); + this.stemmer = parse_option((tmp = options.stemmer) && new Map(tmp), null, this.stemmer); + this.replacer = parse_option(options.replacer, null, this.replacer); + this.minlength = parse_option(options.minlength, 1, this.minlength); + this.maxlength = parse_option(options.maxlength, 0, this.maxlength); + + // minimum required tokenizer by this encoder + //this.tokenize = options["tokenize"] || ""; + + // auto-balanced cache + { + this.cache = tmp = parse_option(options.cache, true, this.cache); + if(tmp){ + this.timer = null; + this.cache_size = typeof tmp === "number" ? tmp : 2e5; + this.cache_enc = new Map(); + this.cache_prt = new Map(); + this.cache_enc_length = 128; + this.cache_prt_length = 128; + } + } + + // regex temporary state + this.matcher_str = ""; + this.matcher_test = null; + this.stemmer_str = ""; + this.stemmer_test = null; + + // prebuilt + // if(this.filter && this.split){ + // for(const key of this.filter){ + // const tmp = key.replace(this.split, ""); + // if(key !== tmp){ + // this.filter.delete(key); + // this.filter.add(tmp); + // } + // } + // } + if(this.matcher){ + for(const key of this.matcher.keys()){ + this.matcher_str += (this.matcher_str ? "|" : "") + key; + } + } + if(this.stemmer){ + for(const key of this.stemmer.keys()){ + this.stemmer_str += (this.stemmer_str ? "|" : "") + key; + } + } + + // if(SUPPORT_COMPRESSION){ + // this.compression = parse_option(options.compress || options.compression, 0, this.compression); + // if(this.compression && !table){ + // table = new Array(radix); + // for(let i = 0; i < radix; i++) table[i] = i + 33; + // table = String.fromCharCode.apply(null, table); + // } + // } + + return this; +}; + +Encoder.prototype.addMatcher = function(match, replace){ + // regex: + if(typeof match === "object"){ + return this.addReplacer(match, replace); + } + // a single char: + if(match.length < 2){ + return this.addMapper(match, replace); + } + this.matcher || (this.matcher = new Map()); + this.matcher.set(match , replace); + this.matcher_str += (this.matcher_str ? "|" : "") + match; + this.matcher_test = null; //new RegExp("(" + this.matcher_str + ")"); + this.cache && this.invalidate(); + return this; +}; + +Encoder.prototype.addStemmer = function(match, replace){ + this.stemmer || (this.stemmer = new Map()); + this.stemmer.set(match, replace); + this.stemmer_str += (this.stemmer_str ? "|" : "") + match; + this.stemmer_test = null; //new RegExp("(" + this.stemmer_str + ")"); + this.cache && this.invalidate(); + return this; +}; + +Encoder.prototype.addFilter = function(str){ + this.filter || (this.filter = new Set()); + this.filter.add(str); + this.cache && this.invalidate(); + return this; +}; + +Encoder.prototype.addMapper = function(char_match, char_replace){ + // regex: + if(typeof char_match === "object"){ + return this.addReplacer(char_match, char_replace); + } + // not a char: + if(char_match.length > 1){ + return this.addMatcher(char_match, char_replace); + } + this.mapper || (this.mapper = new Map()); + this.mapper.set(char_match, char_replace); + this.cache && this.invalidate(); + return this; +}; + +Encoder.prototype.addReplacer = function(match, replace){ + if(typeof match === "string") match = new RegExp(match, "g"); + this.replacer || (this.replacer = []); + this.replacer.push(match, replace || ""); + this.cache && this.invalidate(); + return this; +}; + +{ + Encoder.prototype.invalidate = function(){ + this.cache_enc.clear(); + this.cache_prt.clear(); + }; +} + +Encoder.prototype.encode = function(str){ + + //if(!str) return str; + // todo remove dupe terms + + if(this.cache && str.length <= this.cache_enc_length){ + if(this.timer){ + if(this.cache_enc.has(str)){ + return this.cache_enc.get(str); + } + } + else { + this.timer = setTimeout(clear$1, 0, this); + } + } + + // 1. apply charset normalization + if(this.normalize){ + if(typeof this.normalize === "function"){ + str = this.normalize(str); + } + else if(normalize){ + str = str.normalize("NFKD").replace(normalize, "").toLowerCase(); + } + else { + str = str.toLowerCase(); + // if(SUPPORT_CHARSET){ + // this.mapper = this.mapper + // // todo replace spread + // ? new Map([.../** @type {!Iterable} */(normalize_mapper), ...this.mapper]) + // : new Map(/** @type {Map} */ (normalize_mapper)); + // } + } + //if(!str) return str; + } + + // 2. apply custom encoder (can replace split) + if(this.prepare){ + str = this.prepare(str); + } + + // 3. split numbers into triplets + if(this.numeric && str.length > 3){ + str = str.replace(numeric_split_prev_char, "$1 $2") + .replace(numeric_split_next_char, "$1 $2") + .replace(numeric_split_length, "$1 "); + } + + // if(this.matcher && (str.length > 1)){ + // this.matcher_test || ( + // this.matcher_test = new RegExp("(" + this.matcher_str + ")", "g") + // ); + // str = str.replace(this.matcher_test, match => this.matcher.get(match)); + // } + // if(this.stemmer){ + // this.stemmer_test || ( + // this.stemmer_test = new RegExp("(?!\\b)(" + this.stemmer_str + ")(\\b|_)", "g") + // ); + // str = str.replace(this.stemmer_test, match => this.stemmer.get(match)); + // } + + const skip = !(this.dedupe || this.mapper || this.filter || this.matcher || this.stemmer || this.replacer); + let final = []; + let words = this.split || this.split === "" + ? str.split(/** @type {string|RegExp} */ (this.split)) + : str; //[str]; + + for(let i = 0, word, base; i < words.length; i++){ + // filter empty entries + if(!(word = base = words[i])){ + continue; + } + if(word.length < this.minlength){ + continue; + } + if(skip) { + final.push(word); + continue; + } + + // 1. pre-filter before cache + if(this.filter && this.filter.has(word)){ + continue; + } + + if(this.cache && word.length <= this.cache_prt_length){ + if(this.timer){ + const tmp = this.cache_prt.get(word); + //if(this.cache_prt.has(word)){ + if(tmp || tmp === ""){ + //word = this.cache_prt.get(word); + tmp && final.push(tmp); + //word ? words[i] = word : words.splice(i--, 1); + continue; + } + } + else { + this.timer = setTimeout(clear$1, 0, this); + } + } + + let postfilter; + + // if(this.normalize === true && normalize){ + // word = word.normalize("NFKD").replace(normalize, ""); + // postfilter = 1; + // } + + // if(this.normalize){ + // if(typeof this.normalize === "function"){ + // word = this.normalize(word); + // } + // else if(normalize){ + // word = word.normalize("NFKD").replace(normalize, "").toLowerCase(); + // } + // else{ + // word = word.toLowerCase(); + // this.mapper = this.mapper + // ? new Map([...normalize_mapper, ...this.mapper]) + // : new Map(/** @type {Map} */ normalize_mapper); + // } + // postfilter = 1; + // //if(!str) return str; + // } + + // 2. apply stemmer after matcher + if(this.stemmer && (word.length > 2)){ + // for(const item of this.stemmer){ + // const key = item[0]; + // const value = item[1]; + // + // if(word.length > key.length && word.endsWith(key)){ + // word = word.substring(0, word.length - key.length) + value; + // break; + // } + // + // // const position = word.length - key.length; + // // if(position > 0 && word.substring(position) === key){ + // // word = word.substring(0, position) + value; + // // break; + // // } + // } + this.stemmer_test || ( + this.stemmer_test = new RegExp("(?!^)(" + this.stemmer_str + ")$") + ); + word = word.replace(this.stemmer_test, match => this.stemmer.get(match)); + postfilter = 1; + } + + // 3. apply matcher + if(this.matcher && (word.length > 1)){ + this.matcher_test || ( + this.matcher_test = new RegExp("(" + this.matcher_str + ")", "g") + ); + word = word.replace(this.matcher_test, match => this.matcher.get(match)); + postfilter = 1; + } + + // 4. post-filter after matcher and stemmer was applied + if(word && postfilter && (word.length < this.minlength || (this.filter && this.filter.has(word)))){ + word = ""; + } + + // 5. apply mapper and collapsing + if(word && (this.mapper || (this.dedupe && word.length > 1))){ + //word = this.replace_dedupe(word); + //word = replace_deduped(word, this.mapper, true); + let final = ""; + for(let i = 0, prev = "", char, tmp; i < word.length; i++){ + char = word.charAt(i); + if(char !== prev || !this.dedupe){ + tmp = this.mapper && this.mapper.get(char); + if(!tmp && tmp !== "") + final += (prev = char); + else if((tmp !== prev || !this.dedupe) && (prev = tmp)) + final += tmp; + } + } + word = final; + } + + // apply custom regex + if(word && this.replacer){ + for(let i = 0; word && (i < this.replacer.length); i+=2){ + word = word.replace(this.replacer[i], this.replacer[i+1]); + } + } + + // slower variants for removing same chars in a row: + //word = word.replace(/([^0-9])\1+/g, "$1"); + //word = word.replace(/(.)\1+/g, "$1"); + //word = word.replace(/(?<=(.))\1+/g, ""); + + // if(word){ + // words[i] = word; + // } + + if(this.cache && base.length <= this.cache_prt_length){ + this.cache_prt.set(base, word); + if(this.cache_prt.size > this.cache_size){ + this.cache_prt.clear(); + this.cache_prt_length = this.cache_prt_length / 1.1 | 0; + } + } + + //word || words.splice(i--, 1); + word && final.push(word); + } + + //words = final; + // else if(this.filter){ + // for(let i = 0, word; i < words.length; i++){ + // if((word = words[i]) && !this.filter.has(word)){ + // //filtered.push(word); + // words.splice(i--, 1); + // } + // } + // } + + if(this.finalize){ + final = this.finalize(final) || final; + } + + if(this.cache && str.length <= this.cache_enc_length){ + this.cache_enc.set(str, final); + if(this.cache_enc.size > this.cache_size){ + this.cache_enc.clear(); + this.cache_enc_length = this.cache_enc_length / 1.1 | 0; + } + } + + return final; +}; + +// Encoder.prototype.compress = function(str) { +// +// //return str; +// //if(!str) return str; +// +// if(SUPPORT_CACHE && this.cache && str.length <= this.cache_prt_length){ +// if(this.timer){ +// if(this.cache_cmp.has(str)){ +// return this.cache_cmp.get(str); +// } +// } +// else{ +// this.timer = setTimeout(clear, 0, this); +// } +// } +// +// const result = typeof this.compression === "function" +// ? this.compression(str) +// : hash(str); //window.hash(str); +// +// if(SUPPORT_CACHE && this.cache && str.length <= this.cache_prt_length){ +// this.cache_cmp.set(str, result); +// this.cache_cmp.size > this.cache_size && +// this.cache_cmp.clear(); +// } +// +// return result; +// }; + +// function hash(str){ +// return str; +// } + +function clear$1(self){ + self.timer = null; + self.cache_enc.clear(); + self.cache_prt.clear(); +} + +async function handler(data) { + + data = data["data"]; + + /** @type Index */ + const index = self["_index"]; + const args = data["args"]; + const task = data["task"]; + + switch(task){ + + case "init": + + /** @type IndexOptions */ + let options = data["options"] || {}; + let filepath = options.config; + if(filepath){ + options = filepath; + // will be replaced after build with the line below because + // there is an issue with closure compiler dynamic import + options = (await import(filepath))["default"]; + } + + const factory = data["factory"]; + + if(factory){ + + // export the FlexSearch global payload to "self" + Function("return " + factory)()(self); + + /** @type Index */ + self["_index"] = new self["FlexSearch"]["Index"](options); + + // destroy the exported payload + delete self["FlexSearch"]; + } + else { + + self["_index"] = new Index(options); + } + + postMessage({ "id": data["id"] }); + break; + + default: + + const id = data["id"]; + const message = index[task].apply(index, args); + postMessage( + task === "search" + ? { "id": id, "msg": message } + : { "id": id } + ); + } +} + +let pid = 0; + +/** + * @param {IndexOptions=} options + * @constructor + */ + +function WorkerIndex(options = {}){ + + if(!this) { + return new WorkerIndex(options); + } + + // the factory is the outer wrapper from the build + // it uses "self" as a trap for node.js + let factory = typeof self !== "undefined" + ? self["_factory"] + : typeof window !== "undefined" + ? window["_factory"] + : null; + if(factory){ + factory = factory.toString(); + } + + const is_node_js = typeof window === "undefined" /*&& self["exports"]*/; + const _self = this; + + /** + * @this {WorkerIndex} + */ + function init(worker){ + + this.worker = worker; + this.resolver = create_object(); + + if(!this.worker){ + return; + } + + function onmessage(msg){ + msg = msg["data"] || msg; + const id = msg["id"]; + const res = id && _self.resolver[id]; + if(res){ + res(msg["msg"]); + delete _self.resolver[id]; + } + } + + is_node_js + ? this.worker["on"]("message", onmessage) + : this.worker.onmessage = onmessage; + + if(options.config){ + + // when extern configuration needs to be loaded + // it needs to return a promise to await for + return new Promise(function(resolve){ + + _self.resolver[++pid] = function(){ + resolve(_self); + }; + + _self.worker.postMessage({ + "id": pid, + "task": "init", + "factory": factory, + "options": options + }); + }); + } + + this.worker.postMessage({ + "task": "init", + "factory": factory, + "options": options + }); + + return this; + } + + const worker = create(factory, is_node_js, options.worker); + //worker.worker = true; + return worker.then + ? worker.then(function(worker){ + return init.call(_self, worker); + }) + : init.call(this, worker); +} + +register$1("add"); +register$1("append"); +register$1("search"); +register$1("update"); +register$1("remove"); + +function register$1(key){ + + WorkerIndex.prototype[key] = + WorkerIndex.prototype[key + "Async"] = async function(){ + + const self = this; + const args = [].slice.call(arguments); + const arg = args[args.length - 1]; + let callback; + + if(is_function(arg)){ + callback = arg; + args.splice(args.length - 1, 1); + } + + const promise = new Promise(function(resolve){ + //setTimeout(function(){ + self.resolver[++pid] = resolve; + self.worker.postMessage({ + "task": key, + "id": pid, + "args": args + }); + //}); + }); + + if(callback){ + promise.then(callback); + return this; + } + else { + + return promise; + } + }; +} + +function create(factory, is_node_js, worker_path){ + + let worker; + + worker = is_node_js ? + // This eval will be removed when compiling, it isn't there in final build + + typeof module !== "undefined" + ? (0, eval)('new (require("worker_threads")["Worker"])(__dirname + "/node/node.js")') + //: (0,eval)('new ((await import("worker_threads"))["Worker"])(import.meta.dirname + "/worker/node.mjs")') + //: (0,eval)('new ((await import("worker_threads"))["Worker"])((1,eval)(\"import.meta.dirname\") + "/node/node.mjs")') + : (0, eval)('import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)(\"import.meta.dirname\") + "/node/node.mjs"); })') + //: import("worker_threads").then(function(worker){ return new worker["Worker"](import.meta.dirname + "/worker/node.mjs"); }) + + //eval('new (require("worker_threads")["Worker"])(__dirname + "/node/node.js")') + :( + factory ? + new window.Worker(URL.createObjectURL( + new Blob( + ["onmessage=" + handler.toString()], + { "type": "text/javascript" } + ) + )) + : + new window.Worker(is_string(worker_path) ? worker_path : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", "module/worker/worker.js") /*"worker/worker.js"*/, { type: "module" }) + ); + + return worker; +} + +function apply_async(prototype){ + register.call(prototype, "add"); + register.call(prototype, "append"); + register.call(prototype, "search"); + register.call(prototype, "update"); + register.call(prototype, "remove"); + // prototype.addAsync = prototype.add; + // prototype.appendAsync = prototype.append; + // prototype.searchAsync = prototype.search; + // prototype.updateAsync = prototype.update; + // prototype.removeAsync = prototype.remove; +} + +// let cycle; +// let budget = 0; +// +// function tick(resolve){ +// cycle = null; +// budget = 0; +// resolve(); +// } + +/* + +automatisch + */ + +/** + * @param {!string} key + * @this {Index|Document} + */ + +function register(key){ + this[key + "Async"] = function(){ + + // // prevent stack overflow of adding too much tasks to the same event loop + // // actually limit stack to 1,000,000 tasks every ~4ms + // cycle || ( + // cycle = new Promise(resolve => setTimeout(tick, 0, resolve)) + // ); + // + // // apply different performance budgets + // if(key === "update" || key === "remove" && this.fastupdate === false){ + // budget += 1000 * this.resolution; + // if(this.depth) + // budget += 1000 * this.resolution_ctx; + // } + // else if(key === "search"){ + // budget++; + // } + // else{ + // budget += 20 * this.resolution; + // if(this.depth) + // budget += 20 * this.resolution_ctx; + // } + // + // // wait for the event loop cycle + // if(budget >= 1e6){ + // await cycle; + // } + + const args = /*[].slice.call*/(arguments); + const arg = args[args.length - 1]; + let callback; + + if(typeof arg === "function"){ + callback = arg; + delete args[args.length - 1]; + } + + //this.async = true; + const res = this[key].apply(this, args); + //this.async = false; + if(callback){ + res.then + ? res.then(callback) + : callback(res); + } + return res; + }; +} + +// TODO return promises instead of inner await + + +function async(callback, self, field, key, index_doc, index, data, on_done){ + + //setTimeout(function(){ + + const res = callback(field ? field + "." + key : key, JSON.stringify(data)); + + // await isn't supported by ES5 + + if(res && res["then"]){ + + res["then"](function(){ + + self.export(callback, self, field, index_doc, index + 1, on_done); + }); + } + else { + + self.export(callback, self, field, index_doc, index + 1, on_done); + } + //}); +} + +/** + * @param callback + * @param self + * @param field + * @param index_doc + * @param index + * @param on_done + * @this {Index|Document} + */ + +function exportIndex(callback, self, field, index_doc, index, on_done){ + + let return_value = true; + if (typeof on_done === 'undefined') { + return_value = new Promise((resolve) => { + on_done = resolve; + }); + } + + let key, data; + + switch(index || (index = 0)){ + + case 0: + + key = "reg"; + + // fastupdate isn't supported by export + + if(this.fastupdate){ + + data = create_object(); + + for(let key of this.reg.keys()){ + + data[key] = 1; + } + } + else { + + data = this.reg; + } + + break; + + case 1: + + key = "cfg"; + data = { + "doc": 0, + "opt": this.optimize ? 1 : 0 + }; + + break; + + case 2: + + key = "map"; + data = this.map; + break; + + case 3: + + key = "ctx"; + data = this.ctx; + break; + + default: + + if (typeof field === 'undefined' && on_done) { + + on_done(); + } + + return; + } + + async(callback, self || this, field, key, index_doc, index, data, on_done); + + return return_value; +} + +/** + * @this Index + */ + +function importIndex(key, data){ + + if(!data){ + + return; + } + + if(is_string(data)){ + + data = JSON.parse(data); + } + + switch(key){ + + case "cfg": + + this.optimize = !!data["opt"]; + break; + + case "reg": + + // fastupdate isn't supported by import + + this.fastupdate = false; + this.reg = data; + break; + + case "map": + + this.map = data; + break; + + case "ctx": + + this.ctx = data; + break; + } +} + +/** + * @this Document + */ + +function exportDocument(callback, self, field, index_doc, index, on_done){ + + let return_value; + if (typeof on_done === 'undefined') { + return_value = new Promise((resolve) => { + on_done = resolve; + }); + } + + index || (index = 0); + index_doc || (index_doc = 0); + + if(index_doc < this.field.length){ + + const field = this.field[index_doc]; + const idx = this.index[field]; + + self = this; + + //setTimeout(function(){ + + if(!idx.export(callback, self, index ? field/*.replace(":", "-")*/ : "", index_doc, index++, on_done)){ + + index_doc++; + index = 1; + + self.export(callback, self, field, index_doc, index, on_done); + } + //}); + } + else { + + let key, data; + + switch(index){ + + case 1: + + key = "tag"; + data = this.tagindex; + field = null; + break; + + case 2: + + key = "store"; + data = this.store; + field = null; + break; + + // case 3: + // + // key = "reg"; + // data = this.register; + // break; + + default: + + on_done(); + return; + } + + async(callback, this, field, key, index_doc, index, data, on_done); + } + + return return_value +} + +/** + * @this Document + */ + +function importDocument(key, data){ + + if(!data){ + + return; + } + + if(is_string(data)){ + + data = JSON.parse(data); + } + + switch(key){ + + case "tag": + + this.tagindex = data; + break; + + case "reg": + + // fastupdate isn't supported by import + + this.fastupdate = false; + this.reg = data; + + for(let i = 0, index; i < this.field.length; i++){ + + index = this.index[this.field[i]]; + index.reg = data; + index.fastupdate = false; + } + + break; + + case "store": + + this.store = data; + break; + + default: + + key = key.split("."); + const field = key[0]; + key = key[1]; + + if(field && key){ + + this.index[field].import(key, data); + } + } +} + +/* +reg: "1,2,3,4,5,6,7,8,9" +map: "gulliver:1,2,3|4,5,6|7,8,9;" +ctx: "gulliver+travel:1,2,3|4,5,6|7,8,9;" +*/ + +/** + * @this Index + * @param {boolean} withFunctionWrapper + * @return {string} + */ + +function serialize(withFunctionWrapper = true){ + + if(!this.reg.size) return ""; + + let reg = ''; + let type = ""; + for(const key of this.reg.keys()){ + type || (type = typeof key); + reg += (reg ? ',' : '') + (type === "string" ? '"' + key + '"' : key); + } + reg = 'index.reg=new Set([' + reg + ']);'; + + let map = ''; + for(const item of this.map.entries()){ + const key = item[0]; + const value = item[1]; + let res = ''; + for(let i = 0, ids; i < value.length; i++){ + ids = value[i] || ['']; + let str = ''; + for(let j = 0; j < ids.length; j++){ + str += (str ? ',' : '') + (type === "string" ? '"' + ids[j] + '"' : ids[j]); + } + str = '[' + str + ']'; + res += (res ? ',' : '') + str; + } + res = '["' + key + '",[' + res + ']]'; + map += (map ? ',' : '') + res; + } + map = "index.map=new Map([" + map + "]);"; + + let ctx = ''; + for(const context of this.ctx.entries()){ + const key_ctx = context[0]; + const value_ctx = context[1]; + + for(const item of value_ctx.entries()){ + const key = item[0]; + const value = item[1]; + + let res = ''; + for(let i = 0, ids; i < value.length; i++){ + ids = value[i] || ['']; + let str = ''; + for(let j = 0; j < ids.length; j++){ + str += (str ? ',' : '') + (type === "string" ? '"' + ids[j] + '"' : ids[j]); + } + str = '[' + str + ']'; + res += (res ? ',' : '') + str; + } + res = 'new Map([["' + key + '",[' + res + ']]])'; + res = '["' + key_ctx + '",' + res + ']'; + ctx += (ctx ? ',' : '') + res; + } + } + ctx = "index.ctx=new Map([" + ctx + "]);"; + + return withFunctionWrapper + ? "function inject(index){" + reg + map + ctx + "}" + : reg + map + ctx +} + +// export function exportSnapshot(flexsearch){ +// +// if(!flexsearch.reg.size) return; +// +// let reg = ''; +// let type = ""; +// for(const key of flexsearch.reg.keys()){ +// type || (type = typeof key); +// reg += (reg ? ',' : '') + (type === "string" ? '"' + key + '"' : key); +// } +// reg = "f.reg=[" + reg + "];"; +// +// let map = ''; +// for(const item of flexsearch.map.entries()){ +// const key = item[0]; +// const value = item[1]; +// let res = ''; +// for(let i = 0, ids; i < value.length; i++){ +// ids = value[i] || ['']; +// let str = ''; +// for(let j = 0; j < ids.length; j++){ +// str += (str ? ',' : '') + (type === "string" ? '"' + ids[j] + '"' : ids[j]); +// } +// str = "[ +// res += (res ? '|' : '') + str; +// } +// map += (map ? ';' : '') + key + ':' + res; +// } +// +// +// let ctx = ''; +// for(const context of flexsearch.ctx.entries()){ +// const key_ctx = context[0]; +// const value_ctx = context[1]; +// +// for(const item of value_ctx.entries()){ +// const key = item[0]; +// const value = item[1]; +// +// let res = ''; +// for(let i = 0, ids; i < value.length; i++){ +// ids = value[i] || ['']; +// let str = ''; +// for(let j = 0; j < ids.length; j++){ +// str += (str ? ',' : '') + (type === "string" ? '"' + ids[j] + '"' : ids[j]); +// } +// res += (res ? '|' : '') + str; +// } +// ctx += (ctx ? ';' : '') + key_ctx + '+' + key + ':' + res; +// } +// } +// +// return reg + '#' + map + '#' + ctx; +// } +// +// export function importSnapshot(flexsearch, input){ +// +// if(!input) return; +// +// let pos_reg = input.indexOf("#"); +// const reg = input.substring(0, pos_reg).split(","); +// flexsearch.reg = new Set(reg); +// +// let pos_map = input.indexOf("#", pos_reg + 1); +// const map = input.substring(pos_reg + 1, pos_map).split(";").map(res => { +// const split = res.split(":"); +// split[1] = split[1].split("|").map(ids => ids ? ids.split(",") : null); +// return split; +// }); +// flexsearch.map = new Map(map); +// +// input = input.substring(pos_map + 1); +// if(input){ +// const ctx = input.split(";").map(res => { +// const split = res.split(":"); +// const context = split[0].split("+"); +// const map = new Map([ +// [context[1], split[1].split("|").map(ids => ids ? ids.split(",") : null)] +// ]); +// return [context[0], map] +// }); +// flexsearch.ctx = new Map(ctx); +// } +// } + +// KeystoreObj.prototype.destroy = function(){ +// this.index = null; +// this.keys = null; +// this.proxy = null; +// }; + +function _slice(self, start, end, splice){ + let arr = []; + for(let i = 0, index; i < self.index.length; i++){ + index = self.index[i]; + if(start >= index.length){ + start -= index.length; + } + else { + const tmp = index[splice ? "splice" : "slice"](start, end); + const length = tmp.length; + if(length){ + arr = arr.length + ? arr.concat(tmp) + : tmp; + end -= length; + if(splice) self.length -= length; + if(!end) break; + } + start = 0; + } + } + return arr; +} + +/** + * @param arr + * @constructor + */ + +function KeystoreArray(arr){ + + if(!this){ + return new KeystoreArray(arr); + } + + this.index = arr ? [arr] : []; + this.length = arr ? arr.length : 0; + const self = this; + + return /*this.proxy =*/ new Proxy([], { + get(target, key) { + if(key === "length"){ + return self.length; + } + if(key === "push"){ + return function(value){ + self.index[self.index.length - 1].push(value); + self.length++; + } + } + if(key === "pop"){ + return function(){ + if(self.length){ + self.length--; + return self.index[self.index.length - 1].pop(); + } + } + } + if(key === "indexOf"){ + return function(key){ + let index = 0; + for(let i = 0, arr, tmp; i < self.index.length; i++){ + arr = self.index[i]; + //if(!arr.includes(key)) continue; + tmp = arr.indexOf(key); + if(tmp >= 0) return index + tmp; + index += arr.length; + } + return -1; + } + } + if(key === "includes"){ + return function(key){ + for(let i = 0; i < self.index.length; i++){ + if(self.index[i].includes(key)){ + return true; + } + } + return false; + } + } + if(key === "slice"){ + return function(start, end){ + return _slice( + self, + start || 0, + end || self.length, + false + ); + } + } + if(key === "splice"){ + return function(start, end){ + return _slice( + self, + start || 0, + end || self.length, + // splice: + true + ); + } + } + if(key === "constructor"){ + return Array; + } + if(typeof key === "symbol" /*|| isNaN(key)*/){ + // not supported + return; + } + const index = key / (2**31) | 0; + const arr = self.index[index]; + return arr && arr[key]; + }, + set(target, key, value){ + const index = key / (2**31) | 0; + const arr = self.index[index] || (self.index[index] = []); + arr[key] = value; + self.length++; + return true; + } + }); +} + +KeystoreArray.prototype.clear = function(){ + this.index.length = 0; +}; + +KeystoreArray.prototype.destroy = function(){ + this.index = null; + this.proxy = null; +}; + +KeystoreArray.prototype.push = function(val){}; + +/** + * @param bitlength + * @constructor + */ + +function KeystoreMap(bitlength = 8){ + + if(!this){ + return new KeystoreMap(bitlength); + } + + this.index = create_object(); + this.refs = []; + this.size = 0; + + if(bitlength > 32){ + this.crc = lcg64; + this.bit = BigInt(bitlength); + } + else { + this.crc = lcg$1; + this.bit = bitlength; + } +} + +KeystoreMap.prototype.get = function(key) { + const address = this.crc(key); + const map = this.index[address]; + return map && map.get(key); +}; + +KeystoreMap.prototype.set = function(key, value){ + const address = this.crc(key); + let map = this.index[address]; + if(map){ + let size = map.size; + map.set(key, value); + size -= map.size; + size && this.size++; + } + else { + this.index[address] = map = new Map([[key, value]]); + this.refs.push(map); + } +}; + +/** + * @param bitlength + * @constructor + */ + +function KeystoreSet(bitlength = 8){ + + if(!this){ + return new KeystoreSet(bitlength); + } + + // using plain Object with numeric key access + // just for max performance + this.index = create_object(); + this.refs = []; + + if(bitlength > 32){ + this.crc = lcg64; + this.bit = BigInt(bitlength); + } + else { + this.crc = lcg$1; + this.bit = bitlength; + } +} + +KeystoreSet.prototype.add = function(key){ + const address = this.crc(key); + let set = this.index[address]; + if(set){ + let size = set.size; + set.add(key); + size -= set.size; + size && this.size++; + } + else { + this.index[address] = set = new Set([key]); + this.refs.push(set); + } +}; + +KeystoreMap.prototype.has = +KeystoreSet.prototype.has = function(key) { + const address = this.crc(key); + const map_or_set = this.index[address]; + return map_or_set && map_or_set.has(key); +}; + +/* +KeystoreMap.prototype.size = +KeystoreSet.prototype.size = function(){ + let size = 0; + const values = Object.values(this.index); + for(let i = 0; i < values.length; i++){ + size += values[i].size; + } + return size; +}; +*/ + +KeystoreMap.prototype.delete = +KeystoreSet.prototype.delete = function(key){ + const address = this.crc(key); + const map_or_set = this.index[address]; + // set && (set.size === 1 + // ? this.index.delete(address) + // : set.delete(key)); + map_or_set && + map_or_set.delete(key) && + this.size--; +}; + +KeystoreMap.prototype.clear = +KeystoreSet.prototype.clear = function(){ + this.index = create_object(); + this.refs = []; + this.size = 0; +}; + +// KeystoreMap.prototype.destroy = +// KeystoreSet.prototype.destroy = function(){ +// this.index = null; +// this.refs = null; +// this.proxy = null; +// }; + +KeystoreMap.prototype.values = +KeystoreSet.prototype.values = function*(){ + // alternatively iterate through this.keys[] + //const refs = Object.values(this.index); + for(let i = 0; i < this.refs.length; i++){ + for(let value of this.refs[i].values()){ + yield value; + } + } +}; + +KeystoreMap.prototype.keys = +KeystoreSet.prototype.keys = function*(){ + //const values = Object.values(this.index); + for(let i = 0; i < this.refs.length; i++){ + for(let key of this.refs[i].keys()){ + yield key; + } + } +}; + +KeystoreMap.prototype.entries = +KeystoreSet.prototype.entries = function*(){ + //const values = Object.values(this.index); + for(let i = 0; i < this.refs.length; i++){ + for(let entry of this.refs[i].entries()){ + yield entry; + } + } +}; + +/** + * Linear Congruential Generator (LCG) + * @param str + * @this {KeystoreMap|KeystoreSet} + */ + +function lcg$1(str) { + let range = 2 ** this.bit - 1; + if(typeof str == "number"){ + return str & range; + } + let crc = 0, bit = this.bit + 1; + for(let i = 0; i < str.length; i++) { + crc = (crc * bit ^ str.charCodeAt(i)) & range; + } + // shift Int32 to UInt32 because negative numbers + // extremely slows down key lookup + return this.bit === 32 + ? crc + 2 ** 31 + : crc;// & 0xFFFF; +} + +/** + * @param str + * @this {KeystoreMap|KeystoreSet} + */ + +function lcg64(str) { + let range = BigInt(2) ** /** @type {!BigInt} */ (this.bit) - BigInt(1); + let type = typeof str; + if(type === "bigint"){ + return /** @type {!BigInt} */ (str) & range; + } + if(type === "number"){ + return BigInt(str) & range; + } + let crc = BigInt(0), bit = /** @type {!BigInt} */ (this.bit) + BigInt(1); + for(let i = 0; i < str.length; i++){ + crc = (crc * bit ^ BigInt(str.charCodeAt(i))) & range; + } + return crc;// & 0xFFFFFFFFFFFFFFFF; +} + +// COMPILER BLOCK --> + +/** + * + * @param id + * @param content + * @param {boolean=} _append + * @returns {Document|Promise} + */ + +Document.prototype.add = function(id, content, _append){ + + if(is_object(id)){ + + content = id; + id = parse_simple(content, this.key); + } + + if(content && (id || (id === 0))){ + + if(!_append && this.reg.has(id)){ + return this.update(id, content); + } + + // this.field does not include db tag indexes + for(let i = 0, tree; i < this.field.length; i++){ + + tree = this.tree[i]; + + const index = this.index.get(this.field[i]); + if(typeof tree === "function"){ + const tmp = tree(content); + if(tmp){ + index.add(id, tmp, /* append: */ false, /* skip update: */ true); + } + } + else { + const filter = tree._filter; + if(filter && !filter(content)){ + continue; + } + if(tree.constructor === String){ + tree = ["" + tree]; + } + else if(is_string(tree)){ + tree = [tree]; + } + add_index(content, tree, this.marker, 0, index, id, tree[0], _append); + } + } + + if(this.tag){ + + //console.log(this.tag, this.tagtree) + + for(let x = 0; x < this.tagtree.length; x++){ + + let tree = this.tagtree[x]; + let field = this.tagfield[x]; + let ref = this.tag.get(field); + let dupes = create_object(); + let tags; + + if(typeof tree === "function"){ + tags = tree(content); + if(!tags) continue; + } + else { + const filter = tree._filter; + if(filter && !filter(content)){ + continue; + } + if(tree.constructor === String){ + tree = "" + tree; + } + tags = parse_simple(content, tree); + } + + if(!ref || !tags){ + ref || (console.warn("Tag '" + field + "' was not found")); + continue; + } + + if(is_string(tags)){ + tags = [tags]; + } + + for(let i = 0, tag, arr; i < tags.length; i++){ + + tag = tags[i]; + //console.log(this.tag, tag, key, field) + + if(!dupes[tag]){ + dupes[tag] = 1; + + let tmp; + tmp = ref.get(tag); + tmp ? arr = tmp : ref.set(tag, arr = []); + + if(!_append || ! /** @type {!Array|KeystoreArray} */(arr).includes(id)){ + + // auto-upgrade to keystore array if max size exceeded + { + if(arr.length === 2**31-1 /*|| !(arr instanceof KeystoreArray)*/){ + const keystore = new KeystoreArray(arr); + if(this.fastupdate){ + for(let value of this.reg.values()){ + if(value.includes(arr)){ + value[value.indexOf(arr)] = keystore; + } + } + } + ref.set(tag, arr = keystore); + } + } + + arr.push(id); + + // add a reference to the register for fast updates + if(this.fastupdate){ + const tmp = this.reg.get(id); + tmp ? tmp.push(arr) + : this.reg.set(id, [arr]); + } + } + } + } + } + } + + if(this.store && (!_append || !this.store.has(id))){ + + let payload; + + if(this.storetree){ + + payload = create_object(); + + for(let i = 0, tree; i < this.storetree.length; i++){ + tree = this.storetree[i]; + + const filter = tree._filter; + if(filter && !filter(content)){ + continue; + } + let custom; + if(typeof tree === "function"){ + custom = tree(content); + if(!custom) continue; + tree = [tree._field]; + } + else if(is_string(tree) || tree.constructor === String){ + payload[tree] = content[tree]; + continue; + } + + store_value(content, payload, tree, 0, tree[0], custom); + } + } + + this.store.set(id, payload || content); + } + } + + return this; +}; + +// TODO support generic function created from string when tree depth > 1 + +/** + * @param obj + * @param store + * @param tree + * @param pos + * @param key + * @param {*=} custom + */ + +function store_value(obj, store, tree, pos, key, custom){ + + obj = obj[key]; + + // reached target field + if(pos === (tree.length - 1)){ + + // store target value + store[key] = custom || obj; + } + else if(obj){ + + if(is_array(obj)){ + + store = store[key] = new Array(obj.length); + + for(let i = 0; i < obj.length; i++){ + // do not increase pos (an array is not a field) + store_value(obj, store, tree, pos, i); + } + } + else { + + store = store[key] || (store[key] = create_object()); + key = tree[++pos]; + store_value(obj, store, tree, pos, key); + } + } +} + +function add_index(obj, tree, marker, pos, index, id, key, _append){ + + if((obj = obj[key])){ + + // reached target field + if(pos === (tree.length - 1)){ + + // handle target value + if(is_array(obj)){ + + // append array contents so each entry gets a new scoring context + if(marker[pos]){ + for(let i = 0; i < obj.length; i++){ + index.add(id, obj[i], /* append: */ true, /* skip update: */ true); + } + return; + } + + // or join array contents and use one scoring context + obj = obj.join(" "); + } + + index.add(id, obj, _append, /* skip_update: */ true); + } + else { + + if(is_array(obj)){ + for(let i = 0; i < obj.length; i++){ + // do not increase index, an array is not a field + add_index(obj, tree, marker, pos, index, id, i, _append); + } + } + else { + key = tree[++pos]; + add_index(obj, tree, marker, pos, index, id, key, _append); + } + } + } + else { + if(index.db){ + index.remove(id); + } + } +} + +// COMPILER BLOCK --> + +/* + + from -> result[ + res[score][id], + res[score][id], + ] + + to -> [id] + +*/ + +/** + * @param arrays + * @param {number} resolution + * @param limit + * @param offset + * @param suggest + * @param {number=} boost + * @param {boolean=} resolve + * @returns {Array} + */ + +function intersect$1(arrays, resolution, limit, offset, suggest, boost, resolve) { + + const length = arrays.length; + + let result = []; + let check; + let count; + + // alternatively the results could be sorted by length up + //arrays.sort(sort_by_length_up); + + check = create_object(); + + for(let y = 0, ids, id, res_arr, tmp; y < resolution; y++){ + + for(let x = 0; x < length; x++){ + + res_arr = arrays[x]; + + if(y < res_arr.length && (ids = res_arr[y])){ + + for(let z = 0; z < ids.length; z++){ + + id = ids[z]; + + if((count = check[id])){ + check[id]++; + // tmp.count++; + // tmp.sum += y; + } + else { + count = 0; + check[id] = 1; + // check[id] = { + // count: 1, + // sum: y + // }; + } + + tmp = result[count] || (result[count] = []); + + if(!resolve){ + // boost everything after first result + let score = y + (x ? 0 : boost || 0); + tmp = tmp[score] || (tmp[score] = []); + } + + tmp.push(id); + } + } + } + } + + // result.sort(function(a, b){ + // return check[a] - check[b]; + // }); + + const result_len = result.length; + + if(result_len){ + + if(!suggest){ + + if(result_len < length){ + return []; + } + + result = result[result_len - 1]; + + if(limit || offset){ + if(resolve){ + if((result.length > limit) || offset){ + result = result.slice(offset, limit + offset); + } + } + else { + const final = []; + for(let i = 0, arr; i < result.length; i++){ + arr = result[i]; + if(arr.length > offset){ + offset -= arr.length; + continue; + } + if((arr.length > limit) || offset){ + arr = arr.slice(offset, limit + offset); + limit -= arr.length; + if(offset) offset -= arr.length; + } + final.push(arr); + if(!limit){ + break; + } + } + return final.length > 1 + ? concat(final) + : final[0]; + } + } + } + else { + + result = result.length > 1 + ? union$1(result, offset, limit, resolve, 0) + : result[0]; + } + } + + return result; +} + +function union$1(arrays, offset, limit, resolve, boost){ + + const result = []; + const check = create_object(); + let ids, id, arr_len = arrays.length, ids_len, count = 0; + + if(!resolve){ + + let maxres = get_max_len(arrays); + + for(let k = 0; k < maxres; k++){ + + for(let i = arr_len - 1; i >= 0; i--){ + + ids = arrays[i][k]; + ids_len = ids && ids.length; + + if(ids_len) for(let j = 0; j < ids_len; j++){ + + id = ids[j]; + + if(!check[id]){ + check[id] = 1; + if(offset){ + offset--; + } + else { + let score = k + (i < arr_len - 1 ? boost || 0 : 0); + const arr = result[score] || (result[score] = []); + arr.push(id); + if(++count === limit){ + return result; + } + } + } + } + } + } + } + else { + + for(let i = arr_len - 1; i >= 0; i--){ + + ids = arrays[i]; + ids_len = ids.length; + + for(let j = 0; j < ids_len; j++){ + + id = ids[j]; + + if(!check[id]){ + check[id] = 1; + if(offset){ + offset--; + } + else { + result.push(id); + if(result.length === limit){ + return result; + } + } + } + } + } + } + + return result; +} + +/** + * @param {Array} mandatory + * @param {Array>} arrays + * @returns {Array} + */ + +function intersect_union(mandatory, arrays) { + + const check = create_object(); + const result = []; + + for(let x = 0, ids; x < arrays.length; x++){ + ids = arrays[x]; + for(let i = 0; i < ids.length; i++){ + check[ids[i]] = 1; + } + } + + for(let i = 0, id; i < mandatory.length; i++){ + id = mandatory[i]; + if(check[id] === 1){ + result.push(id); + check[id] = 2; + } + } + + return result; +} + +// export function intersect_union(mandatory, arrays, resolution) { +// +// const check = create_object(); +// const union = create_object(); +// const result = []; +// +// for(let x = 0; x < mandatory.length; x++){ +// check[mandatory[x]] = 1; +// } +// +// +// for(let y = 0, ids, id; y < resolution; y++){ +// for(let x = 0; x < arrays.length; x++){ +// +// ids = arrays[x]; +// +// if(y < ids.length){ +// +// id = ids[y]; +// +// if(check[id]){ +// +// if(!union[id]){ +// +// union[id] = 1; +// result.push(id); +// } +// } +// } +// } +// } +// +// return result; +// } + +// +// /** +// * Implementation based on Object[key] provides better suggestions +// * capabilities and has less performance scaling issues on large indexes. +// * +// * @param arrays +// * @param limit +// * @param offset +// * @param {boolean|Array=} suggest +// * @param {boolean=} resolve +// * @returns {Array} +// */ +// +// export function intersect(arrays, limit, offset, suggest, resolve) { +// +// const length = arrays.length; +// +// // todo remove +// // if(length < 2){ +// // throw new Error("Not optimized intersect"); +// // } +// +// let result = []; +// let size = 0; +// let check; +// let check_suggest; +// let check_new; +// let res_arr; +// +// if(suggest){ +// suggest = []; +// } +// +// // 1. a reversed order prioritize the order of words from a query +// // because it ends with the first term. +// // 2. process terms in reversed order often has advantage for +// // the fast path "end reached". +// +// // alternatively the results could be sorted by length up +// //arrays.sort(sort_by_length_up); +// +// // todo the outer loop should be the res array instead of term array, +// // this isn't just simple because the intersection calculation needs to reflect this +// //const maxlen = get_max_len(arrays); +// +// for(let x = length - 1, found; x >= 0; x--){ +// //for(let x = 0, found; x < length; x++){ +// +// res_arr = arrays[x]; +// check_new = create_object(); +// found = !check; +// +// // process relevance in forward order (direction is +// // important for adding IDs during the last round) +// +// for(let y = 0, ids; y < res_arr.length; y++){ +// +// ids = res_arr[y]; +// if(!ids || !ids.length) continue; +// +// for(let z = 0, id; z < ids.length; z++){ +// +// id = ids[z]; +// +// // check exists starting from the 2nd slot +// if(check){ +// if(check[id]){ +// +// // check if in last round +// if(!x){ +// //if(x === length - 1){ +// +// if(offset){ +// offset--; +// } +// else{ +// +// result[size++] = id; +// +// if(size === limit){ +// // fast path "end reached" +// return result /*resolve === false +// ? { result, suggest } +// :*/ +// } +// } +// } +// +// if(x || suggest){ +// //if((x < length - 1) || suggest){ +// check_new[id] = 1; +// } +// +// found = true; +// } +// +// if(suggest){ +// +// if(!check_suggest[id]){ +// check_suggest[id] = 1; +// const arr = suggest[y] || (suggest[y] = []); +// arr.push(id); +// } +// +// // OLD: +// // +// // check_idx = (check_suggest[id] || 0) + 1; +// // check_suggest[id] = check_idx; +// // +// // // do not adding IDs which are already included in the result (saves one loop) +// // // the first intersection match has the check index 2, so shift by -2 +// // +// // if(check_idx < length){ +// // +// // const tmp = suggest[check_idx - 2] || (suggest[check_idx - 2] = []); +// // tmp[tmp.length] = id; +// // } +// } +// } +// else{ +// +// // pre-fill in first round +// check_new[id] = 1; +// } +// } +// } +// +// if(suggest){ +// +// // re-use the first pre-filled check for suggestions +// check || (check_suggest = check_new); +// } +// else if(!found){ +// +// return []; +// } +// +// check = check_new; +// } +// +// // return intermediate result +// // if(resolve === false){ +// // return { result, suggest }; +// // } +// +// if(suggest){ +// +// // needs to iterate in reverse direction +// for(let x = suggest.length - 1, ids, len; x >= 0; x--){ +// +// ids = suggest[x]; +// len = ids.length; +// +// for(let y = 0, id; y < len; y++){ +// +// id = ids[y]; +// +// if(!check[id]){ +// +// if(offset){ +// offset--; +// } +// else{ +// +// result[size++] = id; +// +// if(size === limit){ +// // fast path "end reached" +// return result; +// } +// } +// +// check[id] = 1; +// } +// } +// } +// } +// +// return result; +// } + +/** + * Implementation based on Array.includes() provides better performance, + * but it needs at least one word in the query which is less frequent. + * Also on large indexes it does not scale well performance-wise. + * This strategy also lacks of suggestion capabilities (matching & sorting). + * + * @param arrays + * @param limit + * @param offset + * @param {boolean|Array=} suggest + * @returns {Array} + */ + +// export function intersect(arrays, limit, offset, suggest) { +// +// const length = arrays.length; +// let result = []; +// let check; +// +// // determine shortest array and collect results +// // from the sparse relevance arrays +// +// let smallest_size; +// let smallest_arr; +// let smallest_index; +// +// for(let x = 0; x < length; x++){ +// +// const arr = arrays[x]; +// const len = arr.length; +// +// let size = 0; +// +// for(let y = 0, tmp; y < len; y++){ +// +// tmp = arr[y]; +// +// if(tmp){ +// +// size += tmp.length; +// } +// } +// +// if(!smallest_size || (size < smallest_size)){ +// +// smallest_size = size; +// smallest_arr = arr; +// smallest_index = x; +// } +// } +// +// smallest_arr = smallest_arr.length === 1 ? +// +// smallest_arr[0] +// : +// concat(smallest_arr); +// +// if(suggest){ +// +// suggest = [smallest_arr]; +// check = create_object(); +// } +// +// let size = 0; +// let steps = 0; +// +// // process terms in reversed order often results in better performance. +// // the outer loop must be the words array, using the +// // smallest array here disables the "fast fail" optimization. +// +// for(let x = length - 1; x >= 0; x--){ +// +// if(x !== smallest_index){ +// +// steps++; +// +// const word_arr = arrays[x]; +// const word_arr_len = word_arr.length; +// const new_arr = []; +// +// let count = 0; +// +// for(let z = 0, id; z < smallest_arr.length; z++){ +// +// id = smallest_arr[z]; +// +// let found; +// +// // process relevance in forward order (direction is +// // important for adding IDs during the last round) +// +// for(let y = 0; y < word_arr_len; y++){ +// +// const arr = word_arr[y]; +// +// if(arr.length){ +// +// found = arr.includes(id); +// +// if(found){ +// +// // check if in last round +// +// if(steps === length - 1){ +// +// if(offset){ +// +// offset--; +// } +// else{ +// +// result[size++] = id; +// +// if(size === limit){ +// +// // fast path "end reached" +// +// return result; +// } +// } +// +// if(suggest){ +// +// check[id] = 1; +// } +// } +// +// break; +// } +// } +// } +// +// if(found){ +// +// new_arr[count++] = id; +// } +// } +// +// if(suggest){ +// +// suggest[steps] = new_arr; +// } +// else if(!count){ +// +// return []; +// } +// +// smallest_arr = new_arr; +// } +// } +// +// if(suggest){ +// +// // needs to iterate in reverse direction +// +// for(let x = suggest.length - 1, arr, len; x >= 0; x--){ +// +// arr = suggest[x]; +// len = arr && arr.length; +// +// if(len){ +// +// for(let y = 0, id; y < len; y++){ +// +// id = arr[y]; +// +// if(!check[id]){ +// +// check[id] = 1; +// +// if(offset){ +// +// offset--; +// } +// else{ +// +// result[size++] = id; +// +// if(size === limit){ +// +// // fast path "end reached" +// +// return result; +// } +// } +// } +// } +// } +// } +// } +// +// return result; +// } + +// COMPILER BLOCK --> + +/** + * @param {!string|DocumentSearchOptions} query + * @param {number|DocumentSearchOptions=} limit + * @param {DocumentSearchOptions=} options + * @param {Array=} _promises For internal use only. + * @returns {Promise|Array} + */ + +Document.prototype.search = function(query, limit, options, _promises){ + + if(!options){ + if(!limit && is_object(query)){ + options = /** @type {DocumentSearchOptions} */ (query); + query = ""; + } + else if(is_object(limit)){ + options = /** @type {DocumentSearchOptions} */ (limit); + limit = 0; + } + } + + let result = [], result_field = []; + let pluck, enrich, merge, suggest; + let field, tag, offset, count = 0, highlight; + + if(options){ + + if(is_array(options)){ + options = { + index: options + }; + } + + query = options.query || query; + pluck = options.pluck; + merge = options.merge; + field = pluck || options.field || options.index; + tag = this.tag && options.tag; + enrich = this.store && options.enrich; + suggest = options.suggest; + highlight = options.highlight; + //resolve = !SUPPORT_RESOLVER || (options.resolve !== false); + limit = options.limit || limit; + offset = options.offset || 0; + limit || (limit = 100); + + if(tag && (!this.db || !_promises)){ + + if(tag.constructor !== Array){ + tag = [tag]; + } + + let pairs = []; + + for(let i = 0, field; i < tag.length; i++){ + field = tag[i]; + if(is_string(field)){ + throw new Error("A tag option can't be a string, instead it needs a { field: tag } format."); + } + // default array notation + if(field.field && field.tag){ + const value = field.tag; + if(value.constructor === Array){ + for(let k = 0; k < value.length; k++){ + pairs.push(field.field, value[k]); + } + } + else { + pairs.push(field.field, value); + } + } + // shorter object notation + else { + const keys = Object.keys(field); + for(let j = 0, key, value; j < keys.length; j++){ + key = keys[j]; + value = field[key]; + if(value.constructor === Array){ + for(let k = 0; k < value.length; k++){ + pairs.push(key, value[k]); + } + } + else { + pairs.push(key, value); + } + } + } + } + + if(!pairs.length){ + throw new Error("Your tag definition within the search options is probably wrong. No valid tags found."); + } + + // tag used as pairs from this point + tag = pairs; + + // when tags is used and no query was set, + // then just return the tag indexes + if(!query){ + + let promises = []; + if(pairs.length) for(let j = 0; j < pairs.length; j+=2){ + let ids; + if(this.db){ + const index = this.index.get(pairs[j]); + if(!index){ + { + console.warn("Tag '" + pairs[j] + ":" + pairs[j + 1] + "' will be skipped because there is no field '" + pairs[j] + "'."); + } + continue; + } + promises.push(ids = index.db.tag(pairs[j + 1], limit, offset, enrich)); + } + else { + ids = get_tag.call(this, pairs[j], pairs[j + 1], limit, offset, enrich); + } + result.push({ + "field": pairs[j], + "tag": pairs[j + 1], + "result": ids + }); + } + + if(promises.length){ + return Promise.all(promises).then(function(promises){ + for(let j = 0; j < promises.length; j++){ + result[j].result = promises[j]; + } + return result; + }); + } + + return result; + } + } + + // extend to multi field search by default + if(is_string(field)){ + field = [field]; + } + } + + field || (field = this.field); + let promises = !_promises && (this.worker || this.db /*|| this.async*/) && []; + let db_tag_search; + + // multi field search + // field could be a custom set of selected fields by this query + // db tag indexes are also included in this field list + for(let i = 0, res, key, len; i < field.length; i++){ + + key = field[i]; + + if(this.db && this.tag){ + // tree is missing when it is a tag-only index (db) + if(!this.tree[i]){ + continue; + } + } + + let field_options; + + if(!is_string(key)){ + field_options = key; + key = field_options.field; + query = field_options.query || query; + limit = field_options.limit || limit; + offset = field_options.offset || offset; + suggest = (field_options.suggest || suggest); + enrich = this.store && (field_options.enrich || enrich); + } + + if(_promises){ + res = _promises[i]; + } + else { + let opt = field_options || options; + let index = this.index.get(key); + + if(tag){ + if(this.db){ + opt.tag = tag; + db_tag_search = index.db.support_tag_search; + opt.field = field; + } + if(!db_tag_search){ + opt.enrich = false; + } + } + if(promises){ + promises[i] = index.search/*Async*/(query, limit, opt); + // restore enrich state + opt && enrich && (opt.enrich = enrich); + // just collect and continue + continue; + } + else { + res = index.search(query, limit, opt); + // restore enrich state + opt && enrich && (opt.enrich = enrich); + } + } + + len = res && res.length; + + // todo when no term was matched but tag was retrieved extend suggestion to tags + // every field has to intersect against all selected tag fields + if(tag && len){ + + const arr = []; + let count = 0; + + // tags are only applied in resolve phase when it's a db + if(this.db && _promises){ + if(!db_tag_search){ + + // retrieve tag results assigned to it's field + for(let y = field.length; y < _promises.length; y++){ + + let ids = _promises[y]; + let len = ids && ids.length; + + if(len){ + count++; + arr.push(ids); + } + else if(!suggest){ + // no tags found + return result; + } + } + } + } + else { + + // tag[] are pairs at this line + for(let y = 0, ids, len; y < tag.length; y+=2){ + ids = this.tag.get(tag[y]); + + if(!ids){ + { + console.warn("Tag '" + tag[y] + ":" + tag[y + 1] + "' will be skipped because there is no field '" + tag[y] + "'."); + } + if(suggest){ + continue; + } + else { + return result; + } + } + + ids = ids && ids.get(tag[y + 1]); + len = ids && ids.length; + + if(len){ + count++; + arr.push(ids); + } + else if(!suggest){ + // no tags found + return result; + } + } + } + + if(count){ + res = intersect_union(res, arr); // intersect(arr, limit, offset) + len = res.length; + if(!len && !suggest){ + // nothing matched + return result; + } + // move counter back by 1 + count--; + } + } + + if(len){ + result_field[count] = key; + result.push(res); + count++; + } + else if(field.length === 1){ + // fast path: nothing matched + return result; + } + } + + if(promises){ + if(this.db){ + // todo when a tag index is never a search index this could be extracted + // push tag promises to the end + if(tag && tag.length && !db_tag_search){ + for(let y = 0; y < tag.length; y += 2){ + // it needs to retrieve data from tag pairs + const index = this.index.get(tag[y]); + if(!index){ + { + console.warn("Tag '" + tag[y] + ":" + tag[y + 1] + "' was not found because there is no field '" + tag[y] + "'."); + } + if(suggest){ + continue; + } + else { + return result; + } + } + promises.push(index.db.tag(tag[y + 1], limit, offset, /* enrich */ false)); + } + } + } + + const self = this; + + // TODO unroll this recursion + return Promise.all(promises).then(function(result){ + return result.length + ? self.search(query, limit, options, /* promises: */ result) + : result; + }); + } + + if(!count){ + return result; + } + if(pluck && (!enrich || !this.store)){ + return result[0]; + } + + promises = []; + + for(let i = 0, res; i < result_field.length; i++){ + + res = result[i]; + + if(enrich && res.length && !res[0].doc){ + if(!this.db){ + if(res.length){ + res = apply_enrich.call(this, res); + } + } + else { + // the documents are stored on the first field + promises.push(res = this.index.get(this.field[0]).db.enrich(res)); + } + } + + if(pluck){ + return res; + } + + result[i] = { + "field": result_field[i], + "result": res + }; + } + + if(enrich && SUPPORT_PERSISTENT && this.db && promises.length){ + const self = this; + return Promise.all(promises).then(function(promises){ + for(let j = 0; j < promises.length; j++){ + result[j]["result"] = promises[j]; + } + return merge + ? merge_fields(result, limit) + : highlight + ? highlight_fields(result, query, self.index, self.field, self.tree, highlight) + : result; + }); + } + + return merge + ? merge_fields(result, limit) + : highlight + ? highlight_fields(result, query, this.index, this.field, this.tree, highlight) + : result; +}; + +/* + + some matching term + + + */ + +function highlight_fields(result, query, index, field, tree, template, limit, offset){ + + // if(typeof template === "string"){ + // template = new RegExp(template, "g"); + // } + + let encoder; + + for(let i = 0, res, field, enc, path; i < result.length; i++){ + + res = result[i].result; + field = result[i].field; + enc = index.get(field).encoder; + path = tree[field.indexOf(field)]; + + if(enc !== encoder){ + encoder = enc; + encoder.encode(query); + } + + for(let j = 0; j < res.length; j++){ + let str = ""; + let content = parse_simple(res[j].doc, path); + + let split = encoder.encode(content); + + for(let k = 0; k < split.length; k++){ + str += split[k].replace(new RegExp("(" + split[k] + ")", "g"), template.replace("$1", content)); + } + + console.log(result,index, template); + + res[j].highlight = str; + } + } + + return result; +} + +// todo support Resolver +// todo when searching through multiple fields each term should +// be found at least by one field to get a valid match without +// using suggestion explicitly + +function merge_fields(fields, limit, offset){ + const final = []; + const set = create_object(); + for(let i = 0, field, res; i < fields.length; i++){ + field = fields[i]; + res = field.result; + for(let j = 0, id, entry, tmp; j < res.length; j++){ + entry = res[j]; + id = entry.id; + tmp = set[id]; + if(!tmp){ + // offset was already applied on field indexes + // if(offset){ + // offset--; + // continue; + // } + // apply limit from last round, because just fields could + // be pushed without adding new results + if(final.length === limit){ + return final; + } + entry.field = set[id] = [field.field]; + final.push(entry); + } + else { + tmp.push(field.field); + } + } + } + return final; +} + +/** + * @this Document + */ + +function get_tag(tag, key, limit, offset, enrich){ + let res = this.tag.get(tag); + if(!res){ + console.warn("Tag '" + tag + "' was not found"); + return []; + } + res = res && res.get(key); + let len = res && (res.length - offset); + + if(len && (len > 0)){ + if((len > limit) || offset){ + res = res.slice(offset, offset + limit); + } + if(enrich){ + res = apply_enrich.call(this, res); + } + return res; + } +} + +/** + * @this Document + */ + +function apply_enrich(res){ + + const arr = new Array(res.length); + + for(let x = 0, id; x < res.length; x++){ + id = res[x]; + arr[x] = { + "id": id, + "doc": this.store.get(id) + }; + } + + return arr; +} + +/**! + * FlexSearch.js + * Author and Copyright: Thomas Wilkerling + * Licence: Apache-2.0 + * Hosted by Nextapps GmbH + * https://github.com/nextapps-de/flexsearch + */ + + +/** + * @constructor + * @param {!DocumentOptions} options + */ + +function Document(options){ + + if(!this) { + return new Document(options); + } + + /** @type DocumentDescriptor */ + const document = options.document || options.doc || options; + let tmp, keystore; + + this.tree = []; + this.field = []; + this.marker = []; + this.key = ((tmp = document.key || document.id) && parse_tree(tmp, this.marker)) || "id"; + + keystore = (options.keystore || 0); + keystore && (this.keystore = keystore); + this.fastupdate = !!options.fastupdate; + this.reg = this.fastupdate + ? (keystore && SUPPORT_KEYSTORE ? new KeystoreMap(keystore) : new Map()) + : (keystore && SUPPORT_KEYSTORE ? new KeystoreSet(keystore) : new Set()); + + { + // todo support custom filter function + this.storetree = (tmp = document.store || null) && tmp !== true && []; + this.store = tmp && ( + keystore && SUPPORT_KEYSTORE + ? new KeystoreMap(keystore) + : new Map() + ); + } + + { + this.cache = (tmp = options.cache || null) && new CacheClass(tmp); + // do not apply cache again for the indexes since .searchCache() + // is just a wrapper over .search() + options.cache = false; + } + + { + this.worker = options.worker; + } + + // if(SUPPORT_ASYNC){ + // // this switch is used by recall of promise callbacks + // this.async = false; + // } + + /** + * @type {Map} + * @export + */ + this.index = parse_descriptor.call(this, options, document); + + { + this.tag = null; + // TODO case-insensitive tags? + if((tmp = document.tag)){ + if(typeof tmp === "string"){ + tmp = [tmp]; + } + if(tmp.length){ + this.tag = new Map(); + this.tagtree = []; + this.tagfield = []; + for(let i = 0, params, field; i < tmp.length; i++){ + params = tmp[i]; + field = params.field || params; + if(!field){ + throw new Error("The tag field from the document descriptor is undefined."); + } + if(params.custom){ + this.tagtree[i] = params.custom; + } + else { + this.tagtree[i] = parse_tree(field, this.marker); + if(params.filter){ + if(typeof this.tagtree[i] === "string"){ + // it needs an object to put a property to it + this.tagtree[i] = new String(this.tagtree[i]); + } + this.tagtree[i]._filter = params.filter; + } + } + // the tag fields needs to be hold by indices + this.tagfield[i] = field; + this.tag.set(field, new Map()); + } + } + } + } + + // resolve worker promises and swap instances + if(this.worker){ + const promises = []; + for(const index of this.index.values()){ + index.then && promises.push(index); + } + if(promises.length){ + const self = this; + return Promise.all(promises).then(function(promises){ + let count = 0; + for(const item of self.index.entries()){ + const key = item[0]; + const index = item[1]; + index.then && self.index.set(key, promises[count++]); + } + return self; + }); + } + } + else { + options.db && this.mount(options.db); + } +} + +{ + + Document.prototype.mount = function(db){ + + let fields = this.field; + + if(this.tag){ + // tag indexes are referenced by field + // move tags to their field indexes respectively + for(let i = 0, field; i < this.tagfield.length; i++){ + field = this.tagfield[i]; + let index;// = this.index.get(field); + //if(!index){ + // create raw index when not exists + this.index.set(field, index = new Index({}, this.reg)); + // copy and push to the field selection + if(fields === this.field){ + fields = fields.slice(0); + } + // tag indexes also needs to be upgraded to db instances + fields.push(field); + //} + // assign reference + index.tag = this.tag.get(field); + } + } + + const promises = []; + const config = { + db: db.db, + type: db.type, + fastupdate: db.fastupdate + }; + + // upgrade all indexes to db instances + for(let i = 0, index, field; i < fields.length; i++){ + config.field = field = fields[i]; + index = this.index.get(field); + const dbi = new db.constructor(db.id, config); + // take over the storage id + dbi.id = db.id; + promises[i] = dbi.mount(index); + // add an identification property + index.document = true; + if(i){ + // the register has to export just one time + // also it's needed by the index for ID contain check + index.bypass = true; + } + else { + // the datastore has to export one time + index.store = this.store; + } + } + + //this.async = true; + this.db = true; + return Promise.all(promises); + }; + + Document.prototype.commit = async function(replace, append){ + // parallel: + const promises = []; + for(const index of this.index.values()){ + promises.push(index.db.commit(index, replace, append)); + } + await Promise.all(promises); + this.reg.clear(); + // queued: + // for(const index of this.index.values()){ + // await index.db.commit(index, replace, append); + // } + // this.reg.clear(); + }; + + Document.prototype.destroy = function(){ + const promises = []; + for(const idx of this.index.values()){ + promises.push(idx.destroy()); + } + return Promise.all(promises); + }; +} + +/** + * @this Document + */ + +function parse_descriptor(options, document){ + + const index = new Map(); + let field = document.index || document.field || document; + + if(is_string(field)){ + field = [field]; + } + + for(let i = 0, key, opt; i < field.length; i++){ + + key = field[i]; + + if(!is_string(key)){ + opt = key; + key = key.field; + } + + opt = /** @type DocumentIndexOptions */ ( + is_object(opt) + ? Object.assign({}, options, opt) + : options + ); + + if(this.worker){ + const worker = new WorkerIndex(opt); + if(worker){ + // worker could be a promise + // it needs to be resolved and swapped later + index.set(key, worker); + } + else { + // fallback when not supported + this.worker = false; + } + } + + if(!this.worker){ + index.set(key, new Index(opt, this.reg)); + } + + if(opt.custom){ + this.tree[i] = opt.custom; + } + else { + this.tree[i] = parse_tree(key, this.marker); + if(opt.filter){ + if(typeof this.tree[i] === "string"){ + // it needs an object to put a property to it + this.tree[i] = new String(this.tree[i]); + } + this.tree[i]._filter = opt.filter; + } + } + + this.field[i] = key; + } + + if(this.storetree){ + + let stores = document.store; + if(is_string(stores)) stores = [stores]; + + for(let i = 0, store, field; i < stores.length; i++){ + store = /** @type Array */ (stores[i]); + field = store.field || store; + if(store.custom){ + this.storetree[i] = store.custom; + store.custom._field = field; + } + else { + this.storetree[i] = parse_tree(field, this.marker); + if(store.filter){ + if(typeof this.storetree[i] === "string"){ + // it needs an object to put a property to it + this.storetree[i] = new String(this.storetree[i]); + } + this.storetree[i]._filter = store.filter; + } + } + } + } + + return index; +} + +function parse_tree(key, marker){ + + const tree = key.split(":"); + let count = 0; + + for(let i = 0; i < tree.length; i++){ + key = tree[i]; + // todo apply some indexes e.g. [0], [-1], [0-2] + if(key[key.length - 1] === "]"){ + key = key.substring(0, key.length - 2); + if(key){ + marker[count] = true; + } + } + if(key){ + tree[count++] = key; + } + } + + if(count < tree.length){ + tree.length = count; + } + + return count > 1 ? tree : tree[0]; +} + +Document.prototype.append = function(id, content){ + return this.add(id, content, true); +}; + +Document.prototype.update = function(id, content){ + return this.remove(id).add(id, content); +}; + +Document.prototype.remove = function(id){ + + if(is_object(id)){ + id = parse_simple(id, this.key); + } + + for(const index of this.index.values()){ + index.remove(id, /* skip deletion */ true); + } + + if(this.reg.has(id)){ + + if(this.tag){ + // when fastupdate was enabled all ids are already removed + if(!this.fastupdate){ + for(let field of this.tag.values()){ + for(let item of field){ + const tag = item[0]; + const ids = item[1]; + const pos = ids.indexOf(id); + if(pos > -1){ + ids.length > 1 + ? ids.splice(pos, 1) + : field.delete(tag); + } + } + } + } + } + + if(this.store){ + this.store.delete(id); + } + + this.reg.delete(id); + } + + // the cache could be used outside the InMemory store + if(this.cache){ + this.cache.remove(id); + } + + return this; +}; + +Document.prototype.clear = function(){ + + //const promises = []; + + for(const index of this.index.values()){ + // db index will add clear task + index.clear(); + // const promise = index.clear(); + // if(promise instanceof Promise){ + // promises.push(promise); + // } + } + + if(this.tag){ + for(const tags of this.tag.values()){ + tags.clear(); + } + } + + if(this.store){ + this.store.clear(); + } + + return this; /*promises.length + ? Promise.all(promises) + :*/ +}; + +Document.prototype.contain = function(id){ + + if(this.db){ + return this.index.get(this.field[0]).db.has(id); + } + + return this.reg.has(id); +}; + +Document.prototype.cleanup = function(){ + + for(const index of this.index.values()){ + index.cleanup(); + } + + return this; +}; + +{ + + Document.prototype.get = function(id){ + + if(this.db){ + return this.index.get(this.field[0]).db.enrich(id).then(function(result){ + return result[0] && result[0].doc; + }); + } + + return this.store.get(id); + }; + + Document.prototype.set = function(id, store){ + + this.store.set(id, store); + return this; + }; +} + +{ + // todo mo + Document.prototype.searchCache = searchCache; +} + +{ + + Document.prototype.export = exportDocument; + Document.prototype.import = importDocument; +} + +{ + + apply_async(Document.prototype); +} + +/** + * @param {string|Object} query + * @param {number|Object=} limit + * @param {Object=} options + * @this {Index|Document} + * @returns {Array|Promise} + */ + +function searchCache(query, limit, options){ + + query = (typeof query === "object" + ? "" + query.query + : "" + query + ).toLowerCase(); + + //let encoded = this.encoder.encode(query).join(" "); + let cache = this.cache.get(query); + if(!cache){ + cache = this.search(query, limit, options); + if(cache.then){ + const self = this; + cache.then(function(cache){ + self.cache.set(query, cache); + return cache; + }); + } + this.cache.set(query, cache); + } + return cache; +} + +/** + * @param {boolean|number=} limit + * @constructor + */ + +function CacheClass(limit){ + /** @private */ + this.limit = (!limit || limit === true) ? 1000 : limit; + /** @private */ + this.cache = new Map(); + /** @private */ + this.last = ""; +} + +CacheClass.prototype.set = function(key, value){ + //if(!this.cache.has(key)){ + this.cache.set(this.last = key, value); + if(this.cache.size > this.limit){ + this.cache.delete(this.cache.keys().next().value); + } + //} +}; + +CacheClass.prototype.get = function(key){ + const cache = this.cache.get(key); + if(cache && this.last !== key){ + this.cache.delete(key); + this.cache.set(this.last = key, cache); + } + return cache; +}; + +CacheClass.prototype.remove = function(id){ + for(const item of this.cache){ + const key = item[0]; + const value = item[1]; + if(value.includes(id)){ + this.cache.delete(key); + } + } +}; + +CacheClass.prototype.clear = function(){ + this.cache.clear(); + this.last = ""; +}; + +/** @type EncoderOptions */ +const options$9 = { + normalize: false, + dedupe: false +}; + +/** @type EncoderOptions */ +const options$8 = { + normalize: function(str){ + return str.toLowerCase(); + }, + dedupe: false +}; + +/** @type EncoderOptions */ +const options$7 = { + normalize: true, + dedupe: true +}; + +const soundex$1 = new Map([ + ["b", "p"], + //["p", "p"], + + //["f", "f"], + ["v", "f"], + ["w", "f"], + + //["s", "s"], + ["z", "s"], + ["x", "s"], + + ["d", "t"], + //["t", "t"], + + //["m", "m"], + ["n", "m"], + + //["k", "k"], + ["c", "k"], + ["g", "k"], + ["j", "k"], + ["q", "k"], + + //["r", "r"], + //["h", "h"], + //["l", "l"], + + //["a", "a"], + + //["e", "e"], + ["i", "e"], + ["y", "e"], + + //["o", "o"], + ["u", "o"] +]); + +/** @type EncoderOptions */ +const options$6 = { + normalize: true, + dedupe: true, + mapper: soundex$1 +}; + +const matcher = new Map([ + ["ai", "ei"], + ["ae", "a"], + ["oe", "o"], + ["ue", "u"], + ["sh", "s"], + ["ch", "c"], + ["th", "t"], + ["ph", "f"], + ["pf", "f"] +]); + +const replacer = [ + /([^aeo])h([aeo$])/g, "$1$2", + /([aeo])h([^aeo]|$)/g, "$1$2", +]; + +/** @type EncoderOptions */ +const options$5 = { + normalize: true, + dedupe: true, + mapper: soundex$1, + replacer: replacer, + matcher: matcher +}; + +const compact = [ + /(?!^)[aeoy]/g, "" // old: aioy +]; + +/** @type EncoderOptions */ +const options$4 = { + normalize: true, + dedupe: true, + mapper: soundex$1, + replacer: replacer.concat(compact), + matcher: matcher +}; + +/** @type EncoderOptions */ +const options$3 = { + normalize: true, + dedupe: false, + include: { + letter: true + }, + finalize: function(arr){ + for(let i = 0; i < arr.length; i++){ + arr[i] = soundex(arr[i]); + } + } +}; + +const codes = { + "a": "", "e": "", "i": "", "o": "", "u": "", "y": "", + "b": 1, "f": 1, "p": 1, "v": 1, + "c": 2, "g": 2, "j": 2, "k": 2, "q": 2, "s": 2, "x": 2, "z": 2, "ß": 2, + "d": 3, "t": 3, + "l": 4, + "m": 5, "n": 5, + "r": 6 +}; + +function soundex(stringToEncode){ + + let encodedString = stringToEncode.charAt(0); + let last = codes[encodedString]; + for(let i = 1, char; i < stringToEncode.length; i++){ + char = stringToEncode.charAt(i); + // Remove all occurrences of "h" and "w" + if(char !== "h" && char !== "w"){ + // Replace all consonants with digits + char = codes[char]; + // Remove all occurrences of a,e,i,o,u,y except first letter + if(char){ + // Replace all adjacent same digits with one digit + if(char !== last){ + encodedString += char; + last = char; + if(encodedString.length === 4){ + break; + } + } + } + } + } + // while(encodedString.length < 4){ + // encodedString += "0"; + // } + return encodedString; +} + +const regex$2 = /[\x00-\x7F]+/g; + +/** @type EncoderOptions */ +const options$2 = { + rtl: true, + normalize: false, + dedupe: true, + prepare: function(str){ + return ("" + str).replace(regex$2, " ") + } +}; + +const regex$1 = /[\x00-\x7F]+/g; + +/** @type EncoderOptions */ +const options$1 = { + normalize: false, + dedupe: true, + split: "", + prepare: function(str){ + return ("" + str).replace(regex$1, "") + } +}; + +const regex = /[\x00-\x7F]+/g; + +/** @type EncoderOptions */ +const options = { + normalize: false, + dedupe: true, + prepare: function(str){ + return ("" + str).replace(regex, " ") + } +}; + +// export const global_lang = create_object(); +//export const global_charset = create_object(); + +var Charset = { + LatinExact: options$9, + LatinDefault: options$8, + LatinSimple: options$7, + LatinBalance: options$6, + LatinAdvanced: options$5, + LatinExtra: options$4, + LatinSoundex: options$3, + ArabicDefault: options$2, + CjkDefault: options$1, + CyrillicDefault: options +}; + +// global_charset["latin:exact"] = charset_exact; +// global_charset["latin:default"] = charset_default; +// global_charset["latin:simple"] = charset_simple; +// global_charset["latin:balance"] = charset_balance; +// global_charset["latin:advanced"] = charset_advanced; +// global_charset["latin:extra"] = charset_extra; +// global_charset["latin:soundex"] = charset_soundex; + + +/** + * @param {!string} name + * @param {Object} charset + */ + +// export function registerCharset(name, charset){ +// global_charset[name] = charset; +// } + +/** + * @param {!string} name + * @param {Object} lang + */ + +// export function registerLanguage(name, lang){ +// global_lang[name] = lang; +// } + +// COMPILER BLOCK --> + +/** + * @enum {Object} + * @const + */ + +const presets = { + + "memory": { + resolution: 1 + }, + + "performance": { + resolution: 6, + fastupdate: true, + context: { + depth: 1, + resolution: 3 + } + }, + + "match": { + tokenize: "forward" + }, + + "score": { + resolution: 9, + context: { + depth: 2, + resolution: 9 + } + } +}; + +/** + * + * @param {!IndexOptions|string} options + * @return {IndexOptions} + */ + +function apply_preset(options){ + + const preset = is_string(options) + ? options + : options["preset"]; + + if(preset){ + if(!presets[preset]){ + console.warn("Preset not found: " + preset); + } + options = Object.assign({}, presets[preset], /** @type {Object} */ (options)); + } + + return options; +} + +const data = create_object(); + +/** + * @param {!string} name + */ + +function tick(name){ + + /** @type {!Object} */ + const profiler = data["profiler"] || (data["profiler"] = {}); + + profiler[name] || (profiler[name] = 0); + profiler[name]++; +} + +// COMPILER BLOCK --> +// <-- COMPILER BLOCK + +let table;// = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/"; +let timer; +const cache = new Map(); + +function toRadix(number, radix = 255) { + + if(!table){ + table = new Array(radix); + // the char code 0 could be a special marker + for(let i = 0; i < radix; i++) table[i] = i + 1; + table = String.fromCharCode.apply(null, table); + } + + let rixit; + let residual = number; + let result = ""; + + while(true){ + rixit = residual % radix; + result = table.charAt(rixit) + result; + residual = residual / radix | 0; + if(!residual) + break; + } + + return result; +} + +function default_compress(str){ + + { + if(timer){ + if(cache.has(str)){ + return cache.get(str); + } + } + else { + timer = setTimeout(clear); + } + } + + /* 2 ** ((level + 1.5) * 1.6 | 0) */ + + const result = toRadix( + typeof str == "number" + ? str + : lcg(str) + ); + + { + cache.size > 2e5 && cache.clear(); + cache.set(str, result); + } + + return result; +} + +function lcg(str) { + let range = 2 ** 32 - 1; + if(typeof str == "number"){ + return str & range; + } + let crc = 0, bit = 32 + 1; + for(let i = 0; i < str.length; i++) { + crc = (crc * bit ^ str.charCodeAt(i)) & range; + } + // shift up from Int32 to UInt32 range 0xFFFFFFFF + return crc + 2 ** 31; +} + +function clear(){ + timer = null; + cache.clear(); +} + +// COMPILER BLOCK --> + +// TODO: +// string + number as text +// boolean, null, undefined as ? + + +/** + * @param {!number|string} id + * @param {!string} content + * @param {boolean=} _append + * @param {boolean=} _skip_update + */ + +Index.prototype.add = function(id, content, _append, _skip_update){ + + if(content && (id || (id === 0))){ + + // todo check skip_update + //_skip_update = false; + + if(!_skip_update && !_append){ + if(this.reg.has(id)){ + return this.update(id, content); + } + } + + // do not force a string as input + // https://github.com/nextapps-de/flexsearch/issues/432 + content = this.encoder.encode(content); + const word_length = content.length; + + if(word_length){ + + // check context dupes to skip all contextual redundancy along a document + + const dupes_ctx = create_object(); + const dupes = create_object(); + const depth = this.depth; + const resolution = this.resolution; + + for(let i = 0; i < word_length; i++){ + + let term = content[this.rtl ? word_length - 1 - i : i]; + let term_length = term.length; + + // skip dupes will break the context chain + + if(term_length /*&& (term_length >= this.minlength)*/ && (depth || !dupes[term])){ + + let score = this.score + ? this.score(content, term, i, null, 0) + : get_score(resolution, word_length, i); + let token = ""; + + switch(this.tokenize){ + + case "full": + if(term_length > 2){ + for(let x = 0; x < term_length; x++){ + for(let y = term_length; y > x; y--){ + + //if((y - x) >= this.minlength){ + token = term.substring(x, y); + const partial_score = this.score + ? this.score(content, term, i, token, x) + : get_score(resolution, word_length, i, term_length, x); + this.push_index(dupes, token, partial_score, id, _append); + //} + } + } + break; + } + // fallthrough to next case when term length < 3 + case "reverse": + // skip last round (this token exist already in "forward") + if(term_length > 1){ + for(let x = term_length - 1; x > 0; x--){ + token = term[x] + token; + //if(token.length >= this.minlength){ + const partial_score = this.score + ? this.score(content, term, i, token, x) + : get_score(resolution, word_length, i, term_length, x); + this.push_index(dupes, token, partial_score, id, _append); + //} + } + token = ""; + } + + // fallthrough to next case to apply forward also + case "forward": + if(term_length > 1){ + for(let x = 0; x < term_length; x++){ + token += term[x]; + //if(token.length >= this.minlength){ + this.push_index(dupes, token, score, id, _append); + //} + } + break; + } + + // fallthrough to next case when token has a length of 1 + default: + // case "strict": + + // todo move boost to search + // if(this.boost){ + // score = Math.min((score / this.boost(content, term, i)) | 0, resolution - 1); + // } + + this.push_index(dupes, term, score, id, _append); + + // context is just supported by tokenizer "strict" + if(depth){ + + if((word_length > 1) && (i < (word_length - 1))){ + + // check inner dupes to skip repeating words in the current context + const dupes_inner = create_object(); + const resolution = this.resolution_ctx; + const keyword = term; + const size = Math.min(depth + 1, word_length - i); + + dupes_inner[keyword] = 1; + + for(let x = 1; x < size; x++){ + + term = content[this.rtl ? word_length - 1 - i - x : i + x]; + + if(term /*&& (term.length >= this.minlength)*/ && !dupes_inner[term]){ + + dupes_inner[term] = 1; + + const context_score = this.score + ? this.score(content, keyword, i, term, x) + : get_score(resolution + ((word_length / 2) > resolution ? 0 : 1), word_length, i, size - 1, x - 1); + const swap = this.bidirectional && (term > keyword); + this.push_index(dupes_ctx, swap ? keyword : term, context_score, id, _append, swap ? term : keyword); + } + } + } + } + } + } + } + + this.fastupdate || this.reg.add(id); + } + else { + content = ""; + } + } + + if(this.db){ + // when the term has no valid content (e.g. empty), + // then it was not added to the ID registry for removal + content || this.commit_task.push({ "del": id }); + this.commit_auto && autoCommit(this); + } + + return this; +}; + +/** + * @private + * @param dupes + * @param term + * @param score + * @param id + * @param {boolean=} append + * @param {string=} keyword + */ + +Index.prototype.push_index = function(dupes, term, score, id, append, keyword){ + + let arr = keyword ? this.ctx : this.map; + let tmp; + + if(!dupes[term] || (keyword && !(tmp = dupes[term])[keyword])){ + + if(keyword){ + + dupes = tmp || (dupes[term] = create_object()); + dupes[keyword] = 1; + + if(this.compress){ + keyword = default_compress(keyword); + } + + tmp = arr.get(keyword); + tmp ? arr = tmp + : arr.set(keyword, arr = new Map()); + } + else { + + dupes[term] = 1; + } + + if(this.compress){ + term = default_compress(term); + } + + tmp = arr.get(term); + tmp ? arr = tmp : arr.set(term, arr = tmp = []); + // the ID array will be upgraded dynamically + arr = arr[score] || (arr[score] = []); + + if(!append || !arr.includes(id)){ + + // auto-upgrade to keystore array if max size exceeded + { + if(arr.length === 2**31-1 /*|| !(arr instanceof KeystoreArray)*/){ + const keystore = new KeystoreArray(arr); + if(this.fastupdate){ + for(let value of this.reg.values()){ + if(value.includes(arr)){ + value[value.indexOf(arr)] = keystore; + } + } + } + tmp[score] = arr = keystore; + } + } + + arr.push(id); + + // add a reference to the register for fast updates + if(this.fastupdate){ + const tmp = this.reg.get(id); + tmp ? tmp.push(arr) + : this.reg.set(id, [arr]); + } + } + } +}; + +/** + * @param {number} resolution + * @param {number} length + * @param {number} i + * @param {number=} term_length + * @param {number=} x + * @returns {number} + */ + +function get_score(resolution, length, i, term_length, x){ + + // console.log("resolution", resolution); + // console.log("length", length); + // console.log("term_length", term_length); + // console.log("i", i); + // console.log("x", x); + // console.log((resolution - 1) / (length + (term_length || 0)) * (i + (x || 0)) + 1); + + // the first resolution slot is reserved for the best match, + // when a query matches the first word(s). + + // also to stretch score to the whole range of resolution, the + // calculation is shift by one and cut the floating point. + // this needs the resolution "1" to be handled additionally. + + // do not stretch the resolution more than the term length will + // improve performance and memory, also it improves scoring in + // most cases between a short document and a long document + + return i && (resolution > 1) ? ( + + (length + (term_length || 0)) <= resolution ? + + i + (x || 0) + : + ((resolution - 1) / (length + (term_length || 0)) * (i + (x || 0)) + 1) | 0 + ): + 0; +} + +/* + from -> res[score][id] + to -> [id] +*/ + +/** + * Aggregate the union of a single raw result + * @param {!Array} result + * @param {!number} limit + * @param {number=} offset + * @param {boolean=} enrich + * @return Array + */ + +function resolve_default(result, limit, offset, enrich){ + + // fast path: when there is just one slot in the result + if(result.length === 1){ + result = result[0]; + result = offset || (result.length > limit) + ? (limit + ? result.slice(offset, offset + limit) + : result.slice(offset) + ) + : result; + return enrich + ? enrich_result(result) + : result; + } + + // this is an optimized workaround instead of + // just doing result = concat(result) + + let final = []; + + for(let i = 0, arr, len; i < result.length; i++){ + if(!(arr = result[i]) || !(len = arr.length)) continue; + + if(offset){ + // forward offset pointer + if(offset >= len){ + offset -= len; + continue; + } + // apply offset pointer when length differs + if(offset < len){ + arr = limit + ? arr.slice(offset, offset + limit) + : arr.slice(offset); + len = arr.length; + offset = 0; + } + } + + if(!final.length){ + // fast path: when limit was reached in first slot + if(len >= limit){ + if(len > limit){ + arr = arr.slice(0, limit); + } + return enrich + ? enrich_result(arr) + : arr; + } + final = [arr]; + } + else { + if(len > limit){ + arr = arr.slice(0, limit); + len = arr.length; + } + final.push(arr); + } + + // reduce limit + limit -= len; + + // todo remove + // if(limit < 0){ + // throw new Error("Impl.Error"); + // } + + // break if limit was reached + if(!limit){ + break; + } + } + + // todo remove + if(!final.length){ + //throw new Error("No results found"); + return final; + } + + final = final.length > 1 + ? concat(final) + : final[0]; + + return enrich + ? enrich_result(final) + : final; +} + +function enrich_result(ids){ + for(let i = 0; i < ids.length; i++){ + ids[i] = { + score: i, + id: ids[i] + }; + } + return ids; +} + +Resolver.prototype.or = function(){ + + const self = this; + let args = arguments; + let first_argument = args[0]; + + if(first_argument.then){ + return first_argument.then(function(){ + return self.or.apply(self, args); + }); + } + + if(first_argument[0]){ + // fix false passed parameter style + if(first_argument[0].index){ + return this.or.apply(this, first_argument); + } + } + + let final = []; + let promises = []; + let limit = 0, offset = 0, enrich, resolve; + + for(let i = 0, query; i < args.length; i++){ + + query = /** @type {string|ResolverOptions} */ ( + args[i] + ); + + if(query){ + + limit = query.limit || 0; + offset = query.offset || 0; + enrich = query.enrich; + resolve = query.resolve; + + let result; + if(query.constructor === Resolver){ + result = query.result; + } + else if(query.constructor === Array){ + result = query; + } + else if(query.index){ + query.resolve = false; + result = query.index.search(query).result; + } + else if(query.and){ + result = this.and(query.and); + } + else if(query.xor){ + result = this.xor(query.xor); + } + else if(query.not){ + result = this.not(query.not); + } + else { + continue; + } + + final[i] = result; + + if(result.then){ + promises.push(result); //{ query, result }; + } + } + } + + if(promises.length){ + return Promise.all(promises).then(function(){ + //self.result.length && (final = [self.result].concat(final)); + // the suggest-union was re-used from but there it needs reversed order + self.result.length && (final = final.concat([self.result])); + self.result = union(final, limit, offset, enrich, resolve, self.boostval); + return resolve ? self.result : self; + }); + } + + if(final.length){ + //this.result.length && (final = [this.result].concat(final)); + // the suggest-union was re-used but there it needs reversed order + this.result.length && (final = final.concat([this.result])); + this.result = union(final, limit, offset, enrich, resolve, this.boostval); + } + return resolve ? this.result : this; +}; + +/** + * Aggregate the union of N raw results + * @param result + * @param limit + * @param offset + * @param enrich + * @param resolve + * @param boost + * @return {Array} + */ + +function union(result, limit, offset, enrich, resolve, boost){ + + if(!result.length){ + // todo remove + //console.log("Empty Result") + return result; + } + + if(typeof limit === "object"){ + offset = limit.offset || 0; + enrich = limit.enrich || false; + limit = limit.limit || 0; + } + + if(result.length < 2){ + // todo remove + //console.log("Single Result") + if(resolve){ + return resolve_default(result[0], limit, offset, enrich); + } + else { + return result[0]; + } + } + + // the suggest-union + return union$1(result/*.reverse()*/, offset, limit, resolve, boost); + + // let final = []; + // let count = 0; + // let dupe = create_object(); + // let maxres = get_max_len(result); + // + // for(let j = 0, ids; j < maxres; j++){ + // for(let i = 0, res; i < result.length; i++){ + // res = result[i]; + // if(!res) continue; + // ids = res[j]; + // if(!ids) continue; + // + // for(let k = 0, id; k < ids.length; k++){ + // id = ids[k]; + // if(!dupe[id]){ + // dupe[id] = 1; + // if(offset){ + // offset--; + // continue; + // } + // if(resolve){ + // final.push(id); + // } + // else{ + // // shift resolution by boost (inverse) + // const index = j + (boost || 0); + // final[index] || (final[index] = []); + // final[index].push(id); + // } + // if(limit && ++count === limit){ + // //this.boost = 0; + // return final; + // } + // } + // } + // } + // } + // + // //this.boost = 0; + // return final; +} + +Resolver.prototype.and = function(){ + if(this.result.length){ + + const self = this; + let args = arguments; + let first_argument = args[0]; + + if(first_argument.then){ + return first_argument.then(function(){ + return self.and.apply(self, args); + }); + } + + if(first_argument[0]){ + // fix false passed parameter style + if(first_argument[0].index){ + return this.and.apply(this, first_argument); + } + } + + let final = []; + let promises = []; + let limit = 0, offset = 0, enrich, resolve, suggest; + + for(let i = 0, query; i < args.length; i++){ + + query = /** @type {string|ResolverOptions} */ ( + args[i] + ); + + if(query){ + + limit = query.limit || 0; + offset = query.offset || 0; + enrich = query.enrich; + resolve = query.resolve; + suggest = query.suggest; + + let result; + if(query.constructor === Resolver){ + result = query.result; + } + else if(query.constructor === Array){ + result = query; + } + else if(query.index){ + query.resolve = false; + result = query.index.search(query).result; + } + else if(query.or){ + result = this.or(query.or); + } + else if(query.xor){ + result = this.xor(query.xor); + } + else if(query.not){ + result = this.not(query.not); + } + else { + continue; + } + + final[i] = result; + + if(result.then){ + promises.push(result); //{ query, result }; + } + } + } + + if(!final.length){ + this.result = final; + return resolve ? this.result : this; + } + + if(promises.length){ + return Promise.all(promises).then(function(){ + final = [self.result].concat(final); + self.result = intersect(final, limit, offset, enrich, resolve, self.boostval, suggest); + return resolve ? self.result : self; + }); + } + + final = [this.result].concat(final); + this.result = intersect(final, limit, offset, enrich, resolve, this.boostval, suggest); + return resolve ? this.result : this; + } + return this; +}; + +/** + * Aggregate the intersection of N raw results + * @param result + * @param limit + * @param offset + * @param enrich + * @param resolve + * @param boost + * @param suggest + * @return {Array} + */ + +function intersect(result, limit, offset, enrich, resolve, boost, suggest){ + + // if(!result.length){ + // // todo remove + // console.log("Empty Result") + // return result; + // } + + if(result.length < 2){ + return []; + } + + let final = []; + let maxres = get_max_len(result); + if(!maxres) return final; + + //console.log(result) + + return intersect$1(result, maxres, limit, offset, suggest, boost, resolve); + + // for(let j = 0, ids, res = result[0]; j < res.length; j++){ + // ids = res[j]; + // for(let k = 0; k < ids.length; k++){ + // contain[ids[k]] = 1; + // } + // } + + // for(let i = 0, res; i < result.length; i++){ + // res = result[i]; + // if(!res || !res.length) return []; + // let contain_new = create_object(); + // let match = 0; + // let last_round = i === result.length - 1; + // + // for(let j = 0, ids; j < maxres; j++){ + // ids = res[j]; + // if(!ids) continue; + // + // for(let k = 0, id, min; k < ids.length; k++){ + // id = ids[k]; + // // fill in first round + // if(!i){ + // // shift resolution +1 + // // shift resolution by boost (inverse) + // contain_new[id] = j + 1 + (i ? boost : 0); + // match = 1; + // } + // // result in last round + // else if(last_round){ + // if((min = contain[id])){ + // match = 1; + // //if(!contain_new[id]){ + // if(offset){ + // offset--; + // continue; + // } + // if(resolve){ + // final.push(id); + // } + // else{ + // // reduce resolution -1 + // min--; + // if(j < min) min = j; + // final[min] || (final[min] = []); + // final[min].push(id); + // } + // if(limit && ++count === limit){ + // //this.boost = 0; + // return final; + // } + // // shift resolution +1 + // //contain_new[id] = min + 1; + // //} + // } + // } + // // check for intersection + // else if((min = contain[id])){ + // // shift resolution +1 + // if(j + 1 < min) min = j + 1; + // contain_new[id] = min; + // match = 1; + // } + // } + // } + // + // if(!match){ + // //this.boost = 0; + // return []; + // } + // + // contain = contain_new; + // } + // + // //this.boost = 0; + // return final; +} + +Resolver.prototype.xor = function(){ + const self = this; + let args = arguments; + let first_argument = args[0]; + + if(first_argument.then){ + return first_argument.then(function(){ + return self.xor.apply(self, args); + }); + } + + if(first_argument[0]){ + // fix false passed parameter style + if(first_argument[0].index){ + return this.xor.apply(this, first_argument); + } + } + + let final = []; + let promises = []; + let limit = 0, offset = 0, enrich, resolve; + + for(let i = 0, query; i < args.length; i++){ + + query = /** @type {string|ResolverOptions} */ ( + args[i] + ); + + if(query){ + + limit = query.limit || 0; + offset = query.offset || 0; + enrich = query.enrich; + resolve = query.resolve; + + let result; + if(query.constructor === Resolver){ + result = query.result; + } + else if(query.constructor === Array){ + result = query; + } + else if(query.index){ + query.resolve = false; + result = query.index.search(query).result; + } + else if(query.or){ + result = this.or(query.or); + } + else if(query.and){ + result = this.and(query.and); + } + else if(query.not){ + result = this.not(query.not); + } + else { + continue; + } + + final[i] = result; + + if(result.then){ + promises.push(result); //{ query, result }; + } + } + } + + if(promises.length){ + return Promise.all(promises).then(function(){ + self.result.length && (final = [self.result].concat(final)); + self.result = exclusive(final, limit, offset, enrich, !resolve, self.boostval); + return resolve ? self.result : self; + }); + } + + if(final.length){ + this.result.length && (final = [this.result].concat(final)); + this.result = exclusive(final, limit, offset, enrich, !resolve, self.boostval); + } + return resolve ? this.result : this; +}; + +/** + * @param result + * @param limit + * @param offset + * @param enrich + * @param resolve + * @param boost + * @return {Array} + */ + +function exclusive(result, limit, offset, enrich, resolve, boost){ + + if(!result.length){ + // todo remove + //console.log("Empty Result") + return result; + } + + if(result.length < 2){ + // todo remove + //console.log("Single Result") + if(resolve){ + return resolve_default(result[0], limit, offset, enrich); + } + else { + return result[0]; + } + } + + const final = []; + const check = create_object(); + let maxres = 0; + + for(let i = 0, res; i < result.length; i++){ + res = result[i]; + if(!res) continue; + + for(let j = 0, ids; j < res.length; j++){ + ids = res[j]; + if(!ids) continue + + if(maxres < ids.length) maxres = ids.length; + + for(let k = 0, id; k < ids.length; k++){ + id = ids[k]; + check[id] + ? check[id]++ + : check[id] = 1; + } + } + } + + for(let j = 0, ids, count = 0; j < maxres; j++){ + + for(let i = 0, res; i < result.length; i++){ + res = result[i]; + if(!res) continue; + + ids = res[j]; + if(!ids) continue; + + for(let k = 0, id; k < ids.length; k++){ + id = ids[k]; + if(check[id] === 1){ + if(offset){ + offset--; + continue; + } + if(resolve){ + final.push(id); + if(final.length === limit){ + return final; + } + } + else { + // shift resolution by boost (inverse) + const index = j + (i ? boost : 0); + final[index] || (final[index] = []); + final[index].push(id); + if(++count === limit){ + return final; + } + } + } + } + } + } + + //this.boost = 0; + return final; +} + +Resolver.prototype.not = function(){ + const self = this; + let args = arguments; + let first_argument = args[0]; + + if(first_argument.then){ + return first_argument.then(function(){ + return self.not.apply(self, args); + }); + } + + if(first_argument[0]){ + // fix false passed parameter style + if(first_argument[0].index){ + return this.not.apply(this, first_argument); + } + } + + let final = []; + let promises = []; + let limit = 0, offset = 0, resolve; + + for(let i = 0, query; i < args.length; i++){ + + query = /** @type {string|ResolverOptions} */ ( + args[i] + ); + + if(query){ + + limit = query.limit || 0; + offset = query.offset || 0; + query.enrich; + resolve = query.resolve; + + let result; + if(query.constructor === Resolver){ + result = query.result; + } + else if(query.constructor === Array){ + result = query; + } + else if(query.index){ + query.resolve = false; + result = query.index.search(query).result; + } + else if(query.or){ + result = this.or(query.or); + } + else if(query.and){ + result = this.and(query.and); + } + else if(query.xor){ + result = this.xor(query.xor); + } + else { + continue; + } + + final[i] = result; + + if(result.then){ + promises.push(result); //{ query, result }; + } + } + } + + if(promises.length){ + return Promise.all(promises).then(function(){ + self.result = exclusion.call(self, final, limit, offset, resolve); + return resolve ? self.result : self; + }); + } + + if(final.length){ + this.result = exclusion.call(this, final, limit, offset, resolve); + } + + return resolve ? this.result : this; +}; + +/** + * @param result + * @param limit + * @param offset + * @param resolve + * @this Resolver + * @return {Array} + */ + +function exclusion(result, limit, offset, resolve){ + + if(!result.length){ + return this.result; + } + + const final = []; + const exclude = new Set(result.flat().flat()); + + for(let j = 0, ids, count = 0; j < this.result.length; j++){ + ids = this.result[j]; + if(!ids) continue; + + for(let k = 0, id; k < ids.length; k++){ + id = ids[k]; + if(!exclude.has(id)){ + if(offset){ + offset--; + continue; + } + if(resolve){ + final.push(id); + if(final.length === limit){ + return final; + } + } + else { + final[j] || (final[j] = []); + final[j].push(id); + if(++count === limit){ + return final; + } + } + } + } + } + + return final; +} + +/** + * @param {Array|ResolverOptions=} result + * @constructor + */ + +function Resolver(result){ + if(!this){ + return new Resolver(result); + } + if(result && result.index){ + result.resolve = false; + this.index = result.index; + this.boostval = result.boost || 0; + this.result = result.index.search(result).result; + return this; + } + if(result.constructor === Resolver){ + // todo test this branch + //console.log("Resolver Loopback") + return result; + } + this.index = null; + this.result = result || []; + this.boostval = 0; +} + +Resolver.prototype.limit = function(limit){ + if(this.result.length){ + const final = []; + let count = 0; + for(let j = 0, ids; j < this.result.length; j++){ + ids = this.result[j]; + if(ids.length + count < limit){ + final[j] = ids; + count += ids.length; + } + else { + final[j] = ids.slice(0, limit - count); + this.result = final; + break; + } + } + } + return this; +}; + +Resolver.prototype.offset = function(offset){ + if(this.result.length){ + const final = []; + let count = 0; + for(let j = 0, ids; j < this.result.length; j++){ + ids = this.result[j]; + if(ids.length + count < offset){ + count += ids.length; + } + else { + final[j] = ids.slice(offset - count); + count = offset; + } + } + this.result = final; + } + return this; +}; + +Resolver.prototype.boost = function(boost){ + this.boostval += boost; + return this; +}; + +/** + * @param {number|ResolverOptions=} limit + * @param {number=} offset + * @param {boolean=} enrich + */ + +Resolver.prototype.resolve = function(limit, offset, enrich){ + set_resolve(1); + const result = this.result; + this.index = null; + this.result = null; + + if(result.length){ + if(typeof limit === "object"){ + enrich = limit.enrich; + offset = limit.offset; + limit = limit.limit; + } + return resolve_default(result, limit || 100, offset, enrich); + } + + return result; +}; + +// COMPILER BLOCK --> + +let global_resolve = 1; +function set_resolve(resolve){ + global_resolve = resolve; +} + +/** + * @param {string|SearchOptions} query + * @param {number|SearchOptions=} limit + * @param {SearchOptions=} options + * @returns {Array|Resolver|Promise} + */ + +Index.prototype.search = function(query, limit, options){ + + if(!options){ + if(!limit && is_object(query)){ + options = /** @type {!SearchOptions} */ (query); + query = ""; + } + else if(is_object(limit)){ + options = /** @type {!SearchOptions} */ (limit); + limit = 0; + } + } + + let result = []; + let length; + let context, suggest, offset = 0, resolve, enrich, tag, boost; + + if(options){ + query = options.query || query; + limit = options.limit || limit; + offset = options.offset || 0; + context = options.context; + suggest = options.suggest; + resolve = (global_resolve && options.resolve !== false); + resolve || (global_resolve = 0); + enrich = resolve && options.enrich; + boost = options.boost; + tag = this.db && options.tag; + } + else { + resolve = this.resolve || global_resolve; + } + + // todo: term deduplication during encoding when context is disabled + + // do not force a string as input + // https://github.com/nextapps-de/flexsearch/issues/432 + query = /** @type {Array} */ (this.encoder.encode(query)); + length = query.length; + limit || !resolve || (limit = 100); + + // fast path single term + if(length === 1){ + return single_term_query.call( + this, + query[0], // term + "", // ctx + limit, + offset, + resolve, + enrich, + tag + ); + } + + // TODO: dedupe terms within encoder? + // TODO: deduplication will break the context chain + + context = this.depth && context !== false; + + // fast path single context + if(length === 2 && context && !suggest){ + return single_term_query.call( + this, + query[0], // term + query[1], // ctx + limit, + offset, + resolve, + enrich, + tag + ); + } + + let maxlength = 0; + let minlength = 0; + + if(length > 1){ + + // term deduplication will break the context chain + // todo add context to dupe check + const dupes = create_object(); + const query_new = []; + + // if(context){ + // keyword = query[0]; + // dupes[keyword] = 1; + // query_new.push(keyword); + // maxlength = minlength = keyword.length; + // i = 1; + // } + + for(let i = 0, term; i < length; i++){ + + term = query[i]; + + if(term && !dupes[term]){ + + // todo add keyword check + // this fast path can't apply to persistent indexes + if(!suggest && !(this.db) && !this.get_array(term/*, keyword*/)){ + + // fast path "not found" + return resolve + ? result + : new Resolver(result); + } + else { + + query_new.push(term); + dupes[term] = 1; + } + + const term_length = term.length; + maxlength = Math.max(maxlength, term_length); + minlength = minlength ? Math.min(minlength, term_length) : term_length; + } + // else if(term && (!this.depth || context === false)){ + // query_new.push(term); + // } + } + + query = query_new; + length = query.length; + } + + // the term length could be changed after deduplication + + if(!length){ + return resolve + ? result + : new Resolver(result); + } + + let index = 0, keyword; + + // fast path single term + if(length === 1){ + return single_term_query.call( + this, + query[0], // term + "", // ctx + limit, + offset, + resolve, + enrich, + tag + ); + } + + // fast path single context + if(length === 2 && context && !suggest){ + return single_term_query.call( + this, + query[0], // term + query[1], // ctx + limit, + offset, + resolve, + enrich, + tag + ); + } + + if(length > 1){ + if(context){ + // start with context right away + keyword = query[0]; + index = 1; + } + // todo + else if(maxlength > 9 && (maxlength / minlength) > 3){ + // sorting terms will break the context chain + // bigger terms has less occurrence + // this might also reduce the intersection task + // todo check intersection order + query.sort(sort_by_length_down); + } + } + + // from this point there are just multi-term queries + + if(this.db){ + + if(this.db.search){ + // when the configuration is not supported it returns false + const result = this.db.search(this, query, limit, offset, suggest, resolve, enrich, tag); + if(result !== false) return result; + } + + const self = this; + return (async function(){ + + for(let arr, term; index < length; index++){ + + term = query[index]; + + if(keyword){ + + arr = await self.get_array(term, keyword, 0, 0, false, false); + arr = add_result( + arr, + result, + suggest, + self.resolution_ctx, + // 0, // /** @type {!number} */ (limit), + // 0, // offset, + // length === 2 + // /*, term, keyword*/ + ); + + // the context is a moving window where the keyword is going forward like a cursor + // 1. when suggestion enabled just forward keyword if term was found + // 2. as long as the result is empty forward the pointer also + if(!suggest || (arr !== false) || !result.length){ + keyword = term; + } + } + else { + + arr = await self.get_array(term, "", 0, 0, false, false); + arr = add_result( + arr, + result, + suggest, + self.resolution, + // 0, // /** @type {!number} */ (limit), + // 0, // offset, + // length === 1 + // /*, term*/ + ); + } + + // limit reached + if(arr){ + return arr; + } + + // apply suggestions on last loop + if(suggest && (index === length - 1)){ + let length = result.length; + if(!length){ + // fallback to non-contextual search when no result was found + if(keyword){ + keyword = ""; + index = -1; + continue; + } + return result; + } + else if(length === 1){ + return resolve + ? resolve_default(result[0], /** @type {number} */ (limit), offset) + : new Resolver(result[0]); + } + } + } + + return resolve + ? intersect$1(result, self.resolution, /** @type {number} */ (limit), offset, suggest, boost, resolve) + : new Resolver(result[0]) + }()); + } + + for(let arr, term; index < length; index++){ + + term = query[index]; + + if(keyword){ + + arr = this.get_array(term, keyword, 0, 0, false, false); + arr = /*this.*/add_result( + arr, + result, + suggest, + this.resolution_ctx, + // 0, // /** @type {!number} */ (limit), + // 0, // offset, + // length === 2 + // /*, term, keyword*/ + ); + + // 1. when suggestion enabled just forward keyword if term was found + // 2. as long as the result is empty forward the pointer also + if(!suggest || (arr !== false) || !result.length){ + keyword = term; + } + } + else { + + arr = this.get_array(term, "", 0, 0, false, false); + arr = /*this.*/add_result( + arr, + result, + suggest, + this.resolution, + // 0, // /** @type {!number} */ (limit), + // 0, // offset, + // length === 1 + // /*, term*/ + ); + } + + // limit reached + if(arr){ + return /** @type {Array} */ (arr); + } + + // apply suggestions on last loop + if(suggest && (index === length - 1)){ + const length = result.length; + if(!length){ + // fallback to non-contextual search when no result was found + if(keyword){ + keyword = ""; + index = -1; + continue; + } + return result; + } + else if(length === 1){ + return resolve + ? resolve_default(result[0], limit, offset) + : new Resolver(result[0]); + } + } + } + + result = intersect$1(result, this.resolution, limit, offset, suggest, boost, resolve); + + return resolve + ? result + : new Resolver(result); +}; + +/** + * @param term + * @param keyword + * @param limit + * @param offset + * @param resolve + * @param enrich + * @param tag + * @this Index + * @return {Array|Resolver} + */ + +function single_term_query(term, keyword, limit, offset, resolve, enrich, tag){ + + const result = this.get_array(term, keyword, limit, offset, resolve, enrich, tag); + + if(this.db){ + return result.then(function(result){ + if(resolve) return result; + return result && result.length + ? (resolve ? resolve_default(result, limit, offset): new Resolver(result)) + : resolve ? [] : new Resolver([]); + }); + } + + return result && result.length + ? (resolve ? resolve_default(result, limit, offset) : new Resolver(result)) + : resolve ? [] : new Resolver([]); +} + +/** + * Returns a 1-dimensional finalized array when the result is done (fast path return), + * returns false when suggestions is enabled and no result was found, + * or returns nothing when a set was pushed successfully to the results + * + * @private + * @param {Array} arr + * @param {Array} result + * @param {Array} suggest + * @param {number} resolution + * @return {Array|boolean|undefined} + */ + +function add_result(arr, result, suggest, resolution/*, limit, offset single_term, term, keyword*/){ + + let word_arr = []; + //let arr;// = keyword ? this.ctx : this.map; + //arr = this.get_array(term, keyword); + + if(arr){ + + //const resolution = Math.min(arr.length, keyword ? this.resolution_ctx : this.resolution); + // apply reduced resolution for queries + resolution = Math.min(arr.length, resolution); + + for(let x = 0, size = 0, tmp; x < resolution; x++){ + if((tmp = arr[x])){ + + // if(offset){ + // // apply offset right here on single terms + // if(tmp && single_term){ + // if(tmp.length <= offset){ + // offset -= tmp.length; + // tmp = null; + // } + // else{ + // tmp = tmp.slice(offset); + // offset = 0; + // } + // } + // } + + if(tmp){ + + // keep score (sparse array): + word_arr[x] = tmp; + // simplified score order: + //word_arr.push(tmp); + + // if(single_term){ + // size += tmp.length; + // if(size >= limit){ + // // fast path: + // // a single term does not need to pre-collect results + // break; + // } + // } + } + } + } + + if(word_arr.length){ + // if(single_term){ + // // fast path optimization + // // offset was already applied at this point + // // return an array will stop the query process immediately + // return resolve_default(word_arr, limit, 0); + // } + + result.push(word_arr); + // return nothing will continue the query + return; + } + } + + // 1. return an empty array will stop the loop + // 2. return a false value to prevent stop when using suggestions + return !suggest && word_arr; +} + +Index.prototype.get_array = function(term, keyword, limit, offset, resolve, enrich, tag){ + + let arr, swap; + + if(keyword){ + swap = this.bidirectional && (term > keyword); + } + + if(this.compress){ + term = default_compress(term); + keyword && (keyword = default_compress(keyword)); + } + + if(this.db){ + return keyword + ? this.db.get( + swap ? keyword : term, // term + swap ? term : keyword, // ctx + limit, + offset, + resolve, + enrich, + tag + ) + : this.db.get( + term, + "", // ctx + limit, + offset, + resolve, + enrich, + tag + ); + } + + if(keyword){ + // the frequency of the starting letter is slightly less + // on the last half of the alphabet (m-z) in almost every latin language, + // so we sort downwards (https://en.wikipedia.org/wiki/Letter_frequency) + arr = this.ctx.get(swap ? term : keyword); + arr = arr && arr.get(swap ? keyword : term); + } + else { + arr = this.map.get(term); + } + + return arr; +}; + +// COMPILER BLOCK --> + +/** + * @param {boolean=} _skip_deletion + */ + +Index.prototype.remove = function(id, _skip_deletion){ + + const refs = this.reg.size && ( + this.fastupdate + ? this.reg.get(id) + : this.reg.has(id) + ); + + if(refs){ + + if(this.fastupdate){ + + // fast updates did not fully cleanup the key entries + + for(let i = 0, tmp; i < refs.length; i++){ + if((tmp = refs[i])){ + // todo check + //if(tmp.length < 1) throw new Error("invalid length"); + //if(tmp.indexOf(id) < 0) throw new Error("invalid id"); + if(tmp.length < 2){ + tmp.pop(); + } + else { + const index = tmp.indexOf(id); + index === refs.length - 1 + ? tmp.pop() + : tmp.splice(index, 1); + } + } + } + + // todo variation which cleans up, requires to push [ctx, key] instead of arr to the index.reg + // for(let i = 0, arr, term, keyword; i < refs.length; i++){ + // arr = refs[i]; + // if(typeof arr === "string"){ + // arr = this.map.get(term = arr); + // } + // else{ + // arr = this.ctx.get(keyword = arr[0]); + // arr && (arr = arr.get(arr[1])); + // } + // let counter = 0, found; + // if(arr && arr.length){ + // for(let j = 0, tmp; j < arr.length; j++){ + // if((tmp = arr[j])){ + // if(!found && tmp.length){ + // const index = tmp.indexOf(id); + // if(index >= 0){ + // tmp.splice(index, 1); + // // the index [ctx, key]:[res, id] is unique + // found = 1; + // } + // } + // if(tmp.length){ + // counter++; + // if(found){ + // break; + // } + // } + // else{ + // delete arr[j]; + // } + // } + // } + // } + // if(!counter){ + // keyword + // ? this.ctx.delete(keyword) + // : this.map.delete(term); + // } + // } + } + else { + + remove_index(this.map, id/*, this.resolution*/); + this.depth && + remove_index(this.ctx, id/*, this.resolution_ctx*/); + } + + _skip_deletion || this.reg.delete(id); + } + + if(this.db){ + this.commit_task.push({ "del": id }); + this.commit_auto && autoCommit(this); + //return this.db.remove(id); + } + + // the cache could be used outside the InMemory store + if(this.cache){ + this.cache.remove(id); + } + + return this; +}; + +/** + * @param map + * @param id + * @return {number} + */ + +function remove_index(map, id){ + + // a check counter of filled resolution slots + // to prevent removing the field + let count = 0; + + if(is_array(map)){ + for(let x = 0, arr, index; x < map.length; x++){ + if((arr = map[x]) && arr.length){ + index = arr.indexOf(id); + if(index >= 0){ + if(arr.length > 1){ + arr.splice(index, 1); + count++; + } + else { + // remove resolution slot + delete map[x]; + } + // the index key:[res, id] is unique + break; + } + else { + count++; + } + } + } + } + else for(let item of map){ + const key = item[0]; + const value = item[1]; + const tmp = remove_index(value, id); + tmp ? count += tmp + : map.delete(key); + } + + return count; +} + +/**! + * FlexSearch.js + * Author and Copyright: Thomas Wilkerling + * Licence: Apache-2.0 + * Hosted by Nextapps GmbH + * https://github.com/nextapps-de/flexsearch + */ + + +/** + * @constructor + * @param {IndexOptions|string=} options Options or preset as string + * @param {Map|Set|KeystoreSet|KeystoreMap=} _register + */ + +function Index(options, _register){ + + if(!this){ + return new Index(options); + } + + tick("Index.create"); + + options = options + ? apply_preset(options) + : {}; + + /** @type ContextOptions */ + const context = options.context || {}; + const encoder = is_string(options.encoder) + ? Charset[options.encoder] + : options.encode || options.encoder || ( + options$8 + ); + /** @type Encoder */ + this.encoder = encoder.encode + ? encoder + : typeof encoder === "object" + ? (new Encoder(encoder) + + ) + : { encode: encoder }; + + { + this.compress = options.compress || options.compression || false; + } + + let tmp; + this.resolution = options.resolution || 9; + this.tokenize = tmp = options.tokenize || "strict"; + this.depth = (tmp === "strict" && context.depth) || 0; + this.bidirectional = context.bidirectional !== false; + this.fastupdate = !!options.fastupdate; + this.score = options.score || null; + + tmp = (options.keystore || 0); + tmp && (this.keystore = tmp); + + this.map = tmp && SUPPORT_KEYSTORE ? new KeystoreMap(tmp) : new Map(); + this.ctx = tmp && SUPPORT_KEYSTORE ? new KeystoreMap(tmp) : new Map(); + this.reg = _register || ( + this.fastupdate + ? (tmp && SUPPORT_KEYSTORE ? new KeystoreMap(tmp) : new Map()) + : (tmp && SUPPORT_KEYSTORE ? new KeystoreSet(tmp) : new Set()) + ); + this.resolution_ctx = context.resolution || 1; + this.rtl = (encoder.rtl) || options.rtl || false; + + { + this.cache = (tmp = options.cache || null) && new CacheClass(tmp); + } + + { + this.resolve = options.resolve !== false; + } + + { + if((tmp = options.db)){ + this.db = this.mount(tmp); + } + this.commit_auto = options.commit !== false; + this.commit_task = []; + this.commit_timer = null; + } +} + +{ + Index.prototype.mount = function(db){ + if(this.commit_timer){ + clearTimeout(this.commit_timer); + this.commit_timer = null; + } + return db.mount(this); + }; + Index.prototype.commit = function(replace, append){ + if(this.commit_timer){ + clearTimeout(this.commit_timer); + this.commit_timer = null; + } + return this.db.commit(this, replace, append); + }; + Index.prototype.destroy = function(){ + if(this.commit_timer){ + clearTimeout(this.commit_timer); + this.commit_timer = null; + } + return this.db.destroy(); + }; +} + +/** + * @param {!Index} self + * @param {boolean=} replace + * @param {boolean=} append + */ + +function autoCommit(self, replace, append){ + if(!self.commit_timer){ + self.commit_timer = setTimeout(function(){ + self.commit_timer = null; + self.db.commit(self, replace, append); + }, 0); + } +} + +Index.prototype.clear = function(){ + + this.map.clear(); + this.ctx.clear(); + this.reg.clear(); + + { + this.cache && + this.cache.clear(); + } + + if(this.db){ + this.commit_timer && clearTimeout(this.commit_timer); + this.commit_timer = null; + this.commit_task = [{ "clear": true }]; + } + + return this; +}; + +/** + * @param {!number|string} id + * @param {!string} content + */ + +Index.prototype.append = function(id, content){ + return this.add(id, content, true); +}; + +Index.prototype.contain = function(id){ + return this.db + ? this.db.has(id) + : this.reg.has(id); +}; + +Index.prototype.update = function(id, content){ + + const self = this; + const res = this.remove(id); + return res && res.then + ? res.then(() => self.add(id, content)) + : this.add(id, content); +}; + +/** + * @param map + * @return {number} + */ + +function cleanup_index(map){ + + let count = 0; + + if(is_array(map)){ + for(let i = 0, arr; i < map.length; i++){ + (arr = map[i]) && + (count += arr.length); + } + } + else for(const item of map){ + const key = item[0]; + const value = item[1]; + const tmp = cleanup_index(value); + tmp ? count += tmp + : map.delete(key); + } + + return count; +} + +Index.prototype.cleanup = function(){ + + if(!this.fastupdate){ + console.info("Cleanup the index isn't required when not using \"fastupdate\"."); + return this; + } + + cleanup_index(this.map); + this.depth && + cleanup_index(this.ctx); + + return this; +}; + +{ + + Index.prototype.searchCache = searchCache; +} + +{ + + Index.prototype.export = exportIndex; + Index.prototype.import = importIndex; + Index.prototype.serialize = serialize; +} + +{ + + apply_async(Index.prototype); +} + // COMPILER BLOCK --> const VERSION = 1; diff --git a/dist/flexsearch.bundle.debug.js b/dist/flexsearch.bundle.debug.js index cf92f08..698ab1e 100644 --- a/dist/flexsearch.bundle.debug.js +++ b/dist/flexsearch.bundle.debug.js @@ -224,71 +224,102 @@ function ka(a) { a.H.clear(); a.J.clear(); } -;function la(a, b, c) { - a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - let d = this.cache.get(a); - if (!d) { - d = this.search(a, b, c); - if (d.then) { - const e = this; - d.then(function(f) { - e.cache.set(a, f); - return f; - }); - } - this.cache.set(a, d); +;async function la(a) { + a = a.data; + var b = self._index; + const c = a.args; + var d = a.task; + switch(d) { + case "init": + d = a.options || {}; + (b = d.config) && (d = b); + (b = a.factory) ? (Function("return " + b)()(self), self._index = new self.FlexSearch.Index(d), delete self.FlexSearch) : self._index = new L(d); + postMessage({id:a.id}); + break; + default: + a = a.id, b = b[d].apply(b, c), postMessage("search" === d ? {id:a, msg:b} : {id:a}); } - return d; } -function L(a) { - this.limit = a && !0 !== a ? a : 1000; - this.cache = new Map(); - this.h = ""; -} -L.prototype.set = function(a, b) { - this.cache.set(this.h = a, b); - this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); -}; -L.prototype.get = function(a) { - const b = this.cache.get(a); - b && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, b)); - return b; -}; -L.prototype.remove = function(a) { - for (const b of this.cache) { - const c = b[0]; - b[1].includes(a) && this.cache.delete(c); - } -}; -L.prototype.clear = function() { - this.cache.clear(); - this.h = ""; -}; -const ma = {normalize:function(a) { - return a.toLowerCase(); -}, dedupe:!1}; -const na = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); -const oa = new Map([["ai", "ei"], ["ae", "a"], ["oe", "o"], ["ue", "u"], ["sh", "s"], ["ch", "c"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), pa = [/([^aeo])h([aeo$])/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2"]; -const qa = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; -const ra = /[\x00-\x7F]+/g; -const sa = /[\x00-\x7F]+/g; -const ta = /[\x00-\x7F]+/g; -var ua = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:ma, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:na}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:na, replacer:pa, matcher:oa}, LatinExtra:{normalize:!0, dedupe:!0, mapper:na, replacer:pa.concat([/(?!^)[aeoy]/g, ""]), matcher:oa}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { - for (let c = 0; c < a.length; c++) { - var b = a[c]; - let d = b.charAt(0), e = qa[d]; - for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = qa[g]) || g === e || (d += g, e = g, 4 !== d.length)); f++) { +;let M = 0; +function N(a = {}) { + function b(g) { + function h(k) { + k = k.data || k; + const l = k.id, m = l && e.h[l]; + m && (m(k.msg), delete e.h[l]); + } + this.worker = g; + this.h = A(); + if (this.worker) { + d ? this.worker.on("message", h) : this.worker.onmessage = h; + if (a.config) { + return new Promise(function(k) { + e.h[++M] = function() { + k(e); + }; + e.worker.postMessage({id:M, task:"init", factory:c, options:a}); + }); + } + this.worker.postMessage({task:"init", factory:c, options:a}); + return this; } - a[c] = d; } -}}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(ra, " "); -}}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(sa, ""); -}}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(ta, " "); -}}}; -function va(a, b, c, d) { + if (!this) { + return new N(a); + } + let c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; + c && (c = c.toString()); + const d = "undefined" === typeof window, e = this, f = ma(c, d, a.worker); + return f.then ? f.then(function(g) { + return b.call(e, g); + }) : b.call(this, f); +} +O("add"); +O("append"); +O("search"); +O("update"); +O("remove"); +function O(a) { + N.prototype[a] = N.prototype[a + "Async"] = async function() { + const b = this, c = [].slice.call(arguments); + var d = c[c.length - 1]; + let e; + "function" === typeof d && (e = d, c.splice(c.length - 1, 1)); + d = new Promise(function(f) { + b.h[++M] = f; + b.worker.postMessage({task:a, id:M, args:c}); + }); + return e ? (d.then(e), this) : d; + }; +} +function ma(a, b, c) { + return b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + la.toString()], {type:"text/javascript"}))) : new window.Worker(B(c) ? c : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", + "module/worker/worker.js"), {type:"module"}); +} +;function na(a) { + P.call(a, "add"); + P.call(a, "append"); + P.call(a, "search"); + P.call(a, "update"); + P.call(a, "remove"); +} +function P(a) { + this[a + "Async"] = function() { + var b = arguments; + const c = b[b.length - 1]; + let d; + "function" === typeof c && (d = c, delete b[b.length - 1]); + b = this[a].apply(this, b); + d && (b.then ? b.then(d) : d(b)); + return b; + }; +} +;function oa(a, b, c, d, e, f, g, h) { + (d = a(c ? c + "." + d : d, JSON.stringify(g))) && d.then ? d.then(function() { + b.export(a, b, c, e, f + 1, h); + }) : b.export(a, b, c, e, f + 1, h); +} +;function pa(a, b, c, d) { let e = []; for (let f = 0, g; f < a.index.length; f++) { if (g = a.index[f], b >= g.length) { @@ -304,9 +335,9 @@ function va(a, b, c, d) { } return e; } -function M(a) { +function Q(a) { if (!this) { - return new M(a); + return new Q(a); } this.index = a ? [a] : []; this.length = a ? a.length : 0; @@ -354,12 +385,12 @@ function M(a) { } if ("slice" === d) { return function(e, f) { - return va(b, e || 0, f || b.length, !1); + return pa(b, e || 0, f || b.length, !1); }; } if ("splice" === d) { return function(e, f) { - return va(b, e || 0, f || b.length, !0); + return pa(b, e || 0, f || b.length, !0); }; } if ("constructor" === d) { @@ -375,81 +406,81 @@ function M(a) { return !0; }}); } -M.prototype.clear = function() { +Q.prototype.clear = function() { this.index.length = 0; }; -M.prototype.destroy = function() { +Q.prototype.destroy = function() { this.proxy = this.index = null; }; -M.prototype.push = function() { +Q.prototype.push = function() { }; -function N(a = 8) { +function R(a = 8) { if (!this) { - return new N(a); + return new R(a); } this.index = A(); this.B = []; this.size = 0; - 32 < a ? (this.h = wa, this.A = BigInt(a)) : (this.h = xa, this.A = a); + 32 < a ? (this.h = qa, this.A = BigInt(a)) : (this.h = ra, this.A = a); } -N.prototype.get = function(a) { +R.prototype.get = function(a) { const b = this.index[this.h(a)]; return b && b.get(a); }; -N.prototype.set = function(a, b) { +R.prototype.set = function(a, b) { var c = this.h(a); let d = this.index[c]; d ? (c = d.size, d.set(a, b), (c -= d.size) && this.size++) : (this.index[c] = d = new Map([[a, b]]), this.B.push(d)); }; -function O(a = 8) { +function S(a = 8) { if (!this) { - return new O(a); + return new S(a); } this.index = A(); this.h = []; - 32 < a ? (this.B = wa, this.A = BigInt(a)) : (this.B = xa, this.A = a); + 32 < a ? (this.B = qa, this.A = BigInt(a)) : (this.B = ra, this.A = a); } -O.prototype.add = function(a) { +S.prototype.add = function(a) { var b = this.B(a); let c = this.index[b]; c ? (b = c.size, c.add(a), (b -= c.size) && this.size++) : (this.index[b] = c = new Set([a]), this.h.push(c)); }; -u = N.prototype; -u.has = O.prototype.has = function(a) { +u = R.prototype; +u.has = S.prototype.has = function(a) { const b = this.index[this.B(a)]; return b && b.has(a); }; -u.delete = O.prototype.delete = function(a) { +u.delete = S.prototype.delete = function(a) { const b = this.index[this.B(a)]; b && b.delete(a) && this.size--; }; -u.clear = O.prototype.clear = function() { +u.clear = S.prototype.clear = function() { this.index = A(); this.h = []; this.size = 0; }; -u.values = O.prototype.values = function*() { +u.values = S.prototype.values = function*() { for (let a = 0; a < this.h.length; a++) { for (let b of this.h[a].values()) { yield b; } } }; -u.keys = O.prototype.keys = function*() { +u.keys = S.prototype.keys = function*() { for (let a = 0; a < this.h.length; a++) { for (let b of this.h[a].keys()) { yield b; } } }; -u.entries = O.prototype.entries = function*() { +u.entries = S.prototype.entries = function*() { for (let a = 0; a < this.h.length; a++) { for (let b of this.h[a].entries()) { yield b; } } }; -function xa(a) { +function ra(a) { let b = 2 ** this.A - 1; if ("number" == typeof a) { return a & b; @@ -460,7 +491,7 @@ function xa(a) { } return 32 === this.A ? c + 2 ** 31 : c; } -function wa(a) { +function qa(a) { let b = BigInt(2) ** this.A - BigInt(1); var c = typeof a; if ("bigint" === c) { @@ -476,153 +507,132 @@ function wa(a) { } return c; } -;function ya(a, b, c, d, e, f, g, h) { - (d = a(c ? c + "." + d : d, JSON.stringify(g))) && d.then ? d.then(function() { - b.export(a, b, c, e, f + 1, h); - }) : b.export(a, b, c, e, f + 1, h); -} -;const za = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -function Aa(a) { - P.call(a, "add"); - P.call(a, "append"); - P.call(a, "search"); - P.call(a, "update"); - P.call(a, "remove"); -} -function P(a) { - this[a + "Async"] = function() { - var b = arguments; - const c = b[b.length - 1]; - let d; - "function" === typeof c && (d = c, delete b[b.length - 1]); - b = this[a].apply(this, b); - d && (b.then ? b.then(d) : d(b)); - return b; - }; -} -;A(); -Q.prototype.add = function(a, b, c, d) { +;T.prototype.add = function(a, b, c) { + D(a) && (b = a, a = I(b, this.key)); if (b && (a || 0 === a)) { - if (!d && !c && this.reg.has(a)) { + if (!c && this.reg.has(a)) { return this.update(a, b); } - b = this.encoder.encode(b); - if (d = b.length) { - const l = A(), m = A(), p = this.depth, n = this.resolution; - for (let q = 0; q < d; q++) { - let t = b[this.rtl ? d - 1 - q : q]; - var e = t.length; - if (e && (p || !m[t])) { - var f = this.score ? this.score(b, t, q, null, 0) : R(n, d, q), g = ""; - switch(this.tokenize) { - case "full": - if (2 < e) { - for (f = 0; f < e; f++) { - for (var h = e; h > f; h--) { - g = t.substring(f, h); - var k = this.score ? this.score(b, t, q, g, f) : R(n, d, q, e, f); - S(this, m, g, k, a, c); - } - } - break; - } - case "reverse": - if (1 < e) { - for (h = e - 1; 0 < h; h--) { - g = t[h] + g, k = this.score ? this.score(b, t, q, g, h) : R(n, d, q, e, h), S(this, m, g, k, a, c); - } - g = ""; - } - case "forward": - if (1 < e) { - for (h = 0; h < e; h++) { - g += t[h], S(this, m, g, f, a, c); - } - break; - } - default: - if (S(this, m, t, f, a, c), p && 1 < d && q < d - 1) { - for (e = A(), g = this.R, f = t, h = Math.min(p + 1, d - q), e[f] = 1, k = 1; k < h; k++) { - if ((t = b[this.rtl ? d - 1 - q - k : q + k]) && !e[t]) { - e[t] = 1; - const r = this.score ? this.score(b, f, q, t, k) : R(g + (d / 2 > g ? 0 : 1), d, q, h - 1, k - 1), v = this.bidirectional && t > f; - S(this, l, v ? f : t, r, a, c, v ? t : f); - } - } - } - } + for (let h = 0, k; h < this.field.length; h++) { + k = this.D[h]; + var d = this.index.get(this.field[h]); + if ("function" === typeof k) { + var e = k(b); + e && d.add(a, e, !1, !0); + } else { + if (e = k.I, !e || e(b)) { + k.constructor === String ? k = ["" + k] : B(k) && (k = [k]), sa(b, k, this.K, 0, d, a, k[0], c); } } - this.fastupdate || this.reg.add(a); - } else { - b = ""; + } + if (this.tag) { + for (d = 0; d < this.G.length; d++) { + var f = this.G[d], g = this.N[d]; + e = this.tag.get(g); + let h = A(); + if ("function" === typeof f) { + if (f = f(b), !f) { + continue; + } + } else { + const k = f.I; + if (k && !k(b)) { + continue; + } + f.constructor === String && (f = "" + f); + f = I(b, f); + } + if (e && f) { + B(f) && (f = [f]); + for (let k = 0, l, m; k < f.length; k++) { + if (l = f[k], !h[l] && (h[l] = 1, (g = e.get(l)) ? m = g : e.set(l, m = []), !c || !m.includes(a))) { + if (m.length === 2 ** 31 - 1) { + g = new Q(m); + if (this.fastupdate) { + for (let p of this.reg.values()) { + p.includes(m) && (p[p.indexOf(m)] = g); + } + } + e.set(l, m = g); + } + m.push(a); + this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])); + } + } + } else { + e || console.warn("Tag '" + g + "' was not found"); + } + } + } + if (this.store && (!c || !this.store.has(a))) { + let h; + if (this.C) { + h = A(); + for (let k = 0, l; k < this.C.length; k++) { + l = this.C[k]; + if ((c = l.I) && !c(b)) { + continue; + } + let m; + if ("function" === typeof l) { + m = l(b); + if (!m) { + continue; + } + l = [l.U]; + } else if (B(l) || l.constructor === String) { + h[l] = b[l]; + continue; + } + ta(b, h, l, 0, l[0], m); + } + } + this.store.set(a, h || b); } } - this.db && (b || this.commit_task.push({del:a}), this.T && Ba(this)); return this; }; -function S(a, b, c, d, e, f, g) { - let h = g ? a.ctx : a.map, k; - if (!b[c] || !g || !(k = b[c])[g]) { - if (g ? (b = k || (b[c] = A()), b[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !f || !h.includes(e)) { - if (h.length === 2 ** 31 - 1) { - b = new M(h); - if (a.fastupdate) { - for (let l of a.reg.values()) { - l.includes(h) && (l[l.indexOf(h)] = b); +function ta(a, b, c, d, e, f) { + a = a[e]; + if (d === c.length - 1) { + b[e] = f || a; + } else if (a) { + if (a.constructor === Array) { + for (b = b[e] = Array(a.length), e = 0; e < a.length; e++) { + ta(a, b, c, d, e); + } + } else { + b = b[e] || (b[e] = A()), e = c[++d], ta(a, b, c, d, e); + } + } +} +function sa(a, b, c, d, e, f, g, h) { + if (a = a[g]) { + if (d === b.length - 1) { + if (a.constructor === Array) { + if (c[d]) { + for (b = 0; b < a.length; b++) { + e.add(f, a[b], !0, !0); } + return; } - k[d] = h = b; + a = a.join(" "); } - h.push(e); - a.fastupdate && ((d = a.reg.get(e)) ? d.push(h) : a.reg.set(e, [h])); - } - } -} -function R(a, b, c, d, e) { - return c && 1 < a ? b + (d || 0) <= a ? c + (e || 0) : (a - 1) / (b + (d || 0)) * (c + (e || 0)) + 1 | 0 : 0; -} -;function T(a, b, c, d) { - if (1 === a.length) { - return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, d ? Ca(a) : a; - } - let e = []; - for (let f = 0, g, h; f < a.length; f++) { - if ((g = a[f]) && (h = g.length)) { - if (c) { - if (c >= h) { - c -= h; - continue; + e.add(f, a, h, !0); + } else { + if (a.constructor === Array) { + for (g = 0; g < a.length; g++) { + sa(a, b, c, d, e, f, g, h); } - c < h && (g = b ? g.slice(c, c + b) : g.slice(c), h = g.length, c = 0); - } - if (e.length) { - h > b && (g = g.slice(0, b), h = g.length), e.push(g); } else { - if (h >= b) { - return h > b && (g = g.slice(0, b)), d ? Ca(g) : g; - } - e = [g]; - } - b -= h; - if (!b) { - break; + g = b[++d], sa(a, b, c, d, e, f, g, h); } } + } else { + e.db && e.remove(f); } - if (!e.length) { - return e; - } - e = 1 < e.length ? [].concat.apply([], e) : e[0]; - return d ? Ca(e) : e; } -function Ca(a) { - for (let b = 0; b < a.length; b++) { - a[b] = {score:b, id:a[b]}; - } - return a; -} -;function Da(a, b, c, d, e, f, g) { +;function ua(a, b, c, d, e, f, g) { const h = a.length; let k = [], l; var m; @@ -638,7 +648,7 @@ function Ca(a) { } if (a = k.length) { if (e) { - k = 1 < k.length ? Ea(k, d, c, g, 0) : k[0]; + k = 1 < k.length ? va(k, d, c, g, 0) : k[0]; } else { if (a < h) { return []; @@ -671,7 +681,7 @@ function Ca(a) { } return k; } -function Ea(a, b, c, d, e) { +function va(a, b, c, d, e) { const f = [], g = A(); let h; var k = a.length; @@ -714,7 +724,7 @@ function Ea(a, b, c, d, e) { } return f; } -function Fa(a, b) { +function wa(a, b) { const c = A(), d = []; for (let e = 0, f; e < b.length; e++) { f = b[e]; @@ -727,7 +737,692 @@ function Fa(a, b) { } return d; } -;U.prototype.or = function() { +;T.prototype.search = function(a, b, c, d) { + c || (!b && D(a) ? (c = a, a = "") : D(b) && (c = b, b = 0)); + let e = [], f = [], g; + let h; + let k; + let l, m = 0, p; + if (c) { + c.constructor === Array && (c = {index:c}); + a = c.query || a; + g = c.pluck; + h = c.merge; + k = g || c.field || c.index; + var n = this.tag && c.tag; + var q = this.store && c.enrich; + var t = c.suggest; + p = c.V; + b = c.limit || b; + l = c.offset || 0; + b || (b = 100); + if (n && (!this.db || !d)) { + n.constructor !== Array && (n = [n]); + var r = []; + for (let y = 0, w; y < n.length; y++) { + w = n[y]; + if (B(w)) { + throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); + } + if (w.field && w.tag) { + var v = w.tag; + if (v.constructor === Array) { + for (var x = 0; x < v.length; x++) { + r.push(w.field, v[x]); + } + } else { + r.push(w.field, v); + } + } else { + v = Object.keys(w); + for (let C = 0, K, E; C < v.length; C++) { + if (K = v[C], E = w[K], E.constructor === Array) { + for (x = 0; x < E.length; x++) { + r.push(K, E[x]); + } + } else { + r.push(K, E); + } + } + } + } + if (!r.length) { + throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); + } + n = r; + if (!a) { + t = []; + if (r.length) { + for (n = 0; n < r.length; n += 2) { + if (this.db) { + d = this.index.get(r[n]); + if (!d) { + console.warn("Tag '" + r[n] + ":" + r[n + 1] + "' will be skipped because there is no field '" + r[n] + "'."); + continue; + } + t.push(d = d.db.tag(r[n + 1], b, l, q)); + } else { + d = xa.call(this, r[n], r[n + 1], b, l, q); + } + e.push({field:r[n], tag:r[n + 1], result:d}); + } + } + return t.length ? Promise.all(t).then(function(y) { + for (let w = 0; w < y.length; w++) { + e[w].result = y[w]; + } + return e; + }) : e; + } + } + B(k) && (k = [k]); + } + k || (k = this.field); + r = !d && (this.worker || this.db) && []; + let F; + for (let y = 0, w, C, K; y < k.length; y++) { + C = k[y]; + if (this.db && this.tag && !this.D[y]) { + continue; + } + let E; + B(C) || (E = C, C = E.field, a = E.query || a, b = E.limit || b, l = E.offset || l, t = E.suggest || t, q = this.store && (E.enrich || q)); + if (d) { + w = d[y]; + } else { + if (v = E || c, x = this.index.get(C), n && (this.db && (v.tag = n, F = x.db.support_tag_search, v.field = k), F || (v.enrich = !1)), r) { + r[y] = x.search(a, b, v); + v && q && (v.enrich = q); + continue; + } else { + w = x.search(a, b, v), v && q && (v.enrich = q); + } + } + K = w && w.length; + if (n && K) { + v = []; + x = 0; + if (this.db && d) { + if (!F) { + for (let G = k.length; G < d.length; G++) { + let H = d[G]; + if (H && H.length) { + x++, v.push(H); + } else if (!t) { + return e; + } + } + } + } else { + for (let G = 0, H, cb; G < n.length; G += 2) { + H = this.tag.get(n[G]); + if (!H) { + if (console.warn("Tag '" + n[G] + ":" + n[G + 1] + "' will be skipped because there is no field '" + n[G] + "'."), t) { + continue; + } else { + return e; + } + } + if (cb = (H = H && H.get(n[G + 1])) && H.length) { + x++, v.push(H); + } else if (!t) { + return e; + } + } + } + if (x) { + w = wa(w, v); + K = w.length; + if (!K && !t) { + return e; + } + x--; + } + } + if (K) { + f[m] = C, e.push(w), m++; + } else if (1 === k.length) { + return e; + } + } + if (r) { + if (this.db && n && n.length && !F) { + for (q = 0; q < n.length; q += 2) { + d = this.index.get(n[q]); + if (!d) { + if (console.warn("Tag '" + n[q] + ":" + n[q + 1] + "' was not found because there is no field '" + n[q] + "'."), t) { + continue; + } else { + return e; + } + } + r.push(d.db.tag(n[q + 1], b, l, !1)); + } + } + const y = this; + return Promise.all(r).then(function(w) { + return w.length ? y.search(a, b, c, w) : w; + }); + } + if (!m) { + return e; + } + if (g && (!q || !this.store)) { + return e[0]; + } + r = []; + for (let y = 0, w; y < f.length; y++) { + w = e[y]; + q && w.length && !w[0].doc && (this.db ? r.push(w = this.index.get(this.field[0]).db.enrich(w)) : w.length && (w = ya.call(this, w))); + if (g) { + return w; + } + e[y] = {field:f[y], result:w}; + } + if (q && this.db && r.length) { + const y = this; + return Promise.all(r).then(function(w) { + for (let C = 0; C < w.length; C++) { + e[C].result = w[C]; + } + return h ? za(e, b) : p ? Aa(e, a, y.index, y.D, p) : e; + }); + } + return h ? za(e, b) : p ? Aa(e, a, this.index, this.D, p) : e; +}; +function Aa(a, b, c, d, e) { + let f; + for (let g = 0, h, k, l, m; g < a.length; g++) { + h = a[g].result; + k = a[g].field; + l = c.get(k).encoder; + m = d[k.indexOf(k)]; + l !== f && (f = l, f.encode(b)); + for (let p = 0; p < h.length; p++) { + let n = "", q = I(h[p].doc, m), t = f.encode(q); + for (let r = 0; r < t.length; r++) { + n += t[r].replace(new RegExp("(" + t[r] + ")", "g"), e.replace("$1", q)); + } + console.log(a, c, e); + h[p].V = n; + } + } + return a; +} +function za(a, b) { + const c = [], d = A(); + for (let e = 0, f, g; e < a.length; e++) { + f = a[e]; + g = f.result; + for (let h = 0, k, l, m; h < g.length; h++) { + if (l = g[h], k = l.id, m = d[k]) { + m.push(f.field); + } else { + if (c.length === b) { + return c; + } + l.field = d[k] = [f.field]; + c.push(l); + } + } + } + return c; +} +function xa(a, b, c, d, e) { + let f = this.tag.get(a); + if (!f) { + return console.warn("Tag '" + a + "' was not found"), []; + } + if ((a = (f = f && f.get(b)) && f.length - d) && 0 < a) { + if (a > c || d) { + f = f.slice(d, d + c); + } + e && (f = ya.call(this, f)); + return f; + } +} +function ya(a) { + const b = Array(a.length); + for (let c = 0, d; c < a.length; c++) { + d = a[c], b[c] = {id:d, doc:this.store.get(d)}; + } + return b; +} +;function T(a) { + if (!this) { + return new T(a); + } + const b = a.document || a.doc || a; + let c, d; + this.D = []; + this.field = []; + this.K = []; + this.key = (c = b.key || b.id) && Ba(c, this.K) || "id"; + (d = a.keystore || 0) && (this.keystore = d); + this.reg = (this.fastupdate = !!a.fastupdate) ? d ? new R(d) : new Map() : d ? new S(d) : new Set(); + this.C = (c = b.store || null) && !0 !== c && []; + this.store = c && (d ? new R(d) : new Map()); + this.cache = (c = a.cache || null) && new U(c); + a.cache = !1; + this.worker = a.worker; + this.index = Ca.call(this, a, b); + this.tag = null; + if (c = b.tag) { + if ("string" === typeof c && (c = [c]), c.length) { + this.tag = new Map(); + this.G = []; + this.N = []; + for (let e = 0, f, g; e < c.length; e++) { + f = c[e]; + g = f.field || f; + if (!g) { + throw Error("The tag field from the document descriptor is undefined."); + } + f.custom ? this.G[e] = f.custom : (this.G[e] = Ba(g, this.K), f.filter && ("string" === typeof this.G[e] && (this.G[e] = new String(this.G[e])), this.G[e].I = f.filter)); + this.N[e] = g; + this.tag.set(g, new Map()); + } + } + } + if (this.worker) { + a = []; + for (const e of this.index.values()) { + e.then && a.push(e); + } + if (a.length) { + const e = this; + return Promise.all(a).then(function(f) { + let g = 0; + for (const h of e.index.entries()) { + const k = h[0]; + h[1].then && e.index.set(k, f[g++]); + } + return e; + }); + } + } else { + a.db && this.mount(a.db); + } +} +u = T.prototype; +u.mount = function(a) { + let b = this.field; + if (this.tag) { + for (let e = 0, f; e < this.N.length; e++) { + f = this.N[e]; + var c = void 0; + this.index.set(f, c = new L({}, this.reg)); + b === this.field && (b = b.slice(0)); + b.push(f); + c.tag = this.tag.get(f); + } + } + c = []; + const d = {db:a.db, type:a.type, fastupdate:a.fastupdate}; + for (let e = 0, f, g; e < b.length; e++) { + d.field = g = b[e]; + f = this.index.get(g); + const h = new a.constructor(a.id, d); + h.id = a.id; + c[e] = h.mount(f); + f.document = !0; + e ? f.bypass = !0 : f.store = this.store; + } + this.db = !0; + return Promise.all(c); +}; +u.commit = async function(a, b) { + const c = []; + for (const d of this.index.values()) { + c.push(d.db.commit(d, a, b)); + } + await Promise.all(c); + this.reg.clear(); +}; +u.destroy = function() { + const a = []; + for (const b of this.index.values()) { + a.push(b.destroy()); + } + return Promise.all(a); +}; +function Ca(a, b) { + const c = new Map(); + let d = b.index || b.field || b; + B(d) && (d = [d]); + for (let e = 0, f, g; e < d.length; e++) { + f = d[e]; + B(f) || (g = f, f = f.field); + g = D(g) ? Object.assign({}, a, g) : a; + if (this.worker) { + const h = new N(g); + c.set(f, h); + } + this.worker || c.set(f, new L(g, this.reg)); + g.custom ? this.D[e] = g.custom : (this.D[e] = Ba(f, this.K), g.filter && ("string" === typeof this.D[e] && (this.D[e] = new String(this.D[e])), this.D[e].I = g.filter)); + this.field[e] = f; + } + if (this.C) { + a = b.store; + B(a) && (a = [a]); + for (let e = 0, f, g; e < a.length; e++) { + f = a[e], g = f.field || f, f.custom ? (this.C[e] = f.custom, f.custom.U = g) : (this.C[e] = Ba(g, this.K), f.filter && ("string" === typeof this.C[e] && (this.C[e] = new String(this.C[e])), this.C[e].I = f.filter)); + } + } + return c; +} +function Ba(a, b) { + const c = a.split(":"); + let d = 0; + for (let e = 0; e < c.length; e++) { + a = c[e], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (b[d] = !0), a && (c[d++] = a); + } + d < c.length && (c.length = d); + return 1 < d ? c : c[0]; +} +u.append = function(a, b) { + return this.add(a, b, !0); +}; +u.update = function(a, b) { + return this.remove(a).add(a, b); +}; +u.remove = function(a) { + D(a) && (a = I(a, this.key)); + for (var b of this.index.values()) { + b.remove(a, !0); + } + if (this.reg.has(a)) { + if (this.tag && !this.fastupdate) { + for (let c of this.tag.values()) { + for (let d of c) { + b = d[0]; + const e = d[1], f = e.indexOf(a); + -1 < f && (1 < e.length ? e.splice(f, 1) : c.delete(b)); + } + } + } + this.store && this.store.delete(a); + this.reg.delete(a); + } + this.cache && this.cache.remove(a); + return this; +}; +u.clear = function() { + for (const a of this.index.values()) { + a.clear(); + } + if (this.tag) { + for (const a of this.tag.values()) { + a.clear(); + } + } + this.store && this.store.clear(); + return this; +}; +u.contain = function(a) { + return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a); +}; +u.cleanup = function() { + for (const a of this.index.values()) { + a.cleanup(); + } + return this; +}; +u.get = function(a) { + return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(b) { + return b[0] && b[0].doc; + }) : this.store.get(a); +}; +u.set = function(a, b) { + this.store.set(a, b); + return this; +}; +u.searchCache = Da; +u.export = function(a, b, c, d, e, f) { + let g; + "undefined" === typeof f && (g = new Promise(k => { + f = k; + })); + e || (e = 0); + d || (d = 0); + if (d < this.field.length) { + c = this.field[d]; + var h = this.index[c]; + b = this; + h.export(a, b, e ? c : "", d, e++, f) || (d++, b.export(a, b, c, d, 1, f)); + } else { + switch(e) { + case 1: + b = "tag"; + h = this.A; + c = null; + break; + case 2: + b = "store"; + h = this.store; + c = null; + break; + default: + f(); + return; + } + oa(a, this, c, b, d, e, h, f); + } + return g; +}; +u.import = function(a, b) { + if (b) { + switch(B(b) && (b = JSON.parse(b)), a) { + case "tag": + this.A = b; + break; + case "reg": + this.fastupdate = !1; + this.reg = b; + for (let d = 0, e; d < this.field.length; d++) { + e = this.index[this.field[d]], e.reg = b, e.fastupdate = !1; + } + break; + case "store": + this.store = b; + break; + default: + a = a.split("."); + const c = a[0]; + a = a[1]; + c && a && this.index[c].import(a, b); + } + } +}; +na(T.prototype); +function Da(a, b, c) { + a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); + let d = this.cache.get(a); + if (!d) { + d = this.search(a, b, c); + if (d.then) { + const e = this; + d.then(function(f) { + e.cache.set(a, f); + return f; + }); + } + this.cache.set(a, d); + } + return d; +} +function U(a) { + this.limit = a && !0 !== a ? a : 1000; + this.cache = new Map(); + this.h = ""; +} +U.prototype.set = function(a, b) { + this.cache.set(this.h = a, b); + this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); +}; +U.prototype.get = function(a) { + const b = this.cache.get(a); + b && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, b)); + return b; +}; +U.prototype.remove = function(a) { + for (const b of this.cache) { + const c = b[0]; + b[1].includes(a) && this.cache.delete(c); + } +}; +U.prototype.clear = function() { + this.cache.clear(); + this.h = ""; +}; +const Ea = {normalize:function(a) { + return a.toLowerCase(); +}, dedupe:!1}; +const Fa = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); +const Ga = new Map([["ai", "ei"], ["ae", "a"], ["oe", "o"], ["ue", "u"], ["sh", "s"], ["ch", "c"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Ha = [/([^aeo])h([aeo$])/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2"]; +const Ia = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; +const Ja = /[\x00-\x7F]+/g; +const Ka = /[\x00-\x7F]+/g; +const La = /[\x00-\x7F]+/g; +var Ma = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Ea, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Fa}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Fa, replacer:Ha, matcher:Ga}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Fa, replacer:Ha.concat([/(?!^)[aeoy]/g, ""]), matcher:Ga}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { + for (let c = 0; c < a.length; c++) { + var b = a[c]; + let d = b.charAt(0), e = Ia[d]; + for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = Ia[g]) || g === e || (d += g, e = g, 4 !== d.length)); f++) { + } + a[c] = d; + } +}}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { + return ("" + a).replace(Ja, " "); +}}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { + return ("" + a).replace(Ka, ""); +}}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { + return ("" + a).replace(La, " "); +}}}; +const Na = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +A(); +L.prototype.add = function(a, b, c, d) { + if (b && (a || 0 === a)) { + if (!d && !c && this.reg.has(a)) { + return this.update(a, b); + } + b = this.encoder.encode(b); + if (d = b.length) { + const l = A(), m = A(), p = this.depth, n = this.resolution; + for (let q = 0; q < d; q++) { + let t = b[this.rtl ? d - 1 - q : q]; + var e = t.length; + if (e && (p || !m[t])) { + var f = this.score ? this.score(b, t, q, null, 0) : Oa(n, d, q), g = ""; + switch(this.tokenize) { + case "full": + if (2 < e) { + for (f = 0; f < e; f++) { + for (var h = e; h > f; h--) { + g = t.substring(f, h); + var k = this.score ? this.score(b, t, q, g, f) : Oa(n, d, q, e, f); + V(this, m, g, k, a, c); + } + } + break; + } + case "reverse": + if (1 < e) { + for (h = e - 1; 0 < h; h--) { + g = t[h] + g, k = this.score ? this.score(b, t, q, g, h) : Oa(n, d, q, e, h), V(this, m, g, k, a, c); + } + g = ""; + } + case "forward": + if (1 < e) { + for (h = 0; h < e; h++) { + g += t[h], V(this, m, g, f, a, c); + } + break; + } + default: + if (V(this, m, t, f, a, c), p && 1 < d && q < d - 1) { + for (e = A(), g = this.R, f = t, h = Math.min(p + 1, d - q), e[f] = 1, k = 1; k < h; k++) { + if ((t = b[this.rtl ? d - 1 - q - k : q + k]) && !e[t]) { + e[t] = 1; + const r = this.score ? this.score(b, f, q, t, k) : Oa(g + (d / 2 > g ? 0 : 1), d, q, h - 1, k - 1), v = this.bidirectional && t > f; + V(this, l, v ? f : t, r, a, c, v ? t : f); + } + } + } + } + } + } + this.fastupdate || this.reg.add(a); + } else { + b = ""; + } + } + this.db && (b || this.commit_task.push({del:a}), this.T && Pa(this)); + return this; +}; +function V(a, b, c, d, e, f, g) { + let h = g ? a.ctx : a.map, k; + if (!b[c] || g && !(k = b[c])[g]) { + if (g ? (b = k || (b[c] = A()), b[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !f || !h.includes(e)) { + if (h.length === 2 ** 31 - 1) { + b = new Q(h); + if (a.fastupdate) { + for (let l of a.reg.values()) { + l.includes(h) && (l[l.indexOf(h)] = b); + } + } + k[d] = h = b; + } + h.push(e); + a.fastupdate && ((d = a.reg.get(e)) ? d.push(h) : a.reg.set(e, [h])); + } + } +} +function Oa(a, b, c, d, e) { + return c && 1 < a ? b + (d || 0) <= a ? c + (e || 0) : (a - 1) / (b + (d || 0)) * (c + (e || 0)) + 1 | 0 : 0; +} +;function W(a, b, c, d) { + if (1 === a.length) { + return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, d ? Qa(a) : a; + } + let e = []; + for (let f = 0, g, h; f < a.length; f++) { + if ((g = a[f]) && (h = g.length)) { + if (c) { + if (c >= h) { + c -= h; + continue; + } + c < h && (g = b ? g.slice(c, c + b) : g.slice(c), h = g.length, c = 0); + } + if (e.length) { + h > b && (g = g.slice(0, b), h = g.length), e.push(g); + } else { + if (h >= b) { + return h > b && (g = g.slice(0, b)), d ? Qa(g) : g; + } + e = [g]; + } + b -= h; + if (!b) { + break; + } + } + } + if (!e.length) { + return e; + } + e = 1 < e.length ? [].concat.apply([], e) : e[0]; + return d ? Qa(e) : e; +} +function Qa(a) { + for (let b = 0; b < a.length; b++) { + a[b] = {score:b, id:a[b]}; + } + return a; +} +;X.prototype.or = function() { const a = this; let b = arguments; var c = b[0]; @@ -749,7 +1444,7 @@ function Fa(a, b) { g = l.enrich; h = l.resolve; let m; - if (l.constructor === U) { + if (l.constructor === X) { m = l.result; } else if (l.constructor === Array) { m = l; @@ -771,21 +1466,21 @@ function Fa(a, b) { if (c.length) { return Promise.all(c).then(function() { a.result.length && (d = d.concat([a.result])); - a.result = Ga(d, e, f, g, h, a.F); + a.result = Ra(d, e, f, g, h, a.F); return h ? a.result : a; }); } - d.length && (this.result.length && (d = d.concat([this.result])), this.result = Ga(d, e, f, g, h, this.F)); + d.length && (this.result.length && (d = d.concat([this.result])), this.result = Ra(d, e, f, g, h, this.F)); return h ? this.result : this; }; -function Ga(a, b, c, d, e, f) { +function Ra(a, b, c, d, e, f) { if (!a.length) { return a; } "object" === typeof b && (c = b.offset || 0, d = b.enrich || !1, b = b.limit || 0); - return 2 > a.length ? e ? T(a[0], b, c, d) : a[0] : Ea(a, c, b, e, f); + return 2 > a.length ? e ? W(a[0], b, c, d) : a[0] : va(a, c, b, e, f); } -;U.prototype.and = function() { +;X.prototype.and = function() { if (this.result.length) { const b = this; let c = arguments; @@ -808,7 +1503,7 @@ function Ga(a, b, c, d, e, f) { g = l.resolve; h = l.suggest; let m; - if (l.constructor === U) { + if (l.constructor === X) { m = l.result; } else if (l.constructor === Array) { m = l; @@ -833,26 +1528,26 @@ function Ga(a, b, c, d, e, f) { if (a.length) { return Promise.all(a).then(function() { d = [b.result].concat(d); - b.result = Ha(d, e, f, g, b.F, h); + b.result = Sa(d, e, f, g, b.F, h); return g ? b.result : b; }); } d = [this.result].concat(d); - this.result = Ha(d, e, f, g, this.F, h); + this.result = Sa(d, e, f, g, this.F, h); return g ? this.result : this; } return this; }; -function Ha(a, b, c, d, e, f) { +function Sa(a, b, c, d, e, f) { if (2 > a.length) { return []; } let g = []; A(); let h = ca(a); - return h ? Da(a, h, b, c, f, e, d) : g; + return h ? ua(a, h, b, c, f, e, d) : g; } -;U.prototype.xor = function() { +;X.prototype.xor = function() { const a = this; let b = arguments; var c = b[0]; @@ -874,7 +1569,7 @@ function Ha(a, b, c, d, e, f) { g = l.enrich; h = l.resolve; let m; - if (l.constructor === U) { + if (l.constructor === X) { m = l.result; } else if (l.constructor === Array) { m = l; @@ -896,19 +1591,19 @@ function Ha(a, b, c, d, e, f) { if (c.length) { return Promise.all(c).then(function() { a.result.length && (d = [a.result].concat(d)); - a.result = Ia(d, e, f, g, !h, a.F); + a.result = Ta(d, e, f, g, !h, a.F); return h ? a.result : a; }); } - d.length && (this.result.length && (d = [this.result].concat(d)), this.result = Ia(d, e, f, g, !h, a.F)); + d.length && (this.result.length && (d = [this.result].concat(d)), this.result = Ta(d, e, f, g, !h, a.F)); return h ? this.result : this; }; -function Ia(a, b, c, d, e, f) { +function Ta(a, b, c, d, e, f) { if (!a.length) { return a; } if (2 > a.length) { - return e ? T(a[0], b, c, d) : a[0]; + return e ? W(a[0], b, c, d) : a[0]; } d = []; const g = A(); @@ -955,7 +1650,7 @@ function Ia(a, b, c, d, e, f) { } return d; } -;U.prototype.not = function() { +;X.prototype.not = function() { const a = this; let b = arguments; var c = b[0]; @@ -976,7 +1671,7 @@ function Ia(a, b, c, d, e, f) { f = k.offset || 0; g = k.resolve; let l; - if (k.constructor === U) { + if (k.constructor === X) { l = k.result; } else if (k.constructor === Array) { l = k; @@ -997,14 +1692,14 @@ function Ia(a, b, c, d, e, f) { } if (c.length) { return Promise.all(c).then(function() { - a.result = Ja.call(a, d, e, f, g); + a.result = Ua.call(a, d, e, f, g); return g ? a.result : a; }); } - d.length && (this.result = Ja.call(this, d, e, f, g)); + d.length && (this.result = Ua.call(this, d, e, f, g)); return g ? this.result : this; }; -function Ja(a, b, c, d) { +function Ua(a, b, c, d) { if (!a.length) { return this.result; } @@ -1033,21 +1728,21 @@ function Ja(a, b, c, d) { } return e; } -;function U(a) { +;function X(a) { if (!this) { - return new U(a); + return new X(a); } if (a && a.index) { return a.resolve = !1, this.index = a.index, this.F = a.boost || 0, this.result = a.index.search(a).result, this; } - if (a.constructor === U) { + if (a.constructor === X) { return a; } this.index = null; this.result = a || []; this.F = 0; } -U.prototype.limit = function(a) { +X.prototype.limit = function(a) { if (this.result.length) { const b = []; let c = 0; @@ -1063,7 +1758,7 @@ U.prototype.limit = function(a) { } return this; }; -U.prototype.offset = function(a) { +X.prototype.offset = function(a) { if (this.result.length) { const b = []; let c = 0; @@ -1074,18 +1769,18 @@ U.prototype.offset = function(a) { } return this; }; -U.prototype.boost = function(a) { +X.prototype.boost = function(a) { this.F += a; return this; }; -U.prototype.resolve = function(a, b, c) { - Ka = 1; +X.prototype.resolve = function(a, b, c) { + Va = 1; const d = this.result; this.result = this.index = null; - return d.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), T(d, a || 100, b, c)) : d; + return d.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), W(d, a || 100, b, c)) : d; }; -let Ka = 1; -Q.prototype.search = function(a, b, c) { +let Va = 1; +L.prototype.search = function(a, b, c) { c || (!b && D(a) ? (c = a, a = "") : D(b) && (c = b, b = 0)); let d = [], e; let f, g = 0, h, k, l, m; @@ -1095,34 +1790,34 @@ Q.prototype.search = function(a, b, c) { g = c.offset || 0; var p = c.context; f = c.suggest; - (h = Ka && !1 !== c.resolve) || (Ka = 0); + (h = Va && !1 !== c.resolve) || (Va = 0); k = h && c.enrich; m = c.boost; l = this.db && c.tag; } else { - h = this.resolve || Ka; + h = this.resolve || Va; } a = this.encoder.encode(a); e = a.length; b || !h || (b = 100); if (1 === e) { - return La.call(this, a[0], "", b, g, h, k, l); + return Wa.call(this, a[0], "", b, g, h, k, l); } p = this.depth && !1 !== p; if (2 === e && p && !f) { - return La.call(this, a[0], a[1], b, g, h, k, l); + return Wa.call(this, a[0], a[1], b, g, h, k, l); } let n = c = 0; if (1 < e) { const r = A(), v = []; - for (let x = 0, E; x < e; x++) { - if ((E = a[x]) && !r[E]) { - if (f || this.db || V(this, E)) { - v.push(E), r[E] = 1; + for (let x = 0, F; x < e; x++) { + if ((F = a[x]) && !r[F]) { + if (f || this.db || Y(this, F)) { + v.push(F), r[F] = 1; } else { - return h ? d : new U(d); + return h ? d : new X(d); } - const y = E.length; + const y = F.length; c = Math.max(c, y); n = n ? Math.min(n, y) : y; } @@ -1131,14 +1826,14 @@ Q.prototype.search = function(a, b, c) { e = a.length; } if (!e) { - return h ? d : new U(d); + return h ? d : new X(d); } let q = 0, t; if (1 === e) { - return La.call(this, a[0], "", b, g, h, k, l); + return Wa.call(this, a[0], "", b, g, h, k, l); } if (2 === e && p && !f) { - return La.call(this, a[0], a[1], b, g, h, k, l); + return Wa.call(this, a[0], a[1], b, g, h, k, l); } 1 < e && (p ? (t = a[0], q = 1) : 9 < c && 3 < c / n && a.sort(aa)); if (this.db) { @@ -1149,13 +1844,13 @@ Q.prototype.search = function(a, b, c) { return async function() { for (let v, x; q < e; q++) { x = a[q]; - t ? (v = await V(r, x, t, 0, 0, !1, !1), v = Ma(v, d, f, r.R), f && !1 === v && d.length || (t = x)) : (v = await V(r, x, "", 0, 0, !1, !1), v = Ma(v, d, f, r.resolution)); + t ? (v = await Y(r, x, t, 0, 0, !1, !1), v = Xa(v, d, f, r.R), f && !1 === v && d.length || (t = x)) : (v = await Y(r, x, "", 0, 0, !1, !1), v = Xa(v, d, f, r.resolution)); if (v) { return v; } if (f && q === e - 1) { - let E = d.length; - if (!E) { + let F = d.length; + if (!F) { if (t) { t = ""; q = -1; @@ -1163,17 +1858,17 @@ Q.prototype.search = function(a, b, c) { } return d; } - if (1 === E) { - return h ? T(d[0], b, g) : new U(d[0]); + if (1 === F) { + return h ? W(d[0], b, g) : new X(d[0]); } } } - return h ? Da(d, r.resolution, b, g, f, m, h) : new U(d[0]); + return h ? ua(d, r.resolution, b, g, f, m, h) : new X(d[0]); }(); } for (let r, v; q < e; q++) { v = a[q]; - t ? (r = V(this, v, t, 0, 0, !1, !1), r = Ma(r, d, f, this.R), f && !1 === r && d.length || (t = v)) : (r = V(this, v, "", 0, 0, !1, !1), r = Ma(r, d, f, this.resolution)); + t ? (r = Y(this, v, t, 0, 0, !1, !1), r = Xa(r, d, f, this.R), f && !1 === r && d.length || (t = v)) : (r = Y(this, v, "", 0, 0, !1, !1), r = Xa(r, d, f, this.resolution)); if (r) { return r; } @@ -1188,20 +1883,20 @@ Q.prototype.search = function(a, b, c) { return d; } if (1 === p) { - return h ? T(d[0], b, g) : new U(d[0]); + return h ? W(d[0], b, g) : new X(d[0]); } } } - d = Da(d, this.resolution, b, g, f, m, h); - return h ? d : new U(d); + d = ua(d, this.resolution, b, g, f, m, h); + return h ? d : new X(d); }; -function La(a, b, c, d, e, f, g) { - a = V(this, a, b, c, d, e, f, g); +function Wa(a, b, c, d, e, f, g) { + a = Y(this, a, b, c, d, e, f, g); return this.db ? a.then(function(h) { - return e ? h : h && h.length ? e ? T(h, c, d) : new U(h) : e ? [] : new U([]); - }) : a && a.length ? e ? T(a, c, d) : new U(a) : e ? [] : new U([]); + return e ? h : h && h.length ? e ? W(h, c, d) : new X(h) : e ? [] : new X([]); + }) : a && a.length ? e ? W(a, c, d) : new X(a) : e ? [] : new X([]); } -function Ma(a, b, c, d) { +function Xa(a, b, c, d) { let e = []; if (a) { d = Math.min(a.length, d); @@ -1215,7 +1910,7 @@ function Ma(a, b, c, d) { } return !c && e; } -function V(a, b, c, d, e, f, g, h) { +function Y(a, b, c, d, e, f, g, h) { let k; c && (k = a.bidirectional && b > c); if (a.db) { @@ -1224,7 +1919,7 @@ function V(a, b, c, d, e, f, g, h) { a = c ? (a = a.ctx.get(k ? b : c)) && a.get(k ? c : b) : a.map.get(b); return a; } -;Q.prototype.remove = function(a, b) { +;L.prototype.remove = function(a, b) { const c = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (c) { if (this.fastupdate) { @@ -1239,15 +1934,15 @@ function V(a, b, c, d, e, f, g, h) { } } } else { - Na(this.map, a), this.depth && Na(this.ctx, a); + Ya(this.map, a), this.depth && Ya(this.ctx, a); } b || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.T && Ba(this)); + this.db && (this.commit_task.push({del:a}), this.T && Pa(this)); this.cache && this.cache.remove(a); return this; }; -function Na(a, b) { +function Ya(a, b) { let c = 0; if (a.constructor === Array) { for (let d = 0, e, f; d < a.length; d++) { @@ -1262,24 +1957,24 @@ function Na(a, b) { } } else { for (let d of a) { - const e = d[0], f = Na(d[1], b); + const e = d[0], f = Ya(d[1], b); f ? c += f : a.delete(e); } } return c; } -;function Q(a, b) { +;function L(a, b) { if (!this) { - return new Q(a); + return new L(a); } if (a) { var c = B(a) ? a : a.preset; - c && (za[c] || console.warn("Preset not found: " + c), a = Object.assign({}, za[c], a)); + c && (Na[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Na[c], a)); } else { a = {}; } c = a.context || {}; - const d = B(a.encoder) ? ua[a.encoder] : a.encode || a.encoder || ma; + const d = B(a.encoder) ? Ma[a.encoder] : a.encode || a.encoder || Ea; this.encoder = d.encode ? d : "object" === typeof d ? new J(d) : {encode:d}; let e; this.resolution = a.resolution || 9; @@ -1289,12 +1984,12 @@ function Na(a, b) { this.fastupdate = !!a.fastupdate; this.score = a.score || null; (e = a.keystore || 0) && (this.keystore = e); - this.map = e ? new N(e) : new Map(); - this.ctx = e ? new N(e) : new Map(); - this.reg = b || (this.fastupdate ? e ? new N(e) : new Map() : e ? new O(e) : new Set()); + this.map = e ? new R(e) : new Map(); + this.ctx = e ? new R(e) : new Map(); + this.reg = b || (this.fastupdate ? e ? new R(e) : new Map() : e ? new S(e) : new Set()); this.R = c.resolution || 1; this.rtl = d.rtl || a.rtl || !1; - this.cache = (e = a.cache || null) && new L(e); + this.cache = (e = a.cache || null) && new U(e); this.resolve = !1 !== a.resolve; if (e = a.db) { this.db = this.mount(e); @@ -1303,7 +1998,7 @@ function Na(a, b) { this.commit_task = []; this.commit_timer = null; } -u = Q.prototype; +u = L.prototype; u.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); @@ -1316,7 +2011,7 @@ u.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function Ba(a) { +function Pa(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); @@ -1340,7 +2035,7 @@ u.update = function(a, b) { const c = this, d = this.remove(a); return d && d.then ? d.then(() => c.add(a, b)) : this.add(a, b); }; -function Oa(a) { +function Za(a) { let b = 0; if (a.constructor === Array) { for (let c = 0, d; c < a.length; c++) { @@ -1348,7 +2043,7 @@ function Oa(a) { } } else { for (const c of a) { - const d = c[0], e = Oa(c[1]); + const d = c[0], e = Za(c[1]); e ? b += e : a.delete(d); } } @@ -1358,11 +2053,11 @@ u.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Oa(this.map); - this.depth && Oa(this.ctx); + Za(this.map); + this.depth && Za(this.ctx); return this; }; -u.searchCache = la; +u.searchCache = Da; u.export = function(a, b, c, d, e, f) { let g = !0; "undefined" === typeof f && (g = new Promise(l => { @@ -1397,7 +2092,7 @@ u.export = function(a, b, c, d, e, f) { "undefined" === typeof c && f && f(); return; } - ya(a, b || this, c, h, d, e, k, f); + oa(a, b || this, c, h, d, e, k, f); return g; }; u.import = function(a, b) { @@ -1468,702 +2163,7 @@ u.serialize = function(a = !0) { e = "index.ctx=new Map([" + e + "]);"; return a ? "function inject(index){" + b + d + e + "}" : b + d + e; }; -Aa(Q.prototype); -async function Pa(a) { - a = a.data; - var b = self._index; - const c = a.args; - var d = a.task; - switch(d) { - case "init": - d = a.options || {}; - (b = d.config) && (d = b); - (b = a.factory) ? (Function("return " + b)()(self), self._index = new self.FlexSearch.Index(d), delete self.FlexSearch) : self._index = new Q(d); - postMessage({id:a.id}); - break; - default: - a = a.id, b = b[d].apply(b, c), postMessage("search" === d ? {id:a, msg:b} : {id:a}); - } -} -;let Qa = 0; -function W(a = {}) { - function b(g) { - function h(k) { - k = k.data || k; - const l = k.id, m = l && e.h[l]; - m && (m(k.msg), delete e.h[l]); - } - this.worker = g; - this.h = A(); - if (this.worker) { - d ? this.worker.on("message", h) : this.worker.onmessage = h; - if (a.config) { - return new Promise(function(k) { - e.h[++Qa] = function() { - k(e); - }; - e.worker.postMessage({id:Qa, task:"init", factory:c, options:a}); - }); - } - this.worker.postMessage({task:"init", factory:c, options:a}); - return this; - } - } - if (!this) { - return new W(a); - } - let c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; - c && (c = c.toString()); - const d = "undefined" === typeof window, e = this, f = Ra(c, d, a.worker); - return f.then ? f.then(function(g) { - return b.call(e, g); - }) : b.call(this, f); -} -X("add"); -X("append"); -X("search"); -X("update"); -X("remove"); -function X(a) { - W.prototype[a] = W.prototype[a + "Async"] = async function() { - const b = this, c = [].slice.call(arguments); - var d = c[c.length - 1]; - let e; - "function" === typeof d && (e = d, c.splice(c.length - 1, 1)); - d = new Promise(function(f) { - b.h[++Qa] = f; - b.worker.postMessage({task:a, id:Qa, args:c}); - }); - return e ? (d.then(e), this) : d; - }; -} -function Ra(a, b, c) { - return b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Pa.toString()], {type:"text/javascript"}))) : new window.Worker(B(c) ? c : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", - "module/worker/worker.js"), {type:"module"}); -} -;Y.prototype.add = function(a, b, c) { - D(a) && (b = a, a = I(b, this.key)); - if (b && (a || 0 === a)) { - if (!c && this.reg.has(a)) { - return this.update(a, b); - } - for (let h = 0, k; h < this.field.length; h++) { - k = this.D[h]; - var d = this.index.get(this.field[h]); - if ("function" === typeof k) { - var e = k(b); - e && d.add(a, e, !1, !0); - } else { - if (e = k.I, !e || e(b)) { - k.constructor === String ? k = ["" + k] : B(k) && (k = [k]), Sa(b, k, this.K, 0, d, a, k[0], c); - } - } - } - if (this.tag) { - for (d = 0; d < this.G.length; d++) { - var f = this.G[d], g = this.N[d]; - e = this.tag.get(g); - let h = A(); - if ("function" === typeof f) { - if (f = f(b), !f) { - continue; - } - } else { - const k = f.I; - if (k && !k(b)) { - continue; - } - f.constructor === String && (f = "" + f); - f = I(b, f); - } - if (e && f) { - B(f) && (f = [f]); - for (let k = 0, l, m; k < f.length; k++) { - if (l = f[k], !h[l] && (h[l] = 1, (g = e.get(l)) ? m = g : e.set(l, m = []), !c || !m.includes(a))) { - if (m.length === 2 ** 31 - 1) { - g = new M(m); - if (this.fastupdate) { - for (let p of this.reg.values()) { - p.includes(m) && (p[p.indexOf(m)] = g); - } - } - e.set(l, m = g); - } - m.push(a); - this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])); - } - } - } else { - e || console.warn("Tag '" + g + "' was not found"); - } - } - } - if (this.store && (!c || !this.store.has(a))) { - let h; - if (this.C) { - h = A(); - for (let k = 0, l; k < this.C.length; k++) { - l = this.C[k]; - if ((c = l.I) && !c(b)) { - continue; - } - let m; - if ("function" === typeof l) { - m = l(b); - if (!m) { - continue; - } - l = [l.U]; - } else if (B(l) || l.constructor === String) { - h[l] = b[l]; - continue; - } - Ta(b, h, l, 0, l[0], m); - } - } - this.store.set(a, h || b); - } - } - return this; -}; -function Ta(a, b, c, d, e, f) { - a = a[e]; - if (d === c.length - 1) { - b[e] = f || a; - } else if (a) { - if (a.constructor === Array) { - for (b = b[e] = Array(a.length), e = 0; e < a.length; e++) { - Ta(a, b, c, d, e); - } - } else { - b = b[e] || (b[e] = A()), e = c[++d], Ta(a, b, c, d, e); - } - } -} -function Sa(a, b, c, d, e, f, g, h) { - if (a = a[g]) { - if (d === b.length - 1) { - if (a.constructor === Array) { - if (c[d]) { - for (b = 0; b < a.length; b++) { - e.add(f, a[b], !0, !0); - } - return; - } - a = a.join(" "); - } - e.add(f, a, h, !0); - } else { - if (a.constructor === Array) { - for (g = 0; g < a.length; g++) { - Sa(a, b, c, d, e, f, g, h); - } - } else { - g = b[++d], Sa(a, b, c, d, e, f, g, h); - } - } - } else { - e.db && e.remove(f); - } -} -;Y.prototype.search = function(a, b, c, d) { - c || (!b && D(a) ? (c = a, a = "") : D(b) && (c = b, b = 0)); - let e = [], f = [], g; - let h; - let k; - let l, m = 0, p; - if (c) { - c.constructor === Array && (c = {index:c}); - a = c.query || a; - g = c.pluck; - h = c.merge; - k = g || c.field || c.index; - var n = this.tag && c.tag; - var q = this.store && c.enrich; - var t = c.suggest; - p = c.V; - b = c.limit || b; - l = c.offset || 0; - b || (b = 100); - if (n && (!this.db || !d)) { - n.constructor !== Array && (n = [n]); - var r = []; - for (let y = 0, w; y < n.length; y++) { - w = n[y]; - if (B(w)) { - throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); - } - if (w.field && w.tag) { - var v = w.tag; - if (v.constructor === Array) { - for (var x = 0; x < v.length; x++) { - r.push(w.field, v[x]); - } - } else { - r.push(w.field, v); - } - } else { - v = Object.keys(w); - for (let C = 0, K, F; C < v.length; C++) { - if (K = v[C], F = w[K], F.constructor === Array) { - for (x = 0; x < F.length; x++) { - r.push(K, F[x]); - } - } else { - r.push(K, F); - } - } - } - } - if (!r.length) { - throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); - } - n = r; - if (!a) { - t = []; - if (r.length) { - for (n = 0; n < r.length; n += 2) { - if (this.db) { - d = this.index.get(r[n]); - if (!d) { - console.warn("Tag '" + r[n] + ":" + r[n + 1] + "' will be skipped because there is no field '" + r[n] + "'."); - continue; - } - t.push(d = d.db.tag(r[n + 1], b, l, q)); - } else { - d = Ua.call(this, r[n], r[n + 1], b, l, q); - } - e.push({field:r[n], tag:r[n + 1], result:d}); - } - } - return t.length ? Promise.all(t).then(function(y) { - for (let w = 0; w < y.length; w++) { - e[w].result = y[w]; - } - return e; - }) : e; - } - } - B(k) && (k = [k]); - } - k || (k = this.field); - r = !d && (this.worker || this.db) && []; - let E; - for (let y = 0, w, C, K; y < k.length; y++) { - C = k[y]; - if (this.db && this.tag && !this.D[y]) { - continue; - } - let F; - B(C) || (F = C, C = F.field, a = F.query || a, b = F.limit || b, l = F.offset || l, t = F.suggest || t, q = this.store && (F.enrich || q)); - if (d) { - w = d[y]; - } else { - if (v = F || c, x = this.index.get(C), n && (this.db && (v.tag = n, E = x.db.support_tag_search, v.field = k), E || (v.enrich = !1)), r) { - r[y] = x.search(a, b, v); - v && q && (v.enrich = q); - continue; - } else { - w = x.search(a, b, v), v && q && (v.enrich = q); - } - } - K = w && w.length; - if (n && K) { - v = []; - x = 0; - if (this.db && d) { - if (!E) { - for (let G = k.length; G < d.length; G++) { - let H = d[G]; - if (H && H.length) { - x++, v.push(H); - } else if (!t) { - return e; - } - } - } - } else { - for (let G = 0, H, fb; G < n.length; G += 2) { - H = this.tag.get(n[G]); - if (!H) { - if (console.warn("Tag '" + n[G] + ":" + n[G + 1] + "' will be skipped because there is no field '" + n[G] + "'."), t) { - continue; - } else { - return e; - } - } - if (fb = (H = H && H.get(n[G + 1])) && H.length) { - x++, v.push(H); - } else if (!t) { - return e; - } - } - } - if (x) { - w = Fa(w, v); - K = w.length; - if (!K && !t) { - return e; - } - x--; - } - } - if (K) { - f[m] = C, e.push(w), m++; - } else if (1 === k.length) { - return e; - } - } - if (r) { - if (this.db && n && n.length && !E) { - for (q = 0; q < n.length; q += 2) { - d = this.index.get(n[q]); - if (!d) { - if (console.warn("Tag '" + n[q] + ":" + n[q + 1] + "' was not found because there is no field '" + n[q] + "'."), t) { - continue; - } else { - return e; - } - } - r.push(d.db.tag(n[q + 1], b, l, !1)); - } - } - const y = this; - return Promise.all(r).then(function(w) { - return w.length ? y.search(a, b, c, w) : w; - }); - } - if (!m) { - return e; - } - if (g && (!q || !this.store)) { - return e[0]; - } - r = []; - for (let y = 0, w; y < f.length; y++) { - w = e[y]; - q && w.length && !w[0].doc && (this.db ? r.push(w = this.index.get(this.field[0]).db.enrich(w)) : w.length && (w = Va.call(this, w))); - if (g) { - return w; - } - e[y] = {field:f[y], result:w}; - } - if (q && this.db && r.length) { - const y = this; - return Promise.all(r).then(function(w) { - for (let C = 0; C < w.length; C++) { - e[C].result = w[C]; - } - return h ? Wa(e, b) : p ? Xa(e, a, y.index, y.D, p) : e; - }); - } - return h ? Wa(e, b) : p ? Xa(e, a, this.index, this.D, p) : e; -}; -function Xa(a, b, c, d, e) { - let f; - for (let g = 0, h, k, l, m; g < a.length; g++) { - h = a[g].result; - k = a[g].field; - l = c.get(k).encoder; - m = d[k.indexOf(k)]; - l !== f && (f = l, f.encode(b)); - for (let p = 0; p < h.length; p++) { - let n = "", q = I(h[p].doc, m), t = f.encode(q); - for (let r = 0; r < t.length; r++) { - n += t[r].replace(new RegExp("(" + t[r] + ")", "g"), e.replace("$1", q)); - } - console.log(a, c, e); - h[p].V = n; - } - } - return a; -} -function Wa(a, b) { - const c = [], d = A(); - for (let e = 0, f, g; e < a.length; e++) { - f = a[e]; - g = f.result; - for (let h = 0, k, l, m; h < g.length; h++) { - if (l = g[h], k = l.id, m = d[k]) { - m.push(f.field); - } else { - if (c.length === b) { - return c; - } - l.field = d[k] = [f.field]; - c.push(l); - } - } - } - return c; -} -function Ua(a, b, c, d, e) { - let f = this.tag.get(a); - if (!f) { - return console.warn("Tag '" + a + "' was not found"), []; - } - if ((a = (f = f && f.get(b)) && f.length - d) && 0 < a) { - if (a > c || d) { - f = f.slice(d, d + c); - } - e && (f = Va.call(this, f)); - return f; - } -} -function Va(a) { - const b = Array(a.length); - for (let c = 0, d; c < a.length; c++) { - d = a[c], b[c] = {id:d, doc:this.store.get(d)}; - } - return b; -} -;function Y(a) { - if (!this) { - return new Y(a); - } - const b = a.document || a.doc || a; - let c, d; - this.D = []; - this.field = []; - this.K = []; - this.key = (c = b.key || b.id) && Ya(c, this.K) || "id"; - (d = a.keystore || 0) && (this.keystore = d); - this.reg = (this.fastupdate = !!a.fastupdate) ? d ? new N(d) : new Map() : d ? new O(d) : new Set(); - this.C = (c = b.store || null) && !0 !== c && []; - this.store = c && (d ? new N(d) : new Map()); - this.cache = (c = a.cache || null) && new L(c); - a.cache = !1; - this.worker = a.worker; - this.index = Za.call(this, a, b); - this.tag = null; - if (c = b.tag) { - if ("string" === typeof c && (c = [c]), c.length) { - this.tag = new Map(); - this.G = []; - this.N = []; - for (let e = 0, f, g; e < c.length; e++) { - f = c[e]; - g = f.field || f; - if (!g) { - throw Error("The tag field from the document descriptor is undefined."); - } - f.custom ? this.G[e] = f.custom : (this.G[e] = Ya(g, this.K), f.filter && ("string" === typeof this.G[e] && (this.G[e] = new String(this.G[e])), this.G[e].I = f.filter)); - this.N[e] = g; - this.tag.set(g, new Map()); - } - } - } - if (this.worker) { - a = []; - for (const e of this.index.values()) { - e.then && a.push(e); - } - if (a.length) { - const e = this; - return Promise.all(a).then(function(f) { - let g = 0; - for (const h of e.index.entries()) { - const k = h[0]; - h[1].then && e.index.set(k, f[g++]); - } - return e; - }); - } - } else { - a.db && this.mount(a.db); - } -} -u = Y.prototype; -u.mount = function(a) { - let b = this.field; - if (this.tag) { - for (let e = 0, f; e < this.N.length; e++) { - f = this.N[e]; - var c = void 0; - this.index.set(f, c = new Q({}, this.reg)); - b === this.field && (b = b.slice(0)); - b.push(f); - c.tag = this.tag.get(f); - } - } - c = []; - const d = {db:a.db, type:a.type, fastupdate:a.fastupdate}; - for (let e = 0, f, g; e < b.length; e++) { - d.field = g = b[e]; - f = this.index.get(g); - const h = new a.constructor(a.id, d); - h.id = a.id; - c[e] = h.mount(f); - f.document = !0; - e ? f.bypass = !0 : f.store = this.store; - } - this.db = !0; - return Promise.all(c); -}; -u.commit = async function(a, b) { - const c = []; - for (const d of this.index.values()) { - c.push(d.db.commit(d, a, b)); - } - await Promise.all(c); - this.reg.clear(); -}; -u.destroy = function() { - const a = []; - for (const b of this.index.values()) { - a.push(b.destroy()); - } - return Promise.all(a); -}; -function Za(a, b) { - const c = new Map(); - let d = b.index || b.field || b; - B(d) && (d = [d]); - for (let e = 0, f, g; e < d.length; e++) { - f = d[e]; - B(f) || (g = f, f = f.field); - g = D(g) ? Object.assign({}, a, g) : a; - if (this.worker) { - const h = new W(g); - c.set(f, h); - } - this.worker || c.set(f, new Q(g, this.reg)); - g.custom ? this.D[e] = g.custom : (this.D[e] = Ya(f, this.K), g.filter && ("string" === typeof this.D[e] && (this.D[e] = new String(this.D[e])), this.D[e].I = g.filter)); - this.field[e] = f; - } - if (this.C) { - a = b.store; - B(a) && (a = [a]); - for (let e = 0, f, g; e < a.length; e++) { - f = a[e], g = f.field || f, f.custom ? (this.C[e] = f.custom, f.custom.U = g) : (this.C[e] = Ya(g, this.K), f.filter && ("string" === typeof this.C[e] && (this.C[e] = new String(this.C[e])), this.C[e].I = f.filter)); - } - } - return c; -} -function Ya(a, b) { - const c = a.split(":"); - let d = 0; - for (let e = 0; e < c.length; e++) { - a = c[e], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (b[d] = !0), a && (c[d++] = a); - } - d < c.length && (c.length = d); - return 1 < d ? c : c[0]; -} -u.append = function(a, b) { - return this.add(a, b, !0); -}; -u.update = function(a, b) { - return this.remove(a).add(a, b); -}; -u.remove = function(a) { - D(a) && (a = I(a, this.key)); - for (var b of this.index.values()) { - b.remove(a, !0); - } - if (this.reg.has(a)) { - if (this.tag && !this.fastupdate) { - for (let c of this.tag.values()) { - for (let d of c) { - b = d[0]; - const e = d[1], f = e.indexOf(a); - -1 < f && (1 < e.length ? e.splice(f, 1) : c.delete(b)); - } - } - } - this.store && this.store.delete(a); - this.reg.delete(a); - } - this.cache && this.cache.remove(a); - return this; -}; -u.clear = function() { - for (const a of this.index.values()) { - a.clear(); - } - if (this.tag) { - for (const a of this.tag.values()) { - a.clear(); - } - } - this.store && this.store.clear(); - return this; -}; -u.contain = function(a) { - return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a); -}; -u.cleanup = function() { - for (const a of this.index.values()) { - a.cleanup(); - } - return this; -}; -u.get = function(a) { - return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(b) { - return b[0] && b[0].doc; - }) : this.store.get(a); -}; -u.set = function(a, b) { - this.store.set(a, b); - return this; -}; -u.searchCache = la; -u.export = function(a, b, c, d, e, f) { - let g; - "undefined" === typeof f && (g = new Promise(k => { - f = k; - })); - e || (e = 0); - d || (d = 0); - if (d < this.field.length) { - c = this.field[d]; - var h = this.index[c]; - b = this; - h.export(a, b, e ? c : "", d, e++, f) || (d++, b.export(a, b, c, d, 1, f)); - } else { - switch(e) { - case 1: - b = "tag"; - h = this.A; - c = null; - break; - case 2: - b = "store"; - h = this.store; - c = null; - break; - default: - f(); - return; - } - ya(a, this, c, b, d, e, h, f); - } - return g; -}; -u.import = function(a, b) { - if (b) { - switch(B(b) && (b = JSON.parse(b)), a) { - case "tag": - this.A = b; - break; - case "reg": - this.fastupdate = !1; - this.reg = b; - for (let d = 0, e; d < this.field.length; d++) { - e = this.index[this.field[d]], e.reg = b, e.fastupdate = !1; - } - break; - case "store": - this.store = b; - break; - default: - a = a.split("."); - const c = a[0]; - a = a[1]; - c && a && this.index[c].import(a, b); - } - } -}; -Aa(Y.prototype); +na(L.prototype); const $a = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), ab = ["map", "ctx", "tag", "reg", "cfg"]; function bb(a, b = {}) { if (!this) { @@ -2407,7 +2407,7 @@ u.commit = async function(a, b, c) { } }), a.map.clear(), a.ctx.clear(), a.tag && a.tag.clear(), a.store && a.store.clear(), a.document || a.reg.clear()); }; -function cb(a, b, c) { +function db(a, b, c) { const d = a.value; let e, f, g = 0; for (let h = 0, k; h < d.length; h++) { @@ -2436,17 +2436,17 @@ u.remove = function(a) { return Promise.all([this.transaction("map", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && cb(c, a); + c && db(c, a); }; }), this.transaction("ctx", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && cb(c, a); + c && db(c, a); }; }), this.transaction("tag", "readwrite", function(b) { b.openCursor().onsuccess = function() { const c = this.result; - c && cb(c, a, !0); + c && db(c, a, !0); }; }), this.transaction("reg", "readwrite", function(b) { for (let c = 0; c < a.length; c++) { @@ -2466,9 +2466,9 @@ function Z(a) { a = null; }); } -;const db = {Index:Q, Charset:ua, Encoder:J, Document:Y, Worker:W, Resolver:U, IndexedDB:bb, Language:{}}, eb = self; +;const eb = {Index:L, Charset:Ma, Encoder:J, Document:T, Worker:N, Resolver:X, IndexedDB:bb, Language:{}}, fb = self; let gb; -(gb = eb.define) && gb.amd ? gb([], function() { - return db; -}) : "object" === typeof eb.exports ? eb.exports = db : eb.FlexSearch = db; +(gb = fb.define) && gb.amd ? gb([], function() { + return eb; +}) : "object" === typeof fb.exports ? fb.exports = eb : fb.FlexSearch = eb; }(this||self)); diff --git a/dist/flexsearch.bundle.min.js b/dist/flexsearch.bundle.min.js index c2e4b0e..8e7f095 100644 --- a/dist/flexsearch.bundle.min.js +++ b/dist/flexsearch.bundle.min.js @@ -19,70 +19,70 @@ z(a.minlength,1,this.minlength);this.maxlength=z(a.maxlength,0,this.maxlength);i I.prototype.encode=function(a){if(this.cache&&a.length<=this.h)if(this.L){if(this.H.has(a))return this.H.get(a)}else this.L=setTimeout(ka,0,this);this.normalize&&(a="function"===typeof this.normalize?this.normalize(a):ja?a.normalize("NFKD").replace(ja,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(l)),k=1);this.matcher&& 1this.matcher.get(l)),k=1);g&&k&&(g.lengththis.S&&(this.J.clear(),this.A=this.A/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.h&&(this.H.set(a,c),this.H.size>this.S&&(this.H.clear(),this.h=this.h/1.1|0));return c};function ka(a){a.L=null;a.H.clear();a.J.clear()};function la(a,b,c){a=("object"===typeof a?""+a.query:a).toLowerCase();let d=this.cache.get(a);if(!d){d=this.search(a,b,c);if(d.then){const e=this;d.then(function(f){e.cache.set(a,f);return f})}this.cache.set(a,d)}return d}function K(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}K.prototype.set=function(a,b){this.cache.set(this.h=a,b);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)}; -K.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};K.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};K.prototype.clear=function(){this.cache.clear();this.h=""};const ma={normalize:function(a){return a.toLowerCase()},dedupe:!1};const na=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const oa=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),pa=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];const qa={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const ra=/[\x00-\x7F]+/g;const sa=/[\x00-\x7F]+/g;const ta=/[\x00-\x7F]+/g;var ua={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:ma,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:na},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:na,replacer:pa,matcher:oa},LatinExtra:{normalize:!0,dedupe:!0,mapper:na,replacer:pa.concat([/(?!^)[aeoy]/g,""]),matcher:oa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;c=g.length)b-=g.length;else{b=g[d?"splice":"slice"](b,c);const h=b.length;if(h&&(e=e.length?e.concat(b):b,c-=h,d&&(a.length-=h),!c))break;b=0}return e} -function M(a){if(!this)return new M(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){let f=0;for(let g=0,h,k;gf;h--){g=t.substring(f,h);var k=this.score?this.score(b,t,q,g,f):R(p,d,q,e,f);S(this,m,g,k,a,c)}break}case "reverse":if(1< -e){for(h=e-1;0g?0:1),d,q,h-1,k-1),v=this.bidirectional&&t>f;S(this,l,v?f:t,r,a,c,v?t:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& -(b||this.commit_task.push({del:a}),this.T&&Ba(this));return this};function S(a,b,c,d,e,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||!g||!(k=b[c])[g])if(g?(b=k||(b[c]=A()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new M(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}} -function R(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?Ca(a):a;let e=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=g.length),e.push(g);else{if(h>=b)return h>b&&(g=g.slice(0,b)),d?Ca(g):g;e=[g]}b-=h;if(!b)break}if(!e.length)return e;e=1c||d)k=k.slice(d,c+d)}else{e=[];for(let n=0,p;nd)d-=p.length;else{if(p.length>c||d)p=p.slice(d, +this.cache&&h.length<=this.A&&(this.J.set(h,g),this.J.size>this.S&&(this.J.clear(),this.A=this.A/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.h&&(this.H.set(a,c),this.H.size>this.S&&(this.H.clear(),this.h=this.h/1.1|0));return c};function ka(a){a.L=null;a.H.clear();a.J.clear()};async function la(a){a=a.data;var b=self._index;const c=a.args;var d=a.task;switch(d){case "init":d=a.options||{};(b=d.config)&&(d=(await import(b))["default"]);(b=a.factory)?(Function("return "+b)()(self),self._index=new self.FlexSearch.Index(d),delete self.FlexSearch):self._index=new K(d);postMessage({id:a.id});break;default:a=a.id,b=b[d].apply(b,c),postMessage("search"===d?{id:a,msg:b}:{id:a})}};let M=0; +function N(a={}){function b(g){function h(k){k=k.data||k;const l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=g;this.h=A();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.h[++M]=function(){k(e)};e.worker.postMessage({id:M,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}if(!this)return new N(a);let c="undefined"!==typeof self?self._factory:"undefined"!==typeof window? +window._factory:null;c&&(c=c.toString());const d="undefined"===typeof window,e=this,f=ma(c,d,a.worker);return f.then?f.then(function(g){return b.call(e,g)}):b.call(this,f)}O("add");O("append");O("search");O("update");O("remove"); +function O(a){N.prototype[a]=N.prototype[a+"Async"]=async function(){const b=this,c=[].slice.call(arguments);var d=c[c.length-1];let e;"function"===typeof d&&(e=d,c.splice(c.length-1,1));d=new Promise(function(f){b.h[++M]=f;b.worker.postMessage({task:a,id:M,args:c})});return e?(d.then(e),this):d}} +function ma(a,b,c){return b?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+la.toString()],{type:"text/javascript"}))):new window.Worker(C(c)?c:(0,eval)("import.meta.url").replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", +"module/worker/worker.js"),{type:"module"})};function na(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}function P(a){this[a+"Async"]=function(){var b=arguments;const c=b[b.length-1];let d;"function"===typeof c&&(d=c,delete b[b.length-1]);b=this[a].apply(this,b);d&&(b.then?b.then(d):d(b));return b}};function oa(a,b,c,d,e,f,g,h){(d=a(c?c+"."+d:d,JSON.stringify(g)))&&d.then?d.then(function(){b.export(a,b,c,e,f+1,h)}):b.export(a,b,c,e,f+1,h)};function pa(a,b,c,d){let e=[];for(let f=0,g;f=g.length)b-=g.length;else{b=g[d?"splice":"slice"](b,c);const h=b.length;if(h&&(e=e.length?e.concat(b):b,c-=h,d&&(a.length-=h),!c))break;b=0}return e} +function Q(a){if(!this)return new Q(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){let f=0;for(let g=0,h,k;gc||d)k=k.slice(d,c+d)}else{e=[];for(let n=0,p;nd)d-=p.length;else{if(p.length>c||d)p=p.slice(d, c+d),c-=p.length,d&&(d-=p.length);e.push(p);if(!c)break}return 1a.length?e?T(a[0],b,c,d):a[0]:Ea(a,c,b,e,f)};U.prototype.and=function(){if(this.result.length){const b=this;let c=arguments;var a=c[0];if(a.then)return a.then(function(){return b.and.apply(b,c)});if(a[0]&&a[0].index)return this.and.apply(this,a);let d=[];a=[];let e=0,f=0,g,h;for(let k=0,l;ka.length)return[];let g=[];A();let h=ca(a);return h?Da(a,h,b,c,f,e,d):g};U.prototype.xor=function(){const a=this;let b=arguments;var c=b[0];if(c.then)return c.then(function(){return a.xor.apply(a,b)});if(c[0]&&c[0].index)return this.xor.apply(this,c);let d=[];c=[];let e=0,f=0,g,h;for(let k=0,l;ka.length)return e?T(a[0],b,c,d):a[0];d=[];const g=A();let h=0;for(let k=0,l;kc);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,f,g,h):a.db.get(b,"",d,e,f,g,h);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};Q.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else Na(this.map,a),this.depth&&Na(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&Ba(this));this.cache&&this.cache.remove(a);return this}; -function Na(a,b){let c=0;if(a.constructor===Array)for(let d=0,e,f;dc.add(a,b)):this.add(a,b)}; -function Oa(a){let b=0;if(a.constructor===Array)for(let c=0,d;c{f=l}));let h,k;switch(e||(e=0)){case 0:h="reg";if(this.fastupdate){k=A();for(let l of this.reg.keys())k[l]=1}else k=this.reg;break;case 1:h="cfg";k={doc:0,opt:this.h?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.ctx;break;default:"undefined"===typeof c&&f&&f();return}ya(a,b||this,c,h,d,e,k,f);return g}; -u.import=function(a,b){if(b)switch(C(b)&&(b=JSON.parse(b)),a){case "cfg":this.h=!!b.opt;break;case "reg":this.fastupdate=!1;this.reg=b;break;case "map":this.map=b;break;case "ctx":this.ctx=b}}; -u.serialize=function(a=!0){if(!this.reg.size)return"";let b="",c="";for(var d of this.reg.keys())c||(c=typeof d),b+=(b?",":"")+("string"===c?'"'+d+'"':d);b="index.reg=new Set(["+b+"]);";d="";for(var e of this.map.entries()){var f=e[0],g=e[1],h="";for(let m=0,n;mc||d)a=a.slice(d,d+c);e&&(a=Va.call(this,a));return a}} -function Va(a){const b=Array(a.length);for(let c=0,d;cc||d)a=a.slice(d,d+c);e&&(a=ya.call(this,a));return a}} +function ya(a){const b=Array(a.length);for(let c=0,d;c{f=k}));e||(e=0);d||(d=0);if(d{f=k}));e||(e=0);d||(d=0);if(dthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +U.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};U.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};U.prototype.clear=function(){this.cache.clear();this.h=""};const Ea={normalize:function(a){return a.toLowerCase()},dedupe:!1};const Fa=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const Ga=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),Ha=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];const Ia={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const Ja=/[\x00-\x7F]+/g;const Ka=/[\x00-\x7F]+/g;const La=/[\x00-\x7F]+/g;var Ma={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Ea,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Fa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Fa,replacer:Ha,matcher:Ga},LatinExtra:{normalize:!0,dedupe:!0,mapper:Fa,replacer:Ha.concat([/(?!^)[aeoy]/g,""]),matcher:Ga},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cf;h--){g=t.substring(f,h);var k=this.score?this.score(b,t,q,g,f):Oa(p,d,q,e,f);V(this,m,g,k,a,c)}break}case "reverse":if(1< +e){for(h=e-1;0g?0:1),d,q,h-1,k-1),v=this.bidirectional&&t>f;V(this,l,v?f:t,r,a,c,v?t:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& +(b||this.commit_task.push({del:a}),this.T&&Pa(this));return this};function V(a,b,c,d,e,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||g&&!(k=b[c])[g])if(g?(b=k||(b[c]=A()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new Q(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}} +function Oa(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?Qa(a):a;let e=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=g.length),e.push(g);else{if(h>=b)return h>b&&(g=g.slice(0,b)),d?Qa(g):g;e=[g]}b-=h;if(!b)break}if(!e.length)return e;e=1a.length?e?W(a[0],b,c,d):a[0]:va(a,c,b,e,f)};X.prototype.and=function(){if(this.result.length){const b=this;let c=arguments;var a=c[0];if(a.then)return a.then(function(){return b.and.apply(b,c)});if(a[0]&&a[0].index)return this.and.apply(this,a);let d=[];a=[];let e=0,f=0,g,h;for(let k=0,l;ka.length)return[];let g=[];A();let h=ca(a);return h?ua(a,h,b,c,f,e,d):g};X.prototype.xor=function(){const a=this;let b=arguments;var c=b[0];if(c.then)return c.then(function(){return a.xor.apply(a,b)});if(c[0]&&c[0].index)return this.xor.apply(this,c);let d=[];c=[];let e=0,f=0,g,h;for(let k=0,l;ka.length)return e?W(a[0],b,c,d):a[0];d=[];const g=A();let h=0;for(let k=0,l;kc);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,f,g,h):a.db.get(b,"",d,e,f,g,h);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};K.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else Ya(this.map,a),this.depth&&Ya(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&Pa(this));this.cache&&this.cache.remove(a);return this}; +function Ya(a,b){let c=0;if(a.constructor===Array)for(let d=0,e,f;dc.add(a,b)):this.add(a,b)}; +function Za(a){let b=0;if(a.constructor===Array)for(let c=0,d;c{f=l}));let h,k;switch(e||(e=0)){case 0:h="reg";if(this.fastupdate){k=A();for(let l of this.reg.keys())k[l]=1}else k=this.reg;break;case 1:h="cfg";k={doc:0,opt:this.h?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.ctx;break;default:"undefined"===typeof c&&f&&f();return}oa(a,b||this,c,h,d,e,k,f);return g}; +u.import=function(a,b){if(b)switch(C(b)&&(b=JSON.parse(b)),a){case "cfg":this.h=!!b.opt;break;case "reg":this.fastupdate=!1;this.reg=b;break;case "map":this.map=b;break;case "ctx":this.ctx=b}}; +u.serialize=function(a=!0){if(!this.reg.size)return"";let b="",c="";for(var d of this.reg.keys())c||(c=typeof d),b+=(b?",":"")+("string"===c?'"'+d+'"':d);b="index.reg=new Set(["+b+"]);";d="";for(var e of this.map.entries()){var f=e[0],g=e[1],h="";for(let m=0,n;m{e.objectStoreNames.contains(f)||e.createObjectStore(f)})};d.onblocked=function(e){console.error("blocked",e);c()};d.onerror=function(e){console.error(this.error,e);c()};d.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; u.close=function(){this.db.close();this.db=null};u.destroy=function(){return $a.deleteDatabase(this.id+(this.field?":"+this.field:""))};u.clear=function(){const a=this.db.transaction(ab,"readwrite");for(let b=0;b=m.length){d-=m.length;continue}const n=c?d+Math.min(m.length-d,c):m.length;for(let p=d;pm&&!f&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(f=1),0<=m)if(e=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};const db={Index:Q,Charset:ua,Encoder:I,Document:Y,Worker:W,Resolver:U,IndexedDB:bb,Language:{}},eb=self;let gb;(gb=eb.define)&&gb.amd?gb([],function(){return db}):"object"===typeof eb.exports?eb.exports=db:eb.FlexSearch=db;}(this||self)); +function db(a,b,c){const d=a.value;let e,f,g=0;for(let h=0,k;hm&&!f&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(f=1),0<=m)if(e=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};const eb={Index:K,Charset:Ma,Encoder:I,Document:T,Worker:N,Resolver:X,IndexedDB:cb,Language:{}},fb=self;let gb;(gb=fb.define)&&gb.amd?gb([],function(){return eb}):"object"===typeof fb.exports?fb.exports=eb:fb.FlexSearch=eb;}(this||self)); diff --git a/dist/flexsearch.bundle.module.debug.js b/dist/flexsearch.bundle.module.debug.js index b654bdb..8c55bf7 100644 --- a/dist/flexsearch.bundle.module.debug.js +++ b/dist/flexsearch.bundle.module.debug.js @@ -223,71 +223,102 @@ function ka(a) { a.H.clear(); a.J.clear(); } -;function la(a, b, c) { - a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); - let d = this.cache.get(a); - if (!d) { - d = this.search(a, b, c); - if (d.then) { - const e = this; - d.then(function(f) { - e.cache.set(a, f); - return f; - }); - } - this.cache.set(a, d); +;async function la(a) { + a = a.data; + var b = self._index; + const c = a.args; + var d = a.task; + switch(d) { + case "init": + d = a.options || {}; + (b = d.config) && (d = b); + (b = a.factory) ? (Function("return " + b)()(self), self._index = new self.FlexSearch.Index(d), delete self.FlexSearch) : self._index = new L(d); + postMessage({id:a.id}); + break; + default: + a = a.id, b = b[d].apply(b, c), postMessage("search" === d ? {id:a, msg:b} : {id:a}); } - return d; } -function L(a) { - this.limit = a && !0 !== a ? a : 1000; - this.cache = new Map(); - this.h = ""; -} -L.prototype.set = function(a, b) { - this.cache.set(this.h = a, b); - this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); -}; -L.prototype.get = function(a) { - const b = this.cache.get(a); - b && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, b)); - return b; -}; -L.prototype.remove = function(a) { - for (const b of this.cache) { - const c = b[0]; - b[1].includes(a) && this.cache.delete(c); - } -}; -L.prototype.clear = function() { - this.cache.clear(); - this.h = ""; -}; -const ma = {normalize:function(a) { - return a.toLowerCase(); -}, dedupe:!1}; -const na = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); -const oa = new Map([["ai", "ei"], ["ae", "a"], ["oe", "o"], ["ue", "u"], ["sh", "s"], ["ch", "c"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), pa = [/([^aeo])h([aeo$])/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2"]; -const qa = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; -const ra = /[\x00-\x7F]+/g; -const sa = /[\x00-\x7F]+/g; -const ta = /[\x00-\x7F]+/g; -var ua = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:ma, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:na}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:na, replacer:pa, matcher:oa}, LatinExtra:{normalize:!0, dedupe:!0, mapper:na, replacer:pa.concat([/(?!^)[aeoy]/g, ""]), matcher:oa}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { - for (let c = 0; c < a.length; c++) { - var b = a[c]; - let d = b.charAt(0), e = qa[d]; - for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = qa[g]) || g === e || (d += g, e = g, 4 !== d.length)); f++) { +;let M = 0; +function N(a = {}) { + function b(g) { + function h(k) { + k = k.data || k; + const l = k.id, m = l && e.h[l]; + m && (m(k.msg), delete e.h[l]); + } + this.worker = g; + this.h = A(); + if (this.worker) { + d ? this.worker.on("message", h) : this.worker.onmessage = h; + if (a.config) { + return new Promise(function(k) { + e.h[++M] = function() { + k(e); + }; + e.worker.postMessage({id:M, task:"init", factory:c, options:a}); + }); + } + this.worker.postMessage({task:"init", factory:c, options:a}); + return this; } - a[c] = d; } -}}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(ra, " "); -}}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(sa, ""); -}}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(ta, " "); -}}}; -function va(a, b, c, d) { + if (!this) { + return new N(a); + } + let c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; + c && (c = c.toString()); + const d = "undefined" === typeof window, e = this, f = ma(c, d, a.worker); + return f.then ? f.then(function(g) { + return b.call(e, g); + }) : b.call(this, f); +} +O("add"); +O("append"); +O("search"); +O("update"); +O("remove"); +function O(a) { + N.prototype[a] = N.prototype[a + "Async"] = async function() { + const b = this, c = [].slice.call(arguments); + var d = c[c.length - 1]; + let e; + "function" === typeof d && (e = d, c.splice(c.length - 1, 1)); + d = new Promise(function(f) { + b.h[++M] = f; + b.worker.postMessage({task:a, id:M, args:c}); + }); + return e ? (d.then(e), this) : d; + }; +} +function ma(a, b, c) { + return b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"](import.meta.dirname + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + la.toString()], {type:"text/javascript"}))) : new window.Worker(B(c) ? c : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", + "module/worker/worker.js"), {type:"module"}); +} +;function na(a) { + P.call(a, "add"); + P.call(a, "append"); + P.call(a, "search"); + P.call(a, "update"); + P.call(a, "remove"); +} +function P(a) { + this[a + "Async"] = function() { + var b = arguments; + const c = b[b.length - 1]; + let d; + "function" === typeof c && (d = c, delete b[b.length - 1]); + b = this[a].apply(this, b); + d && (b.then ? b.then(d) : d(b)); + return b; + }; +} +;function oa(a, b, c, d, e, f, g, h) { + (d = a(c ? c + "." + d : d, JSON.stringify(g))) && d.then ? d.then(function() { + b.export(a, b, c, e, f + 1, h); + }) : b.export(a, b, c, e, f + 1, h); +} +;function pa(a, b, c, d) { let e = []; for (let f = 0, g; f < a.index.length; f++) { if (g = a.index[f], b >= g.length) { @@ -303,9 +334,9 @@ function va(a, b, c, d) { } return e; } -function M(a) { +function Q(a) { if (!this) { - return new M(a); + return new Q(a); } this.index = a ? [a] : []; this.length = a ? a.length : 0; @@ -353,12 +384,12 @@ function M(a) { } if ("slice" === d) { return function(e, f) { - return va(b, e || 0, f || b.length, !1); + return pa(b, e || 0, f || b.length, !1); }; } if ("splice" === d) { return function(e, f) { - return va(b, e || 0, f || b.length, !0); + return pa(b, e || 0, f || b.length, !0); }; } if ("constructor" === d) { @@ -374,81 +405,81 @@ function M(a) { return !0; }}); } -M.prototype.clear = function() { +Q.prototype.clear = function() { this.index.length = 0; }; -M.prototype.destroy = function() { +Q.prototype.destroy = function() { this.proxy = this.index = null; }; -M.prototype.push = function() { +Q.prototype.push = function() { }; -function N(a = 8) { +function R(a = 8) { if (!this) { - return new N(a); + return new R(a); } this.index = A(); this.B = []; this.size = 0; - 32 < a ? (this.h = wa, this.A = BigInt(a)) : (this.h = xa, this.A = a); + 32 < a ? (this.h = qa, this.A = BigInt(a)) : (this.h = ra, this.A = a); } -N.prototype.get = function(a) { +R.prototype.get = function(a) { const b = this.index[this.h(a)]; return b && b.get(a); }; -N.prototype.set = function(a, b) { +R.prototype.set = function(a, b) { var c = this.h(a); let d = this.index[c]; d ? (c = d.size, d.set(a, b), (c -= d.size) && this.size++) : (this.index[c] = d = new Map([[a, b]]), this.B.push(d)); }; -function O(a = 8) { +function S(a = 8) { if (!this) { - return new O(a); + return new S(a); } this.index = A(); this.h = []; - 32 < a ? (this.B = wa, this.A = BigInt(a)) : (this.B = xa, this.A = a); + 32 < a ? (this.B = qa, this.A = BigInt(a)) : (this.B = ra, this.A = a); } -O.prototype.add = function(a) { +S.prototype.add = function(a) { var b = this.B(a); let c = this.index[b]; c ? (b = c.size, c.add(a), (b -= c.size) && this.size++) : (this.index[b] = c = new Set([a]), this.h.push(c)); }; -u = N.prototype; -u.has = O.prototype.has = function(a) { +u = R.prototype; +u.has = S.prototype.has = function(a) { const b = this.index[this.B(a)]; return b && b.has(a); }; -u.delete = O.prototype.delete = function(a) { +u.delete = S.prototype.delete = function(a) { const b = this.index[this.B(a)]; b && b.delete(a) && this.size--; }; -u.clear = O.prototype.clear = function() { +u.clear = S.prototype.clear = function() { this.index = A(); this.h = []; this.size = 0; }; -u.values = O.prototype.values = function*() { +u.values = S.prototype.values = function*() { for (let a = 0; a < this.h.length; a++) { for (let b of this.h[a].values()) { yield b; } } }; -u.keys = O.prototype.keys = function*() { +u.keys = S.prototype.keys = function*() { for (let a = 0; a < this.h.length; a++) { for (let b of this.h[a].keys()) { yield b; } } }; -u.entries = O.prototype.entries = function*() { +u.entries = S.prototype.entries = function*() { for (let a = 0; a < this.h.length; a++) { for (let b of this.h[a].entries()) { yield b; } } }; -function xa(a) { +function ra(a) { let b = 2 ** this.A - 1; if ("number" == typeof a) { return a & b; @@ -459,7 +490,7 @@ function xa(a) { } return 32 === this.A ? c + 2 ** 31 : c; } -function wa(a) { +function qa(a) { let b = BigInt(2) ** this.A - BigInt(1); var c = typeof a; if ("bigint" === c) { @@ -475,153 +506,132 @@ function wa(a) { } return c; } -;function ya(a, b, c, d, e, f, g, h) { - (d = a(c ? c + "." + d : d, JSON.stringify(g))) && d.then ? d.then(function() { - b.export(a, b, c, e, f + 1, h); - }) : b.export(a, b, c, e, f + 1, h); -} -;const za = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -function Aa(a) { - P.call(a, "add"); - P.call(a, "append"); - P.call(a, "search"); - P.call(a, "update"); - P.call(a, "remove"); -} -function P(a) { - this[a + "Async"] = function() { - var b = arguments; - const c = b[b.length - 1]; - let d; - "function" === typeof c && (d = c, delete b[b.length - 1]); - b = this[a].apply(this, b); - d && (b.then ? b.then(d) : d(b)); - return b; - }; -} -;A(); -Q.prototype.add = function(a, b, c, d) { +;T.prototype.add = function(a, b, c) { + D(a) && (b = a, a = I(b, this.key)); if (b && (a || 0 === a)) { - if (!d && !c && this.reg.has(a)) { + if (!c && this.reg.has(a)) { return this.update(a, b); } - b = this.encoder.encode(b); - if (d = b.length) { - const l = A(), m = A(), p = this.depth, n = this.resolution; - for (let q = 0; q < d; q++) { - let t = b[this.rtl ? d - 1 - q : q]; - var e = t.length; - if (e && (p || !m[t])) { - var f = this.score ? this.score(b, t, q, null, 0) : R(n, d, q), g = ""; - switch(this.tokenize) { - case "full": - if (2 < e) { - for (f = 0; f < e; f++) { - for (var h = e; h > f; h--) { - g = t.substring(f, h); - var k = this.score ? this.score(b, t, q, g, f) : R(n, d, q, e, f); - S(this, m, g, k, a, c); - } - } - break; - } - case "reverse": - if (1 < e) { - for (h = e - 1; 0 < h; h--) { - g = t[h] + g, k = this.score ? this.score(b, t, q, g, h) : R(n, d, q, e, h), S(this, m, g, k, a, c); - } - g = ""; - } - case "forward": - if (1 < e) { - for (h = 0; h < e; h++) { - g += t[h], S(this, m, g, f, a, c); - } - break; - } - default: - if (S(this, m, t, f, a, c), p && 1 < d && q < d - 1) { - for (e = A(), g = this.R, f = t, h = Math.min(p + 1, d - q), e[f] = 1, k = 1; k < h; k++) { - if ((t = b[this.rtl ? d - 1 - q - k : q + k]) && !e[t]) { - e[t] = 1; - const r = this.score ? this.score(b, f, q, t, k) : R(g + (d / 2 > g ? 0 : 1), d, q, h - 1, k - 1), v = this.bidirectional && t > f; - S(this, l, v ? f : t, r, a, c, v ? t : f); - } - } - } - } + for (let h = 0, k; h < this.field.length; h++) { + k = this.D[h]; + var d = this.index.get(this.field[h]); + if ("function" === typeof k) { + var e = k(b); + e && d.add(a, e, !1, !0); + } else { + if (e = k.I, !e || e(b)) { + k.constructor === String ? k = ["" + k] : B(k) && (k = [k]), sa(b, k, this.K, 0, d, a, k[0], c); } } - this.fastupdate || this.reg.add(a); - } else { - b = ""; + } + if (this.tag) { + for (d = 0; d < this.G.length; d++) { + var f = this.G[d], g = this.N[d]; + e = this.tag.get(g); + let h = A(); + if ("function" === typeof f) { + if (f = f(b), !f) { + continue; + } + } else { + const k = f.I; + if (k && !k(b)) { + continue; + } + f.constructor === String && (f = "" + f); + f = I(b, f); + } + if (e && f) { + B(f) && (f = [f]); + for (let k = 0, l, m; k < f.length; k++) { + if (l = f[k], !h[l] && (h[l] = 1, (g = e.get(l)) ? m = g : e.set(l, m = []), !c || !m.includes(a))) { + if (m.length === 2 ** 31 - 1) { + g = new Q(m); + if (this.fastupdate) { + for (let p of this.reg.values()) { + p.includes(m) && (p[p.indexOf(m)] = g); + } + } + e.set(l, m = g); + } + m.push(a); + this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])); + } + } + } else { + e || console.warn("Tag '" + g + "' was not found"); + } + } + } + if (this.store && (!c || !this.store.has(a))) { + let h; + if (this.C) { + h = A(); + for (let k = 0, l; k < this.C.length; k++) { + l = this.C[k]; + if ((c = l.I) && !c(b)) { + continue; + } + let m; + if ("function" === typeof l) { + m = l(b); + if (!m) { + continue; + } + l = [l.U]; + } else if (B(l) || l.constructor === String) { + h[l] = b[l]; + continue; + } + ta(b, h, l, 0, l[0], m); + } + } + this.store.set(a, h || b); } } - this.db && (b || this.commit_task.push({del:a}), this.T && Ba(this)); return this; }; -function S(a, b, c, d, e, f, g) { - let h = g ? a.ctx : a.map, k; - if (!b[c] || !g || !(k = b[c])[g]) { - if (g ? (b = k || (b[c] = A()), b[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !f || !h.includes(e)) { - if (h.length === 2 ** 31 - 1) { - b = new M(h); - if (a.fastupdate) { - for (let l of a.reg.values()) { - l.includes(h) && (l[l.indexOf(h)] = b); +function ta(a, b, c, d, e, f) { + a = a[e]; + if (d === c.length - 1) { + b[e] = f || a; + } else if (a) { + if (a.constructor === Array) { + for (b = b[e] = Array(a.length), e = 0; e < a.length; e++) { + ta(a, b, c, d, e); + } + } else { + b = b[e] || (b[e] = A()), e = c[++d], ta(a, b, c, d, e); + } + } +} +function sa(a, b, c, d, e, f, g, h) { + if (a = a[g]) { + if (d === b.length - 1) { + if (a.constructor === Array) { + if (c[d]) { + for (b = 0; b < a.length; b++) { + e.add(f, a[b], !0, !0); } + return; } - k[d] = h = b; + a = a.join(" "); } - h.push(e); - a.fastupdate && ((d = a.reg.get(e)) ? d.push(h) : a.reg.set(e, [h])); - } - } -} -function R(a, b, c, d, e) { - return c && 1 < a ? b + (d || 0) <= a ? c + (e || 0) : (a - 1) / (b + (d || 0)) * (c + (e || 0)) + 1 | 0 : 0; -} -;function T(a, b, c, d) { - if (1 === a.length) { - return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, d ? Ca(a) : a; - } - let e = []; - for (let f = 0, g, h; f < a.length; f++) { - if ((g = a[f]) && (h = g.length)) { - if (c) { - if (c >= h) { - c -= h; - continue; + e.add(f, a, h, !0); + } else { + if (a.constructor === Array) { + for (g = 0; g < a.length; g++) { + sa(a, b, c, d, e, f, g, h); } - c < h && (g = b ? g.slice(c, c + b) : g.slice(c), h = g.length, c = 0); - } - if (e.length) { - h > b && (g = g.slice(0, b), h = g.length), e.push(g); } else { - if (h >= b) { - return h > b && (g = g.slice(0, b)), d ? Ca(g) : g; - } - e = [g]; - } - b -= h; - if (!b) { - break; + g = b[++d], sa(a, b, c, d, e, f, g, h); } } + } else { + e.db && e.remove(f); } - if (!e.length) { - return e; - } - e = 1 < e.length ? [].concat.apply([], e) : e[0]; - return d ? Ca(e) : e; } -function Ca(a) { - for (let b = 0; b < a.length; b++) { - a[b] = {score:b, id:a[b]}; - } - return a; -} -;function Da(a, b, c, d, e, f, g) { +;function ua(a, b, c, d, e, f, g) { const h = a.length; let k = [], l; var m; @@ -637,7 +647,7 @@ function Ca(a) { } if (a = k.length) { if (e) { - k = 1 < k.length ? Ea(k, d, c, g, 0) : k[0]; + k = 1 < k.length ? va(k, d, c, g, 0) : k[0]; } else { if (a < h) { return []; @@ -670,7 +680,7 @@ function Ca(a) { } return k; } -function Ea(a, b, c, d, e) { +function va(a, b, c, d, e) { const f = [], g = A(); let h; var k = a.length; @@ -713,7 +723,7 @@ function Ea(a, b, c, d, e) { } return f; } -function Fa(a, b) { +function wa(a, b) { const c = A(), d = []; for (let e = 0, f; e < b.length; e++) { f = b[e]; @@ -726,7 +736,692 @@ function Fa(a, b) { } return d; } -;U.prototype.or = function() { +;T.prototype.search = function(a, b, c, d) { + c || (!b && D(a) ? (c = a, a = "") : D(b) && (c = b, b = 0)); + let e = [], f = [], g; + let h; + let k; + let l, m = 0, p; + if (c) { + c.constructor === Array && (c = {index:c}); + a = c.query || a; + g = c.pluck; + h = c.merge; + k = g || c.field || c.index; + var n = this.tag && c.tag; + var q = this.store && c.enrich; + var t = c.suggest; + p = c.V; + b = c.limit || b; + l = c.offset || 0; + b || (b = 100); + if (n && (!this.db || !d)) { + n.constructor !== Array && (n = [n]); + var r = []; + for (let y = 0, w; y < n.length; y++) { + w = n[y]; + if (B(w)) { + throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); + } + if (w.field && w.tag) { + var v = w.tag; + if (v.constructor === Array) { + for (var x = 0; x < v.length; x++) { + r.push(w.field, v[x]); + } + } else { + r.push(w.field, v); + } + } else { + v = Object.keys(w); + for (let C = 0, K, E; C < v.length; C++) { + if (K = v[C], E = w[K], E.constructor === Array) { + for (x = 0; x < E.length; x++) { + r.push(K, E[x]); + } + } else { + r.push(K, E); + } + } + } + } + if (!r.length) { + throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); + } + n = r; + if (!a) { + t = []; + if (r.length) { + for (n = 0; n < r.length; n += 2) { + if (this.db) { + d = this.index.get(r[n]); + if (!d) { + console.warn("Tag '" + r[n] + ":" + r[n + 1] + "' will be skipped because there is no field '" + r[n] + "'."); + continue; + } + t.push(d = d.db.tag(r[n + 1], b, l, q)); + } else { + d = xa.call(this, r[n], r[n + 1], b, l, q); + } + e.push({field:r[n], tag:r[n + 1], result:d}); + } + } + return t.length ? Promise.all(t).then(function(y) { + for (let w = 0; w < y.length; w++) { + e[w].result = y[w]; + } + return e; + }) : e; + } + } + B(k) && (k = [k]); + } + k || (k = this.field); + r = !d && (this.worker || this.db) && []; + let F; + for (let y = 0, w, C, K; y < k.length; y++) { + C = k[y]; + if (this.db && this.tag && !this.D[y]) { + continue; + } + let E; + B(C) || (E = C, C = E.field, a = E.query || a, b = E.limit || b, l = E.offset || l, t = E.suggest || t, q = this.store && (E.enrich || q)); + if (d) { + w = d[y]; + } else { + if (v = E || c, x = this.index.get(C), n && (this.db && (v.tag = n, F = x.db.support_tag_search, v.field = k), F || (v.enrich = !1)), r) { + r[y] = x.search(a, b, v); + v && q && (v.enrich = q); + continue; + } else { + w = x.search(a, b, v), v && q && (v.enrich = q); + } + } + K = w && w.length; + if (n && K) { + v = []; + x = 0; + if (this.db && d) { + if (!F) { + for (let G = k.length; G < d.length; G++) { + let H = d[G]; + if (H && H.length) { + x++, v.push(H); + } else if (!t) { + return e; + } + } + } + } else { + for (let G = 0, H, $a; G < n.length; G += 2) { + H = this.tag.get(n[G]); + if (!H) { + if (console.warn("Tag '" + n[G] + ":" + n[G + 1] + "' will be skipped because there is no field '" + n[G] + "'."), t) { + continue; + } else { + return e; + } + } + if ($a = (H = H && H.get(n[G + 1])) && H.length) { + x++, v.push(H); + } else if (!t) { + return e; + } + } + } + if (x) { + w = wa(w, v); + K = w.length; + if (!K && !t) { + return e; + } + x--; + } + } + if (K) { + f[m] = C, e.push(w), m++; + } else if (1 === k.length) { + return e; + } + } + if (r) { + if (this.db && n && n.length && !F) { + for (q = 0; q < n.length; q += 2) { + d = this.index.get(n[q]); + if (!d) { + if (console.warn("Tag '" + n[q] + ":" + n[q + 1] + "' was not found because there is no field '" + n[q] + "'."), t) { + continue; + } else { + return e; + } + } + r.push(d.db.tag(n[q + 1], b, l, !1)); + } + } + const y = this; + return Promise.all(r).then(function(w) { + return w.length ? y.search(a, b, c, w) : w; + }); + } + if (!m) { + return e; + } + if (g && (!q || !this.store)) { + return e[0]; + } + r = []; + for (let y = 0, w; y < f.length; y++) { + w = e[y]; + q && w.length && !w[0].doc && (this.db ? r.push(w = this.index.get(this.field[0]).db.enrich(w)) : w.length && (w = ya.call(this, w))); + if (g) { + return w; + } + e[y] = {field:f[y], result:w}; + } + if (q && this.db && r.length) { + const y = this; + return Promise.all(r).then(function(w) { + for (let C = 0; C < w.length; C++) { + e[C].result = w[C]; + } + return h ? za(e, b) : p ? Aa(e, a, y.index, y.D, p) : e; + }); + } + return h ? za(e, b) : p ? Aa(e, a, this.index, this.D, p) : e; +}; +function Aa(a, b, c, d, e) { + let f; + for (let g = 0, h, k, l, m; g < a.length; g++) { + h = a[g].result; + k = a[g].field; + l = c.get(k).encoder; + m = d[k.indexOf(k)]; + l !== f && (f = l, f.encode(b)); + for (let p = 0; p < h.length; p++) { + let n = "", q = I(h[p].doc, m), t = f.encode(q); + for (let r = 0; r < t.length; r++) { + n += t[r].replace(new RegExp("(" + t[r] + ")", "g"), e.replace("$1", q)); + } + console.log(a, c, e); + h[p].V = n; + } + } + return a; +} +function za(a, b) { + const c = [], d = A(); + for (let e = 0, f, g; e < a.length; e++) { + f = a[e]; + g = f.result; + for (let h = 0, k, l, m; h < g.length; h++) { + if (l = g[h], k = l.id, m = d[k]) { + m.push(f.field); + } else { + if (c.length === b) { + return c; + } + l.field = d[k] = [f.field]; + c.push(l); + } + } + } + return c; +} +function xa(a, b, c, d, e) { + let f = this.tag.get(a); + if (!f) { + return console.warn("Tag '" + a + "' was not found"), []; + } + if ((a = (f = f && f.get(b)) && f.length - d) && 0 < a) { + if (a > c || d) { + f = f.slice(d, d + c); + } + e && (f = ya.call(this, f)); + return f; + } +} +function ya(a) { + const b = Array(a.length); + for (let c = 0, d; c < a.length; c++) { + d = a[c], b[c] = {id:d, doc:this.store.get(d)}; + } + return b; +} +;function T(a) { + if (!this) { + return new T(a); + } + const b = a.document || a.doc || a; + let c, d; + this.D = []; + this.field = []; + this.K = []; + this.key = (c = b.key || b.id) && Ba(c, this.K) || "id"; + (d = a.keystore || 0) && (this.keystore = d); + this.reg = (this.fastupdate = !!a.fastupdate) ? d ? new R(d) : new Map() : d ? new S(d) : new Set(); + this.C = (c = b.store || null) && !0 !== c && []; + this.store = c && (d ? new R(d) : new Map()); + this.cache = (c = a.cache || null) && new U(c); + a.cache = !1; + this.worker = a.worker; + this.index = Ca.call(this, a, b); + this.tag = null; + if (c = b.tag) { + if ("string" === typeof c && (c = [c]), c.length) { + this.tag = new Map(); + this.G = []; + this.N = []; + for (let e = 0, f, g; e < c.length; e++) { + f = c[e]; + g = f.field || f; + if (!g) { + throw Error("The tag field from the document descriptor is undefined."); + } + f.custom ? this.G[e] = f.custom : (this.G[e] = Ba(g, this.K), f.filter && ("string" === typeof this.G[e] && (this.G[e] = new String(this.G[e])), this.G[e].I = f.filter)); + this.N[e] = g; + this.tag.set(g, new Map()); + } + } + } + if (this.worker) { + a = []; + for (const e of this.index.values()) { + e.then && a.push(e); + } + if (a.length) { + const e = this; + return Promise.all(a).then(function(f) { + let g = 0; + for (const h of e.index.entries()) { + const k = h[0]; + h[1].then && e.index.set(k, f[g++]); + } + return e; + }); + } + } else { + a.db && this.mount(a.db); + } +} +u = T.prototype; +u.mount = function(a) { + let b = this.field; + if (this.tag) { + for (let e = 0, f; e < this.N.length; e++) { + f = this.N[e]; + var c = void 0; + this.index.set(f, c = new L({}, this.reg)); + b === this.field && (b = b.slice(0)); + b.push(f); + c.tag = this.tag.get(f); + } + } + c = []; + const d = {db:a.db, type:a.type, fastupdate:a.fastupdate}; + for (let e = 0, f, g; e < b.length; e++) { + d.field = g = b[e]; + f = this.index.get(g); + const h = new a.constructor(a.id, d); + h.id = a.id; + c[e] = h.mount(f); + f.document = !0; + e ? f.bypass = !0 : f.store = this.store; + } + this.db = !0; + return Promise.all(c); +}; +u.commit = async function(a, b) { + const c = []; + for (const d of this.index.values()) { + c.push(d.db.commit(d, a, b)); + } + await Promise.all(c); + this.reg.clear(); +}; +u.destroy = function() { + const a = []; + for (const b of this.index.values()) { + a.push(b.destroy()); + } + return Promise.all(a); +}; +function Ca(a, b) { + const c = new Map(); + let d = b.index || b.field || b; + B(d) && (d = [d]); + for (let e = 0, f, g; e < d.length; e++) { + f = d[e]; + B(f) || (g = f, f = f.field); + g = D(g) ? Object.assign({}, a, g) : a; + if (this.worker) { + const h = new N(g); + c.set(f, h); + } + this.worker || c.set(f, new L(g, this.reg)); + g.custom ? this.D[e] = g.custom : (this.D[e] = Ba(f, this.K), g.filter && ("string" === typeof this.D[e] && (this.D[e] = new String(this.D[e])), this.D[e].I = g.filter)); + this.field[e] = f; + } + if (this.C) { + a = b.store; + B(a) && (a = [a]); + for (let e = 0, f, g; e < a.length; e++) { + f = a[e], g = f.field || f, f.custom ? (this.C[e] = f.custom, f.custom.U = g) : (this.C[e] = Ba(g, this.K), f.filter && ("string" === typeof this.C[e] && (this.C[e] = new String(this.C[e])), this.C[e].I = f.filter)); + } + } + return c; +} +function Ba(a, b) { + const c = a.split(":"); + let d = 0; + for (let e = 0; e < c.length; e++) { + a = c[e], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (b[d] = !0), a && (c[d++] = a); + } + d < c.length && (c.length = d); + return 1 < d ? c : c[0]; +} +u.append = function(a, b) { + return this.add(a, b, !0); +}; +u.update = function(a, b) { + return this.remove(a).add(a, b); +}; +u.remove = function(a) { + D(a) && (a = I(a, this.key)); + for (var b of this.index.values()) { + b.remove(a, !0); + } + if (this.reg.has(a)) { + if (this.tag && !this.fastupdate) { + for (let c of this.tag.values()) { + for (let d of c) { + b = d[0]; + const e = d[1], f = e.indexOf(a); + -1 < f && (1 < e.length ? e.splice(f, 1) : c.delete(b)); + } + } + } + this.store && this.store.delete(a); + this.reg.delete(a); + } + this.cache && this.cache.remove(a); + return this; +}; +u.clear = function() { + for (const a of this.index.values()) { + a.clear(); + } + if (this.tag) { + for (const a of this.tag.values()) { + a.clear(); + } + } + this.store && this.store.clear(); + return this; +}; +u.contain = function(a) { + return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a); +}; +u.cleanup = function() { + for (const a of this.index.values()) { + a.cleanup(); + } + return this; +}; +u.get = function(a) { + return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(b) { + return b[0] && b[0].doc; + }) : this.store.get(a); +}; +u.set = function(a, b) { + this.store.set(a, b); + return this; +}; +u.searchCache = Da; +u.export = function(a, b, c, d, e, f) { + let g; + "undefined" === typeof f && (g = new Promise(k => { + f = k; + })); + e || (e = 0); + d || (d = 0); + if (d < this.field.length) { + c = this.field[d]; + var h = this.index[c]; + b = this; + h.export(a, b, e ? c : "", d, e++, f) || (d++, b.export(a, b, c, d, 1, f)); + } else { + switch(e) { + case 1: + b = "tag"; + h = this.A; + c = null; + break; + case 2: + b = "store"; + h = this.store; + c = null; + break; + default: + f(); + return; + } + oa(a, this, c, b, d, e, h, f); + } + return g; +}; +u.import = function(a, b) { + if (b) { + switch(B(b) && (b = JSON.parse(b)), a) { + case "tag": + this.A = b; + break; + case "reg": + this.fastupdate = !1; + this.reg = b; + for (let d = 0, e; d < this.field.length; d++) { + e = this.index[this.field[d]], e.reg = b, e.fastupdate = !1; + } + break; + case "store": + this.store = b; + break; + default: + a = a.split("."); + const c = a[0]; + a = a[1]; + c && a && this.index[c].import(a, b); + } + } +}; +na(T.prototype); +function Da(a, b, c) { + a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); + let d = this.cache.get(a); + if (!d) { + d = this.search(a, b, c); + if (d.then) { + const e = this; + d.then(function(f) { + e.cache.set(a, f); + return f; + }); + } + this.cache.set(a, d); + } + return d; +} +function U(a) { + this.limit = a && !0 !== a ? a : 1000; + this.cache = new Map(); + this.h = ""; +} +U.prototype.set = function(a, b) { + this.cache.set(this.h = a, b); + this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); +}; +U.prototype.get = function(a) { + const b = this.cache.get(a); + b && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, b)); + return b; +}; +U.prototype.remove = function(a) { + for (const b of this.cache) { + const c = b[0]; + b[1].includes(a) && this.cache.delete(c); + } +}; +U.prototype.clear = function() { + this.cache.clear(); + this.h = ""; +}; +const Ea = {normalize:function(a) { + return a.toLowerCase(); +}, dedupe:!1}; +const Fa = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); +const Ga = new Map([["ai", "ei"], ["ae", "a"], ["oe", "o"], ["ue", "u"], ["sh", "s"], ["ch", "c"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), Ha = [/([^aeo])h([aeo$])/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2"]; +const Ia = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; +const Ja = /[\x00-\x7F]+/g; +const Ka = /[\x00-\x7F]+/g; +const La = /[\x00-\x7F]+/g; +var Ma = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Ea, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Fa}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Fa, replacer:Ha, matcher:Ga}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Fa, replacer:Ha.concat([/(?!^)[aeoy]/g, ""]), matcher:Ga}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { + for (let c = 0; c < a.length; c++) { + var b = a[c]; + let d = b.charAt(0), e = Ia[d]; + for (let f = 1, g; f < b.length && (g = b.charAt(f), "h" === g || "w" === g || !(g = Ia[g]) || g === e || (d += g, e = g, 4 !== d.length)); f++) { + } + a[c] = d; + } +}}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { + return ("" + a).replace(Ja, " "); +}}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { + return ("" + a).replace(Ka, ""); +}}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { + return ("" + a).replace(La, " "); +}}}; +const Na = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +A(); +L.prototype.add = function(a, b, c, d) { + if (b && (a || 0 === a)) { + if (!d && !c && this.reg.has(a)) { + return this.update(a, b); + } + b = this.encoder.encode(b); + if (d = b.length) { + const l = A(), m = A(), p = this.depth, n = this.resolution; + for (let q = 0; q < d; q++) { + let t = b[this.rtl ? d - 1 - q : q]; + var e = t.length; + if (e && (p || !m[t])) { + var f = this.score ? this.score(b, t, q, null, 0) : Oa(n, d, q), g = ""; + switch(this.tokenize) { + case "full": + if (2 < e) { + for (f = 0; f < e; f++) { + for (var h = e; h > f; h--) { + g = t.substring(f, h); + var k = this.score ? this.score(b, t, q, g, f) : Oa(n, d, q, e, f); + V(this, m, g, k, a, c); + } + } + break; + } + case "reverse": + if (1 < e) { + for (h = e - 1; 0 < h; h--) { + g = t[h] + g, k = this.score ? this.score(b, t, q, g, h) : Oa(n, d, q, e, h), V(this, m, g, k, a, c); + } + g = ""; + } + case "forward": + if (1 < e) { + for (h = 0; h < e; h++) { + g += t[h], V(this, m, g, f, a, c); + } + break; + } + default: + if (V(this, m, t, f, a, c), p && 1 < d && q < d - 1) { + for (e = A(), g = this.R, f = t, h = Math.min(p + 1, d - q), e[f] = 1, k = 1; k < h; k++) { + if ((t = b[this.rtl ? d - 1 - q - k : q + k]) && !e[t]) { + e[t] = 1; + const r = this.score ? this.score(b, f, q, t, k) : Oa(g + (d / 2 > g ? 0 : 1), d, q, h - 1, k - 1), v = this.bidirectional && t > f; + V(this, l, v ? f : t, r, a, c, v ? t : f); + } + } + } + } + } + } + this.fastupdate || this.reg.add(a); + } else { + b = ""; + } + } + this.db && (b || this.commit_task.push({del:a}), this.T && Pa(this)); + return this; +}; +function V(a, b, c, d, e, f, g) { + let h = g ? a.ctx : a.map, k; + if (!b[c] || g && !(k = b[c])[g]) { + if (g ? (b = k || (b[c] = A()), b[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !f || !h.includes(e)) { + if (h.length === 2 ** 31 - 1) { + b = new Q(h); + if (a.fastupdate) { + for (let l of a.reg.values()) { + l.includes(h) && (l[l.indexOf(h)] = b); + } + } + k[d] = h = b; + } + h.push(e); + a.fastupdate && ((d = a.reg.get(e)) ? d.push(h) : a.reg.set(e, [h])); + } + } +} +function Oa(a, b, c, d, e) { + return c && 1 < a ? b + (d || 0) <= a ? c + (e || 0) : (a - 1) / (b + (d || 0)) * (c + (e || 0)) + 1 | 0 : 0; +} +;function W(a, b, c, d) { + if (1 === a.length) { + return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, d ? Qa(a) : a; + } + let e = []; + for (let f = 0, g, h; f < a.length; f++) { + if ((g = a[f]) && (h = g.length)) { + if (c) { + if (c >= h) { + c -= h; + continue; + } + c < h && (g = b ? g.slice(c, c + b) : g.slice(c), h = g.length, c = 0); + } + if (e.length) { + h > b && (g = g.slice(0, b), h = g.length), e.push(g); + } else { + if (h >= b) { + return h > b && (g = g.slice(0, b)), d ? Qa(g) : g; + } + e = [g]; + } + b -= h; + if (!b) { + break; + } + } + } + if (!e.length) { + return e; + } + e = 1 < e.length ? [].concat.apply([], e) : e[0]; + return d ? Qa(e) : e; +} +function Qa(a) { + for (let b = 0; b < a.length; b++) { + a[b] = {score:b, id:a[b]}; + } + return a; +} +;X.prototype.or = function() { const a = this; let b = arguments; var c = b[0]; @@ -748,7 +1443,7 @@ function Fa(a, b) { g = l.enrich; h = l.resolve; let m; - if (l.constructor === U) { + if (l.constructor === X) { m = l.result; } else if (l.constructor === Array) { m = l; @@ -770,21 +1465,21 @@ function Fa(a, b) { if (c.length) { return Promise.all(c).then(function() { a.result.length && (d = d.concat([a.result])); - a.result = Ga(d, e, f, g, h, a.F); + a.result = Ra(d, e, f, g, h, a.F); return h ? a.result : a; }); } - d.length && (this.result.length && (d = d.concat([this.result])), this.result = Ga(d, e, f, g, h, this.F)); + d.length && (this.result.length && (d = d.concat([this.result])), this.result = Ra(d, e, f, g, h, this.F)); return h ? this.result : this; }; -function Ga(a, b, c, d, e, f) { +function Ra(a, b, c, d, e, f) { if (!a.length) { return a; } "object" === typeof b && (c = b.offset || 0, d = b.enrich || !1, b = b.limit || 0); - return 2 > a.length ? e ? T(a[0], b, c, d) : a[0] : Ea(a, c, b, e, f); + return 2 > a.length ? e ? W(a[0], b, c, d) : a[0] : va(a, c, b, e, f); } -;U.prototype.and = function() { +;X.prototype.and = function() { if (this.result.length) { const b = this; let c = arguments; @@ -807,7 +1502,7 @@ function Ga(a, b, c, d, e, f) { g = l.resolve; h = l.suggest; let m; - if (l.constructor === U) { + if (l.constructor === X) { m = l.result; } else if (l.constructor === Array) { m = l; @@ -832,26 +1527,26 @@ function Ga(a, b, c, d, e, f) { if (a.length) { return Promise.all(a).then(function() { d = [b.result].concat(d); - b.result = Ha(d, e, f, g, b.F, h); + b.result = Sa(d, e, f, g, b.F, h); return g ? b.result : b; }); } d = [this.result].concat(d); - this.result = Ha(d, e, f, g, this.F, h); + this.result = Sa(d, e, f, g, this.F, h); return g ? this.result : this; } return this; }; -function Ha(a, b, c, d, e, f) { +function Sa(a, b, c, d, e, f) { if (2 > a.length) { return []; } let g = []; A(); let h = ca(a); - return h ? Da(a, h, b, c, f, e, d) : g; + return h ? ua(a, h, b, c, f, e, d) : g; } -;U.prototype.xor = function() { +;X.prototype.xor = function() { const a = this; let b = arguments; var c = b[0]; @@ -873,7 +1568,7 @@ function Ha(a, b, c, d, e, f) { g = l.enrich; h = l.resolve; let m; - if (l.constructor === U) { + if (l.constructor === X) { m = l.result; } else if (l.constructor === Array) { m = l; @@ -895,19 +1590,19 @@ function Ha(a, b, c, d, e, f) { if (c.length) { return Promise.all(c).then(function() { a.result.length && (d = [a.result].concat(d)); - a.result = Ia(d, e, f, g, !h, a.F); + a.result = Ta(d, e, f, g, !h, a.F); return h ? a.result : a; }); } - d.length && (this.result.length && (d = [this.result].concat(d)), this.result = Ia(d, e, f, g, !h, a.F)); + d.length && (this.result.length && (d = [this.result].concat(d)), this.result = Ta(d, e, f, g, !h, a.F)); return h ? this.result : this; }; -function Ia(a, b, c, d, e, f) { +function Ta(a, b, c, d, e, f) { if (!a.length) { return a; } if (2 > a.length) { - return e ? T(a[0], b, c, d) : a[0]; + return e ? W(a[0], b, c, d) : a[0]; } d = []; const g = A(); @@ -954,7 +1649,7 @@ function Ia(a, b, c, d, e, f) { } return d; } -;U.prototype.not = function() { +;X.prototype.not = function() { const a = this; let b = arguments; var c = b[0]; @@ -975,7 +1670,7 @@ function Ia(a, b, c, d, e, f) { f = k.offset || 0; g = k.resolve; let l; - if (k.constructor === U) { + if (k.constructor === X) { l = k.result; } else if (k.constructor === Array) { l = k; @@ -996,14 +1691,14 @@ function Ia(a, b, c, d, e, f) { } if (c.length) { return Promise.all(c).then(function() { - a.result = Ja.call(a, d, e, f, g); + a.result = Ua.call(a, d, e, f, g); return g ? a.result : a; }); } - d.length && (this.result = Ja.call(this, d, e, f, g)); + d.length && (this.result = Ua.call(this, d, e, f, g)); return g ? this.result : this; }; -function Ja(a, b, c, d) { +function Ua(a, b, c, d) { if (!a.length) { return this.result; } @@ -1032,21 +1727,21 @@ function Ja(a, b, c, d) { } return e; } -;function U(a) { +;function X(a) { if (!this) { - return new U(a); + return new X(a); } if (a && a.index) { return a.resolve = !1, this.index = a.index, this.F = a.boost || 0, this.result = a.index.search(a).result, this; } - if (a.constructor === U) { + if (a.constructor === X) { return a; } this.index = null; this.result = a || []; this.F = 0; } -U.prototype.limit = function(a) { +X.prototype.limit = function(a) { if (this.result.length) { const b = []; let c = 0; @@ -1062,7 +1757,7 @@ U.prototype.limit = function(a) { } return this; }; -U.prototype.offset = function(a) { +X.prototype.offset = function(a) { if (this.result.length) { const b = []; let c = 0; @@ -1073,18 +1768,18 @@ U.prototype.offset = function(a) { } return this; }; -U.prototype.boost = function(a) { +X.prototype.boost = function(a) { this.F += a; return this; }; -U.prototype.resolve = function(a, b, c) { - Ka = 1; +X.prototype.resolve = function(a, b, c) { + Va = 1; const d = this.result; this.result = this.index = null; - return d.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), T(d, a || 100, b, c)) : d; + return d.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), W(d, a || 100, b, c)) : d; }; -let Ka = 1; -Q.prototype.search = function(a, b, c) { +let Va = 1; +L.prototype.search = function(a, b, c) { c || (!b && D(a) ? (c = a, a = "") : D(b) && (c = b, b = 0)); let d = [], e; let f, g = 0, h, k, l, m; @@ -1094,34 +1789,34 @@ Q.prototype.search = function(a, b, c) { g = c.offset || 0; var p = c.context; f = c.suggest; - (h = Ka && !1 !== c.resolve) || (Ka = 0); + (h = Va && !1 !== c.resolve) || (Va = 0); k = h && c.enrich; m = c.boost; l = this.db && c.tag; } else { - h = this.resolve || Ka; + h = this.resolve || Va; } a = this.encoder.encode(a); e = a.length; b || !h || (b = 100); if (1 === e) { - return La.call(this, a[0], "", b, g, h, k, l); + return Wa.call(this, a[0], "", b, g, h, k, l); } p = this.depth && !1 !== p; if (2 === e && p && !f) { - return La.call(this, a[0], a[1], b, g, h, k, l); + return Wa.call(this, a[0], a[1], b, g, h, k, l); } let n = c = 0; if (1 < e) { const r = A(), v = []; - for (let x = 0, E; x < e; x++) { - if ((E = a[x]) && !r[E]) { - if (f || this.db || V(this, E)) { - v.push(E), r[E] = 1; + for (let x = 0, F; x < e; x++) { + if ((F = a[x]) && !r[F]) { + if (f || this.db || Y(this, F)) { + v.push(F), r[F] = 1; } else { - return h ? d : new U(d); + return h ? d : new X(d); } - const y = E.length; + const y = F.length; c = Math.max(c, y); n = n ? Math.min(n, y) : y; } @@ -1130,14 +1825,14 @@ Q.prototype.search = function(a, b, c) { e = a.length; } if (!e) { - return h ? d : new U(d); + return h ? d : new X(d); } let q = 0, t; if (1 === e) { - return La.call(this, a[0], "", b, g, h, k, l); + return Wa.call(this, a[0], "", b, g, h, k, l); } if (2 === e && p && !f) { - return La.call(this, a[0], a[1], b, g, h, k, l); + return Wa.call(this, a[0], a[1], b, g, h, k, l); } 1 < e && (p ? (t = a[0], q = 1) : 9 < c && 3 < c / n && a.sort(aa)); if (this.db) { @@ -1148,13 +1843,13 @@ Q.prototype.search = function(a, b, c) { return async function() { for (let v, x; q < e; q++) { x = a[q]; - t ? (v = await V(r, x, t, 0, 0, !1, !1), v = Ma(v, d, f, r.R), f && !1 === v && d.length || (t = x)) : (v = await V(r, x, "", 0, 0, !1, !1), v = Ma(v, d, f, r.resolution)); + t ? (v = await Y(r, x, t, 0, 0, !1, !1), v = Xa(v, d, f, r.R), f && !1 === v && d.length || (t = x)) : (v = await Y(r, x, "", 0, 0, !1, !1), v = Xa(v, d, f, r.resolution)); if (v) { return v; } if (f && q === e - 1) { - let E = d.length; - if (!E) { + let F = d.length; + if (!F) { if (t) { t = ""; q = -1; @@ -1162,17 +1857,17 @@ Q.prototype.search = function(a, b, c) { } return d; } - if (1 === E) { - return h ? T(d[0], b, g) : new U(d[0]); + if (1 === F) { + return h ? W(d[0], b, g) : new X(d[0]); } } } - return h ? Da(d, r.resolution, b, g, f, m, h) : new U(d[0]); + return h ? ua(d, r.resolution, b, g, f, m, h) : new X(d[0]); }(); } for (let r, v; q < e; q++) { v = a[q]; - t ? (r = V(this, v, t, 0, 0, !1, !1), r = Ma(r, d, f, this.R), f && !1 === r && d.length || (t = v)) : (r = V(this, v, "", 0, 0, !1, !1), r = Ma(r, d, f, this.resolution)); + t ? (r = Y(this, v, t, 0, 0, !1, !1), r = Xa(r, d, f, this.R), f && !1 === r && d.length || (t = v)) : (r = Y(this, v, "", 0, 0, !1, !1), r = Xa(r, d, f, this.resolution)); if (r) { return r; } @@ -1187,20 +1882,20 @@ Q.prototype.search = function(a, b, c) { return d; } if (1 === p) { - return h ? T(d[0], b, g) : new U(d[0]); + return h ? W(d[0], b, g) : new X(d[0]); } } } - d = Da(d, this.resolution, b, g, f, m, h); - return h ? d : new U(d); + d = ua(d, this.resolution, b, g, f, m, h); + return h ? d : new X(d); }; -function La(a, b, c, d, e, f, g) { - a = V(this, a, b, c, d, e, f, g); +function Wa(a, b, c, d, e, f, g) { + a = Y(this, a, b, c, d, e, f, g); return this.db ? a.then(function(h) { - return e ? h : h && h.length ? e ? T(h, c, d) : new U(h) : e ? [] : new U([]); - }) : a && a.length ? e ? T(a, c, d) : new U(a) : e ? [] : new U([]); + return e ? h : h && h.length ? e ? W(h, c, d) : new X(h) : e ? [] : new X([]); + }) : a && a.length ? e ? W(a, c, d) : new X(a) : e ? [] : new X([]); } -function Ma(a, b, c, d) { +function Xa(a, b, c, d) { let e = []; if (a) { d = Math.min(a.length, d); @@ -1214,7 +1909,7 @@ function Ma(a, b, c, d) { } return !c && e; } -function V(a, b, c, d, e, f, g, h) { +function Y(a, b, c, d, e, f, g, h) { let k; c && (k = a.bidirectional && b > c); if (a.db) { @@ -1223,7 +1918,7 @@ function V(a, b, c, d, e, f, g, h) { a = c ? (a = a.ctx.get(k ? b : c)) && a.get(k ? c : b) : a.map.get(b); return a; } -;Q.prototype.remove = function(a, b) { +;L.prototype.remove = function(a, b) { const c = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (c) { if (this.fastupdate) { @@ -1238,15 +1933,15 @@ function V(a, b, c, d, e, f, g, h) { } } } else { - Na(this.map, a), this.depth && Na(this.ctx, a); + Ya(this.map, a), this.depth && Ya(this.ctx, a); } b || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.T && Ba(this)); + this.db && (this.commit_task.push({del:a}), this.T && Pa(this)); this.cache && this.cache.remove(a); return this; }; -function Na(a, b) { +function Ya(a, b) { let c = 0; if (a.constructor === Array) { for (let d = 0, e, f; d < a.length; d++) { @@ -1261,24 +1956,24 @@ function Na(a, b) { } } else { for (let d of a) { - const e = d[0], f = Na(d[1], b); + const e = d[0], f = Ya(d[1], b); f ? c += f : a.delete(e); } } return c; } -;function Q(a, b) { +;function L(a, b) { if (!this) { - return new Q(a); + return new L(a); } if (a) { var c = B(a) ? a : a.preset; - c && (za[c] || console.warn("Preset not found: " + c), a = Object.assign({}, za[c], a)); + c && (Na[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Na[c], a)); } else { a = {}; } c = a.context || {}; - const d = B(a.encoder) ? ua[a.encoder] : a.encode || a.encoder || ma; + const d = B(a.encoder) ? Ma[a.encoder] : a.encode || a.encoder || Ea; this.encoder = d.encode ? d : "object" === typeof d ? new J(d) : {encode:d}; let e; this.resolution = a.resolution || 9; @@ -1288,12 +1983,12 @@ function Na(a, b) { this.fastupdate = !!a.fastupdate; this.score = a.score || null; (e = a.keystore || 0) && (this.keystore = e); - this.map = e ? new N(e) : new Map(); - this.ctx = e ? new N(e) : new Map(); - this.reg = b || (this.fastupdate ? e ? new N(e) : new Map() : e ? new O(e) : new Set()); + this.map = e ? new R(e) : new Map(); + this.ctx = e ? new R(e) : new Map(); + this.reg = b || (this.fastupdate ? e ? new R(e) : new Map() : e ? new S(e) : new Set()); this.R = c.resolution || 1; this.rtl = d.rtl || a.rtl || !1; - this.cache = (e = a.cache || null) && new L(e); + this.cache = (e = a.cache || null) && new U(e); this.resolve = !1 !== a.resolve; if (e = a.db) { this.db = this.mount(e); @@ -1302,7 +1997,7 @@ function Na(a, b) { this.commit_task = []; this.commit_timer = null; } -u = Q.prototype; +u = L.prototype; u.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); @@ -1315,7 +2010,7 @@ u.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function Ba(a) { +function Pa(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); @@ -1339,7 +2034,7 @@ u.update = function(a, b) { const c = this, d = this.remove(a); return d && d.then ? d.then(() => c.add(a, b)) : this.add(a, b); }; -function Oa(a) { +function Za(a) { let b = 0; if (a.constructor === Array) { for (let c = 0, d; c < a.length; c++) { @@ -1347,7 +2042,7 @@ function Oa(a) { } } else { for (const c of a) { - const d = c[0], e = Oa(c[1]); + const d = c[0], e = Za(c[1]); e ? b += e : a.delete(d); } } @@ -1357,11 +2052,11 @@ u.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - Oa(this.map); - this.depth && Oa(this.ctx); + Za(this.map); + this.depth && Za(this.ctx); return this; }; -u.searchCache = la; +u.searchCache = Da; u.export = function(a, b, c, d, e, f) { let g = !0; "undefined" === typeof f && (g = new Promise(l => { @@ -1396,7 +2091,7 @@ u.export = function(a, b, c, d, e, f) { "undefined" === typeof c && f && f(); return; } - ya(a, b || this, c, h, d, e, k, f); + oa(a, b || this, c, h, d, e, k, f); return g; }; u.import = function(a, b) { @@ -1467,706 +2162,11 @@ u.serialize = function(a = !0) { e = "index.ctx=new Map([" + e + "]);"; return a ? "function inject(index){" + b + d + e + "}" : b + d + e; }; -Aa(Q.prototype); -async function Pa(a) { - a = a.data; - var b = self._index; - const c = a.args; - var d = a.task; - switch(d) { - case "init": - d = a.options || {}; - (b = d.config) && (d = b); - (b = a.factory) ? (Function("return " + b)()(self), self._index = new self.FlexSearch.Index(d), delete self.FlexSearch) : self._index = new Q(d); - postMessage({id:a.id}); - break; - default: - a = a.id, b = b[d].apply(b, c), postMessage("search" === d ? {id:a, msg:b} : {id:a}); - } -} -;let Qa = 0; -function W(a = {}) { - function b(g) { - function h(k) { - k = k.data || k; - const l = k.id, m = l && e.h[l]; - m && (m(k.msg), delete e.h[l]); - } - this.worker = g; - this.h = A(); - if (this.worker) { - d ? this.worker.on("message", h) : this.worker.onmessage = h; - if (a.config) { - return new Promise(function(k) { - e.h[++Qa] = function() { - k(e); - }; - e.worker.postMessage({id:Qa, task:"init", factory:c, options:a}); - }); - } - this.worker.postMessage({task:"init", factory:c, options:a}); - return this; - } - } +na(L.prototype); +const ab = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), bb = ["map", "ctx", "tag", "reg", "cfg"]; +function cb(a, b = {}) { if (!this) { - return new W(a); - } - let c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; - c && (c = c.toString()); - const d = "undefined" === typeof window, e = this, f = Ra(c, d, a.worker); - return f.then ? f.then(function(g) { - return b.call(e, g); - }) : b.call(this, f); -} -X("add"); -X("append"); -X("search"); -X("update"); -X("remove"); -function X(a) { - W.prototype[a] = W.prototype[a + "Async"] = async function() { - const b = this, c = [].slice.call(arguments); - var d = c[c.length - 1]; - let e; - "function" === typeof d && (e = d, c.splice(c.length - 1, 1)); - d = new Promise(function(f) { - b.h[++Qa] = f; - b.worker.postMessage({task:a, id:Qa, args:c}); - }); - return e ? (d.then(e), this) : d; - }; -} -function Ra(a, b, c) { - return b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"](import.meta.dirname + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + Pa.toString()], {type:"text/javascript"}))) : new window.Worker(B(c) ? c : import.meta.url.replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", - "module/worker/worker.js"), {type:"module"}); -} -;Y.prototype.add = function(a, b, c) { - D(a) && (b = a, a = I(b, this.key)); - if (b && (a || 0 === a)) { - if (!c && this.reg.has(a)) { - return this.update(a, b); - } - for (let h = 0, k; h < this.field.length; h++) { - k = this.D[h]; - var d = this.index.get(this.field[h]); - if ("function" === typeof k) { - var e = k(b); - e && d.add(a, e, !1, !0); - } else { - if (e = k.I, !e || e(b)) { - k.constructor === String ? k = ["" + k] : B(k) && (k = [k]), Sa(b, k, this.K, 0, d, a, k[0], c); - } - } - } - if (this.tag) { - for (d = 0; d < this.G.length; d++) { - var f = this.G[d], g = this.N[d]; - e = this.tag.get(g); - let h = A(); - if ("function" === typeof f) { - if (f = f(b), !f) { - continue; - } - } else { - const k = f.I; - if (k && !k(b)) { - continue; - } - f.constructor === String && (f = "" + f); - f = I(b, f); - } - if (e && f) { - B(f) && (f = [f]); - for (let k = 0, l, m; k < f.length; k++) { - if (l = f[k], !h[l] && (h[l] = 1, (g = e.get(l)) ? m = g : e.set(l, m = []), !c || !m.includes(a))) { - if (m.length === 2 ** 31 - 1) { - g = new M(m); - if (this.fastupdate) { - for (let p of this.reg.values()) { - p.includes(m) && (p[p.indexOf(m)] = g); - } - } - e.set(l, m = g); - } - m.push(a); - this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])); - } - } - } else { - e || console.warn("Tag '" + g + "' was not found"); - } - } - } - if (this.store && (!c || !this.store.has(a))) { - let h; - if (this.C) { - h = A(); - for (let k = 0, l; k < this.C.length; k++) { - l = this.C[k]; - if ((c = l.I) && !c(b)) { - continue; - } - let m; - if ("function" === typeof l) { - m = l(b); - if (!m) { - continue; - } - l = [l.U]; - } else if (B(l) || l.constructor === String) { - h[l] = b[l]; - continue; - } - Ta(b, h, l, 0, l[0], m); - } - } - this.store.set(a, h || b); - } - } - return this; -}; -function Ta(a, b, c, d, e, f) { - a = a[e]; - if (d === c.length - 1) { - b[e] = f || a; - } else if (a) { - if (a.constructor === Array) { - for (b = b[e] = Array(a.length), e = 0; e < a.length; e++) { - Ta(a, b, c, d, e); - } - } else { - b = b[e] || (b[e] = A()), e = c[++d], Ta(a, b, c, d, e); - } - } -} -function Sa(a, b, c, d, e, f, g, h) { - if (a = a[g]) { - if (d === b.length - 1) { - if (a.constructor === Array) { - if (c[d]) { - for (b = 0; b < a.length; b++) { - e.add(f, a[b], !0, !0); - } - return; - } - a = a.join(" "); - } - e.add(f, a, h, !0); - } else { - if (a.constructor === Array) { - for (g = 0; g < a.length; g++) { - Sa(a, b, c, d, e, f, g, h); - } - } else { - g = b[++d], Sa(a, b, c, d, e, f, g, h); - } - } - } else { - e.db && e.remove(f); - } -} -;Y.prototype.search = function(a, b, c, d) { - c || (!b && D(a) ? (c = a, a = "") : D(b) && (c = b, b = 0)); - let e = [], f = [], g; - let h; - let k; - let l, m = 0, p; - if (c) { - c.constructor === Array && (c = {index:c}); - a = c.query || a; - g = c.pluck; - h = c.merge; - k = g || c.field || c.index; - var n = this.tag && c.tag; - var q = this.store && c.enrich; - var t = c.suggest; - p = c.V; - b = c.limit || b; - l = c.offset || 0; - b || (b = 100); - if (n && (!this.db || !d)) { - n.constructor !== Array && (n = [n]); - var r = []; - for (let y = 0, w; y < n.length; y++) { - w = n[y]; - if (B(w)) { - throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); - } - if (w.field && w.tag) { - var v = w.tag; - if (v.constructor === Array) { - for (var x = 0; x < v.length; x++) { - r.push(w.field, v[x]); - } - } else { - r.push(w.field, v); - } - } else { - v = Object.keys(w); - for (let C = 0, K, F; C < v.length; C++) { - if (K = v[C], F = w[K], F.constructor === Array) { - for (x = 0; x < F.length; x++) { - r.push(K, F[x]); - } - } else { - r.push(K, F); - } - } - } - } - if (!r.length) { - throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); - } - n = r; - if (!a) { - t = []; - if (r.length) { - for (n = 0; n < r.length; n += 2) { - if (this.db) { - d = this.index.get(r[n]); - if (!d) { - console.warn("Tag '" + r[n] + ":" + r[n + 1] + "' will be skipped because there is no field '" + r[n] + "'."); - continue; - } - t.push(d = d.db.tag(r[n + 1], b, l, q)); - } else { - d = Ua.call(this, r[n], r[n + 1], b, l, q); - } - e.push({field:r[n], tag:r[n + 1], result:d}); - } - } - return t.length ? Promise.all(t).then(function(y) { - for (let w = 0; w < y.length; w++) { - e[w].result = y[w]; - } - return e; - }) : e; - } - } - B(k) && (k = [k]); - } - k || (k = this.field); - r = !d && (this.worker || this.db) && []; - let E; - for (let y = 0, w, C, K; y < k.length; y++) { - C = k[y]; - if (this.db && this.tag && !this.D[y]) { - continue; - } - let F; - B(C) || (F = C, C = F.field, a = F.query || a, b = F.limit || b, l = F.offset || l, t = F.suggest || t, q = this.store && (F.enrich || q)); - if (d) { - w = d[y]; - } else { - if (v = F || c, x = this.index.get(C), n && (this.db && (v.tag = n, E = x.db.support_tag_search, v.field = k), E || (v.enrich = !1)), r) { - r[y] = x.search(a, b, v); - v && q && (v.enrich = q); - continue; - } else { - w = x.search(a, b, v), v && q && (v.enrich = q); - } - } - K = w && w.length; - if (n && K) { - v = []; - x = 0; - if (this.db && d) { - if (!E) { - for (let G = k.length; G < d.length; G++) { - let H = d[G]; - if (H && H.length) { - x++, v.push(H); - } else if (!t) { - return e; - } - } - } - } else { - for (let G = 0, H, cb; G < n.length; G += 2) { - H = this.tag.get(n[G]); - if (!H) { - if (console.warn("Tag '" + n[G] + ":" + n[G + 1] + "' will be skipped because there is no field '" + n[G] + "'."), t) { - continue; - } else { - return e; - } - } - if (cb = (H = H && H.get(n[G + 1])) && H.length) { - x++, v.push(H); - } else if (!t) { - return e; - } - } - } - if (x) { - w = Fa(w, v); - K = w.length; - if (!K && !t) { - return e; - } - x--; - } - } - if (K) { - f[m] = C, e.push(w), m++; - } else if (1 === k.length) { - return e; - } - } - if (r) { - if (this.db && n && n.length && !E) { - for (q = 0; q < n.length; q += 2) { - d = this.index.get(n[q]); - if (!d) { - if (console.warn("Tag '" + n[q] + ":" + n[q + 1] + "' was not found because there is no field '" + n[q] + "'."), t) { - continue; - } else { - return e; - } - } - r.push(d.db.tag(n[q + 1], b, l, !1)); - } - } - const y = this; - return Promise.all(r).then(function(w) { - return w.length ? y.search(a, b, c, w) : w; - }); - } - if (!m) { - return e; - } - if (g && (!q || !this.store)) { - return e[0]; - } - r = []; - for (let y = 0, w; y < f.length; y++) { - w = e[y]; - q && w.length && !w[0].doc && (this.db ? r.push(w = this.index.get(this.field[0]).db.enrich(w)) : w.length && (w = Va.call(this, w))); - if (g) { - return w; - } - e[y] = {field:f[y], result:w}; - } - if (q && this.db && r.length) { - const y = this; - return Promise.all(r).then(function(w) { - for (let C = 0; C < w.length; C++) { - e[C].result = w[C]; - } - return h ? Wa(e, b) : p ? Xa(e, a, y.index, y.D, p) : e; - }); - } - return h ? Wa(e, b) : p ? Xa(e, a, this.index, this.D, p) : e; -}; -function Xa(a, b, c, d, e) { - let f; - for (let g = 0, h, k, l, m; g < a.length; g++) { - h = a[g].result; - k = a[g].field; - l = c.get(k).encoder; - m = d[k.indexOf(k)]; - l !== f && (f = l, f.encode(b)); - for (let p = 0; p < h.length; p++) { - let n = "", q = I(h[p].doc, m), t = f.encode(q); - for (let r = 0; r < t.length; r++) { - n += t[r].replace(new RegExp("(" + t[r] + ")", "g"), e.replace("$1", q)); - } - console.log(a, c, e); - h[p].V = n; - } - } - return a; -} -function Wa(a, b) { - const c = [], d = A(); - for (let e = 0, f, g; e < a.length; e++) { - f = a[e]; - g = f.result; - for (let h = 0, k, l, m; h < g.length; h++) { - if (l = g[h], k = l.id, m = d[k]) { - m.push(f.field); - } else { - if (c.length === b) { - return c; - } - l.field = d[k] = [f.field]; - c.push(l); - } - } - } - return c; -} -function Ua(a, b, c, d, e) { - let f = this.tag.get(a); - if (!f) { - return console.warn("Tag '" + a + "' was not found"), []; - } - if ((a = (f = f && f.get(b)) && f.length - d) && 0 < a) { - if (a > c || d) { - f = f.slice(d, d + c); - } - e && (f = Va.call(this, f)); - return f; - } -} -function Va(a) { - const b = Array(a.length); - for (let c = 0, d; c < a.length; c++) { - d = a[c], b[c] = {id:d, doc:this.store.get(d)}; - } - return b; -} -;function Y(a) { - if (!this) { - return new Y(a); - } - const b = a.document || a.doc || a; - let c, d; - this.D = []; - this.field = []; - this.K = []; - this.key = (c = b.key || b.id) && Ya(c, this.K) || "id"; - (d = a.keystore || 0) && (this.keystore = d); - this.reg = (this.fastupdate = !!a.fastupdate) ? d ? new N(d) : new Map() : d ? new O(d) : new Set(); - this.C = (c = b.store || null) && !0 !== c && []; - this.store = c && (d ? new N(d) : new Map()); - this.cache = (c = a.cache || null) && new L(c); - a.cache = !1; - this.worker = a.worker; - this.index = Za.call(this, a, b); - this.tag = null; - if (c = b.tag) { - if ("string" === typeof c && (c = [c]), c.length) { - this.tag = new Map(); - this.G = []; - this.N = []; - for (let e = 0, f, g; e < c.length; e++) { - f = c[e]; - g = f.field || f; - if (!g) { - throw Error("The tag field from the document descriptor is undefined."); - } - f.custom ? this.G[e] = f.custom : (this.G[e] = Ya(g, this.K), f.filter && ("string" === typeof this.G[e] && (this.G[e] = new String(this.G[e])), this.G[e].I = f.filter)); - this.N[e] = g; - this.tag.set(g, new Map()); - } - } - } - if (this.worker) { - a = []; - for (const e of this.index.values()) { - e.then && a.push(e); - } - if (a.length) { - const e = this; - return Promise.all(a).then(function(f) { - let g = 0; - for (const h of e.index.entries()) { - const k = h[0]; - h[1].then && e.index.set(k, f[g++]); - } - return e; - }); - } - } else { - a.db && this.mount(a.db); - } -} -u = Y.prototype; -u.mount = function(a) { - let b = this.field; - if (this.tag) { - for (let e = 0, f; e < this.N.length; e++) { - f = this.N[e]; - var c = void 0; - this.index.set(f, c = new Q({}, this.reg)); - b === this.field && (b = b.slice(0)); - b.push(f); - c.tag = this.tag.get(f); - } - } - c = []; - const d = {db:a.db, type:a.type, fastupdate:a.fastupdate}; - for (let e = 0, f, g; e < b.length; e++) { - d.field = g = b[e]; - f = this.index.get(g); - const h = new a.constructor(a.id, d); - h.id = a.id; - c[e] = h.mount(f); - f.document = !0; - e ? f.bypass = !0 : f.store = this.store; - } - this.db = !0; - return Promise.all(c); -}; -u.commit = async function(a, b) { - const c = []; - for (const d of this.index.values()) { - c.push(d.db.commit(d, a, b)); - } - await Promise.all(c); - this.reg.clear(); -}; -u.destroy = function() { - const a = []; - for (const b of this.index.values()) { - a.push(b.destroy()); - } - return Promise.all(a); -}; -function Za(a, b) { - const c = new Map(); - let d = b.index || b.field || b; - B(d) && (d = [d]); - for (let e = 0, f, g; e < d.length; e++) { - f = d[e]; - B(f) || (g = f, f = f.field); - g = D(g) ? Object.assign({}, a, g) : a; - if (this.worker) { - const h = new W(g); - c.set(f, h); - } - this.worker || c.set(f, new Q(g, this.reg)); - g.custom ? this.D[e] = g.custom : (this.D[e] = Ya(f, this.K), g.filter && ("string" === typeof this.D[e] && (this.D[e] = new String(this.D[e])), this.D[e].I = g.filter)); - this.field[e] = f; - } - if (this.C) { - a = b.store; - B(a) && (a = [a]); - for (let e = 0, f, g; e < a.length; e++) { - f = a[e], g = f.field || f, f.custom ? (this.C[e] = f.custom, f.custom.U = g) : (this.C[e] = Ya(g, this.K), f.filter && ("string" === typeof this.C[e] && (this.C[e] = new String(this.C[e])), this.C[e].I = f.filter)); - } - } - return c; -} -function Ya(a, b) { - const c = a.split(":"); - let d = 0; - for (let e = 0; e < c.length; e++) { - a = c[e], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (b[d] = !0), a && (c[d++] = a); - } - d < c.length && (c.length = d); - return 1 < d ? c : c[0]; -} -u.append = function(a, b) { - return this.add(a, b, !0); -}; -u.update = function(a, b) { - return this.remove(a).add(a, b); -}; -u.remove = function(a) { - D(a) && (a = I(a, this.key)); - for (var b of this.index.values()) { - b.remove(a, !0); - } - if (this.reg.has(a)) { - if (this.tag && !this.fastupdate) { - for (let c of this.tag.values()) { - for (let d of c) { - b = d[0]; - const e = d[1], f = e.indexOf(a); - -1 < f && (1 < e.length ? e.splice(f, 1) : c.delete(b)); - } - } - } - this.store && this.store.delete(a); - this.reg.delete(a); - } - this.cache && this.cache.remove(a); - return this; -}; -u.clear = function() { - for (const a of this.index.values()) { - a.clear(); - } - if (this.tag) { - for (const a of this.tag.values()) { - a.clear(); - } - } - this.store && this.store.clear(); - return this; -}; -u.contain = function(a) { - return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a); -}; -u.cleanup = function() { - for (const a of this.index.values()) { - a.cleanup(); - } - return this; -}; -u.get = function(a) { - return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(b) { - return b[0] && b[0].doc; - }) : this.store.get(a); -}; -u.set = function(a, b) { - this.store.set(a, b); - return this; -}; -u.searchCache = la; -u.export = function(a, b, c, d, e, f) { - let g; - "undefined" === typeof f && (g = new Promise(k => { - f = k; - })); - e || (e = 0); - d || (d = 0); - if (d < this.field.length) { - c = this.field[d]; - var h = this.index[c]; - b = this; - h.export(a, b, e ? c : "", d, e++, f) || (d++, b.export(a, b, c, d, 1, f)); - } else { - switch(e) { - case 1: - b = "tag"; - h = this.A; - c = null; - break; - case 2: - b = "store"; - h = this.store; - c = null; - break; - default: - f(); - return; - } - ya(a, this, c, b, d, e, h, f); - } - return g; -}; -u.import = function(a, b) { - if (b) { - switch(B(b) && (b = JSON.parse(b)), a) { - case "tag": - this.A = b; - break; - case "reg": - this.fastupdate = !1; - this.reg = b; - for (let d = 0, e; d < this.field.length; d++) { - e = this.index[this.field[d]], e.reg = b, e.fastupdate = !1; - } - break; - case "store": - this.store = b; - break; - default: - a = a.split("."); - const c = a[0]; - a = a[1]; - c && a && this.index[c].import(a, b); - } - } -}; -Aa(Y.prototype); -const $a = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), ab = ["map", "ctx", "tag", "reg", "cfg"]; -function bb(a, b = {}) { - if (!this) { - return new bb(a, b); + return new cb(a, b); } "object" === typeof a && (b = a = a.name); a || console.info("Default storage space was used, because a name was not passed."); @@ -2176,7 +2176,7 @@ function bb(a, b = {}) { this.db = null; this.h = {}; } -u = bb.prototype; +u = cb.prototype; u.mount = function(a) { if (!a.encoder) { return a.mount(this); @@ -2188,10 +2188,10 @@ u.open = function() { let a = this; navigator.storage && navigator.storage.persist(); return this.db || new Promise(function(b, c) { - const d = $a.open(a.id + (a.field ? ":" + a.field : ""), 1); + const d = ab.open(a.id + (a.field ? ":" + a.field : ""), 1); d.onupgradeneeded = function() { const e = a.db = this.result; - ab.forEach(f => { + bb.forEach(f => { e.objectStoreNames.contains(f) || e.createObjectStore(f); }); }; @@ -2217,12 +2217,12 @@ u.close = function() { this.db = null; }; u.destroy = function() { - return $a.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); + return ab.deleteDatabase(this.id + (this.field ? ":" + this.field : "")); }; u.clear = function() { - const a = this.db.transaction(ab, "readwrite"); - for (let b = 0; b < ab.length; b++) { - a.objectStore(ab[b]).clear(); + const a = this.db.transaction(bb, "readwrite"); + for (let b = 0; b < bb.length; b++) { + a.objectStore(bb[b]).clear(); } return Z(a); }; @@ -2465,6 +2465,6 @@ function Z(a) { a = null; }); } -;export default {Index:Q, Charset:ua, Encoder:J, Document:Y, Worker:W, Resolver:U, IndexedDB:bb, Language:{}}; +;export default {Index:L, Charset:Ma, Encoder:J, Document:T, Worker:N, Resolver:X, IndexedDB:cb, Language:{}}; -export const Index=Q;export const Charset=ua;export const Encoder=J;export const Document=Y;export const Worker=W;export const Resolver=U;export const IndexedDB=bb;export const Language={}; \ No newline at end of file +export const Index=L;export const Charset=Ma;export const Encoder=J;export const Document=T;export const Worker=N;export const Resolver=X;export const IndexedDB=cb;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.bundle.module.min.js b/dist/flexsearch.bundle.module.min.js index 5c95bcd..7eb3802 100644 --- a/dist/flexsearch.bundle.module.min.js +++ b/dist/flexsearch.bundle.module.min.js @@ -19,72 +19,72 @@ z(a.minlength,1,this.minlength);this.maxlength=z(a.maxlength,0,this.maxlength);i I.prototype.encode=function(a){if(this.cache&&a.length<=this.h)if(this.L){if(this.H.has(a))return this.H.get(a)}else this.L=setTimeout(ka,0,this);this.normalize&&(a="function"===typeof this.normalize?this.normalize(a):ja?a.normalize("NFKD").replace(ja,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(l)),k=1);this.matcher&& 1this.matcher.get(l)),k=1);g&&k&&(g.lengththis.S&&(this.J.clear(),this.A=this.A/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.h&&(this.H.set(a,c),this.H.size>this.S&&(this.H.clear(),this.h=this.h/1.1|0));return c};function ka(a){a.L=null;a.H.clear();a.J.clear()};function la(a,b,c){a=("object"===typeof a?""+a.query:a).toLowerCase();let d=this.cache.get(a);if(!d){d=this.search(a,b,c);if(d.then){const e=this;d.then(function(f){e.cache.set(a,f);return f})}this.cache.set(a,d)}return d}function K(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}K.prototype.set=function(a,b){this.cache.set(this.h=a,b);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)}; -K.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};K.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};K.prototype.clear=function(){this.cache.clear();this.h=""};const ma={normalize:function(a){return a.toLowerCase()},dedupe:!1};const na=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const oa=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),pa=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];const qa={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const ra=/[\x00-\x7F]+/g;const sa=/[\x00-\x7F]+/g;const ta=/[\x00-\x7F]+/g;var ua={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:ma,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:na},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:na,replacer:pa,matcher:oa},LatinExtra:{normalize:!0,dedupe:!0,mapper:na,replacer:pa.concat([/(?!^)[aeoy]/g,""]),matcher:oa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;c=g.length)b-=g.length;else{b=g[d?"splice":"slice"](b,c);const h=b.length;if(h&&(e=e.length?e.concat(b):b,c-=h,d&&(a.length-=h),!c))break;b=0}return e} -function M(a){if(!this)return new M(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){let f=0;for(let g=0,h,k;gf;h--){g=t.substring(f,h);var k=this.score?this.score(b,t,q,g,f):R(p,d,q,e,f);S(this,m,g,k,a,c)}break}case "reverse":if(1< -e){for(h=e-1;0g?0:1),d,q,h-1,k-1),v=this.bidirectional&&t>f;S(this,l,v?f:t,r,a,c,v?t:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& -(b||this.commit_task.push({del:a}),this.T&&Ba(this));return this};function S(a,b,c,d,e,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||!g||!(k=b[c])[g])if(g?(b=k||(b[c]=A()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new M(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}} -function R(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?Ca(a):a;let e=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=g.length),e.push(g);else{if(h>=b)return h>b&&(g=g.slice(0,b)),d?Ca(g):g;e=[g]}b-=h;if(!b)break}if(!e.length)return e;e=1c||d)k=k.slice(d,c+d)}else{e=[];for(let n=0,p;nd)d-=p.length;else{if(p.length>c||d)p=p.slice(d, +this.cache&&h.length<=this.A&&(this.J.set(h,g),this.J.size>this.S&&(this.J.clear(),this.A=this.A/1.1|0));g&&c.push(g)}this.finalize&&(c=this.finalize(c)||c);this.cache&&a.length<=this.h&&(this.H.set(a,c),this.H.size>this.S&&(this.H.clear(),this.h=this.h/1.1|0));return c};function ka(a){a.L=null;a.H.clear();a.J.clear()};async function la(a){a=a.data;var b=self._index;const c=a.args;var d=a.task;switch(d){case "init":d=a.options||{};(b=d.config)&&(d=(await import(b))["default"]);(b=a.factory)?(Function("return "+b)()(self),self._index=new self.FlexSearch.Index(d),delete self.FlexSearch):self._index=new K(d);postMessage({id:a.id});break;default:a=a.id,b=b[d].apply(b,c),postMessage("search"===d?{id:a,msg:b}:{id:a})}};let M=0; +function N(a={}){function b(g){function h(k){k=k.data||k;const l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=g;this.h=A();if(this.worker){d?this.worker.on("message",h):this.worker.onmessage=h;if(a.config)return new Promise(function(k){e.h[++M]=function(){k(e)};e.worker.postMessage({id:M,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}if(!this)return new N(a);let c="undefined"!==typeof self?self._factory:"undefined"!==typeof window? +window._factory:null;c&&(c=c.toString());const d="undefined"===typeof window,e=this,f=ma(c,d,a.worker);return f.then?f.then(function(g){return b.call(e,g)}):b.call(this,f)}O("add");O("append");O("search");O("update");O("remove"); +function O(a){N.prototype[a]=N.prototype[a+"Async"]=async function(){const b=this,c=[].slice.call(arguments);var d=c[c.length-1];let e;"function"===typeof d&&(e=d,c.splice(c.length-1,1));d=new Promise(function(f){b.h[++M]=f;b.worker.postMessage({task:a,id:M,args:c})});return e?(d.then(e),this):d}} +function ma(a,b,c){return b?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"](import.meta.dirname + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+la.toString()],{type:"text/javascript"}))):new window.Worker(C(c)?c:import.meta.url.replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", +"module/worker/worker.js"),{type:"module"})};function na(a){P.call(a,"add");P.call(a,"append");P.call(a,"search");P.call(a,"update");P.call(a,"remove")}function P(a){this[a+"Async"]=function(){var b=arguments;const c=b[b.length-1];let d;"function"===typeof c&&(d=c,delete b[b.length-1]);b=this[a].apply(this,b);d&&(b.then?b.then(d):d(b));return b}};function oa(a,b,c,d,e,f,g,h){(d=a(c?c+"."+d:d,JSON.stringify(g)))&&d.then?d.then(function(){b.export(a,b,c,e,f+1,h)}):b.export(a,b,c,e,f+1,h)};function pa(a,b,c,d){let e=[];for(let f=0,g;f=g.length)b-=g.length;else{b=g[d?"splice":"slice"](b,c);const h=b.length;if(h&&(e=e.length?e.concat(b):b,c-=h,d&&(a.length-=h),!c))break;b=0}return e} +function Q(a){if(!this)return new Q(a);this.index=a?[a]:[];this.length=a?a.length:0;const b=this;return new Proxy([],{get(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){let f=0;for(let g=0,h,k;gc||d)k=k.slice(d,c+d)}else{e=[];for(let n=0,p;nd)d-=p.length;else{if(p.length>c||d)p=p.slice(d, c+d),c-=p.length,d&&(d-=p.length);e.push(p);if(!c)break}return 1a.length?e?T(a[0],b,c,d):a[0]:Ea(a,c,b,e,f)};U.prototype.and=function(){if(this.result.length){const b=this;let c=arguments;var a=c[0];if(a.then)return a.then(function(){return b.and.apply(b,c)});if(a[0]&&a[0].index)return this.and.apply(this,a);let d=[];a=[];let e=0,f=0,g,h;for(let k=0,l;ka.length)return[];let g=[];A();let h=ca(a);return h?Da(a,h,b,c,f,e,d):g};U.prototype.xor=function(){const a=this;let b=arguments;var c=b[0];if(c.then)return c.then(function(){return a.xor.apply(a,b)});if(c[0]&&c[0].index)return this.xor.apply(this,c);let d=[];c=[];let e=0,f=0,g,h;for(let k=0,l;ka.length)return e?T(a[0],b,c,d):a[0];d=[];const g=A();let h=0;for(let k=0,l;kc);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,f,g,h):a.db.get(b,"",d,e,f,g,h);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};Q.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else Na(this.map,a),this.depth&&Na(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&Ba(this));this.cache&&this.cache.remove(a);return this}; -function Na(a,b){let c=0;if(a.constructor===Array)for(let d=0,e,f;dc.add(a,b)):this.add(a,b)}; -function Oa(a){let b=0;if(a.constructor===Array)for(let c=0,d;c{f=l}));let h,k;switch(e||(e=0)){case 0:h="reg";if(this.fastupdate){k=A();for(let l of this.reg.keys())k[l]=1}else k=this.reg;break;case 1:h="cfg";k={doc:0,opt:this.h?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.ctx;break;default:"undefined"===typeof c&&f&&f();return}ya(a,b||this,c,h,d,e,k,f);return g}; -u.import=function(a,b){if(b)switch(C(b)&&(b=JSON.parse(b)),a){case "cfg":this.h=!!b.opt;break;case "reg":this.fastupdate=!1;this.reg=b;break;case "map":this.map=b;break;case "ctx":this.ctx=b}}; -u.serialize=function(a=!0){if(!this.reg.size)return"";let b="",c="";for(var d of this.reg.keys())c||(c=typeof d),b+=(b?",":"")+("string"===c?'"'+d+'"':d);b="index.reg=new Set(["+b+"]);";d="";for(var e of this.map.entries()){var f=e[0],g=e[1],h="";for(let m=0,n;mc||d)a=a.slice(d,d+c);e&&(a=Va.call(this,a));return a}} -function Va(a){const b=Array(a.length);for(let c=0,d;cc||d)a=a.slice(d,d+c);e&&(a=ya.call(this,a));return a}} +function ya(a){const b=Array(a.length);for(let c=0,d;c{f=k}));e||(e=0);d||(d=0);if(d{e.objectStoreNames.contains(f)||e.createObjectStore(f)})};d.onblocked=function(e){console.error("blocked",e);c()};d.onerror=function(e){console.error(this.error,e);c()};d.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; -u.close=function(){this.db.close();this.db=null};u.destroy=function(){return $a.deleteDatabase(this.id+(this.field?":"+this.field:""))};u.clear=function(){const a=this.db.transaction(ab,"readwrite");for(let b=0;b{f=k}));e||(e=0);d||(d=0);if(dthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +U.prototype.get=function(a){const b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};U.prototype.remove=function(a){for(const b of this.cache){const c=b[0];b[1].includes(a)&&this.cache.delete(c)}};U.prototype.clear=function(){this.cache.clear();this.h=""};const Ea={normalize:function(a){return a.toLowerCase()},dedupe:!1};const Fa=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const Ga=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),Ha=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];const Ia={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const Ja=/[\x00-\x7F]+/g;const Ka=/[\x00-\x7F]+/g;const La=/[\x00-\x7F]+/g;var Ma={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Ea,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Fa},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Fa,replacer:Ha,matcher:Ga},LatinExtra:{normalize:!0,dedupe:!0,mapper:Fa,replacer:Ha.concat([/(?!^)[aeoy]/g,""]),matcher:Ga},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let c=0;cf;h--){g=t.substring(f,h);var k=this.score?this.score(b,t,q,g,f):Oa(p,d,q,e,f);V(this,m,g,k,a,c)}break}case "reverse":if(1< +e){for(h=e-1;0g?0:1),d,q,h-1,k-1),v=this.bidirectional&&t>f;V(this,l,v?f:t,r,a,c,v?t:f)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& +(b||this.commit_task.push({del:a}),this.T&&Pa(this));return this};function V(a,b,c,d,e,f,g){let h=g?a.ctx:a.map,k;if(!b[c]||g&&!(k=b[c])[g])if(g?(b=k||(b[c]=A()),b[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):b[c]=1,(k=h.get(c))?h=k:h.set(c,h=k=[]),h=h[d]||(h[d]=[]),!f||!h.includes(e)){if(h.length===2**31-1){b=new Q(h);if(a.fastupdate)for(let l of a.reg.values())l.includes(h)&&(l[l.indexOf(h)]=b);k[d]=h=b}h.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(h):a.reg.set(e,[h]))}} +function Oa(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?Qa(a):a;let e=[];for(let f=0,g,h;f=h){c-=h;continue}cb&&(g=g.slice(0,b),h=g.length),e.push(g);else{if(h>=b)return h>b&&(g=g.slice(0,b)),d?Qa(g):g;e=[g]}b-=h;if(!b)break}if(!e.length)return e;e=1a.length?e?W(a[0],b,c,d):a[0]:va(a,c,b,e,f)};X.prototype.and=function(){if(this.result.length){const b=this;let c=arguments;var a=c[0];if(a.then)return a.then(function(){return b.and.apply(b,c)});if(a[0]&&a[0].index)return this.and.apply(this,a);let d=[];a=[];let e=0,f=0,g,h;for(let k=0,l;ka.length)return[];let g=[];A();let h=ca(a);return h?ua(a,h,b,c,f,e,d):g};X.prototype.xor=function(){const a=this;let b=arguments;var c=b[0];if(c.then)return c.then(function(){return a.xor.apply(a,b)});if(c[0]&&c[0].index)return this.xor.apply(this,c);let d=[];c=[];let e=0,f=0,g,h;for(let k=0,l;ka.length)return e?W(a[0],b,c,d):a[0];d=[];const g=A();let h=0;for(let k=0,l;kc);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,f,g,h):a.db.get(b,"",d,e,f,g,h);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};K.prototype.remove=function(a,b){const c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const f=e.indexOf(a);f===c.length-1?e.pop():e.splice(f,1)}}else Ya(this.map,a),this.depth&&Ya(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.T&&Pa(this));this.cache&&this.cache.remove(a);return this}; +function Ya(a,b){let c=0;if(a.constructor===Array)for(let d=0,e,f;dc.add(a,b)):this.add(a,b)}; +function $a(a){let b=0;if(a.constructor===Array)for(let c=0,d;c{f=l}));let h,k;switch(e||(e=0)){case 0:h="reg";if(this.fastupdate){k=A();for(let l of this.reg.keys())k[l]=1}else k=this.reg;break;case 1:h="cfg";k={doc:0,opt:this.h?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.ctx;break;default:"undefined"===typeof c&&f&&f();return}oa(a,b||this,c,h,d,e,k,f);return g}; +u.import=function(a,b){if(b)switch(C(b)&&(b=JSON.parse(b)),a){case "cfg":this.h=!!b.opt;break;case "reg":this.fastupdate=!1;this.reg=b;break;case "map":this.map=b;break;case "ctx":this.ctx=b}}; +u.serialize=function(a=!0){if(!this.reg.size)return"";let b="",c="";for(var d of this.reg.keys())c||(c=typeof d),b+=(b?",":"")+("string"===c?'"'+d+'"':d);b="index.reg=new Set(["+b+"]);";d="";for(var e of this.map.entries()){var f=e[0],g=e[1],h="";for(let m=0,n;m{e.objectStoreNames.contains(f)||e.createObjectStore(f)})};d.onblocked=function(e){console.error("blocked",e);c()};d.onerror=function(e){console.error(this.error,e);c()};d.onsuccess=function(){a.db=this.result;a.db.onversionchange=function(){a.close()};b(a)}})}; +u.close=function(){this.db.close();this.db=null};u.destroy=function(){return ab.deleteDatabase(this.id+(this.field?":"+this.field:""))};u.clear=function(){const a=this.db.transaction(bb,"readwrite");for(let b=0;b=m.length){d-=m.length;continue}const n=c?d+Math.min(m.length-d,c):m.length;for(let p=d;p=f.length)return[];if(!b&&!c)return f;f=f.slice(c,c+b);return d?e.enrich(f):f})}; u.enrich=function(a){"object"!==typeof a&&(a=[a]);const b=this.db.transaction("reg","readonly").objectStore("reg"),c=[];for(let d=0;dm&&!f&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(f=1),0<=m)if(e=1,1{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};export default {Index:Q,Charset:ua,Encoder:I,Document:Y,Worker:W,Resolver:U,IndexedDB:bb,Language:{}}; -export const Index=Q;export const Charset=ua;export const Encoder=I;export const Document=Y;export const Worker=W;export const Resolver=U;export const IndexedDB=bb;export const Language={}; \ No newline at end of file +function Z(a){return new Promise((b,c)=>{a.onsuccess=function(){b(this.result)};a.oncomplete=function(){b(this.result)};a.onerror=c;a=null})};export default {Index:K,Charset:Ma,Encoder:I,Document:T,Worker:N,Resolver:X,IndexedDB:cb,Language:{}}; +export const Index=K;export const Charset=Ma;export const Encoder=I;export const Document=T;export const Worker=N;export const Resolver=X;export const IndexedDB=cb;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.compact.debug.js b/dist/flexsearch.compact.debug.js index 1c2b06d..38859eb 100644 --- a/dist/flexsearch.compact.debug.js +++ b/dist/flexsearch.compact.debug.js @@ -210,7 +210,526 @@ function ha(a) { a.F.clear(); a.H.clear(); } -;function ia(a, c, b) { +;function ia(a) { + L.call(a, "add"); + L.call(a, "append"); + L.call(a, "search"); + L.call(a, "update"); + L.call(a, "remove"); +} +function L(a) { + this[a + "Async"] = function() { + var c = arguments; + const b = c[c.length - 1]; + let e; + "function" === typeof b && (e = b, delete c[c.length - 1]); + c = this[a].apply(this, c); + e && (c.then ? c.then(e) : e(c)); + return c; + }; +} +;function ja(a, c, b, e, d, f, g, h) { + (e = a(b ? b + "." + e : e, JSON.stringify(g))) && e.then ? e.then(function() { + c.export(a, c, b, d, f + 1, h); + }) : c.export(a, c, b, d, f + 1, h); +} +;M.prototype.add = function(a, c, b) { + F(a) && (c = a, a = G(c, this.key)); + if (c && (a || 0 === a)) { + if (!b && this.reg.has(a)) { + return this.update(a, c); + } + for (let h = 0, k; h < this.field.length; h++) { + k = this.C[h]; + var e = this.index.get(this.field[h]); + if ("function" === typeof k) { + var d = k(c); + d && e.add(a, d, !1, !0); + } else { + if (d = k.G, !d || d(c)) { + k.constructor === String ? k = ["" + k] : A(k) && (k = [k]), N(c, k, this.I, 0, e, a, k[0], b); + } + } + } + if (this.tag) { + for (e = 0; e < this.B.length; e++) { + var f = this.B[e], g = this.R[e]; + d = this.tag.get(g); + let h = z(); + if ("function" === typeof f) { + if (f = f(c), !f) { + continue; + } + } else { + const k = f.G; + if (k && !k(c)) { + continue; + } + f.constructor === String && (f = "" + f); + f = G(c, f); + } + if (d && f) { + A(f) && (f = [f]); + for (let k = 0, l, m; k < f.length; k++) { + l = f[k], h[l] || (h[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), b && m.includes(a) || (m.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])))); + } + } else { + d || console.warn("Tag '" + g + "' was not found"); + } + } + } + if (this.store && (!b || !this.store.has(a))) { + let h; + if (this.A) { + h = z(); + for (let k = 0, l; k < this.A.length; k++) { + l = this.A[k]; + if ((b = l.G) && !b(c)) { + continue; + } + let m; + if ("function" === typeof l) { + m = l(c); + if (!m) { + continue; + } + l = [l.S]; + } else if (A(l) || l.constructor === String) { + h[l] = c[l]; + continue; + } + O(c, h, l, 0, l[0], m); + } + } + this.store.set(a, h || c); + } + } + return this; +}; +function O(a, c, b, e, d, f) { + a = a[d]; + if (e === b.length - 1) { + c[d] = f || a; + } else if (a) { + if (a.constructor === Array) { + for (c = c[d] = Array(a.length), d = 0; d < a.length; d++) { + O(a, c, b, e, d); + } + } else { + c = c[d] || (c[d] = z()), d = b[++e], O(a, c, b, e, d); + } + } +} +function N(a, c, b, e, d, f, g, h) { + if (a = a[g]) { + if (e === c.length - 1) { + if (a.constructor === Array) { + if (b[e]) { + for (c = 0; c < a.length; c++) { + d.add(f, a[c], !0, !0); + } + return; + } + a = a.join(" "); + } + d.add(f, a, h, !0); + } else { + if (a.constructor === Array) { + for (g = 0; g < a.length; g++) { + N(a, c, b, e, d, f, g, h); + } + } else { + g = c[++e], N(a, c, b, e, d, f, g, h); + } + } + } +} +;function ka(a, c) { + const b = z(), e = []; + for (let d = 0, f; d < c.length; d++) { + f = c[d]; + for (let g = 0; g < f.length; g++) { + b[f[g]] = 1; + } + } + for (let d = 0, f; d < a.length; d++) { + f = a[d], 1 === b[f] && (e.push(f), b[f] = 2); + } + return e; +} +;M.prototype.search = function(a, c, b, e) { + b || (!c && F(a) ? (b = a, a = "") : F(c) && (b = c, c = 0)); + let d = []; + var f = []; + let g, h, k, l, m, n, t = 0, p; + if (b) { + b.constructor === Array && (b = {index:b}); + a = b.query || a; + var q = b.pluck; + h = b.merge; + l = q || b.field || b.index; + m = this.tag && b.tag; + g = this.store && b.enrich; + k = b.suggest; + p = b.T; + c = b.limit || c; + n = b.offset || 0; + c || (c = 100); + if (m) { + m.constructor !== Array && (m = [m]); + var u = []; + for (let x = 0, r; x < m.length; x++) { + r = m[x]; + if (A(r)) { + throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); + } + if (r.field && r.tag) { + var w = r.tag; + if (w.constructor === Array) { + for (var B = 0; B < w.length; B++) { + u.push(r.field, w[B]); + } + } else { + u.push(r.field, w); + } + } else { + w = Object.keys(r); + for (let D = 0, E, C; D < w.length; D++) { + if (E = w[D], C = r[E], C.constructor === Array) { + for (B = 0; B < C.length; B++) { + u.push(E, C[B]); + } + } else { + u.push(E, C); + } + } + } + } + if (!u.length) { + throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); + } + m = u; + if (!a) { + e = []; + if (u.length) { + for (f = 0; f < u.length; f += 2) { + q = la.call(this, u[f], u[f + 1], c, n, g), d.push({field:u[f], tag:u[f + 1], result:q}); + } + } + return e.length ? Promise.all(e).then(function(x) { + for (let r = 0; r < x.length; r++) { + d[r].result = x[r]; + } + return d; + }) : d; + } + } + A(l) && (l = [l]); + } + l || (l = this.field); + u = !e && (this.worker || this.db) && []; + for (let x = 0, r, D, E; x < l.length; x++) { + D = l[x]; + let C; + A(D) || (C = D, D = C.field, a = C.query || a, c = C.limit || c, n = C.offset || n, k = C.suggest || k, g = this.store && (C.enrich || g)); + if (e) { + r = e[x]; + } else { + if (w = C || b, B = this.index.get(D), m && (w.enrich = !1), u) { + u[x] = B.search(a, c, w); + w && g && (w.enrich = g); + continue; + } else { + r = B.search(a, c, w), w && g && (w.enrich = g); + } + } + E = r && r.length; + if (m && E) { + w = []; + B = 0; + for (let H = 0, I, ya; H < m.length; H += 2) { + I = this.tag.get(m[H]); + if (!I) { + if (console.warn("Tag '" + m[H] + ":" + m[H + 1] + "' will be skipped because there is no field '" + m[H] + "'."), k) { + continue; + } else { + return d; + } + } + if (ya = (I = I && I.get(m[H + 1])) && I.length) { + B++, w.push(I); + } else if (!k) { + return d; + } + } + if (B) { + r = ka(r, w); + E = r.length; + if (!E && !k) { + return d; + } + B--; + } + } + if (E) { + f[t] = D, d.push(r), t++; + } else if (1 === l.length) { + return d; + } + } + if (u) { + const x = this; + return Promise.all(u).then(function(r) { + return r.length ? x.search(a, c, b, r) : r; + }); + } + if (!t) { + return d; + } + if (q && (!g || !this.store)) { + return d[0]; + } + u = []; + for (let x = 0, r; x < f.length; x++) { + r = d[x]; + g && r.length && !r[0].doc && r.length && (r = ma.call(this, r)); + if (q) { + return r; + } + d[x] = {field:f[x], result:r}; + } + return h ? na(d, c) : p ? oa(d, a, this.index, this.C, p) : d; +}; +function oa(a, c, b, e, d) { + let f; + for (let g = 0, h, k, l, m; g < a.length; g++) { + h = a[g].result; + k = a[g].field; + l = b.get(k).encoder; + m = e[k.indexOf(k)]; + l !== f && (f = l, f.encode(c)); + for (let n = 0; n < h.length; n++) { + let t = "", p = G(h[n].doc, m), q = f.encode(p); + for (let u = 0; u < q.length; u++) { + t += q[u].replace(new RegExp("(" + q[u] + ")", "g"), d.replace("$1", p)); + } + console.log(a, b, d); + h[n].T = t; + } + } + return a; +} +function na(a, c) { + const b = [], e = z(); + for (let d = 0, f, g; d < a.length; d++) { + f = a[d]; + g = f.result; + for (let h = 0, k, l, m; h < g.length; h++) { + if (l = g[h], k = l.id, m = e[k]) { + m.push(f.field); + } else { + if (b.length === c) { + return b; + } + l.field = e[k] = [f.field]; + b.push(l); + } + } + } + return b; +} +function la(a, c, b, e, d) { + let f = this.tag.get(a); + if (!f) { + return console.warn("Tag '" + a + "' was not found"), []; + } + if ((a = (f = f && f.get(c)) && f.length - e) && 0 < a) { + if (a > b || e) { + f = f.slice(e, e + b); + } + d && (f = ma.call(this, f)); + return f; + } +} +function ma(a) { + const c = Array(a.length); + for (let b = 0, e; b < a.length; b++) { + e = a[b], c[b] = {id:e, doc:this.store.get(e)}; + } + return c; +} +;function M(a) { + if (!this) { + return new M(a); + } + const c = a.document || a.doc || a; + var b; + this.C = []; + this.field = []; + this.I = []; + this.key = (b = c.key || c.id) && P(b, this.I) || "id"; + this.reg = (this.fastupdate = !!a.fastupdate) ? new Map() : new Set(); + this.A = (b = c.store || null) && !0 !== b && []; + this.store = b && new Map(); + this.cache = (b = a.cache || null) && new Q(b); + a.cache = !1; + b = new Map(); + let e = c.index || c.field || c; + A(e) && (e = [e]); + for (let d = 0, f, g; d < e.length; d++) { + f = e[d], A(f) || (g = f, f = f.field), g = F(g) ? Object.assign({}, a, g) : a, b.set(f, new R(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = P(f, this.I), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].G = g.filter)), this.field[d] = f; + } + if (this.A) { + a = c.store; + A(a) && (a = [a]); + for (let d = 0, f, g; d < a.length; d++) { + f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.S = g) : (this.A[d] = P(g, this.I), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].G = f.filter)); + } + } + this.index = b; + this.tag = null; + if (b = c.tag) { + if ("string" === typeof b && (b = [b]), b.length) { + this.tag = new Map(); + this.B = []; + this.R = []; + for (let d = 0, f, g; d < b.length; d++) { + f = b[d]; + g = f.field || f; + if (!g) { + throw Error("The tag field from the document descriptor is undefined."); + } + f.custom ? this.B[d] = f.custom : (this.B[d] = P(g, this.I), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].G = f.filter)); + this.R[d] = g; + this.tag.set(g, new Map()); + } + } + } +} +function P(a, c) { + const b = a.split(":"); + let e = 0; + for (let d = 0; d < b.length; d++) { + a = b[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (c[e] = !0), a && (b[e++] = a); + } + e < b.length && (b.length = e); + return 1 < e ? b : b[0]; +} +v = M.prototype; +v.append = function(a, c) { + return this.add(a, c, !0); +}; +v.update = function(a, c) { + return this.remove(a).add(a, c); +}; +v.remove = function(a) { + F(a) && (a = G(a, this.key)); + for (var c of this.index.values()) { + c.remove(a, !0); + } + if (this.reg.has(a)) { + if (this.tag && !this.fastupdate) { + for (let b of this.tag.values()) { + for (let e of b) { + c = e[0]; + const d = e[1], f = d.indexOf(a); + -1 < f && (1 < d.length ? d.splice(f, 1) : b.delete(c)); + } + } + } + this.store && this.store.delete(a); + this.reg.delete(a); + } + this.cache && this.cache.remove(a); + return this; +}; +v.clear = function() { + for (const a of this.index.values()) { + a.clear(); + } + if (this.tag) { + for (const a of this.tag.values()) { + a.clear(); + } + } + this.store && this.store.clear(); + return this; +}; +v.contain = function(a) { + return this.reg.has(a); +}; +v.cleanup = function() { + for (const a of this.index.values()) { + a.cleanup(); + } + return this; +}; +v.get = function(a) { + return this.store.get(a); +}; +v.set = function(a, c) { + this.store.set(a, c); + return this; +}; +v.searchCache = pa; +v.export = function(a, c, b, e, d, f) { + let g; + "undefined" === typeof f && (g = new Promise(k => { + f = k; + })); + d || (d = 0); + e || (e = 0); + if (e < this.field.length) { + b = this.field[e]; + var h = this.index[b]; + c = this; + h.export(a, c, d ? b : "", e, d++, f) || (e++, c.export(a, c, b, e, 1, f)); + } else { + switch(d) { + case 1: + c = "tag"; + h = this.D; + b = null; + break; + case 2: + c = "store"; + h = this.store; + b = null; + break; + default: + f(); + return; + } + ja(a, this, b, c, e, d, h, f); + } + return g; +}; +v.import = function(a, c) { + if (c) { + switch(A(c) && (c = JSON.parse(c)), a) { + case "tag": + this.D = c; + break; + case "reg": + this.fastupdate = !1; + this.reg = c; + for (let e = 0, d; e < this.field.length; e++) { + d = this.index[this.field[e]], d.reg = c, d.fastupdate = !1; + } + break; + case "store": + this.store = c; + break; + default: + a = a.split("."); + const b = a[0]; + a = a[1]; + b && a && this.index[b].import(a, c); + } + } +}; +ia(M.prototype); +function pa(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); let e = this.cache.get(a); if (!e) { @@ -226,80 +745,57 @@ function ha(a) { } return e; } -function L(a) { +function Q(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -L.prototype.set = function(a, c) { +Q.prototype.set = function(a, c) { this.cache.set(this.h = a, c); this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); }; -L.prototype.get = function(a) { +Q.prototype.get = function(a) { const c = this.cache.get(a); c && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, c)); return c; }; -L.prototype.remove = function(a) { +Q.prototype.remove = function(a) { for (const c of this.cache) { const b = c[0]; c[1].includes(a) && this.cache.delete(b); } }; -L.prototype.clear = function() { +Q.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const ja = {normalize:function(a) { +const qa = {normalize:function(a) { return a.toLowerCase(); }, dedupe:!1}; -const M = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); -const ka = new Map([["ai", "ei"], ["ae", "a"], ["oe", "o"], ["ue", "u"], ["sh", "s"], ["ch", "c"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), la = [/([^aeo])h([aeo$])/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2"]; -const ma = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; -const na = /[\x00-\x7F]+/g; -const oa = /[\x00-\x7F]+/g; -const pa = /[\x00-\x7F]+/g; -var qa = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:ja, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:M}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:M, replacer:la, matcher:ka}, LatinExtra:{normalize:!0, dedupe:!0, mapper:M, replacer:la.concat([/(?!^)[aeoy]/g, ""]), matcher:ka}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +const S = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); +const ra = new Map([["ai", "ei"], ["ae", "a"], ["oe", "o"], ["ue", "u"], ["sh", "s"], ["ch", "c"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), sa = [/([^aeo])h([aeo$])/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2"]; +const ta = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; +const ua = /[\x00-\x7F]+/g; +const va = /[\x00-\x7F]+/g; +const wa = /[\x00-\x7F]+/g; +var xa = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:qa, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:S}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:S, replacer:sa, matcher:ra}, LatinExtra:{normalize:!0, dedupe:!0, mapper:S, replacer:sa.concat([/(?!^)[aeoy]/g, ""]), matcher:ra}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let b = 0; b < a.length; b++) { var c = a[b]; - let e = c.charAt(0), d = ma[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = ma[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let e = c.charAt(0), d = ta[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = ta[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } a[b] = e; } }}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(na, " "); + return ("" + a).replace(ua, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(oa, ""); + return ("" + a).replace(va, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(pa, " "); + return ("" + a).replace(wa, " "); }}}; -function ra(a, c, b, e, d, f, g, h) { - (e = a(b ? b + "." + e : e, JSON.stringify(g))) && e.then ? e.then(function() { - c.export(a, c, b, d, f + 1, h); - }) : c.export(a, c, b, d, f + 1, h); -} -;const sa = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -function ta(a) { - N.call(a, "add"); - N.call(a, "append"); - N.call(a, "search"); - N.call(a, "update"); - N.call(a, "remove"); -} -function N(a) { - this[a + "Async"] = function() { - var c = arguments; - const b = c[c.length - 1]; - let e; - "function" === typeof b && (e = b, delete c[c.length - 1]); - c = this[a].apply(this, c); - e && (c.then ? c.then(e) : e(c)); - return c; - }; -} -;z(); -O.prototype.add = function(a, c, b, e) { +const za = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +z(); +R.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { return this.update(a, c); @@ -311,15 +807,15 @@ O.prototype.add = function(a, c, b, e) { let q = c[this.rtl ? e - 1 - p : p]; var d = q.length; if (d && (n || !m[q])) { - var f = this.score ? this.score(c, q, p, null, 0) : P(t, e, p), g = ""; + var f = this.score ? this.score(c, q, p, null, 0) : T(t, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { for (f = 0; f < d; f++) { for (var h = d; h > f; h--) { g = q.substring(f, h); - var k = this.score ? this.score(c, q, p, g, f) : P(t, e, p, d, f); - Q(this, m, g, k, a, b); + var k = this.score ? this.score(c, q, p, g, f) : T(t, e, p, d, f); + U(this, m, g, k, a, b); } } break; @@ -327,24 +823,24 @@ O.prototype.add = function(a, c, b, e) { case "reverse": if (1 < d) { for (h = d - 1; 0 < h; h--) { - g = q[h] + g, k = this.score ? this.score(c, q, p, g, h) : P(t, e, p, d, h), Q(this, m, g, k, a, b); + g = q[h] + g, k = this.score ? this.score(c, q, p, g, h) : T(t, e, p, d, h), U(this, m, g, k, a, b); } g = ""; } case "forward": if (1 < d) { for (h = 0; h < d; h++) { - g += q[h], Q(this, m, g, f, a, b); + g += q[h], U(this, m, g, f, a, b); } break; } default: - if (Q(this, m, q, f, a, b), n && 1 < e && p < e - 1) { + if (U(this, m, q, f, a, b), n && 1 < e && p < e - 1) { for (d = z(), g = this.P, f = q, h = Math.min(n + 1, e - p), d[f] = 1, k = 1; k < h; k++) { if ((q = c[this.rtl ? e - 1 - p - k : p + k]) && !d[q]) { d[q] = 1; - const u = this.score ? this.score(c, f, p, q, k) : P(g + (e / 2 > g ? 0 : 1), e, p, h - 1, k - 1), w = this.bidirectional && q > f; - Q(this, l, w ? f : q, u, a, b, w ? q : f); + const u = this.score ? this.score(c, f, p, q, k) : T(g + (e / 2 > g ? 0 : 1), e, p, h - 1, k - 1), w = this.bidirectional && q > f; + U(this, l, w ? f : q, u, a, b, w ? q : f); } } } @@ -356,14 +852,16 @@ O.prototype.add = function(a, c, b, e) { } return this; }; -function Q(a, c, b, e, d, f, g) { +function U(a, c, b, e, d, f, g) { let h = g ? a.ctx : a.map, k; - c[b] && g && (k = c[b])[g] || (g ? (c = k || (c[b] = z()), c[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[e] || (h[e] = []), f && h.includes(d) || (h.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(h) : a.reg.set(d, [h])))); + if (!c[b] || g && !(k = c[b])[g]) { + g ? (c = k || (c[b] = z()), c[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[e] || (h[e] = []), f && h.includes(d) || (h.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(h) : a.reg.set(d, [h]))); + } } -function P(a, c, b, e, d) { +function T(a, c, b, e, d) { return b && 1 < a ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; } -;function ua(a, c, b) { +;function Aa(a, c, b) { if (1 === a.length) { return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a; } @@ -393,20 +891,7 @@ function P(a, c, b, e, d) { } return e.length ? e = 1 < e.length ? [].concat.apply([], e) : e[0] : e; } -;function va(a, c) { - const b = z(), e = []; - for (let d = 0, f; d < c.length; d++) { - f = c[d]; - for (let g = 0; g < f.length; g++) { - b[f[g]] = 1; - } - } - for (let d = 0, f; d < a.length; d++) { - f = a[d], 1 === b[f] && (e.push(f), b[f] = 2); - } - return e; -} -;O.prototype.search = function(a, c, b) { +;R.prototype.search = function(a, c, b) { b || (!c && F(a) ? (b = a, a = "") : F(c) && (b = c, c = 0)); var e = [], d = 0; if (b) { @@ -420,11 +905,11 @@ function P(a, c, b, e, d) { b = a.length; c || (c = 100); if (1 === b) { - return R.call(this, a[0], "", c, d); + return V.call(this, a[0], "", c, d); } f = this.depth && !1 !== f; if (2 === b && f && !g) { - return R.call(this, a[0], a[1], c, d); + return V.call(this, a[0], a[1], c, d); } var h = 0, k = 0; if (1 < b) { @@ -432,7 +917,7 @@ function P(a, c, b, e, d) { const n = []; for (let t = 0, p; t < b; t++) { if ((p = a[t]) && !l[p]) { - if (g || S(this, p)) { + if (g || W(this, p)) { n.push(p), l[p] = 1; } else { return e; @@ -450,10 +935,10 @@ function P(a, c, b, e, d) { } l = 0; if (1 === b) { - return R.call(this, a[0], "", c, d); + return V.call(this, a[0], "", c, d); } if (2 === b && f && !g) { - return R.call(this, a[0], a[1], c, d); + return V.call(this, a[0], a[1], c, d); } if (1 < b) { if (f) { @@ -465,7 +950,7 @@ function P(a, c, b, e, d) { } for (let n, t; l < b; l++) { t = a[l]; - m ? (n = S(this, t, m), n = wa(n, e, g, this.P), g && !1 === n && e.length || (m = t)) : (n = S(this, t, ""), n = wa(n, e, g, this.resolution)); + m ? (n = W(this, t, m), n = Ba(n, e, g, this.P), g && !1 === n && e.length || (m = t)) : (n = W(this, t, ""), n = Ba(n, e, g, this.resolution)); if (n) { return n; } @@ -480,7 +965,7 @@ function P(a, c, b, e, d) { return e; } if (1 === f) { - return ua(e[0], c, d); + return Aa(e[0], c, d); } } } @@ -544,10 +1029,10 @@ function P(a, c, b, e, d) { } return e; }; -function R(a, c, b, e) { - return (a = S(this, a, c)) && a.length ? ua(a, b, e) : []; +function V(a, c, b, e) { + return (a = W(this, a, c)) && a.length ? Aa(a, b, e) : []; } -function wa(a, c, b, e) { +function Ba(a, c, b, e) { let d = []; if (a) { e = Math.min(a.length, e); @@ -561,13 +1046,13 @@ function wa(a, c, b, e) { } return !b && d; } -function S(a, c, b) { +function W(a, c, b) { let e; b && (e = a.bidirectional && c > b); a = b ? (a = a.ctx.get(e ? c : b)) && a.get(e ? b : c) : a.map.get(c); return a; } -;O.prototype.remove = function(a, c) { +;R.prototype.remove = function(a, c) { const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (b) { if (this.fastupdate) { @@ -582,14 +1067,14 @@ function S(a, c, b) { } } } else { - T(this.map, a), this.depth && T(this.ctx, a); + X(this.map, a), this.depth && X(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function T(a, c) { +function X(a, c) { let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { @@ -604,24 +1089,24 @@ function T(a, c) { } } else { for (let e of a) { - const d = e[0], f = T(e[1], c); + const d = e[0], f = X(e[1], c); f ? b += f : a.delete(d); } } return b; } -;function O(a, c) { +;function R(a, c) { if (!this) { - return new O(a); + return new R(a); } if (a) { var b = A(a) ? a : a.preset; - b && (sa[b] || console.warn("Preset not found: " + b), a = Object.assign({}, sa[b], a)); + b && (za[b] || console.warn("Preset not found: " + b), a = Object.assign({}, za[b], a)); } else { a = {}; } b = a.context || {}; - const e = A(a.encoder) ? qa[a.encoder] : a.encode || a.encoder || ja; + const e = A(a.encoder) ? xa[a.encoder] : a.encode || a.encoder || qa; this.encoder = e.encode ? e : "object" === typeof e ? new K(e) : {encode:e}; let d; this.resolution = a.resolution || 9; @@ -636,9 +1121,9 @@ function T(a, c) { this.reg = c || (this.fastupdate ? new Map() : new Set()); this.P = b.resolution || 1; this.rtl = e.rtl || a.rtl || !1; - this.cache = (d = a.cache || null) && new L(d); + this.cache = (d = a.cache || null) && new Q(d); } -v = O.prototype; +v = R.prototype; v.clear = function() { this.map.clear(); this.ctx.clear(); @@ -656,7 +1141,7 @@ v.update = function(a, c) { const b = this, e = this.remove(a); return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c); }; -function U(a) { +function Y(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, e; b < a.length; b++) { @@ -664,7 +1149,7 @@ function U(a) { } } else { for (const b of a) { - const e = b[0], d = U(b[1]); + const e = b[0], d = Y(b[1]); d ? c += d : a.delete(e); } } @@ -674,11 +1159,11 @@ v.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - U(this.map); - this.depth && U(this.ctx); + Y(this.map); + this.depth && Y(this.ctx); return this; }; -v.searchCache = ia; +v.searchCache = pa; v.export = function(a, c, b, e, d, f) { let g = !0; "undefined" === typeof f && (g = new Promise(l => { @@ -713,7 +1198,7 @@ v.export = function(a, c, b, e, d, f) { "undefined" === typeof b && f && f(); return; } - ra(a, c || this, b, h, e, d, k, f); + ja(a, c || this, b, h, e, d, k, f); return g; }; v.import = function(a, c) { @@ -784,491 +1269,8 @@ v.serialize = function(a = !0) { d = "index.ctx=new Map([" + d + "]);"; return a ? "function inject(index){" + c + e + d + "}" : c + e + d; }; -ta(O.prototype); -V.prototype.add = function(a, c, b) { - F(a) && (c = a, a = G(c, this.key)); - if (c && (a || 0 === a)) { - if (!b && this.reg.has(a)) { - return this.update(a, c); - } - for (let h = 0, k; h < this.field.length; h++) { - k = this.C[h]; - var e = this.index.get(this.field[h]); - if ("function" === typeof k) { - var d = k(c); - d && e.add(a, d, !1, !0); - } else { - if (d = k.G, !d || d(c)) { - k.constructor === String ? k = ["" + k] : A(k) && (k = [k]), W(c, k, this.I, 0, e, a, k[0], b); - } - } - } - if (this.tag) { - for (e = 0; e < this.B.length; e++) { - var f = this.B[e], g = this.R[e]; - d = this.tag.get(g); - let h = z(); - if ("function" === typeof f) { - if (f = f(c), !f) { - continue; - } - } else { - const k = f.G; - if (k && !k(c)) { - continue; - } - f.constructor === String && (f = "" + f); - f = G(c, f); - } - if (d && f) { - A(f) && (f = [f]); - for (let k = 0, l, m; k < f.length; k++) { - l = f[k], h[l] || (h[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), b && m.includes(a) || (m.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])))); - } - } else { - d || console.warn("Tag '" + g + "' was not found"); - } - } - } - if (this.store && (!b || !this.store.has(a))) { - let h; - if (this.A) { - h = z(); - for (let k = 0, l; k < this.A.length; k++) { - l = this.A[k]; - if ((b = l.G) && !b(c)) { - continue; - } - let m; - if ("function" === typeof l) { - m = l(c); - if (!m) { - continue; - } - l = [l.S]; - } else if (A(l) || l.constructor === String) { - h[l] = c[l]; - continue; - } - X(c, h, l, 0, l[0], m); - } - } - this.store.set(a, h || c); - } - } - return this; -}; -function X(a, c, b, e, d, f) { - a = a[d]; - if (e === b.length - 1) { - c[d] = f || a; - } else if (a) { - if (a.constructor === Array) { - for (c = c[d] = Array(a.length), d = 0; d < a.length; d++) { - X(a, c, b, e, d); - } - } else { - c = c[d] || (c[d] = z()), d = b[++e], X(a, c, b, e, d); - } - } -} -function W(a, c, b, e, d, f, g, h) { - if (a = a[g]) { - if (e === c.length - 1) { - if (a.constructor === Array) { - if (b[e]) { - for (c = 0; c < a.length; c++) { - d.add(f, a[c], !0, !0); - } - return; - } - a = a.join(" "); - } - d.add(f, a, h, !0); - } else { - if (a.constructor === Array) { - for (g = 0; g < a.length; g++) { - W(a, c, b, e, d, f, g, h); - } - } else { - g = c[++e], W(a, c, b, e, d, f, g, h); - } - } - } -} -;V.prototype.search = function(a, c, b, e) { - b || (!c && F(a) ? (b = a, a = "") : F(c) && (b = c, c = 0)); - let d = []; - var f = []; - let g, h, k, l, m, n, t = 0, p; - if (b) { - b.constructor === Array && (b = {index:b}); - a = b.query || a; - var q = b.pluck; - h = b.merge; - l = q || b.field || b.index; - m = this.tag && b.tag; - g = this.store && b.enrich; - k = b.suggest; - p = b.T; - c = b.limit || c; - n = b.offset || 0; - c || (c = 100); - if (m) { - m.constructor !== Array && (m = [m]); - var u = []; - for (let x = 0, r; x < m.length; x++) { - r = m[x]; - if (A(r)) { - throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); - } - if (r.field && r.tag) { - var w = r.tag; - if (w.constructor === Array) { - for (var B = 0; B < w.length; B++) { - u.push(r.field, w[B]); - } - } else { - u.push(r.field, w); - } - } else { - w = Object.keys(r); - for (let D = 0, E, C; D < w.length; D++) { - if (E = w[D], C = r[E], C.constructor === Array) { - for (B = 0; B < C.length; B++) { - u.push(E, C[B]); - } - } else { - u.push(E, C); - } - } - } - } - if (!u.length) { - throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); - } - m = u; - if (!a) { - e = []; - if (u.length) { - for (f = 0; f < u.length; f += 2) { - q = xa.call(this, u[f], u[f + 1], c, n, g), d.push({field:u[f], tag:u[f + 1], result:q}); - } - } - return e.length ? Promise.all(e).then(function(x) { - for (let r = 0; r < x.length; r++) { - d[r].result = x[r]; - } - return d; - }) : d; - } - } - A(l) && (l = [l]); - } - l || (l = this.field); - u = !e && (this.worker || this.db) && []; - for (let x = 0, r, D, E; x < l.length; x++) { - D = l[x]; - let C; - A(D) || (C = D, D = C.field, a = C.query || a, c = C.limit || c, n = C.offset || n, k = C.suggest || k, g = this.store && (C.enrich || g)); - if (e) { - r = e[x]; - } else { - if (w = C || b, B = this.index.get(D), m && (w.enrich = !1), u) { - u[x] = B.search(a, c, w); - w && g && (w.enrich = g); - continue; - } else { - r = B.search(a, c, w), w && g && (w.enrich = g); - } - } - E = r && r.length; - if (m && E) { - w = []; - B = 0; - for (let H = 0, I, Ba; H < m.length; H += 2) { - I = this.tag.get(m[H]); - if (!I) { - if (console.warn("Tag '" + m[H] + ":" + m[H + 1] + "' will be skipped because there is no field '" + m[H] + "'."), k) { - continue; - } else { - return d; - } - } - if (Ba = (I = I && I.get(m[H + 1])) && I.length) { - B++, w.push(I); - } else if (!k) { - return d; - } - } - if (B) { - r = va(r, w); - E = r.length; - if (!E && !k) { - return d; - } - B--; - } - } - if (E) { - f[t] = D, d.push(r), t++; - } else if (1 === l.length) { - return d; - } - } - if (u) { - const x = this; - return Promise.all(u).then(function(r) { - return r.length ? x.search(a, c, b, r) : r; - }); - } - if (!t) { - return d; - } - if (q && (!g || !this.store)) { - return d[0]; - } - u = []; - for (let x = 0, r; x < f.length; x++) { - r = d[x]; - g && r.length && !r[0].doc && r.length && (r = ya.call(this, r)); - if (q) { - return r; - } - d[x] = {field:f[x], result:r}; - } - return h ? za(d, c) : p ? Aa(d, a, this.index, this.C, p) : d; -}; -function Aa(a, c, b, e, d) { - let f; - for (let g = 0, h, k, l, m; g < a.length; g++) { - h = a[g].result; - k = a[g].field; - l = b.get(k).encoder; - m = e[k.indexOf(k)]; - l !== f && (f = l, f.encode(c)); - for (let n = 0; n < h.length; n++) { - let t = "", p = G(h[n].doc, m), q = f.encode(p); - for (let u = 0; u < q.length; u++) { - t += q[u].replace(new RegExp("(" + q[u] + ")", "g"), d.replace("$1", p)); - } - console.log(a, b, d); - h[n].T = t; - } - } - return a; -} -function za(a, c) { - const b = [], e = z(); - for (let d = 0, f, g; d < a.length; d++) { - f = a[d]; - g = f.result; - for (let h = 0, k, l, m; h < g.length; h++) { - if (l = g[h], k = l.id, m = e[k]) { - m.push(f.field); - } else { - if (b.length === c) { - return b; - } - l.field = e[k] = [f.field]; - b.push(l); - } - } - } - return b; -} -function xa(a, c, b, e, d) { - let f = this.tag.get(a); - if (!f) { - return console.warn("Tag '" + a + "' was not found"), []; - } - if ((a = (f = f && f.get(c)) && f.length - e) && 0 < a) { - if (a > b || e) { - f = f.slice(e, e + b); - } - d && (f = ya.call(this, f)); - return f; - } -} -function ya(a) { - const c = Array(a.length); - for (let b = 0, e; b < a.length; b++) { - e = a[b], c[b] = {id:e, doc:this.store.get(e)}; - } - return c; -} -;function V(a) { - if (!this) { - return new V(a); - } - const c = a.document || a.doc || a; - var b; - this.C = []; - this.field = []; - this.I = []; - this.key = (b = c.key || c.id) && Y(b, this.I) || "id"; - this.reg = (this.fastupdate = !!a.fastupdate) ? new Map() : new Set(); - this.A = (b = c.store || null) && !0 !== b && []; - this.store = b && new Map(); - this.cache = (b = a.cache || null) && new L(b); - a.cache = !1; - b = new Map(); - let e = c.index || c.field || c; - A(e) && (e = [e]); - for (let d = 0, f, g; d < e.length; d++) { - f = e[d], A(f) || (g = f, f = f.field), g = F(g) ? Object.assign({}, a, g) : a, b.set(f, new O(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = Y(f, this.I), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].G = g.filter)), this.field[d] = f; - } - if (this.A) { - a = c.store; - A(a) && (a = [a]); - for (let d = 0, f, g; d < a.length; d++) { - f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.S = g) : (this.A[d] = Y(g, this.I), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].G = f.filter)); - } - } - this.index = b; - this.tag = null; - if (b = c.tag) { - if ("string" === typeof b && (b = [b]), b.length) { - this.tag = new Map(); - this.B = []; - this.R = []; - for (let d = 0, f, g; d < b.length; d++) { - f = b[d]; - g = f.field || f; - if (!g) { - throw Error("The tag field from the document descriptor is undefined."); - } - f.custom ? this.B[d] = f.custom : (this.B[d] = Y(g, this.I), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].G = f.filter)); - this.R[d] = g; - this.tag.set(g, new Map()); - } - } - } -} -function Y(a, c) { - const b = a.split(":"); - let e = 0; - for (let d = 0; d < b.length; d++) { - a = b[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (c[e] = !0), a && (b[e++] = a); - } - e < b.length && (b.length = e); - return 1 < e ? b : b[0]; -} -v = V.prototype; -v.append = function(a, c) { - return this.add(a, c, !0); -}; -v.update = function(a, c) { - return this.remove(a).add(a, c); -}; -v.remove = function(a) { - F(a) && (a = G(a, this.key)); - for (var c of this.index.values()) { - c.remove(a, !0); - } - if (this.reg.has(a)) { - if (this.tag && !this.fastupdate) { - for (let b of this.tag.values()) { - for (let e of b) { - c = e[0]; - const d = e[1], f = d.indexOf(a); - -1 < f && (1 < d.length ? d.splice(f, 1) : b.delete(c)); - } - } - } - this.store && this.store.delete(a); - this.reg.delete(a); - } - this.cache && this.cache.remove(a); - return this; -}; -v.clear = function() { - for (const a of this.index.values()) { - a.clear(); - } - if (this.tag) { - for (const a of this.tag.values()) { - a.clear(); - } - } - this.store && this.store.clear(); - return this; -}; -v.contain = function(a) { - return this.reg.has(a); -}; -v.cleanup = function() { - for (const a of this.index.values()) { - a.cleanup(); - } - return this; -}; -v.get = function(a) { - return this.store.get(a); -}; -v.set = function(a, c) { - this.store.set(a, c); - return this; -}; -v.searchCache = ia; -v.export = function(a, c, b, e, d, f) { - let g; - "undefined" === typeof f && (g = new Promise(k => { - f = k; - })); - d || (d = 0); - e || (e = 0); - if (e < this.field.length) { - b = this.field[e]; - var h = this.index[b]; - c = this; - h.export(a, c, d ? b : "", e, d++, f) || (e++, c.export(a, c, b, e, 1, f)); - } else { - switch(d) { - case 1: - c = "tag"; - h = this.D; - b = null; - break; - case 2: - c = "store"; - h = this.store; - b = null; - break; - default: - f(); - return; - } - ra(a, this, b, c, e, d, h, f); - } - return g; -}; -v.import = function(a, c) { - if (c) { - switch(A(c) && (c = JSON.parse(c)), a) { - case "tag": - this.D = c; - break; - case "reg": - this.fastupdate = !1; - this.reg = c; - for (let e = 0, d; e < this.field.length; e++) { - d = this.index[this.field[e]], d.reg = c, d.fastupdate = !1; - } - break; - case "store": - this.store = c; - break; - default: - a = a.split("."); - const b = a[0]; - a = a[1]; - b && a && this.index[b].import(a, c); - } - } -}; -ta(V.prototype); -const Ca = {Index:O, Charset:qa, Encoder:K, Document:V, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, Z = self; +ia(R.prototype); +const Ca = {Index:R, Charset:xa, Encoder:K, Document:M, Worker:null, Resolver:null, IndexedDB:null, Language:{}}, Z = self; let Da; (Da = Z.define) && Da.amd ? Da([], function() { return Ca; diff --git a/dist/flexsearch.compact.min.js b/dist/flexsearch.compact.min.js index f014b06..5365deb 100644 --- a/dist/flexsearch.compact.min.js +++ b/dist/flexsearch.compact.min.js @@ -19,34 +19,34 @@ y(a.minlength,1,this.minlength);this.maxlength=y(a.maxlength,0,this.maxlength);i J.prototype.encode=function(a){if(this.cache&&a.length<=this.h)if(this.J){if(this.F.has(a))return this.F.get(a)}else this.J=setTimeout(ha,0,this);this.normalize&&(a="function"===typeof this.normalize?this.normalize(a):I?a.normalize("NFKD").replace(I,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(l)),k=1);this.matcher&& 1this.matcher.get(l)),k=1);g&&k&&(g.lengththis.O&&(this.H.clear(),this.D=this.D/1.1|0));g&&b.push(g)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.h&&(this.F.set(a,b),this.F.size>this.O&&(this.F.clear(),this.h=this.h/1.1|0));return b};function ha(a){a.J=null;a.F.clear();a.H.clear()};function ia(a,c,b){a=("object"===typeof a?""+a.query:a).toLowerCase();let e=this.cache.get(a);if(!e){e=this.search(a,c,b);if(e.then){const d=this;e.then(function(f){d.cache.set(a,f);return f})}this.cache.set(a,e)}return e}function K(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}K.prototype.set=function(a,c){this.cache.set(this.h=a,c);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)}; -K.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};K.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};K.prototype.clear=function(){this.cache.clear();this.h=""};const ja={normalize:function(a){return a.toLowerCase()},dedupe:!1};const L=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const ka=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),la=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];const ma={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const na=/[\x00-\x7F]+/g;const oa=/[\x00-\x7F]+/g;const pa=/[\x00-\x7F]+/g;var qa={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:ja,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:L},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:L,replacer:la,matcher:ka},LatinExtra:{normalize:!0,dedupe:!0,mapper:L,replacer:la.concat([/(?!^)[aeoy]/g,""]),matcher:ka},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bf;h--){g=q.substring(f,h);var k=this.score?this.score(c,q,p,g,f):O(t,e,p,d,f);P(this,m,g,k,a,b)}break}case "reverse":if(1< -d){for(h=d-1;0g?0:1),e,p,h-1,k-1),w=this.bidirectional&&q>f;P(this,l,w?f:q,u,a,b,w?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function P(a,c,b,e,d,f,g){let h=g?a.ctx:a.map,k;c[b]&&g&&(k=c[b])[g]||(g?(c=k||(c[b]=z()),c[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[e]||(h[e]=[]),f&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h]))))}function O(a,c,b,e,d){return b&&1c?c?a.slice(b,b+c):a.slice(b):a;let e=[];for(let d=0,f,g;d=g){b-=g;continue}bc&&(f=f.slice(0,c),g=f.length),e.push(f);else{if(g>=c)return g>c&&(f=f.slice(0,c)),f;e=[f]}c-=g;if(!c)break}return e.length?e=1this.O&&(this.H.clear(),this.D=this.D/1.1|0));g&&b.push(g)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.h&&(this.F.set(a,b),this.F.size>this.O&&(this.F.clear(),this.h=this.h/1.1|0));return b};function ha(a){a.J=null;a.F.clear();a.H.clear()};function ia(a){K.call(a,"add");K.call(a,"append");K.call(a,"search");K.call(a,"update");K.call(a,"remove")}function K(a){this[a+"Async"]=function(){var c=arguments;const b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);c=this[a].apply(this,c);e&&(c.then?c.then(e):e(c));return c}};function ja(a,c,b,e,d,f,g,h){(e=a(b?b+"."+e:e,JSON.stringify(g)))&&e.then?e.then(function(){c.export(a,c,b,d,f+1,h)}):c.export(a,c,b,d,f+1,h)};L.prototype.add=function(a,c,b){F(a)&&(c=a,a=G(c,this.key));if(c&&(a||0===a)){if(!b&&this.reg.has(a))return this.update(a,c);for(let h=0,k;hb||e)a=a.slice(e,e+b);d&&(a=ma.call(this,a));return a}} +function ma(a){const c=Array(a.length);for(let b=0,e;b{f=k}));d||(d=0);e||(e=0);if(ethis.limit&&this.cache.delete(this.cache.keys().next().value)}; +Q.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};Q.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};Q.prototype.clear=function(){this.cache.clear();this.h=""};const qa={normalize:function(a){return a.toLowerCase()},dedupe:!1};const S=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const ra=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),sa=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];const ta={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const ua=/[\x00-\x7F]+/g;const va=/[\x00-\x7F]+/g;const wa=/[\x00-\x7F]+/g;var ya={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:qa,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:S},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:S,replacer:sa,matcher:ra},LatinExtra:{normalize:!0,dedupe:!0,mapper:S,replacer:sa.concat([/(?!^)[aeoy]/g,""]),matcher:ra},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bf;h--){g=q.substring(f,h);var k=this.score?this.score(c,q,p,g,f):T(t,e,p,d,f);U(this,m,g,k,a,b)}break}case "reverse":if(1< +d){for(h=d-1;0g?0:1),e,p,h-1,k-1),w=this.bidirectional&&q>f;U(this,l,w?f:q,u,a,b,w?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function U(a,c,b,e,d,f,g){let h=g?a.ctx:a.map,k;if(!c[b]||g&&!(k=c[b])[g])g?(c=k||(c[b]=z()),c[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[e]||(h[e]=[]),f&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h])))}function T(a,c,b,e,d){return b&&1c?c?a.slice(b,b+c):a.slice(b):a;let e=[];for(let d=0,f,g;d=g){b-=g;continue}bc&&(f=f.slice(0,c),g=f.length),e.push(f);else{if(g>=c)return g>c&&(f=f.slice(0,c)),f;e=[f]}c-=g;if(!c)break}return e.length?e=1c||d)b=b.slice(d,c+d)}e=b}return e}; -function Q(a,c,b,e){return(a=S(this,a,c))&&a.length?ua(a,b,e):[]}function wa(a,c,b,e){let d=[];if(a){e=Math.min(a.length,e);for(let f=0,g;fb);a=b?(a=a.ctx.get(e?c:b))&&a.get(e?b:c):a.map.get(c);return a};N.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else T(this.map,a),this.depth&&T(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function T(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)}; -function U(a){let c=0;if(a.constructor===Array)for(let b=0,e;b{f=l}));let h,k;switch(d||(d=0)){case 0:h="reg";if(this.fastupdate){k=z();for(let l of this.reg.keys())k[l]=1}else k=this.reg;break;case 1:h="cfg";k={doc:0,opt:this.h?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.ctx;break;default:"undefined"===typeof b&&f&&f();return}ra(a,c||this,b,h,e,d,k,f);return g}; +function V(a,c,b,e){return(a=W(this,a,c))&&a.length?Aa(a,b,e):[]}function Ba(a,c,b,e){let d=[];if(a){e=Math.min(a.length,e);for(let f=0,g;fb);a=b?(a=a.ctx.get(e?c:b))&&a.get(e?b:c):a.map.get(c);return a};R.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else X(this.map,a),this.depth&&X(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function X(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)}; +function Y(a){let c=0;if(a.constructor===Array)for(let b=0,e;b{f=l}));let h,k;switch(d||(d=0)){case 0:h="reg";if(this.fastupdate){k=z();for(let l of this.reg.keys())k[l]=1}else k=this.reg;break;case 1:h="cfg";k={doc:0,opt:this.h?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.ctx;break;default:"undefined"===typeof b&&f&&f();return}ja(a,c||this,b,h,e,d,k,f);return g}; v.import=function(a,c){if(c)switch(C(c)&&(c=JSON.parse(c)),a){case "cfg":this.h=!!c.opt;break;case "reg":this.fastupdate=!1;this.reg=c;break;case "map":this.map=c;break;case "ctx":this.ctx=c}}; v.serialize=function(a=!0){if(!this.reg.size)return"";let c="",b="";for(var e of this.reg.keys())b||(b=typeof e),c+=(c?",":"")+("string"===b?'"'+e+'"':e);c="index.reg=new Set(["+c+"]);";e="";for(var d of this.map.entries()){var f=d[0],g=d[1],h="";for(let m=0,n;mb||e)a=a.slice(e,e+b);d&&(a=ya.call(this,a));return a}} -function ya(a){const c=Array(a.length);for(let b=0,e;b{f=k}));d||(d=0);e||(e=0);if(e b || e) { + f = f.slice(e, e + b); + } + d && (f = la.call(this, f)); + return f; + } +} +function la(a) { + const c = Array(a.length); + for (let b = 0, e; b < a.length; b++) { + e = a[b], c[b] = {id:e, doc:this.store.get(e)}; + } + return c; +} +;function N(a) { + if (!this) { + return new N(a); + } + const c = a.document || a.doc || a; + var b; + this.C = []; + this.field = []; + this.I = []; + this.key = (b = c.key || c.id) && Q(b, this.I) || "id"; + this.reg = (this.fastupdate = !!a.fastupdate) ? new Map() : new Set(); + this.A = (b = c.store || null) && !0 !== b && []; + this.store = b && new Map(); + this.cache = (b = a.cache || null) && new R(b); + a.cache = !1; + b = new Map(); + let e = c.index || c.field || c; + A(e) && (e = [e]); + for (let d = 0, f, g; d < e.length; d++) { + f = e[d], A(f) || (g = f, f = f.field), g = F(g) ? Object.assign({}, a, g) : a, b.set(f, new S(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = Q(f, this.I), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].G = g.filter)), this.field[d] = f; + } + if (this.A) { + a = c.store; + A(a) && (a = [a]); + for (let d = 0, f, g; d < a.length; d++) { + f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.S = g) : (this.A[d] = Q(g, this.I), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].G = f.filter)); + } + } + this.index = b; + this.tag = null; + if (b = c.tag) { + if ("string" === typeof b && (b = [b]), b.length) { + this.tag = new Map(); + this.B = []; + this.R = []; + for (let d = 0, f, g; d < b.length; d++) { + f = b[d]; + g = f.field || f; + if (!g) { + throw Error("The tag field from the document descriptor is undefined."); + } + f.custom ? this.B[d] = f.custom : (this.B[d] = Q(g, this.I), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].G = f.filter)); + this.R[d] = g; + this.tag.set(g, new Map()); + } + } + } +} +function Q(a, c) { + const b = a.split(":"); + let e = 0; + for (let d = 0; d < b.length; d++) { + a = b[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (c[e] = !0), a && (b[e++] = a); + } + e < b.length && (b.length = e); + return 1 < e ? b : b[0]; +} +v = N.prototype; +v.append = function(a, c) { + return this.add(a, c, !0); +}; +v.update = function(a, c) { + return this.remove(a).add(a, c); +}; +v.remove = function(a) { + F(a) && (a = G(a, this.key)); + for (var c of this.index.values()) { + c.remove(a, !0); + } + if (this.reg.has(a)) { + if (this.tag && !this.fastupdate) { + for (let b of this.tag.values()) { + for (let e of b) { + c = e[0]; + const d = e[1], f = d.indexOf(a); + -1 < f && (1 < d.length ? d.splice(f, 1) : b.delete(c)); + } + } + } + this.store && this.store.delete(a); + this.reg.delete(a); + } + this.cache && this.cache.remove(a); + return this; +}; +v.clear = function() { + for (const a of this.index.values()) { + a.clear(); + } + if (this.tag) { + for (const a of this.tag.values()) { + a.clear(); + } + } + this.store && this.store.clear(); + return this; +}; +v.contain = function(a) { + return this.reg.has(a); +}; +v.cleanup = function() { + for (const a of this.index.values()) { + a.cleanup(); + } + return this; +}; +v.get = function(a) { + return this.store.get(a); +}; +v.set = function(a, c) { + this.store.set(a, c); + return this; +}; +v.searchCache = oa; +v.export = function(a, c, b, e, d, f) { + let g; + "undefined" === typeof f && (g = new Promise(k => { + f = k; + })); + d || (d = 0); + e || (e = 0); + if (e < this.field.length) { + b = this.field[e]; + var h = this.index[b]; + c = this; + h.export(a, c, d ? b : "", e, d++, f) || (e++, c.export(a, c, b, e, 1, f)); + } else { + switch(d) { + case 1: + c = "tag"; + h = this.D; + b = null; + break; + case 2: + c = "store"; + h = this.store; + b = null; + break; + default: + f(); + return; + } + ia(a, this, b, c, e, d, h, f); + } + return g; +}; +v.import = function(a, c) { + if (c) { + switch(A(c) && (c = JSON.parse(c)), a) { + case "tag": + this.D = c; + break; + case "reg": + this.fastupdate = !1; + this.reg = c; + for (let e = 0, d; e < this.field.length; e++) { + d = this.index[this.field[e]], d.reg = c, d.fastupdate = !1; + } + break; + case "store": + this.store = c; + break; + default: + a = a.split("."); + const b = a[0]; + a = a[1]; + b && a && this.index[b].import(a, c); + } + } +}; +ha(N.prototype); +function oa(a, c, b) { a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); let e = this.cache.get(a); if (!e) { @@ -225,80 +744,57 @@ function L(a) { } return e; } -function M(a) { +function R(a) { this.limit = a && !0 !== a ? a : 1000; this.cache = new Map(); this.h = ""; } -M.prototype.set = function(a, c) { +R.prototype.set = function(a, c) { this.cache.set(this.h = a, c); this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); }; -M.prototype.get = function(a) { +R.prototype.get = function(a) { const c = this.cache.get(a); c && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, c)); return c; }; -M.prototype.remove = function(a) { +R.prototype.remove = function(a) { for (const c of this.cache) { const b = c[0]; c[1].includes(a) && this.cache.delete(b); } }; -M.prototype.clear = function() { +R.prototype.clear = function() { this.cache.clear(); this.h = ""; }; -const ia = {normalize:function(a) { +const pa = {normalize:function(a) { return a.toLowerCase(); }, dedupe:!1}; -const N = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); -const ja = new Map([["ai", "ei"], ["ae", "a"], ["oe", "o"], ["ue", "u"], ["sh", "s"], ["ch", "c"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), ka = [/([^aeo])h([aeo$])/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2"]; -const la = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; -const ma = /[\x00-\x7F]+/g; -const na = /[\x00-\x7F]+/g; -const oa = /[\x00-\x7F]+/g; -var pa = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:ia, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:N}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:N, replacer:ka, matcher:ja}, LatinExtra:{normalize:!0, dedupe:!0, mapper:N, replacer:ka.concat([/(?!^)[aeoy]/g, ""]), matcher:ja}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { +const T = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); +const qa = new Map([["ai", "ei"], ["ae", "a"], ["oe", "o"], ["ue", "u"], ["sh", "s"], ["ch", "c"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), ra = [/([^aeo])h([aeo$])/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2"]; +const sa = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; +const ta = /[\x00-\x7F]+/g; +const ua = /[\x00-\x7F]+/g; +const wa = /[\x00-\x7F]+/g; +var xa = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:pa, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:T}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:T, replacer:ra, matcher:qa}, LatinExtra:{normalize:!0, dedupe:!0, mapper:T, replacer:ra.concat([/(?!^)[aeoy]/g, ""]), matcher:qa}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { for (let b = 0; b < a.length; b++) { var c = a[b]; - let e = c.charAt(0), d = la[e]; - for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = la[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { + let e = c.charAt(0), d = sa[e]; + for (let f = 1, g; f < c.length && (g = c.charAt(f), "h" === g || "w" === g || !(g = sa[g]) || g === d || (e += g, d = g, 4 !== e.length)); f++) { } a[b] = e; } }}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(ma, " "); + return ("" + a).replace(ta, " "); }}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(na, ""); + return ("" + a).replace(ua, ""); }}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(oa, " "); + return ("" + a).replace(wa, " "); }}}; -function qa(a, c, b, e, d, f, g, h) { - (e = a(b ? b + "." + e : e, JSON.stringify(g))) && e.then ? e.then(function() { - c.export(a, c, b, d, f + 1, h); - }) : c.export(a, c, b, d, f + 1, h); -} -;const ra = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -function sa(a) { - O.call(a, "add"); - O.call(a, "append"); - O.call(a, "search"); - O.call(a, "update"); - O.call(a, "remove"); -} -function O(a) { - this[a + "Async"] = function() { - var c = arguments; - const b = c[c.length - 1]; - let e; - "function" === typeof b && (e = b, delete c[c.length - 1]); - c = this[a].apply(this, c); - e && (c.then ? c.then(e) : e(c)); - return c; - }; -} -;z(); -P.prototype.add = function(a, c, b, e) { +const ya = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +z(); +S.prototype.add = function(a, c, b, e) { if (c && (a || 0 === a)) { if (!e && !b && this.reg.has(a)) { return this.update(a, c); @@ -310,15 +806,15 @@ P.prototype.add = function(a, c, b, e) { let q = c[this.rtl ? e - 1 - p : p]; var d = q.length; if (d && (n || !m[q])) { - var f = this.score ? this.score(c, q, p, null, 0) : Q(t, e, p), g = ""; + var f = this.score ? this.score(c, q, p, null, 0) : U(t, e, p), g = ""; switch(this.tokenize) { case "full": if (2 < d) { for (f = 0; f < d; f++) { for (var h = d; h > f; h--) { g = q.substring(f, h); - var k = this.score ? this.score(c, q, p, g, f) : Q(t, e, p, d, f); - R(this, m, g, k, a, b); + var k = this.score ? this.score(c, q, p, g, f) : U(t, e, p, d, f); + V(this, m, g, k, a, b); } } break; @@ -326,24 +822,24 @@ P.prototype.add = function(a, c, b, e) { case "reverse": if (1 < d) { for (h = d - 1; 0 < h; h--) { - g = q[h] + g, k = this.score ? this.score(c, q, p, g, h) : Q(t, e, p, d, h), R(this, m, g, k, a, b); + g = q[h] + g, k = this.score ? this.score(c, q, p, g, h) : U(t, e, p, d, h), V(this, m, g, k, a, b); } g = ""; } case "forward": if (1 < d) { for (h = 0; h < d; h++) { - g += q[h], R(this, m, g, f, a, b); + g += q[h], V(this, m, g, f, a, b); } break; } default: - if (R(this, m, q, f, a, b), n && 1 < e && p < e - 1) { + if (V(this, m, q, f, a, b), n && 1 < e && p < e - 1) { for (d = z(), g = this.P, f = q, h = Math.min(n + 1, e - p), d[f] = 1, k = 1; k < h; k++) { if ((q = c[this.rtl ? e - 1 - p - k : p + k]) && !d[q]) { d[q] = 1; - const u = this.score ? this.score(c, f, p, q, k) : Q(g + (e / 2 > g ? 0 : 1), e, p, h - 1, k - 1), w = this.bidirectional && q > f; - R(this, l, w ? f : q, u, a, b, w ? q : f); + const u = this.score ? this.score(c, f, p, q, k) : U(g + (e / 2 > g ? 0 : 1), e, p, h - 1, k - 1), w = this.bidirectional && q > f; + V(this, l, w ? f : q, u, a, b, w ? q : f); } } } @@ -355,14 +851,16 @@ P.prototype.add = function(a, c, b, e) { } return this; }; -function R(a, c, b, e, d, f, g) { +function V(a, c, b, e, d, f, g) { let h = g ? a.ctx : a.map, k; - c[b] && g && (k = c[b])[g] || (g ? (c = k || (c[b] = z()), c[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[e] || (h[e] = []), f && h.includes(d) || (h.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(h) : a.reg.set(d, [h])))); + if (!c[b] || g && !(k = c[b])[g]) { + g ? (c = k || (c[b] = z()), c[g] = 1, (k = h.get(g)) ? h = k : h.set(g, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[e] || (h[e] = []), f && h.includes(d) || (h.push(d), a.fastupdate && ((c = a.reg.get(d)) ? c.push(h) : a.reg.set(d, [h]))); + } } -function Q(a, c, b, e, d) { +function U(a, c, b, e, d) { return b && 1 < a ? c + (e || 0) <= a ? b + (d || 0) : (a - 1) / (c + (e || 0)) * (b + (d || 0)) + 1 | 0 : 0; } -;function ta(a, c, b) { +;function za(a, c, b) { if (1 === a.length) { return a = a[0], a = b || a.length > c ? c ? a.slice(b, b + c) : a.slice(b) : a; } @@ -392,20 +890,7 @@ function Q(a, c, b, e, d) { } return e.length ? e = 1 < e.length ? [].concat.apply([], e) : e[0] : e; } -;function ua(a, c) { - const b = z(), e = []; - for (let d = 0, f; d < c.length; d++) { - f = c[d]; - for (let g = 0; g < f.length; g++) { - b[f[g]] = 1; - } - } - for (let d = 0, f; d < a.length; d++) { - f = a[d], 1 === b[f] && (e.push(f), b[f] = 2); - } - return e; -} -;P.prototype.search = function(a, c, b) { +;S.prototype.search = function(a, c, b) { b || (!c && F(a) ? (b = a, a = "") : F(c) && (b = c, c = 0)); var e = [], d = 0; if (b) { @@ -419,11 +904,11 @@ function Q(a, c, b, e, d) { b = a.length; c || (c = 100); if (1 === b) { - return S.call(this, a[0], "", c, d); + return W.call(this, a[0], "", c, d); } f = this.depth && !1 !== f; if (2 === b && f && !g) { - return S.call(this, a[0], a[1], c, d); + return W.call(this, a[0], a[1], c, d); } var h = 0, k = 0; if (1 < b) { @@ -431,7 +916,7 @@ function Q(a, c, b, e, d) { const n = []; for (let t = 0, p; t < b; t++) { if ((p = a[t]) && !l[p]) { - if (g || T(this, p)) { + if (g || X(this, p)) { n.push(p), l[p] = 1; } else { return e; @@ -449,10 +934,10 @@ function Q(a, c, b, e, d) { } l = 0; if (1 === b) { - return S.call(this, a[0], "", c, d); + return W.call(this, a[0], "", c, d); } if (2 === b && f && !g) { - return S.call(this, a[0], a[1], c, d); + return W.call(this, a[0], a[1], c, d); } if (1 < b) { if (f) { @@ -464,7 +949,7 @@ function Q(a, c, b, e, d) { } for (let n, t; l < b; l++) { t = a[l]; - m ? (n = T(this, t, m), n = va(n, e, g, this.P), g && !1 === n && e.length || (m = t)) : (n = T(this, t, ""), n = va(n, e, g, this.resolution)); + m ? (n = X(this, t, m), n = Aa(n, e, g, this.P), g && !1 === n && e.length || (m = t)) : (n = X(this, t, ""), n = Aa(n, e, g, this.resolution)); if (n) { return n; } @@ -479,7 +964,7 @@ function Q(a, c, b, e, d) { return e; } if (1 === f) { - return ta(e[0], c, d); + return za(e[0], c, d); } } } @@ -543,10 +1028,10 @@ function Q(a, c, b, e, d) { } return e; }; -function S(a, c, b, e) { - return (a = T(this, a, c)) && a.length ? ta(a, b, e) : []; +function W(a, c, b, e) { + return (a = X(this, a, c)) && a.length ? za(a, b, e) : []; } -function va(a, c, b, e) { +function Aa(a, c, b, e) { let d = []; if (a) { e = Math.min(a.length, e); @@ -560,13 +1045,13 @@ function va(a, c, b, e) { } return !b && d; } -function T(a, c, b) { +function X(a, c, b) { let e; b && (e = a.bidirectional && c > b); a = b ? (a = a.ctx.get(e ? c : b)) && a.get(e ? b : c) : a.map.get(c); return a; } -;P.prototype.remove = function(a, c) { +;S.prototype.remove = function(a, c) { const b = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (b) { if (this.fastupdate) { @@ -581,14 +1066,14 @@ function T(a, c, b) { } } } else { - U(this.map, a), this.depth && U(this.ctx, a); + Y(this.map, a), this.depth && Y(this.ctx, a); } c || this.reg.delete(a); } this.cache && this.cache.remove(a); return this; }; -function U(a, c) { +function Y(a, c) { let b = 0; if (a.constructor === Array) { for (let e = 0, d, f; e < a.length; e++) { @@ -603,24 +1088,24 @@ function U(a, c) { } } else { for (let e of a) { - const d = e[0], f = U(e[1], c); + const d = e[0], f = Y(e[1], c); f ? b += f : a.delete(d); } } return b; } -;function P(a, c) { +;function S(a, c) { if (!this) { - return new P(a); + return new S(a); } if (a) { var b = A(a) ? a : a.preset; - b && (ra[b] || console.warn("Preset not found: " + b), a = Object.assign({}, ra[b], a)); + b && (ya[b] || console.warn("Preset not found: " + b), a = Object.assign({}, ya[b], a)); } else { a = {}; } b = a.context || {}; - const e = A(a.encoder) ? pa[a.encoder] : a.encode || a.encoder || ia; + const e = A(a.encoder) ? xa[a.encoder] : a.encode || a.encoder || pa; this.encoder = e.encode ? e : "object" === typeof e ? new K(e) : {encode:e}; let d; this.resolution = a.resolution || 9; @@ -635,9 +1120,9 @@ function U(a, c) { this.reg = c || (this.fastupdate ? new Map() : new Set()); this.P = b.resolution || 1; this.rtl = e.rtl || a.rtl || !1; - this.cache = (d = a.cache || null) && new M(d); + this.cache = (d = a.cache || null) && new R(d); } -v = P.prototype; +v = S.prototype; v.clear = function() { this.map.clear(); this.ctx.clear(); @@ -655,7 +1140,7 @@ v.update = function(a, c) { const b = this, e = this.remove(a); return e && e.then ? e.then(() => b.add(a, c)) : this.add(a, c); }; -function V(a) { +function Z(a) { let c = 0; if (a.constructor === Array) { for (let b = 0, e; b < a.length; b++) { @@ -663,7 +1148,7 @@ function V(a) { } } else { for (const b of a) { - const e = b[0], d = V(b[1]); + const e = b[0], d = Z(b[1]); d ? c += d : a.delete(e); } } @@ -673,11 +1158,11 @@ v.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - V(this.map); - this.depth && V(this.ctx); + Z(this.map); + this.depth && Z(this.ctx); return this; }; -v.searchCache = ha; +v.searchCache = oa; v.export = function(a, c, b, e, d, f) { let g = !0; "undefined" === typeof f && (g = new Promise(l => { @@ -712,7 +1197,7 @@ v.export = function(a, c, b, e, d, f) { "undefined" === typeof b && f && f(); return; } - qa(a, c || this, b, h, e, d, k, f); + ia(a, c || this, b, h, e, d, k, f); return g; }; v.import = function(a, c) { @@ -783,490 +1268,7 @@ v.serialize = function(a = !0) { d = "index.ctx=new Map([" + d + "]);"; return a ? "function inject(index){" + c + e + d + "}" : c + e + d; }; -sa(P.prototype); -W.prototype.add = function(a, c, b) { - F(a) && (c = a, a = G(c, this.key)); - if (c && (a || 0 === a)) { - if (!b && this.reg.has(a)) { - return this.update(a, c); - } - for (let h = 0, k; h < this.field.length; h++) { - k = this.C[h]; - var e = this.index.get(this.field[h]); - if ("function" === typeof k) { - var d = k(c); - d && e.add(a, d, !1, !0); - } else { - if (d = k.G, !d || d(c)) { - k.constructor === String ? k = ["" + k] : A(k) && (k = [k]), X(c, k, this.I, 0, e, a, k[0], b); - } - } - } - if (this.tag) { - for (e = 0; e < this.B.length; e++) { - var f = this.B[e], g = this.R[e]; - d = this.tag.get(g); - let h = z(); - if ("function" === typeof f) { - if (f = f(c), !f) { - continue; - } - } else { - const k = f.G; - if (k && !k(c)) { - continue; - } - f.constructor === String && (f = "" + f); - f = G(c, f); - } - if (d && f) { - A(f) && (f = [f]); - for (let k = 0, l, m; k < f.length; k++) { - l = f[k], h[l] || (h[l] = 1, (g = d.get(l)) ? m = g : d.set(l, m = []), b && m.includes(a) || (m.push(a), this.fastupdate && ((g = this.reg.get(a)) ? g.push(m) : this.reg.set(a, [m])))); - } - } else { - d || console.warn("Tag '" + g + "' was not found"); - } - } - } - if (this.store && (!b || !this.store.has(a))) { - let h; - if (this.A) { - h = z(); - for (let k = 0, l; k < this.A.length; k++) { - l = this.A[k]; - if ((b = l.G) && !b(c)) { - continue; - } - let m; - if ("function" === typeof l) { - m = l(c); - if (!m) { - continue; - } - l = [l.S]; - } else if (A(l) || l.constructor === String) { - h[l] = c[l]; - continue; - } - Y(c, h, l, 0, l[0], m); - } - } - this.store.set(a, h || c); - } - } - return this; -}; -function Y(a, c, b, e, d, f) { - a = a[d]; - if (e === b.length - 1) { - c[d] = f || a; - } else if (a) { - if (a.constructor === Array) { - for (c = c[d] = Array(a.length), d = 0; d < a.length; d++) { - Y(a, c, b, e, d); - } - } else { - c = c[d] || (c[d] = z()), d = b[++e], Y(a, c, b, e, d); - } - } -} -function X(a, c, b, e, d, f, g, h) { - if (a = a[g]) { - if (e === c.length - 1) { - if (a.constructor === Array) { - if (b[e]) { - for (c = 0; c < a.length; c++) { - d.add(f, a[c], !0, !0); - } - return; - } - a = a.join(" "); - } - d.add(f, a, h, !0); - } else { - if (a.constructor === Array) { - for (g = 0; g < a.length; g++) { - X(a, c, b, e, d, f, g, h); - } - } else { - g = c[++e], X(a, c, b, e, d, f, g, h); - } - } - } -} -;W.prototype.search = function(a, c, b, e) { - b || (!c && F(a) ? (b = a, a = "") : F(c) && (b = c, c = 0)); - let d = []; - var f = []; - let g, h, k, l, m, n, t = 0, p; - if (b) { - b.constructor === Array && (b = {index:b}); - a = b.query || a; - var q = b.pluck; - h = b.merge; - l = q || b.field || b.index; - m = this.tag && b.tag; - g = this.store && b.enrich; - k = b.suggest; - p = b.T; - c = b.limit || c; - n = b.offset || 0; - c || (c = 100); - if (m) { - m.constructor !== Array && (m = [m]); - var u = []; - for (let x = 0, r; x < m.length; x++) { - r = m[x]; - if (A(r)) { - throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); - } - if (r.field && r.tag) { - var w = r.tag; - if (w.constructor === Array) { - for (var B = 0; B < w.length; B++) { - u.push(r.field, w[B]); - } - } else { - u.push(r.field, w); - } - } else { - w = Object.keys(r); - for (let D = 0, E, C; D < w.length; D++) { - if (E = w[D], C = r[E], C.constructor === Array) { - for (B = 0; B < C.length; B++) { - u.push(E, C[B]); - } - } else { - u.push(E, C); - } - } - } - } - if (!u.length) { - throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); - } - m = u; - if (!a) { - e = []; - if (u.length) { - for (f = 0; f < u.length; f += 2) { - q = wa.call(this, u[f], u[f + 1], c, n, g), d.push({field:u[f], tag:u[f + 1], result:q}); - } - } - return e.length ? Promise.all(e).then(function(x) { - for (let r = 0; r < x.length; r++) { - d[r].result = x[r]; - } - return d; - }) : d; - } - } - A(l) && (l = [l]); - } - l || (l = this.field); - u = !e && (this.worker || this.db) && []; - for (let x = 0, r, D, E; x < l.length; x++) { - D = l[x]; - let C; - A(D) || (C = D, D = C.field, a = C.query || a, c = C.limit || c, n = C.offset || n, k = C.suggest || k, g = this.store && (C.enrich || g)); - if (e) { - r = e[x]; - } else { - if (w = C || b, B = this.index.get(D), m && (w.enrich = !1), u) { - u[x] = B.search(a, c, w); - w && g && (w.enrich = g); - continue; - } else { - r = B.search(a, c, w), w && g && (w.enrich = g); - } - } - E = r && r.length; - if (m && E) { - w = []; - B = 0; - for (let H = 0, I, ya; H < m.length; H += 2) { - I = this.tag.get(m[H]); - if (!I) { - if (console.warn("Tag '" + m[H] + ":" + m[H + 1] + "' will be skipped because there is no field '" + m[H] + "'."), k) { - continue; - } else { - return d; - } - } - if (ya = (I = I && I.get(m[H + 1])) && I.length) { - B++, w.push(I); - } else if (!k) { - return d; - } - } - if (B) { - r = ua(r, w); - E = r.length; - if (!E && !k) { - return d; - } - B--; - } - } - if (E) { - f[t] = D, d.push(r), t++; - } else if (1 === l.length) { - return d; - } - } - if (u) { - const x = this; - return Promise.all(u).then(function(r) { - return r.length ? x.search(a, c, b, r) : r; - }); - } - if (!t) { - return d; - } - if (q && (!g || !this.store)) { - return d[0]; - } - u = []; - for (let x = 0, r; x < f.length; x++) { - r = d[x]; - g && r.length && !r[0].doc && r.length && (r = xa.call(this, r)); - if (q) { - return r; - } - d[x] = {field:f[x], result:r}; - } - return h ? za(d, c) : p ? Aa(d, a, this.index, this.C, p) : d; -}; -function Aa(a, c, b, e, d) { - let f; - for (let g = 0, h, k, l, m; g < a.length; g++) { - h = a[g].result; - k = a[g].field; - l = b.get(k).encoder; - m = e[k.indexOf(k)]; - l !== f && (f = l, f.encode(c)); - for (let n = 0; n < h.length; n++) { - let t = "", p = G(h[n].doc, m), q = f.encode(p); - for (let u = 0; u < q.length; u++) { - t += q[u].replace(new RegExp("(" + q[u] + ")", "g"), d.replace("$1", p)); - } - console.log(a, b, d); - h[n].T = t; - } - } - return a; -} -function za(a, c) { - const b = [], e = z(); - for (let d = 0, f, g; d < a.length; d++) { - f = a[d]; - g = f.result; - for (let h = 0, k, l, m; h < g.length; h++) { - if (l = g[h], k = l.id, m = e[k]) { - m.push(f.field); - } else { - if (b.length === c) { - return b; - } - l.field = e[k] = [f.field]; - b.push(l); - } - } - } - return b; -} -function wa(a, c, b, e, d) { - let f = this.tag.get(a); - if (!f) { - return console.warn("Tag '" + a + "' was not found"), []; - } - if ((a = (f = f && f.get(c)) && f.length - e) && 0 < a) { - if (a > b || e) { - f = f.slice(e, e + b); - } - d && (f = xa.call(this, f)); - return f; - } -} -function xa(a) { - const c = Array(a.length); - for (let b = 0, e; b < a.length; b++) { - e = a[b], c[b] = {id:e, doc:this.store.get(e)}; - } - return c; -} -;function W(a) { - if (!this) { - return new W(a); - } - const c = a.document || a.doc || a; - var b; - this.C = []; - this.field = []; - this.I = []; - this.key = (b = c.key || c.id) && Z(b, this.I) || "id"; - this.reg = (this.fastupdate = !!a.fastupdate) ? new Map() : new Set(); - this.A = (b = c.store || null) && !0 !== b && []; - this.store = b && new Map(); - this.cache = (b = a.cache || null) && new M(b); - a.cache = !1; - b = new Map(); - let e = c.index || c.field || c; - A(e) && (e = [e]); - for (let d = 0, f, g; d < e.length; d++) { - f = e[d], A(f) || (g = f, f = f.field), g = F(g) ? Object.assign({}, a, g) : a, b.set(f, new P(g, this.reg)), g.custom ? this.C[d] = g.custom : (this.C[d] = Z(f, this.I), g.filter && ("string" === typeof this.C[d] && (this.C[d] = new String(this.C[d])), this.C[d].G = g.filter)), this.field[d] = f; - } - if (this.A) { - a = c.store; - A(a) && (a = [a]); - for (let d = 0, f, g; d < a.length; d++) { - f = a[d], g = f.field || f, f.custom ? (this.A[d] = f.custom, f.custom.S = g) : (this.A[d] = Z(g, this.I), f.filter && ("string" === typeof this.A[d] && (this.A[d] = new String(this.A[d])), this.A[d].G = f.filter)); - } - } - this.index = b; - this.tag = null; - if (b = c.tag) { - if ("string" === typeof b && (b = [b]), b.length) { - this.tag = new Map(); - this.B = []; - this.R = []; - for (let d = 0, f, g; d < b.length; d++) { - f = b[d]; - g = f.field || f; - if (!g) { - throw Error("The tag field from the document descriptor is undefined."); - } - f.custom ? this.B[d] = f.custom : (this.B[d] = Z(g, this.I), f.filter && ("string" === typeof this.B[d] && (this.B[d] = new String(this.B[d])), this.B[d].G = f.filter)); - this.R[d] = g; - this.tag.set(g, new Map()); - } - } - } -} -function Z(a, c) { - const b = a.split(":"); - let e = 0; - for (let d = 0; d < b.length; d++) { - a = b[d], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (c[e] = !0), a && (b[e++] = a); - } - e < b.length && (b.length = e); - return 1 < e ? b : b[0]; -} -v = W.prototype; -v.append = function(a, c) { - return this.add(a, c, !0); -}; -v.update = function(a, c) { - return this.remove(a).add(a, c); -}; -v.remove = function(a) { - F(a) && (a = G(a, this.key)); - for (var c of this.index.values()) { - c.remove(a, !0); - } - if (this.reg.has(a)) { - if (this.tag && !this.fastupdate) { - for (let b of this.tag.values()) { - for (let e of b) { - c = e[0]; - const d = e[1], f = d.indexOf(a); - -1 < f && (1 < d.length ? d.splice(f, 1) : b.delete(c)); - } - } - } - this.store && this.store.delete(a); - this.reg.delete(a); - } - this.cache && this.cache.remove(a); - return this; -}; -v.clear = function() { - for (const a of this.index.values()) { - a.clear(); - } - if (this.tag) { - for (const a of this.tag.values()) { - a.clear(); - } - } - this.store && this.store.clear(); - return this; -}; -v.contain = function(a) { - return this.reg.has(a); -}; -v.cleanup = function() { - for (const a of this.index.values()) { - a.cleanup(); - } - return this; -}; -v.get = function(a) { - return this.store.get(a); -}; -v.set = function(a, c) { - this.store.set(a, c); - return this; -}; -v.searchCache = ha; -v.export = function(a, c, b, e, d, f) { - let g; - "undefined" === typeof f && (g = new Promise(k => { - f = k; - })); - d || (d = 0); - e || (e = 0); - if (e < this.field.length) { - b = this.field[e]; - var h = this.index[b]; - c = this; - h.export(a, c, d ? b : "", e, d++, f) || (e++, c.export(a, c, b, e, 1, f)); - } else { - switch(d) { - case 1: - c = "tag"; - h = this.D; - b = null; - break; - case 2: - c = "store"; - h = this.store; - b = null; - break; - default: - f(); - return; - } - qa(a, this, b, c, e, d, h, f); - } - return g; -}; -v.import = function(a, c) { - if (c) { - switch(A(c) && (c = JSON.parse(c)), a) { - case "tag": - this.D = c; - break; - case "reg": - this.fastupdate = !1; - this.reg = c; - for (let e = 0, d; e < this.field.length; e++) { - d = this.index[this.field[e]], d.reg = c, d.fastupdate = !1; - } - break; - case "store": - this.store = c; - break; - default: - a = a.split("."); - const b = a[0]; - a = a[1]; - b && a && this.index[b].import(a, c); - } - } -}; -sa(W.prototype); -export default {Index:P, Charset:pa, Encoder:K, Document:W, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; +ha(S.prototype); +export default {Index:S, Charset:xa, Encoder:K, Document:N, Worker:null, Resolver:null, IndexedDB:null, Language:{}}; -export const Index=P;export const Charset=pa;export const Encoder=K;export const Document=W;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file +export const Index=S;export const Charset=xa;export const Encoder=K;export const Document=N;export const Worker=null;export const Resolver=null;export const IndexedDB=null;export const Language={}; \ No newline at end of file diff --git a/dist/flexsearch.compact.module.min.js b/dist/flexsearch.compact.module.min.js index a7613c9..90123ee 100644 --- a/dist/flexsearch.compact.module.min.js +++ b/dist/flexsearch.compact.module.min.js @@ -19,35 +19,35 @@ y(a.minlength,1,this.minlength);this.maxlength=y(a.maxlength,0,this.maxlength);i J.prototype.encode=function(a){if(this.cache&&a.length<=this.h)if(this.J){if(this.F.has(a))return this.F.get(a)}else this.J=setTimeout(K,0,this);this.normalize&&(a="function"===typeof this.normalize?this.normalize(a):I?a.normalize("NFKD").replace(I,"").toLowerCase():a.toLowerCase());this.prepare&&(a=this.prepare(a));this.numeric&&3this.stemmer.get(l)),k=1);this.matcher&&1this.matcher.get(l)),k=1);g&&k&&(g.lengththis.O&&(this.H.clear(),this.D=this.D/1.1|0));g&&b.push(g)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.h&&(this.F.set(a,b),this.F.size>this.O&&(this.F.clear(),this.h=this.h/1.1|0));return b};function K(a){a.J=null;a.F.clear();a.H.clear()};function ha(a,c,b){a=("object"===typeof a?""+a.query:a).toLowerCase();let e=this.cache.get(a);if(!e){e=this.search(a,c,b);if(e.then){const d=this;e.then(function(f){d.cache.set(a,f);return f})}this.cache.set(a,e)}return e}function L(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}L.prototype.set=function(a,c){this.cache.set(this.h=a,c);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)}; -L.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};L.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};L.prototype.clear=function(){this.cache.clear();this.h=""};const ia={normalize:function(a){return a.toLowerCase()},dedupe:!1};const M=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const ja=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),ka=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];const la={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const ma=/[\x00-\x7F]+/g;const na=/[\x00-\x7F]+/g;const oa=/[\x00-\x7F]+/g;var pa={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:ia,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:M},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:M,replacer:ka,matcher:ja},LatinExtra:{normalize:!0,dedupe:!0,mapper:M,replacer:ka.concat([/(?!^)[aeoy]/g,""]),matcher:ja},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bf;h--){g=q.substring(f,h);var k=this.score?this.score(c,q,p,g,f):P(t,e,p,d,f);Q(this,m,g,k,a,b)}break}case "reverse":if(1< -d){for(h=d-1;0g?0:1),e,p,h-1,k-1),w=this.bidirectional&&q>f;Q(this,l,w?f:q,u,a,b,w?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function Q(a,c,b,e,d,f,g){let h=g?a.ctx:a.map,k;c[b]&&g&&(k=c[b])[g]||(g?(c=k||(c[b]=z()),c[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[e]||(h[e]=[]),f&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h]))))}function P(a,c,b,e,d){return b&&1c?c?a.slice(b,b+c):a.slice(b):a;let e=[];for(let d=0,f,g;d=g){b-=g;continue}bc&&(f=f.slice(0,c),g=f.length),e.push(f);else{if(g>=c)return g>c&&(f=f.slice(0,c)),f;e=[f]}c-=g;if(!c)break}return e.length?e=1this.O&&(this.H.clear(),this.D=this.D/1.1|0));g&&b.push(g)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.h&&(this.F.set(a,b),this.F.size>this.O&&(this.F.clear(),this.h=this.h/1.1|0));return b};function K(a){a.J=null;a.F.clear();a.H.clear()};function ha(a){L.call(a,"add");L.call(a,"append");L.call(a,"search");L.call(a,"update");L.call(a,"remove")}function L(a){this[a+"Async"]=function(){var c=arguments;const b=c[c.length-1];let e;"function"===typeof b&&(e=b,delete c[c.length-1]);c=this[a].apply(this,c);e&&(c.then?c.then(e):e(c));return c}};function ia(a,c,b,e,d,f,g,h){(e=a(b?b+"."+e:e,JSON.stringify(g)))&&e.then?e.then(function(){c.export(a,c,b,d,f+1,h)}):c.export(a,c,b,d,f+1,h)};M.prototype.add=function(a,c,b){F(a)&&(c=a,a=G(c,this.key));if(c&&(a||0===a)){if(!b&&this.reg.has(a))return this.update(a,c);for(let h=0,k;hb||e)a=a.slice(e,e+b);d&&(a=la.call(this,a));return a}} +function la(a){const c=Array(a.length);for(let b=0,e;b{f=k}));d||(d=0);e||(e=0);if(ethis.limit&&this.cache.delete(this.cache.keys().next().value)}; +R.prototype.get=function(a){const c=this.cache.get(a);c&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,c));return c};R.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}};R.prototype.clear=function(){this.cache.clear();this.h=""};const pa={normalize:function(a){return a.toLowerCase()},dedupe:!1};const T=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);const qa=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),ra=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];const sa={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};const ta=/[\x00-\x7F]+/g;const va=/[\x00-\x7F]+/g;const wa=/[\x00-\x7F]+/g;var xa={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:pa,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:T},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:T,replacer:ra,matcher:qa},LatinExtra:{normalize:!0,dedupe:!0,mapper:T,replacer:ra.concat([/(?!^)[aeoy]/g,""]),matcher:qa},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(let b=0;bf;h--){g=q.substring(f,h);var k=this.score?this.score(c,q,p,g,f):U(t,e,p,d,f);V(this,m,g,k,a,b)}break}case "reverse":if(1< +d){for(h=d-1;0g?0:1),e,p,h-1,k-1),w=this.bidirectional&&q>f;V(this,l,w?f:q,u,a,b,w?q:f)}}}}this.fastupdate||this.reg.add(a)}}return this}; +function V(a,c,b,e,d,f,g){let h=g?a.ctx:a.map,k;if(!c[b]||g&&!(k=c[b])[g])g?(c=k||(c[b]=z()),c[g]=1,(k=h.get(g))?h=k:h.set(g,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[e]||(h[e]=[]),f&&h.includes(d)||(h.push(d),a.fastupdate&&((c=a.reg.get(d))?c.push(h):a.reg.set(d,[h])))}function U(a,c,b,e,d){return b&&1c?c?a.slice(b,b+c):a.slice(b):a;let e=[];for(let d=0,f,g;d=g){b-=g;continue}bc&&(f=f.slice(0,c),g=f.length),e.push(f);else{if(g>=c)return g>c&&(f=f.slice(0,c)),f;e=[f]}c-=g;if(!c)break}return e.length?e=1c||d)b=b.slice(d,c+d)}e=b}return e}; -function S(a,c,b,e){return(a=T(this,a,c))&&a.length?ta(a,b,e):[]}function va(a,c,b,e){let d=[];if(a){e=Math.min(a.length,e);for(let f=0,g;fb);a=b?(a=a.ctx.get(e?c:b))&&a.get(e?b:c):a.map.get(c);return a};O.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else U(this.map,a),this.depth&&U(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; -function U(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)}; -function V(a){let c=0;if(a.constructor===Array)for(let b=0,e;b{f=l}));let h,k;switch(d||(d=0)){case 0:h="reg";if(this.fastupdate){k=z();for(let l of this.reg.keys())k[l]=1}else k=this.reg;break;case 1:h="cfg";k={doc:0,opt:this.h?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.ctx;break;default:"undefined"===typeof b&&f&&f();return}qa(a,c||this,b,h,e,d,k,f);return g}; +function W(a,c,b,e){return(a=X(this,a,c))&&a.length?za(a,b,e):[]}function Aa(a,c,b,e){let d=[];if(a){e=Math.min(a.length,e);for(let f=0,g;fb);a=b?(a=a.ctx.get(e?c:b))&&a.get(e?b:c):a.map.get(c);return a};S.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let e=0,d;ed.length)d.pop();else{const f=d.indexOf(a);f===b.length-1?d.pop():d.splice(f,1)}}else Y(this.map,a),this.depth&&Y(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; +function Y(a,c){let b=0;if(a.constructor===Array)for(let e=0,d,f;eb.add(a,c)):this.add(a,c)}; +function Z(a){let c=0;if(a.constructor===Array)for(let b=0,e;b{f=l}));let h,k;switch(d||(d=0)){case 0:h="reg";if(this.fastupdate){k=z();for(let l of this.reg.keys())k[l]=1}else k=this.reg;break;case 1:h="cfg";k={doc:0,opt:this.h?1:0};break;case 2:h="map";k=this.map;break;case 3:h="ctx";k=this.ctx;break;default:"undefined"===typeof b&&f&&f();return}ia(a,c||this,b,h,e,d,k,f);return g}; v.import=function(a,c){if(c)switch(C(c)&&(c=JSON.parse(c)),a){case "cfg":this.h=!!c.opt;break;case "reg":this.fastupdate=!1;this.reg=c;break;case "map":this.map=c;break;case "ctx":this.ctx=c}}; v.serialize=function(a=!0){if(!this.reg.size)return"";let c="",b="";for(var e of this.reg.keys())b||(b=typeof e),c+=(c?",":"")+("string"===b?'"'+e+'"':e);c="index.reg=new Set(["+c+"]);";e="";for(var d of this.map.entries()){var f=d[0],g=d[1],h="";for(let m=0,n;mb||e)a=a.slice(e,e+b);d&&(a=xa.call(this,a));return a}} -function xa(a){const c=Array(a.length);for(let b=0,e;b{f=k}));d||(d=0);e||(e=0);if(e this.limit && this.cache.delete(this.cache.keys().next().value); -}; -R.prototype.get = function(a) { - var b = this.cache.get(a); - b && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, b)); - return b; -}; -R.prototype.remove = function(a) { - for (var b = w(this.cache), c = b.next(); !c.done; c = b.next()) { - c = c.value; - var d = c[0]; - c[1].includes(a) && this.cache.delete(d); - } -}; -R.prototype.clear = function() { - this.cache.clear(); - this.h = ""; -}; -var Ia = {normalize:function(a) { - return a.toLowerCase(); -}, dedupe:!1}; -var Ja = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); -var Ka = new Map([["ai", "ei"], ["ae", "a"], ["oe", "o"], ["ue", "u"], ["sh", "s"], ["ch", "c"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), La = [/([^aeo])h([aeo$])/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2"]; -var Ma = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; -var Na = /[\x00-\x7F]+/g; -var Oa = /[\x00-\x7F]+/g; -var Pa = /[\x00-\x7F]+/g; -var Qa = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:Ia, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:Ja}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:Ja, replacer:La, matcher:Ka}, LatinExtra:{normalize:!0, dedupe:!0, mapper:Ja, replacer:La.concat([/(?!^)[aeoy]/g, ""]), matcher:Ka}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { - for (var b = 0; b < a.length; b++) { - for (var c = a[b], d = c.charAt(0), e = Ma[d], g = 1, f; g < c.length && (f = c.charAt(g), "h" === f || "w" === f || !(f = Ma[f]) || f === e || (d += f, e = f, 4 !== d.length)); g++) { +;function Ma(a) { + Na.call(a, "add"); + Na.call(a, "append"); + Na.call(a, "search"); + Na.call(a, "update"); + Na.call(a, "remove"); +} +function Na(a) { + this[a + "Async"] = function() { + var b = arguments, c = b[b.length - 1]; + if ("function" === typeof c) { + var d = c; + delete b[b.length - 1]; } - a[b] = d; - } -}}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Na, " "); -}}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { - return ("" + a).replace(Oa, ""); -}}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { - return ("" + a).replace(Pa, " "); -}}}; -function Ra(a, b, c, d) { + b = this[a].apply(this, b); + d && (b.then ? b.then(d) : d(b)); + return b; + }; +} +;function Oa(a, b, c, d, e, g, f, h) { + (d = a(c ? c + "." + d : d, JSON.stringify(f))) && d.then ? d.then(function() { + b.export(a, b, c, e, g + 1, h); + }) : b.export(a, b, c, e, g + 1, h); +} +;function Pa(a, b, c, d) { for (var e = [], g = 0, f; g < a.index.length; g++) { if (f = a.index[g], b >= f.length) { b -= f.length; @@ -1179,12 +1220,12 @@ function S(a) { } if ("slice" === d) { return function(e, g) { - return Ra(b, e || 0, g || b.length, !1); + return Pa(b, e || 0, g || b.length, !1); }; } if ("splice" === d) { return function(e, g) { - return Ra(b, e || 0, g || b.length, !0); + return Pa(b, e || 0, g || b.length, !0); }; } if ("constructor" === d) { @@ -1216,7 +1257,7 @@ function T(a) { this.index = M(); this.B = []; this.size = 0; - 32 < a ? (this.h = Sa, this.A = BigInt(a)) : (this.h = Ta, this.A = a); + 32 < a ? (this.h = Qa, this.A = BigInt(a)) : (this.h = Ra, this.A = a); } T.prototype.get = function(a) { var b = this.h(a); @@ -1233,7 +1274,7 @@ function U(a) { } this.index = M(); this.h = []; - 32 < a ? (this.B = Sa, this.A = BigInt(a)) : (this.B = Ta, this.A = a); + 32 < a ? (this.B = Qa, this.A = BigInt(a)) : (this.B = Ra, this.A = a); } U.prototype.add = function(a) { var b = this.B(a), c = this.index[b]; @@ -1253,9 +1294,9 @@ t.clear = U.prototype.clear = function() { this.h = []; this.size = 0; }; -t.values = U.prototype.values = function Ua() { +t.values = U.prototype.values = function Sa() { var b, c = this, d, e, g; - return qa(Ua, function(f) { + return qa(Sa, function(f) { switch(f.h) { case 1: b = 0; @@ -1279,9 +1320,9 @@ t.values = U.prototype.values = function Ua() { } }); }; -t.keys = U.prototype.keys = function Va() { +t.keys = U.prototype.keys = function Ta() { var b, c = this, d, e, g; - return qa(Va, function(f) { + return qa(Ta, function(f) { switch(f.h) { case 1: b = 0; @@ -1305,9 +1346,9 @@ t.keys = U.prototype.keys = function Va() { } }); }; -t.entries = U.prototype.entries = function Wa() { +t.entries = U.prototype.entries = function Ua() { var b, c = this, d, e, g; - return qa(Wa, function(f) { + return qa(Ua, function(f) { switch(f.h) { case 1: b = 0; @@ -1331,7 +1372,7 @@ t.entries = U.prototype.entries = function Wa() { } }); }; -function Ta(a) { +function Ra(a) { var b = Math.pow(2, this.A) - 1; if ("number" == typeof a) { return a & b; @@ -1341,154 +1382,138 @@ function Ta(a) { } return 32 === this.A ? c + Math.pow(2, 31) : c; } -function Sa() { +function Qa() { throw Error("The keystore is limited to 32 for EcmaScript5"); } -;function Xa(a, b, c, d, e, g, f, h) { - (d = a(c ? c + "." + d : d, JSON.stringify(f))) && d.then ? d.then(function() { - b.export(a, b, c, e, g + 1, h); - }) : b.export(a, b, c, e, g + 1, h); -} -;var Ya = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; -function Za(a) { - $a.call(a, "add"); - $a.call(a, "append"); - $a.call(a, "search"); - $a.call(a, "update"); - $a.call(a, "remove"); -} -function $a(a) { - this[a + "Async"] = function() { - var b = arguments, c = b[b.length - 1]; - if ("function" === typeof c) { - var d = c; - delete b[b.length - 1]; - } - b = this[a].apply(this, b); - d && (b.then ? b.then(d) : d(b)); - return b; - }; -} -;M(); -V.prototype.add = function(a, b, c, d) { +;V.prototype.add = function(a, b, c) { + O(a) && (b = a, a = xa(b, this.key)); if (b && (a || 0 === a)) { - if (!d && !c && this.reg.has(a)) { + if (!c && this.reg.has(a)) { return this.update(a, b); } - b = this.encoder.encode(b); - if (d = b.length) { - for (var e = M(), g = M(), f = this.depth, h = this.resolution, k = 0; k < d; k++) { - var l = b[this.rtl ? d - 1 - k : k], m = l.length; - if (m && (f || !g[l])) { - var n = this.score ? this.score(b, l, k, null, 0) : ab(h, d, k), p = ""; - switch(this.tokenize) { - case "full": - if (2 < m) { - for (n = 0; n < m; n++) { - for (var q = m; q > n; q--) { - p = l.substring(n, q); - var r = this.score ? this.score(b, l, k, p, n) : ab(h, d, k, m, n); - bb(this, g, p, r, a, c); + for (var d = 0, e; d < this.field.length; d++) { + e = this.I[d]; + var g = this.index.get(this.field[d]); + if ("function" === typeof e) { + (e = e(b)) && g.add(a, e, !1, !0); + } else { + var f = e.R; + if (!f || f(b)) { + e.constructor === String ? e = ["" + e] : N(e) && (e = [e]), Va(b, e, this.T, 0, g, a, e[0], c); + } + } + } + if (this.tag) { + for (d = 0; d < this.M.length; d++) { + f = this.M[d]; + var h = this.$[d]; + g = this.tag.get(h); + e = M(); + if ("function" === typeof f) { + if (f = f(b), !f) { + continue; + } + } else { + var k = f.R; + if (k && !k(b)) { + continue; + } + f.constructor === String && (f = "" + f); + f = xa(b, f); + } + if (g && f) { + for (N(f) && (f = [f]), h = 0, k = void 0; h < f.length; h++) { + var l = f[h]; + if (!e[l]) { + e[l] = 1; + var m; + (m = g.get(l)) ? k = m : g.set(l, k = []); + if (!c || !k.includes(a)) { + if (k.length === Math.pow(2, 31) - 1) { + m = new S(k); + if (this.fastupdate) { + for (var n = w(this.reg.values()), p = n.next(); !p.done; p = n.next()) { + p = p.value, p.includes(k) && (p[p.indexOf(k)] = m); + } } + g.set(l, k = m); } - break; + k.push(a); + this.fastupdate && ((l = this.reg.get(a)) ? l.push(k) : this.reg.set(a, [k])); } - case "reverse": - if (1 < m) { - for (q = m - 1; 0 < q; q--) { - p = l[q] + p, r = this.score ? this.score(b, l, k, p, q) : ab(h, d, k, m, q), bb(this, g, p, r, a, c); - } - p = ""; - } - case "forward": - if (1 < m) { - for (q = 0; q < m; q++) { - p += l[q], bb(this, g, p, n, a, c); - } - break; - } - default: - if (bb(this, g, l, n, a, c), f && 1 < d && k < d - 1) { - for (m = M(), p = this.aa, n = l, q = Math.min(f + 1, d - k), r = m[n] = 1; r < q; r++) { - if ((l = b[this.rtl ? d - 1 - k - r : k + r]) && !m[l]) { - m[l] = 1; - var u = this.score ? this.score(b, n, k, l, r) : ab(p + (d / 2 > p ? 0 : 1), d, k, q - 1, r - 1), x = this.bidirectional && l > n; - bb(this, e, x ? n : l, u, a, c, x ? l : n); - } - } + } + } + } else { + g || console.warn("Tag '" + h + "' was not found"); + } + } + } + if (this.store && (!c || !this.store.has(a))) { + if (this.H) { + var q = M(); + for (c = 0; c < this.H.length; c++) { + if (d = this.H[c], g = d.R, !g || g(b)) { + g = void 0; + if ("function" === typeof d) { + g = d(b); + if (!g) { + continue; } + d = [d.la]; + } else if (N(d) || d.constructor === String) { + q[d] = b[d]; + continue; + } + Wa(b, q, d, 0, d[0], g); } } } - this.fastupdate || this.reg.add(a); - } else { - b = ""; + this.store.set(a, q || b); } } - this.db && (b || this.commit_task.push({del:a}), this.da && cb(this)); return this; }; -function bb(a, b, c, d, e, g, f) { - var h = f ? a.ctx : a.map, k; - if (!b[c] || !f || !(k = b[c])[f]) { - if (f ? (b = k || (b[c] = M()), b[f] = 1, (k = h.get(f)) ? h = k : h.set(f, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !g || !h.includes(e)) { - if (h.length === Math.pow(2, 31) - 1) { - b = new S(h); - if (a.fastupdate) { - for (c = w(a.reg.values()), g = c.next(); !g.done; g = c.next()) { - g = g.value, g.includes(h) && (g[g.indexOf(h)] = b); +function Wa(a, b, c, d, e, g) { + a = a[e]; + if (d === c.length - 1) { + b[e] = g || a; + } else if (a) { + if (a.constructor === Array) { + for (b = b[e] = Array(a.length), e = 0; e < a.length; e++) { + Wa(a, b, c, d, e); + } + } else { + b = b[e] || (b[e] = M()), e = c[++d], Wa(a, b, c, d, e); + } + } +} +function Va(a, b, c, d, e, g, f, h) { + if (a = a[f]) { + if (d === b.length - 1) { + if (a.constructor === Array) { + if (c[d]) { + for (b = 0; b < a.length; b++) { + e.add(g, a[b], !0, !0); } + return; } - k[d] = h = b; + a = a.join(" "); } - h.push(e); - a.fastupdate && ((d = a.reg.get(e)) ? d.push(h) : a.reg.set(e, [h])); - } - } -} -function ab(a, b, c, d, e) { - return c && 1 < a ? b + (d || 0) <= a ? c + (e || 0) : (a - 1) / (b + (d || 0)) * (c + (e || 0)) + 1 | 0 : 0; -} -;function W(a, b, c, d) { - if (1 === a.length) { - return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, d ? db(a) : a; - } - for (var e = [], g = 0, f = void 0, h = void 0; g < a.length; g++) { - if ((f = a[g]) && (h = f.length)) { - if (c) { - if (c >= h) { - c -= h; - continue; + e.add(g, a, h, !0); + } else { + if (a.constructor === Array) { + for (f = 0; f < a.length; f++) { + Va(a, b, c, d, e, g, f, h); } - c < h && (f = b ? f.slice(c, c + b) : f.slice(c), h = f.length, c = 0); - } - if (e.length) { - h > b && (f = f.slice(0, b), h = f.length), e.push(f); } else { - if (h >= b) { - return h > b && (f = f.slice(0, b)), d ? db(f) : f; - } - e = [f]; - } - b -= h; - if (!b) { - break; + f = b[++d], Va(a, b, c, d, e, g, f, h); } } + } else { + e.db && e.remove(g); } - if (!e.length) { - return e; - } - e = 1 < e.length ? [].concat.apply([], e) : e[0]; - return d ? db(e) : e; } -function db(a) { - for (var b = 0; b < a.length; b++) { - a[b] = {score:b, id:a[b]}; - } - return a; -} -;function eb(a, b, c, d, e, g, f) { +;function Xa(a, b, c, d, e, g, f) { var h = a.length, k = [], l; var m = M(); for (var n = 0, p = void 0, q; n < b; n++) { @@ -1509,7 +1534,7 @@ function db(a) { } if (a = k.length) { if (e) { - k = 1 < k.length ? fb(k, d, c, f, 0) : k[0]; + k = 1 < k.length ? Ya(k, d, c, f, 0) : k[0]; } else { if (a < h) { return []; @@ -1542,7 +1567,7 @@ function db(a) { } return k; } -function fb(a, b, c, d, e) { +function Ya(a, b, c, d, e) { var g = [], f = M(), h = a.length, k = 0; if (d) { for (e = h - 1; 0 <= e; e--) { @@ -1584,7 +1609,7 @@ function fb(a, b, c, d, e) { } return g; } -function gb(a, b) { +function Za(a, b) { for (var c = M(), d = [], e = 0, g; e < b.length; e++) { g = b[e]; for (var f = 0; f < g.length; f++) { @@ -1596,7 +1621,691 @@ function gb(a, b) { } return d; } -;X.prototype.or = function() { +;V.prototype.search = function(a, b, c, d) { + c || (!b && O(a) ? (c = a, a = "") : O(b) && (c = b, b = 0)); + var e = [], g = [], f = 0; + if (c) { + c.constructor === Array && (c = {index:c}); + a = c.query || a; + var h = c.pluck; + var k = c.merge; + var l = h || c.field || c.index; + var m = this.tag && c.tag; + var n = this.store && c.enrich; + var p = c.suggest; + var q = c.na; + b = c.limit || b; + var r = c.offset || 0; + b || (b = 100); + if (m && (!this.db || !d)) { + m.constructor !== Array && (m = [m]); + for (var u = [], x = 0, y = void 0; x < m.length; x++) { + y = m[x]; + if (N(y)) { + throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); + } + if (y.field && y.tag) { + var v = y.tag; + if (v.constructor === Array) { + for (var z = 0; z < v.length; z++) { + u.push(y.field, v[z]); + } + } else { + u.push(y.field, v); + } + } else { + v = Object.keys(y); + z = 0; + for (var A = void 0, D = void 0; z < v.length; z++) { + if (A = v[z], D = y[A], D.constructor === Array) { + for (var E = 0; E < D.length; E++) { + u.push(A, D[E]); + } + } else { + u.push(A, D); + } + } + } + } + if (!u.length) { + throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); + } + m = u; + if (!a) { + g = []; + if (u.length) { + for (h = 0; h < u.length; h += 2) { + p = void 0; + if (this.db) { + p = this.index.get(u[h]); + if (!p) { + console.warn("Tag '" + u[h] + ":" + u[h + 1] + "' will be skipped because there is no field '" + u[h] + "'."); + continue; + } + g.push(p = p.db.tag(u[h + 1], b, r, n)); + } else { + p = ab.call(this, u[h], u[h + 1], b, r, n); + } + e.push({field:u[h], tag:u[h + 1], result:p}); + } + } + return g.length ? Promise.all(g).then(function(P) { + for (var Q = 0; Q < P.length; Q++) { + e[Q].result = P[Q]; + } + return e; + }) : e; + } + } + N(l) && (l = [l]); + } + l || (l = this.field); + u = !d && (this.worker || this.db) && []; + x = 0; + for (z = y = v = void 0; x < l.length; x++) { + if (y = l[x], !this.db || !this.tag || this.I[x]) { + v = void 0; + N(y) || (v = y, y = v.field, a = v.query || a, b = v.limit || b, r = v.offset || r, p = v.suggest || p, n = this.store && (v.enrich || n)); + if (d) { + v = d[x]; + } else { + z = v || c; + v = this.index.get(y); + if (m) { + if (this.db) { + z.tag = m; + var F = v.db.support_tag_search; + z.field = l; + } + F || (z.enrich = !1); + } + if (u) { + u[x] = v.search(a, b, z); + z && n && (z.enrich = n); + continue; + } else { + v = v.search(a, b, z), z && n && (z.enrich = n); + } + } + z = v && v.length; + if (m && z) { + A = []; + D = 0; + if (this.db && d) { + if (!F) { + for (E = l.length; E < d.length; E++) { + var K = d[E]; + if (K && K.length) { + D++, A.push(K); + } else if (!p) { + return e; + } + } + } + } else { + E = 0; + for (var Ib = K = void 0; E < m.length; E += 2) { + K = this.tag.get(m[E]); + if (!K) { + if (console.warn("Tag '" + m[E] + ":" + m[E + 1] + "' will be skipped because there is no field '" + m[E] + "'."), p) { + continue; + } else { + return e; + } + } + if (Ib = (K = K && K.get(m[E + 1])) && K.length) { + D++, A.push(K); + } else if (!p) { + return e; + } + } + } + if (D) { + v = Za(v, A); + z = v.length; + if (!z && !p) { + return e; + } + D--; + } + } + if (z) { + g[f] = y, e.push(v), f++; + } else if (1 === l.length) { + return e; + } + } + } + if (u) { + if (this.db && m && m.length && !F) { + for (n = 0; n < m.length; n += 2) { + g = this.index.get(m[n]); + if (!g) { + if (console.warn("Tag '" + m[n] + ":" + m[n + 1] + "' was not found because there is no field '" + m[n] + "'."), p) { + continue; + } else { + return e; + } + } + u.push(g.db.tag(m[n + 1], b, r, !1)); + } + } + var Jb = this; + return Promise.all(u).then(function(P) { + return P.length ? Jb.search(a, b, c, P) : P; + }); + } + if (!f) { + return e; + } + if (h && (!n || !this.store)) { + return e[0]; + } + u = []; + r = 0; + for (p = void 0; r < g.length; r++) { + p = e[r]; + n && p.length && !p[0].doc && (this.db ? u.push(p = this.index.get(this.field[0]).db.enrich(p)) : p.length && (p = bb.call(this, p))); + if (h) { + return p; + } + e[r] = {field:g[r], result:p}; + } + if (n && this.db && u.length) { + var $a = this; + return Promise.all(u).then(function(P) { + for (var Q = 0; Q < P.length; Q++) { + e[Q].result = P[Q]; + } + return k ? cb(e, b) : q ? db(e, a, $a.index, $a.I, q) : e; + }); + } + return k ? cb(e, b) : q ? db(e, a, this.index, this.I, q) : e; +}; +function db(a, b, c, d, e) { + for (var g, f = 0, h, k, l; f < a.length; f++) { + for (h = a[f].result, k = a[f].field, l = c.get(k).encoder, k = d[k.indexOf(k)], l !== g && (g = l, g.encode(b)), l = 0; l < h.length; l++) { + for (var m = "", n = xa(h[l].doc, k), p = g.encode(n), q = 0; q < p.length; q++) { + m += p[q].replace(new RegExp("(" + p[q] + ")", "g"), e.replace("$1", n)); + } + console.log(a, c, e); + h[l].na = m; + } + } + return a; +} +function cb(a, b) { + for (var c = [], d = M(), e = 0, g, f; e < a.length; e++) { + g = a[e]; + f = g.result; + for (var h = 0, k, l, m; h < f.length; h++) { + if (l = f[h], k = l.id, m = d[k]) { + m.push(g.field); + } else { + if (c.length === b) { + return c; + } + l.field = d[k] = [g.field]; + c.push(l); + } + } + } + return c; +} +function ab(a, b, c, d, e) { + var g = this.tag.get(a); + if (!g) { + return console.warn("Tag '" + a + "' was not found"), []; + } + if ((a = (g = g && g.get(b)) && g.length - d) && 0 < a) { + if (a > c || d) { + g = g.slice(d, d + c); + } + e && (g = bb.call(this, g)); + return g; + } +} +function bb(a) { + for (var b = Array(a.length), c = 0, d; c < a.length; c++) { + d = a[c], b[c] = {id:d, doc:this.store.get(d)}; + } + return b; +} +;function V(a) { + if (!this) { + return new V(a); + } + var b = a.document || a.doc || a, c, d; + this.I = []; + this.field = []; + this.T = []; + this.key = (c = b.key || b.id) && eb(c, this.T) || "id"; + (d = a.keystore || 0) && (this.keystore = d); + this.reg = (this.fastupdate = !!a.fastupdate) ? d ? new T(d) : new Map() : d ? new U(d) : new Set(); + this.H = (c = b.store || null) && !0 !== c && []; + this.store = c && (d ? new T(d) : new Map()); + this.cache = (c = a.cache || null) && new W(c); + a.cache = !1; + this.worker = a.worker; + this.index = fb.call(this, a, b); + this.tag = null; + if (c = b.tag) { + if ("string" === typeof c && (c = [c]), c.length) { + this.tag = new Map(); + this.M = []; + this.$ = []; + b = 0; + for (var e = d = void 0; b < c.length; b++) { + d = c[b]; + e = d.field || d; + if (!e) { + throw Error("The tag field from the document descriptor is undefined."); + } + d.custom ? this.M[b] = d.custom : (this.M[b] = eb(e, this.T), d.filter && ("string" === typeof this.M[b] && (this.M[b] = new String(this.M[b])), this.M[b].R = d.filter)); + this.$[b] = e; + this.tag.set(e, new Map()); + } + } + } + if (this.worker) { + a = []; + c = w(this.index.values()); + for (b = c.next(); !b.done; b = c.next()) { + b = b.value, b.then && a.push(b); + } + if (a.length) { + var g = this; + return Promise.all(a).then(function(f) { + for (var h = 0, k = w(g.index.entries()), l = k.next(); !l.done; l = k.next()) { + l = l.value; + var m = l[0]; + l[1].then && g.index.set(m, f[h++]); + } + return g; + }); + } + } else { + a.db && this.mount(a.db); + } +} +t = V.prototype; +t.mount = function(a) { + var b = this.field; + if (this.tag) { + for (var c = 0, d; c < this.$.length; c++) { + d = this.$[c]; + var e; + this.index.set(d, e = new R({}, this.reg)); + b === this.field && (b = b.slice(0)); + b.push(d); + e.tag = this.tag.get(d); + } + } + c = []; + d = {db:a.db, type:a.type, fastupdate:a.fastupdate}; + e = 0; + for (var g; e < b.length; e++) { + d.field = g = b[e]; + g = this.index.get(g); + var f = new a.constructor(a.id, d); + f.id = a.id; + c[e] = f.mount(g); + g.document = !0; + e ? g.bypass = !0 : g.store = this.store; + } + this.db = !0; + return Promise.all(c); +}; +t.commit = function(a, b) { + var c = this, d, e, g, f; + return I(function(h) { + if (1 == h.h) { + d = []; + e = w(c.index.values()); + for (g = e.next(); !g.done; g = e.next()) { + f = g.value, d.push(f.db.commit(f, a, b)); + } + return G(h, Promise.all(d), 2); + } + c.reg.clear(); + h.h = 0; + }); +}; +t.destroy = function() { + for (var a = [], b = w(this.index.values()), c = b.next(); !c.done; c = b.next()) { + a.push(c.value.destroy()); + } + return Promise.all(a); +}; +function fb(a, b) { + var c = new Map(), d = b.index || b.field || b; + N(d) && (d = [d]); + for (var e = 0, g, f = void 0; e < d.length; e++) { + g = d[e]; + N(g) || (f = g, g = g.field); + f = O(f) ? Object.assign({}, a, f) : a; + if (this.worker) { + var h = new Ja(f); + c.set(g, h); + } + this.worker || c.set(g, new R(f, this.reg)); + f.custom ? this.I[e] = f.custom : (this.I[e] = eb(g, this.T), f.filter && ("string" === typeof this.I[e] && (this.I[e] = new String(this.I[e])), this.I[e].R = f.filter)); + this.field[e] = g; + } + if (this.H) { + for (a = b.store, N(a) && (a = [a]), b = 0; b < a.length; b++) { + d = a[b], e = d.field || d, d.custom ? (this.H[b] = d.custom, d.custom.la = e) : (this.H[b] = eb(e, this.T), d.filter && ("string" === typeof this.H[b] && (this.H[b] = new String(this.H[b])), this.H[b].R = d.filter)); + } + } + return c; +} +function eb(a, b) { + for (var c = a.split(":"), d = 0, e = 0; e < c.length; e++) { + a = c[e], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (b[d] = !0), a && (c[d++] = a); + } + d < c.length && (c.length = d); + return 1 < d ? c : c[0]; +} +t.append = function(a, b) { + return this.add(a, b, !0); +}; +t.update = function(a, b) { + return this.remove(a).add(a, b); +}; +t.remove = function(a) { + O(a) && (a = xa(a, this.key)); + for (var b = w(this.index.values()), c = b.next(); !c.done; c = b.next()) { + c.value.remove(a, !0); + } + if (this.reg.has(a)) { + if (this.tag && !this.fastupdate) { + for (b = w(this.tag.values()), c = b.next(); !c.done; c = b.next()) { + c = c.value; + for (var d = w(c), e = d.next(); !e.done; e = d.next()) { + var g = e.value; + e = g[0]; + g = g[1]; + var f = g.indexOf(a); + -1 < f && (1 < g.length ? g.splice(f, 1) : c.delete(e)); + } + } + } + this.store && this.store.delete(a); + this.reg.delete(a); + } + this.cache && this.cache.remove(a); + return this; +}; +t.clear = function() { + for (var a = w(this.index.values()), b = a.next(); !b.done; b = a.next()) { + b.value.clear(); + } + if (this.tag) { + for (a = w(this.tag.values()), b = a.next(); !b.done; b = a.next()) { + b.value.clear(); + } + } + this.store && this.store.clear(); + return this; +}; +t.contain = function(a) { + return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a); +}; +t.cleanup = function() { + for (var a = w(this.index.values()), b = a.next(); !b.done; b = a.next()) { + b.value.cleanup(); + } + return this; +}; +t.get = function(a) { + return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(b) { + return b[0] && b[0].doc; + }) : this.store.get(a); +}; +t.set = function(a, b) { + this.store.set(a, b); + return this; +}; +t.searchCache = gb; +t.export = function(a, b, c, d, e, g) { + var f; + "undefined" === typeof g && (f = new Promise(function(k) { + g = k; + })); + e || (e = 0); + d || (d = 0); + if (d < this.field.length) { + c = this.field[d]; + var h = this.index[c]; + b = this; + h.export(a, b, e ? c : "", d, e++, g) || (d++, b.export(a, b, c, d, 1, g)); + } else { + switch(e) { + case 1: + b = "tag"; + h = this.A; + c = null; + break; + case 2: + b = "store"; + h = this.store; + c = null; + break; + default: + g(); + return; + } + Oa(a, this, c, b, d, e, h, g); + } + return f; +}; +t.import = function(a, b) { + if (b) { + switch(N(b) && (b = JSON.parse(b)), a) { + case "tag": + this.A = b; + break; + case "reg": + this.fastupdate = !1; + this.reg = b; + a = 0; + for (var c; a < this.field.length; a++) { + c = this.index[this.field[a]], c.reg = b, c.fastupdate = !1; + } + break; + case "store": + this.store = b; + break; + default: + a = a.split("."), c = a[0], a = a[1], c && a && this.index[c].import(a, b); + } + } +}; +Ma(V.prototype); +function gb(a, b, c) { + a = ("object" === typeof a ? "" + a.query : a).toLowerCase(); + var d = this.cache.get(a); + if (!d) { + d = this.search(a, b, c); + if (d.then) { + var e = this; + d.then(function(g) { + e.cache.set(a, g); + return g; + }); + } + this.cache.set(a, d); + } + return d; +} +function W(a) { + this.limit = a && !0 !== a ? a : 1000; + this.cache = new Map(); + this.h = ""; +} +W.prototype.set = function(a, b) { + this.cache.set(this.h = a, b); + this.cache.size > this.limit && this.cache.delete(this.cache.keys().next().value); +}; +W.prototype.get = function(a) { + var b = this.cache.get(a); + b && this.h !== a && (this.cache.delete(a), this.cache.set(this.h = a, b)); + return b; +}; +W.prototype.remove = function(a) { + for (var b = w(this.cache), c = b.next(); !c.done; c = b.next()) { + c = c.value; + var d = c[0]; + c[1].includes(a) && this.cache.delete(d); + } +}; +W.prototype.clear = function() { + this.cache.clear(); + this.h = ""; +}; +var hb = {normalize:function(a) { + return a.toLowerCase(); +}, dedupe:!1}; +var ib = new Map([["b", "p"], ["v", "f"], ["w", "f"], ["z", "s"], ["x", "s"], ["d", "t"], ["n", "m"], ["c", "k"], ["g", "k"], ["j", "k"], ["q", "k"], ["i", "e"], ["y", "e"], ["u", "o"]]); +var jb = new Map([["ai", "ei"], ["ae", "a"], ["oe", "o"], ["ue", "u"], ["sh", "s"], ["ch", "c"], ["th", "t"], ["ph", "f"], ["pf", "f"]]), kb = [/([^aeo])h([aeo$])/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2"]; +var lb = {a:"", e:"", i:"", o:"", u:"", y:"", b:1, f:1, p:1, v:1, c:2, g:2, j:2, k:2, q:2, s:2, x:2, z:2, "\u00df":2, d:3, t:3, l:4, m:5, n:5, r:6}; +var mb = /[\x00-\x7F]+/g; +var nb = /[\x00-\x7F]+/g; +var ob = /[\x00-\x7F]+/g; +var pb = {LatinExact:{normalize:!1, dedupe:!1}, LatinDefault:hb, LatinSimple:{normalize:!0, dedupe:!0}, LatinBalance:{normalize:!0, dedupe:!0, mapper:ib}, LatinAdvanced:{normalize:!0, dedupe:!0, mapper:ib, replacer:kb, matcher:jb}, LatinExtra:{normalize:!0, dedupe:!0, mapper:ib, replacer:kb.concat([/(?!^)[aeoy]/g, ""]), matcher:jb}, LatinSoundex:{normalize:!0, dedupe:!1, include:{letter:!0}, finalize:function(a) { + for (var b = 0; b < a.length; b++) { + for (var c = a[b], d = c.charAt(0), e = lb[d], g = 1, f; g < c.length && (f = c.charAt(g), "h" === f || "w" === f || !(f = lb[f]) || f === e || (d += f, e = f, 4 !== d.length)); g++) { + } + a[b] = d; + } +}}, ArabicDefault:{rtl:!0, normalize:!1, dedupe:!0, prepare:function(a) { + return ("" + a).replace(mb, " "); +}}, CjkDefault:{normalize:!1, dedupe:!0, split:"", prepare:function(a) { + return ("" + a).replace(nb, ""); +}}, CyrillicDefault:{normalize:!1, dedupe:!0, prepare:function(a) { + return ("" + a).replace(ob, " "); +}}}; +var qb = {memory:{resolution:1}, performance:{resolution:6, fastupdate:!0, context:{depth:1, resolution:3}}, match:{tokenize:"forward"}, score:{resolution:9, context:{depth:2, resolution:9}}}; +M(); +R.prototype.add = function(a, b, c, d) { + if (b && (a || 0 === a)) { + if (!d && !c && this.reg.has(a)) { + return this.update(a, b); + } + b = this.encoder.encode(b); + if (d = b.length) { + for (var e = M(), g = M(), f = this.depth, h = this.resolution, k = 0; k < d; k++) { + var l = b[this.rtl ? d - 1 - k : k], m = l.length; + if (m && (f || !g[l])) { + var n = this.score ? this.score(b, l, k, null, 0) : rb(h, d, k), p = ""; + switch(this.tokenize) { + case "full": + if (2 < m) { + for (n = 0; n < m; n++) { + for (var q = m; q > n; q--) { + p = l.substring(n, q); + var r = this.score ? this.score(b, l, k, p, n) : rb(h, d, k, m, n); + sb(this, g, p, r, a, c); + } + } + break; + } + case "reverse": + if (1 < m) { + for (q = m - 1; 0 < q; q--) { + p = l[q] + p, r = this.score ? this.score(b, l, k, p, q) : rb(h, d, k, m, q), sb(this, g, p, r, a, c); + } + p = ""; + } + case "forward": + if (1 < m) { + for (q = 0; q < m; q++) { + p += l[q], sb(this, g, p, n, a, c); + } + break; + } + default: + if (sb(this, g, l, n, a, c), f && 1 < d && k < d - 1) { + for (m = M(), p = this.aa, n = l, q = Math.min(f + 1, d - k), r = m[n] = 1; r < q; r++) { + if ((l = b[this.rtl ? d - 1 - k - r : k + r]) && !m[l]) { + m[l] = 1; + var u = this.score ? this.score(b, n, k, l, r) : rb(p + (d / 2 > p ? 0 : 1), d, k, q - 1, r - 1), x = this.bidirectional && l > n; + sb(this, e, x ? n : l, u, a, c, x ? l : n); + } + } + } + } + } + } + this.fastupdate || this.reg.add(a); + } else { + b = ""; + } + } + this.db && (b || this.commit_task.push({del:a}), this.da && tb(this)); + return this; +}; +function sb(a, b, c, d, e, g, f) { + var h = f ? a.ctx : a.map, k; + if (!b[c] || f && !(k = b[c])[f]) { + if (f ? (b = k || (b[c] = M()), b[f] = 1, (k = h.get(f)) ? h = k : h.set(f, h = new Map())) : b[c] = 1, (k = h.get(c)) ? h = k : h.set(c, h = k = []), h = h[d] || (h[d] = []), !g || !h.includes(e)) { + if (h.length === Math.pow(2, 31) - 1) { + b = new S(h); + if (a.fastupdate) { + for (c = w(a.reg.values()), g = c.next(); !g.done; g = c.next()) { + g = g.value, g.includes(h) && (g[g.indexOf(h)] = b); + } + } + k[d] = h = b; + } + h.push(e); + a.fastupdate && ((d = a.reg.get(e)) ? d.push(h) : a.reg.set(e, [h])); + } + } +} +function rb(a, b, c, d, e) { + return c && 1 < a ? b + (d || 0) <= a ? c + (e || 0) : (a - 1) / (b + (d || 0)) * (c + (e || 0)) + 1 | 0 : 0; +} +;function X(a, b, c, d) { + if (1 === a.length) { + return a = a[0], a = c || a.length > b ? b ? a.slice(c, c + b) : a.slice(c) : a, d ? ub(a) : a; + } + for (var e = [], g = 0, f = void 0, h = void 0; g < a.length; g++) { + if ((f = a[g]) && (h = f.length)) { + if (c) { + if (c >= h) { + c -= h; + continue; + } + c < h && (f = b ? f.slice(c, c + b) : f.slice(c), h = f.length, c = 0); + } + if (e.length) { + h > b && (f = f.slice(0, b), h = f.length), e.push(f); + } else { + if (h >= b) { + return h > b && (f = f.slice(0, b)), d ? ub(f) : f; + } + e = [f]; + } + b -= h; + if (!b) { + break; + } + } + } + if (!e.length) { + return e; + } + e = 1 < e.length ? [].concat.apply([], e) : e[0]; + return d ? ub(e) : e; +} +function ub(a) { + for (var b = 0; b < a.length; b++) { + a[b] = {score:b, id:a[b]}; + } + return a; +} +;Y.prototype.or = function() { var a = this, b = arguments, c = b[0]; if (c.then) { return c.then(function() { @@ -1615,7 +2324,7 @@ function gb(a, b) { f = l.enrich; h = l.resolve; var m = void 0; - if (l.constructor === X) { + if (l.constructor === Y) { m = l.result; } else if (l.constructor === Array) { m = l; @@ -1637,21 +2346,21 @@ function gb(a, b) { if (c.length) { return Promise.all(c).then(function() { a.result.length && (d = d.concat([a.result])); - a.result = hb(d, e, g, f, h, a.J); + a.result = vb(d, e, g, f, h, a.J); return h ? a.result : a; }); } - d.length && (this.result.length && (d = d.concat([this.result])), this.result = hb(d, e, g, f, h, this.J)); + d.length && (this.result.length && (d = d.concat([this.result])), this.result = vb(d, e, g, f, h, this.J)); return h ? this.result : this; }; -function hb(a, b, c, d, e, g) { +function vb(a, b, c, d, e, g) { if (!a.length) { return a; } "object" === typeof b && (c = b.offset || 0, d = b.enrich || !1, b = b.limit || 0); - return 2 > a.length ? e ? W(a[0], b, c, d) : a[0] : fb(a, c, b, e, g); + return 2 > a.length ? e ? X(a[0], b, c, d) : a[0] : Ya(a, c, b, e, g); } -;X.prototype.and = function() { +;Y.prototype.and = function() { if (this.result.length) { var a = this, b = arguments, c = b[0]; if (c.then) { @@ -1671,7 +2380,7 @@ function hb(a, b, c, d, e, g) { f = l.resolve; h = l.suggest; var m = void 0; - if (l.constructor === X) { + if (l.constructor === Y) { m = l.result; } else if (l.constructor === Array) { m = l; @@ -1696,26 +2405,26 @@ function hb(a, b, c, d, e, g) { if (c.length) { return Promise.all(c).then(function() { d = [a.result].concat(d); - a.result = ib(d, e, g, f, a.J, h); + a.result = wb(d, e, g, f, a.J, h); return f ? a.result : a; }); } d = [this.result].concat(d); - this.result = ib(d, e, g, f, this.J, h); + this.result = wb(d, e, g, f, this.J, h); return f ? this.result : this; } return this; }; -function ib(a, b, c, d, e, g) { +function wb(a, b, c, d, e, g) { if (2 > a.length) { return []; } var f = []; M(); var h = ya(a); - return h ? eb(a, h, b, c, g, e, d) : f; + return h ? Xa(a, h, b, c, g, e, d) : f; } -;X.prototype.xor = function() { +;Y.prototype.xor = function() { var a = this, b = arguments, c = b[0]; if (c.then) { return c.then(function() { @@ -1734,7 +2443,7 @@ function ib(a, b, c, d, e, g) { f = l.enrich; h = l.resolve; var m = void 0; - if (l.constructor === X) { + if (l.constructor === Y) { m = l.result; } else if (l.constructor === Array) { m = l; @@ -1756,19 +2465,19 @@ function ib(a, b, c, d, e, g) { if (c.length) { return Promise.all(c).then(function() { a.result.length && (d = [a.result].concat(d)); - a.result = jb(d, e, g, f, !h, a.J); + a.result = xb(d, e, g, f, !h, a.J); return h ? a.result : a; }); } - d.length && (this.result.length && (d = [this.result].concat(d)), this.result = jb(d, e, g, f, !h, a.J)); + d.length && (this.result.length && (d = [this.result].concat(d)), this.result = xb(d, e, g, f, !h, a.J)); return h ? this.result : this; }; -function jb(a, b, c, d, e, g) { +function xb(a, b, c, d, e, g) { if (!a.length) { return a; } if (2 > a.length) { - return e ? W(a[0], b, c, d) : a[0]; + return e ? X(a[0], b, c, d) : a[0]; } d = []; for (var f = M(), h = 0, k = 0, l; k < a.length; k++) { @@ -1813,7 +2522,7 @@ function jb(a, b, c, d, e, g) { } return d; } -;X.prototype.not = function() { +;Y.prototype.not = function() { var a = this, b = arguments, c = b[0]; if (c.then) { return c.then(function() { @@ -1831,7 +2540,7 @@ function jb(a, b, c, d, e, g) { g = k.offset || 0; f = k.resolve; var l = void 0; - if (k.constructor === X) { + if (k.constructor === Y) { l = k.result; } else if (k.constructor === Array) { l = k; @@ -1852,14 +2561,14 @@ function jb(a, b, c, d, e, g) { } if (c.length) { return Promise.all(c).then(function() { - a.result = kb.call(a, d, e, g, f); + a.result = yb.call(a, d, e, g, f); return f ? a.result : a; }); } - d.length && (this.result = kb.call(this, d, e, g, f)); + d.length && (this.result = yb.call(this, d, e, g, f)); return f ? this.result : this; }; -function kb(a, b, c, d) { +function yb(a, b, c, d) { if (!a.length) { return this.result; } @@ -1888,21 +2597,21 @@ function kb(a, b, c, d) { } return e; } -;function X(a) { +;function Y(a) { if (!this) { - return new X(a); + return new Y(a); } if (a && a.index) { return a.resolve = !1, this.index = a.index, this.J = a.boost || 0, this.result = a.index.search(a).result, this; } - if (a.constructor === X) { + if (a.constructor === Y) { return a; } this.index = null; this.result = a || []; this.J = 0; } -X.prototype.limit = function(a) { +Y.prototype.limit = function(a) { if (this.result.length) { for (var b = [], c = 0, d = 0, e; d < this.result.length; d++) { if (e = this.result[d], e.length + c < a) { @@ -1916,7 +2625,7 @@ X.prototype.limit = function(a) { } return this; }; -X.prototype.offset = function(a) { +Y.prototype.offset = function(a) { if (this.result.length) { for (var b = [], c = 0, d = 0, e; d < this.result.length; d++) { e = this.result[d], e.length + c < a ? c += e.length : (b[d] = e.slice(a - c), c = a); @@ -1925,18 +2634,18 @@ X.prototype.offset = function(a) { } return this; }; -X.prototype.boost = function(a) { +Y.prototype.boost = function(a) { this.J += a; return this; }; -X.prototype.resolve = function(a, b, c) { - mb = 1; +Y.prototype.resolve = function(a, b, c) { + zb = 1; var d = this.result; this.result = this.index = null; - return d.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), W(d, a || 100, b, c)) : d; + return d.length ? ("object" === typeof a && (c = a.enrich, b = a.offset, a = a.limit), X(d, a || 100, b, c)) : d; }; -var mb = 1; -V.prototype.search = function(a, b, c) { +var zb = 1; +R.prototype.search = function(a, b, c) { c || (!b && O(a) ? (c = a, a = "") : O(b) && (c = b, b = 0)); var d = [], e = 0, g; if (c) { @@ -1945,31 +2654,31 @@ V.prototype.search = function(a, b, c) { e = c.offset || 0; var f = c.context; var h = c.suggest; - (g = mb && !1 !== c.resolve) || (mb = 0); + (g = zb && !1 !== c.resolve) || (zb = 0); var k = g && c.enrich; var l = c.boost; var m = this.db && c.tag; } else { - g = this.resolve || mb; + g = this.resolve || zb; } a = this.encoder.encode(a); var n = a.length; b || !g || (b = 100); if (1 === n) { - return nb.call(this, a[0], "", b, e, g, k, m); + return Ab.call(this, a[0], "", b, e, g, k, m); } f = this.depth && !1 !== f; if (2 === n && f && !h) { - return nb.call(this, a[0], a[1], b, e, g, k, m); + return Ab.call(this, a[0], a[1], b, e, g, k, m); } var p = c = 0; if (1 < n) { for (var q = M(), r = [], u = 0, x = void 0; u < n; u++) { if ((x = a[u]) && !q[x]) { - if (h || this.db || Y(this, x)) { + if (h || this.db || Z(this, x)) { r.push(x), q[x] = 1; } else { - return g ? d : new X(d); + return g ? d : new Y(d); } x = x.length; c = Math.max(c, x); @@ -1980,14 +2689,14 @@ V.prototype.search = function(a, b, c) { n = a.length; } if (!n) { - return g ? d : new X(d); + return g ? d : new Y(d); } var y = 0; if (1 === n) { - return nb.call(this, a[0], "", b, e, g, k, m); + return Ab.call(this, a[0], "", b, e, g, k, m); } if (2 === n && f && !h) { - return nb.call(this, a[0], a[1], b, e, g, k, m); + return Ab.call(this, a[0], a[1], b, e, g, k, m); } if (1 < n) { if (f) { @@ -2003,28 +2712,28 @@ V.prototype.search = function(a, b, c) { } var z = this; return function() { - var B, D, E; + var A, D, E; return I(function(F) { switch(F.h) { case 1: - D = B = void 0; + D = A = void 0; case 2: if (!(y < n)) { F.h = 4; break; } D = a[y]; - return v ? G(F, Y(z, D, v, 0, 0, !1, !1), 8) : G(F, Y(z, D, "", 0, 0, !1, !1), 7); + return v ? G(F, Z(z, D, v, 0, 0, !1, !1), 8) : G(F, Z(z, D, "", 0, 0, !1, !1), 7); case 7: - B = F.F; - B = ob(B, d, h, z.resolution); + A = F.F; + A = Bb(A, d, h, z.resolution); F.h = 6; break; case 8: - B = F.F, B = ob(B, d, h, z.aa), h && !1 === B && d.length || (v = D); + A = F.F, A = Bb(A, d, h, z.aa), h && !1 === A && d.length || (v = D); case 6: - if (B) { - return F.return(B); + if (A) { + return F.return(A); } if (h && y === n - 1) { E = d.length; @@ -2038,7 +2747,7 @@ V.prototype.search = function(a, b, c) { return F.return(d); } if (1 === E) { - return F.return(g ? W(d[0], b, e) : new X(d[0])); + return F.return(g ? X(d[0], b, e) : new Y(d[0])); } } case 3: @@ -2046,14 +2755,14 @@ V.prototype.search = function(a, b, c) { F.h = 2; break; case 4: - return F.return(g ? eb(d, z.resolution, b, e, h, l, g) : new X(d[0])); + return F.return(g ? Xa(d, z.resolution, b, e, h, l, g) : new Y(d[0])); } }); }(); } for (k = f = void 0; y < n; y++) { k = a[y]; - v ? (f = Y(this, k, v, 0, 0, !1, !1), f = ob(f, d, h, this.aa), h && !1 === f && d.length || (v = k)) : (f = Y(this, k, "", 0, 0, !1, !1), f = ob(f, d, h, this.resolution)); + v ? (f = Z(this, k, v, 0, 0, !1, !1), f = Bb(f, d, h, this.aa), h && !1 === f && d.length || (v = k)) : (f = Z(this, k, "", 0, 0, !1, !1), f = Bb(f, d, h, this.resolution)); if (f) { return f; } @@ -2068,20 +2777,20 @@ V.prototype.search = function(a, b, c) { return d; } if (1 === f) { - return g ? W(d[0], b, e) : new X(d[0]); + return g ? X(d[0], b, e) : new Y(d[0]); } } } - d = eb(d, this.resolution, b, e, h, l, g); - return g ? d : new X(d); + d = Xa(d, this.resolution, b, e, h, l, g); + return g ? d : new Y(d); }; -function nb(a, b, c, d, e, g, f) { - a = Y(this, a, b, c, d, e, g, f); +function Ab(a, b, c, d, e, g, f) { + a = Z(this, a, b, c, d, e, g, f); return this.db ? a.then(function(h) { - return e ? h : h && h.length ? e ? W(h, c, d) : new X(h) : e ? [] : new X([]); - }) : a && a.length ? e ? W(a, c, d) : new X(a) : e ? [] : new X([]); + return e ? h : h && h.length ? e ? X(h, c, d) : new Y(h) : e ? [] : new Y([]); + }) : a && a.length ? e ? X(a, c, d) : new Y(a) : e ? [] : new Y([]); } -function ob(a, b, c, d) { +function Bb(a, b, c, d) { var e = []; if (a) { d = Math.min(a.length, d); @@ -2095,7 +2804,7 @@ function ob(a, b, c, d) { } return !c && e; } -function Y(a, b, c, d, e, g, f, h) { +function Z(a, b, c, d, e, g, f, h) { var k; c && (k = a.bidirectional && b > c); if (a.db) { @@ -2104,7 +2813,7 @@ function Y(a, b, c, d, e, g, f, h) { a = c ? (a = a.ctx.get(k ? b : c)) && a.get(k ? c : b) : a.map.get(b); return a; } -;V.prototype.remove = function(a, b) { +;R.prototype.remove = function(a, b) { var c = this.reg.size && (this.fastupdate ? this.reg.get(a) : this.reg.has(a)); if (c) { if (this.fastupdate) { @@ -2119,15 +2828,15 @@ function Y(a, b, c, d, e, g, f, h) { } } } else { - pb(this.map, a), this.depth && pb(this.ctx, a); + Cb(this.map, a), this.depth && Cb(this.ctx, a); } b || this.reg.delete(a); } - this.db && (this.commit_task.push({del:a}), this.da && cb(this)); + this.db && (this.commit_task.push({del:a}), this.da && tb(this)); this.cache && this.cache.remove(a); return this; }; -function pb(a, b) { +function Cb(a, b) { var c = 0; if (a.constructor === Array) { for (var d = 0, e = void 0, g; d < a.length; d++) { @@ -2142,23 +2851,23 @@ function pb(a, b) { } } else { for (d = w(a), e = d.next(); !e.done; e = d.next()) { - g = e.value, e = g[0], (g = pb(g[1], b)) ? c += g : a.delete(e); + g = e.value, e = g[0], (g = Cb(g[1], b)) ? c += g : a.delete(e); } } return c; } -;function V(a, b) { +;function R(a, b) { if (!this) { - return new V(a); + return new R(a); } if (a) { var c = N(a) ? a : a.preset; - c && (Ya[c] || console.warn("Preset not found: " + c), a = Object.assign({}, Ya[c], a)); + c && (qb[c] || console.warn("Preset not found: " + c), a = Object.assign({}, qb[c], a)); } else { a = {}; } c = a.context || {}; - var d = N(a.encoder) ? Qa[a.encoder] : a.encode || a.encoder || Ia; + var d = N(a.encoder) ? pb[a.encoder] : a.encode || a.encoder || hb; this.encoder = d.encode ? d : "object" === typeof d ? new Fa(d) : {encode:d}; var e; this.resolution = a.resolution || 9; @@ -2173,7 +2882,7 @@ function pb(a, b) { this.reg = b || (this.fastupdate ? e ? new T(e) : new Map() : e ? new U(e) : new Set()); this.aa = c.resolution || 1; this.rtl = d.rtl || a.rtl || !1; - this.cache = (e = a.cache || null) && new R(e); + this.cache = (e = a.cache || null) && new W(e); this.resolve = !1 !== a.resolve; if (e = a.db) { this.db = this.mount(e); @@ -2182,7 +2891,7 @@ function pb(a, b) { this.commit_task = []; this.commit_timer = null; } -t = V.prototype; +t = R.prototype; t.mount = function(a) { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return a.mount(this); @@ -2195,7 +2904,7 @@ t.destroy = function() { this.commit_timer && (clearTimeout(this.commit_timer), this.commit_timer = null); return this.db.destroy(); }; -function cb(a) { +function tb(a) { a.commit_timer || (a.commit_timer = setTimeout(function() { a.commit_timer = null; a.db.commit(a, void 0, void 0); @@ -2221,7 +2930,7 @@ t.update = function(a, b) { return c.add(a, b); }) : this.add(a, b); }; -function qb(a) { +function Db(a) { var b = 0; if (a.constructor === Array) { for (var c = 0, d = void 0; c < a.length; c++) { @@ -2231,7 +2940,7 @@ function qb(a) { for (c = w(a), d = c.next(); !d.done; d = c.next()) { var e = d.value; d = e[0]; - (e = qb(e[1])) ? b += e : a.delete(d); + (e = Db(e[1])) ? b += e : a.delete(d); } } return b; @@ -2240,11 +2949,11 @@ t.cleanup = function() { if (!this.fastupdate) { return console.info('Cleanup the index isn\'t required when not using "fastupdate".'), this; } - qb(this.map); - this.depth && qb(this.ctx); + Db(this.map); + this.depth && Db(this.ctx); return this; }; -t.searchCache = Ha; +t.searchCache = gb; t.export = function(a, b, c, d, e, g) { var f = !0; "undefined" === typeof g && (f = new Promise(function(n) { @@ -2278,7 +2987,7 @@ t.export = function(a, b, c, d, e, g) { "undefined" === typeof c && g && g(); return; } - Xa(a, b || this, c, h, d, e, k, g); + Oa(a, b || this, c, h, d, e, k, g); return f; }; t.import = function(a, b) { @@ -2351,716 +3060,7 @@ t.serialize = function(a) { e = "index.ctx=new Map([" + e + "]);"; return a ? "function inject(index){" + b + d + e + "}" : b + d + e; }; -Za(V.prototype); -function rb(a) { - var b, c, d, e, g, f, h, k; - return I(function(l) { - a = a.data; - b = self._index; - c = a.args; - d = a.task; - switch(d) { - case "init": - e = a.options || {}; - (g = e.config) && (e = g); - (f = a.factory) ? (Function("return " + f)()(self), self._index = new self.FlexSearch.Index(e), delete self.FlexSearch) : self._index = new V(e); - postMessage({id:a.id}); - break; - default: - h = a.id, k = b[d].apply(b, c), postMessage("search" === d ? {id:h, msg:k} : {id:h}); - } - l.h = 0; - }); -} -;var sb = 0; -function tb(a) { - function b(f) { - function h(k) { - k = k.data || k; - var l = k.id, m = l && e.h[l]; - m && (m(k.msg), delete e.h[l]); - } - this.worker = f; - this.h = M(); - if (this.worker) { - d ? this.worker.on("message", h) : this.worker.onmessage = h; - if (a.config) { - return new Promise(function(k) { - e.h[++sb] = function() { - k(e); - }; - e.worker.postMessage({id:sb, task:"init", factory:c, options:a}); - }); - } - this.worker.postMessage({task:"init", factory:c, options:a}); - return this; - } - } - a = void 0 === a ? {} : a; - if (!this) { - return new tb(a); - } - var c = "undefined" !== typeof self ? self._factory : "undefined" !== typeof window ? window._factory : null; - c && (c = c.toString()); - var d = "undefined" === typeof window, e = this, g = ub(c, d, a.worker); - return g.then ? g.then(function(f) { - return b.call(e, f); - }) : b.call(this, g); -} -vb("add"); -vb("append"); -vb("search"); -vb("update"); -vb("remove"); -function vb(a) { - tb.prototype[a] = tb.prototype[a + "Async"] = function() { - var b = this, c = arguments, d, e, g, f, h; - return I(function(k) { - d = b; - e = [].slice.call(c); - g = e[e.length - 1]; - "function" === typeof g && (f = g, e.splice(e.length - 1, 1)); - h = new Promise(function(l) { - d.h[++sb] = l; - d.worker.postMessage({task:a, id:sb, args:e}); - }); - return f ? (h.then(f), k.return(b)) : k.return(h); - }); - }; -} -function ub(a, b, c) { - return b ? "undefined" !== typeof module ? new (require("worker_threads")["Worker"])(__dirname + "/node/node.js") : import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }) : a ? new window.Worker(URL.createObjectURL(new Blob(["onmessage=" + rb.toString()], {type:"text/javascript"}))) : new window.Worker(N(c) ? c : (0,eval)("import.meta.url").replace("/worker.js", "/worker/worker.js").replace("flexsearch.bundle.module.min.js", - "module/worker/worker.js"), {type:"module"}); -} -;Z.prototype.add = function(a, b, c) { - O(a) && (b = a, a = xa(b, this.key)); - if (b && (a || 0 === a)) { - if (!c && this.reg.has(a)) { - return this.update(a, b); - } - for (var d = 0, e; d < this.field.length; d++) { - e = this.I[d]; - var g = this.index.get(this.field[d]); - if ("function" === typeof e) { - (e = e(b)) && g.add(a, e, !1, !0); - } else { - var f = e.R; - if (!f || f(b)) { - e.constructor === String ? e = ["" + e] : N(e) && (e = [e]), wb(b, e, this.T, 0, g, a, e[0], c); - } - } - } - if (this.tag) { - for (d = 0; d < this.M.length; d++) { - f = this.M[d]; - var h = this.$[d]; - g = this.tag.get(h); - e = M(); - if ("function" === typeof f) { - if (f = f(b), !f) { - continue; - } - } else { - var k = f.R; - if (k && !k(b)) { - continue; - } - f.constructor === String && (f = "" + f); - f = xa(b, f); - } - if (g && f) { - for (N(f) && (f = [f]), h = 0, k = void 0; h < f.length; h++) { - var l = f[h]; - if (!e[l]) { - e[l] = 1; - var m; - (m = g.get(l)) ? k = m : g.set(l, k = []); - if (!c || !k.includes(a)) { - if (k.length === Math.pow(2, 31) - 1) { - m = new S(k); - if (this.fastupdate) { - for (var n = w(this.reg.values()), p = n.next(); !p.done; p = n.next()) { - p = p.value, p.includes(k) && (p[p.indexOf(k)] = m); - } - } - g.set(l, k = m); - } - k.push(a); - this.fastupdate && ((l = this.reg.get(a)) ? l.push(k) : this.reg.set(a, [k])); - } - } - } - } else { - g || console.warn("Tag '" + h + "' was not found"); - } - } - } - if (this.store && (!c || !this.store.has(a))) { - if (this.H) { - var q = M(); - for (c = 0; c < this.H.length; c++) { - if (d = this.H[c], g = d.R, !g || g(b)) { - g = void 0; - if ("function" === typeof d) { - g = d(b); - if (!g) { - continue; - } - d = [d.la]; - } else if (N(d) || d.constructor === String) { - q[d] = b[d]; - continue; - } - xb(b, q, d, 0, d[0], g); - } - } - } - this.store.set(a, q || b); - } - } - return this; -}; -function xb(a, b, c, d, e, g) { - a = a[e]; - if (d === c.length - 1) { - b[e] = g || a; - } else if (a) { - if (a.constructor === Array) { - for (b = b[e] = Array(a.length), e = 0; e < a.length; e++) { - xb(a, b, c, d, e); - } - } else { - b = b[e] || (b[e] = M()), e = c[++d], xb(a, b, c, d, e); - } - } -} -function wb(a, b, c, d, e, g, f, h) { - if (a = a[f]) { - if (d === b.length - 1) { - if (a.constructor === Array) { - if (c[d]) { - for (b = 0; b < a.length; b++) { - e.add(g, a[b], !0, !0); - } - return; - } - a = a.join(" "); - } - e.add(g, a, h, !0); - } else { - if (a.constructor === Array) { - for (f = 0; f < a.length; f++) { - wb(a, b, c, d, e, g, f, h); - } - } else { - f = b[++d], wb(a, b, c, d, e, g, f, h); - } - } - } else { - e.db && e.remove(g); - } -} -;Z.prototype.search = function(a, b, c, d) { - c || (!b && O(a) ? (c = a, a = "") : O(b) && (c = b, b = 0)); - var e = [], g = [], f = 0; - if (c) { - c.constructor === Array && (c = {index:c}); - a = c.query || a; - var h = c.pluck; - var k = c.merge; - var l = h || c.field || c.index; - var m = this.tag && c.tag; - var n = this.store && c.enrich; - var p = c.suggest; - var q = c.na; - b = c.limit || b; - var r = c.offset || 0; - b || (b = 100); - if (m && (!this.db || !d)) { - m.constructor !== Array && (m = [m]); - for (var u = [], x = 0, y = void 0; x < m.length; x++) { - y = m[x]; - if (N(y)) { - throw Error("A tag option can't be a string, instead it needs a { field: tag } format."); - } - if (y.field && y.tag) { - var v = y.tag; - if (v.constructor === Array) { - for (var z = 0; z < v.length; z++) { - u.push(y.field, v[z]); - } - } else { - u.push(y.field, v); - } - } else { - v = Object.keys(y); - z = 0; - for (var B = void 0, D = void 0; z < v.length; z++) { - if (B = v[z], D = y[B], D.constructor === Array) { - for (var E = 0; E < D.length; E++) { - u.push(B, D[E]); - } - } else { - u.push(B, D); - } - } - } - } - if (!u.length) { - throw Error("Your tag definition within the search options is probably wrong. No valid tags found."); - } - m = u; - if (!a) { - g = []; - if (u.length) { - for (h = 0; h < u.length; h += 2) { - p = void 0; - if (this.db) { - p = this.index.get(u[h]); - if (!p) { - console.warn("Tag '" + u[h] + ":" + u[h + 1] + "' will be skipped because there is no field '" + u[h] + "'."); - continue; - } - g.push(p = p.db.tag(u[h + 1], b, r, n)); - } else { - p = yb.call(this, u[h], u[h + 1], b, r, n); - } - e.push({field:u[h], tag:u[h + 1], result:p}); - } - } - return g.length ? Promise.all(g).then(function(P) { - for (var Q = 0; Q < P.length; Q++) { - e[Q].result = P[Q]; - } - return e; - }) : e; - } - } - N(l) && (l = [l]); - } - l || (l = this.field); - u = !d && (this.worker || this.db) && []; - x = 0; - for (z = y = v = void 0; x < l.length; x++) { - if (y = l[x], !this.db || !this.tag || this.I[x]) { - v = void 0; - N(y) || (v = y, y = v.field, a = v.query || a, b = v.limit || b, r = v.offset || r, p = v.suggest || p, n = this.store && (v.enrich || n)); - if (d) { - v = d[x]; - } else { - z = v || c; - v = this.index.get(y); - if (m) { - if (this.db) { - z.tag = m; - var F = v.db.support_tag_search; - z.field = l; - } - F || (z.enrich = !1); - } - if (u) { - u[x] = v.search(a, b, z); - z && n && (z.enrich = n); - continue; - } else { - v = v.search(a, b, z), z && n && (z.enrich = n); - } - } - z = v && v.length; - if (m && z) { - B = []; - D = 0; - if (this.db && d) { - if (!F) { - for (E = l.length; E < d.length; E++) { - var K = d[E]; - if (K && K.length) { - D++, B.push(K); - } else if (!p) { - return e; - } - } - } - } else { - E = 0; - for (var Lb = K = void 0; E < m.length; E += 2) { - K = this.tag.get(m[E]); - if (!K) { - if (console.warn("Tag '" + m[E] + ":" + m[E + 1] + "' will be skipped because there is no field '" + m[E] + "'."), p) { - continue; - } else { - return e; - } - } - if (Lb = (K = K && K.get(m[E + 1])) && K.length) { - D++, B.push(K); - } else if (!p) { - return e; - } - } - } - if (D) { - v = gb(v, B); - z = v.length; - if (!z && !p) { - return e; - } - D--; - } - } - if (z) { - g[f] = y, e.push(v), f++; - } else if (1 === l.length) { - return e; - } - } - } - if (u) { - if (this.db && m && m.length && !F) { - for (n = 0; n < m.length; n += 2) { - g = this.index.get(m[n]); - if (!g) { - if (console.warn("Tag '" + m[n] + ":" + m[n + 1] + "' was not found because there is no field '" + m[n] + "'."), p) { - continue; - } else { - return e; - } - } - u.push(g.db.tag(m[n + 1], b, r, !1)); - } - } - var Mb = this; - return Promise.all(u).then(function(P) { - return P.length ? Mb.search(a, b, c, P) : P; - }); - } - if (!f) { - return e; - } - if (h && (!n || !this.store)) { - return e[0]; - } - u = []; - r = 0; - for (p = void 0; r < g.length; r++) { - p = e[r]; - n && p.length && !p[0].doc && (this.db ? u.push(p = this.index.get(this.field[0]).db.enrich(p)) : p.length && (p = zb.call(this, p))); - if (h) { - return p; - } - e[r] = {field:g[r], result:p}; - } - if (n && this.db && u.length) { - var lb = this; - return Promise.all(u).then(function(P) { - for (var Q = 0; Q < P.length; Q++) { - e[Q].result = P[Q]; - } - return k ? Ab(e, b) : q ? Bb(e, a, lb.index, lb.I, q) : e; - }); - } - return k ? Ab(e, b) : q ? Bb(e, a, this.index, this.I, q) : e; -}; -function Bb(a, b, c, d, e) { - for (var g, f = 0, h, k, l; f < a.length; f++) { - for (h = a[f].result, k = a[f].field, l = c.get(k).encoder, k = d[k.indexOf(k)], l !== g && (g = l, g.encode(b)), l = 0; l < h.length; l++) { - for (var m = "", n = xa(h[l].doc, k), p = g.encode(n), q = 0; q < p.length; q++) { - m += p[q].replace(new RegExp("(" + p[q] + ")", "g"), e.replace("$1", n)); - } - console.log(a, c, e); - h[l].na = m; - } - } - return a; -} -function Ab(a, b) { - for (var c = [], d = M(), e = 0, g, f; e < a.length; e++) { - g = a[e]; - f = g.result; - for (var h = 0, k, l, m; h < f.length; h++) { - if (l = f[h], k = l.id, m = d[k]) { - m.push(g.field); - } else { - if (c.length === b) { - return c; - } - l.field = d[k] = [g.field]; - c.push(l); - } - } - } - return c; -} -function yb(a, b, c, d, e) { - var g = this.tag.get(a); - if (!g) { - return console.warn("Tag '" + a + "' was not found"), []; - } - if ((a = (g = g && g.get(b)) && g.length - d) && 0 < a) { - if (a > c || d) { - g = g.slice(d, d + c); - } - e && (g = zb.call(this, g)); - return g; - } -} -function zb(a) { - for (var b = Array(a.length), c = 0, d; c < a.length; c++) { - d = a[c], b[c] = {id:d, doc:this.store.get(d)}; - } - return b; -} -;function Z(a) { - if (!this) { - return new Z(a); - } - var b = a.document || a.doc || a, c, d; - this.I = []; - this.field = []; - this.T = []; - this.key = (c = b.key || b.id) && Cb(c, this.T) || "id"; - (d = a.keystore || 0) && (this.keystore = d); - this.reg = (this.fastupdate = !!a.fastupdate) ? d ? new T(d) : new Map() : d ? new U(d) : new Set(); - this.H = (c = b.store || null) && !0 !== c && []; - this.store = c && (d ? new T(d) : new Map()); - this.cache = (c = a.cache || null) && new R(c); - a.cache = !1; - this.worker = a.worker; - this.index = Db.call(this, a, b); - this.tag = null; - if (c = b.tag) { - if ("string" === typeof c && (c = [c]), c.length) { - this.tag = new Map(); - this.M = []; - this.$ = []; - b = 0; - for (var e = d = void 0; b < c.length; b++) { - d = c[b]; - e = d.field || d; - if (!e) { - throw Error("The tag field from the document descriptor is undefined."); - } - d.custom ? this.M[b] = d.custom : (this.M[b] = Cb(e, this.T), d.filter && ("string" === typeof this.M[b] && (this.M[b] = new String(this.M[b])), this.M[b].R = d.filter)); - this.$[b] = e; - this.tag.set(e, new Map()); - } - } - } - if (this.worker) { - a = []; - c = w(this.index.values()); - for (b = c.next(); !b.done; b = c.next()) { - b = b.value, b.then && a.push(b); - } - if (a.length) { - var g = this; - return Promise.all(a).then(function(f) { - for (var h = 0, k = w(g.index.entries()), l = k.next(); !l.done; l = k.next()) { - l = l.value; - var m = l[0]; - l[1].then && g.index.set(m, f[h++]); - } - return g; - }); - } - } else { - a.db && this.mount(a.db); - } -} -t = Z.prototype; -t.mount = function(a) { - var b = this.field; - if (this.tag) { - for (var c = 0, d; c < this.$.length; c++) { - d = this.$[c]; - var e; - this.index.set(d, e = new V({}, this.reg)); - b === this.field && (b = b.slice(0)); - b.push(d); - e.tag = this.tag.get(d); - } - } - c = []; - d = {db:a.db, type:a.type, fastupdate:a.fastupdate}; - e = 0; - for (var g; e < b.length; e++) { - d.field = g = b[e]; - g = this.index.get(g); - var f = new a.constructor(a.id, d); - f.id = a.id; - c[e] = f.mount(g); - g.document = !0; - e ? g.bypass = !0 : g.store = this.store; - } - this.db = !0; - return Promise.all(c); -}; -t.commit = function(a, b) { - var c = this, d, e, g, f; - return I(function(h) { - if (1 == h.h) { - d = []; - e = w(c.index.values()); - for (g = e.next(); !g.done; g = e.next()) { - f = g.value, d.push(f.db.commit(f, a, b)); - } - return G(h, Promise.all(d), 2); - } - c.reg.clear(); - h.h = 0; - }); -}; -t.destroy = function() { - for (var a = [], b = w(this.index.values()), c = b.next(); !c.done; c = b.next()) { - a.push(c.value.destroy()); - } - return Promise.all(a); -}; -function Db(a, b) { - var c = new Map(), d = b.index || b.field || b; - N(d) && (d = [d]); - for (var e = 0, g, f = void 0; e < d.length; e++) { - g = d[e]; - N(g) || (f = g, g = g.field); - f = O(f) ? Object.assign({}, a, f) : a; - if (this.worker) { - var h = new tb(f); - c.set(g, h); - } - this.worker || c.set(g, new V(f, this.reg)); - f.custom ? this.I[e] = f.custom : (this.I[e] = Cb(g, this.T), f.filter && ("string" === typeof this.I[e] && (this.I[e] = new String(this.I[e])), this.I[e].R = f.filter)); - this.field[e] = g; - } - if (this.H) { - for (a = b.store, N(a) && (a = [a]), b = 0; b < a.length; b++) { - d = a[b], e = d.field || d, d.custom ? (this.H[b] = d.custom, d.custom.la = e) : (this.H[b] = Cb(e, this.T), d.filter && ("string" === typeof this.H[b] && (this.H[b] = new String(this.H[b])), this.H[b].R = d.filter)); - } - } - return c; -} -function Cb(a, b) { - for (var c = a.split(":"), d = 0, e = 0; e < c.length; e++) { - a = c[e], "]" === a[a.length - 1] && (a = a.substring(0, a.length - 2)) && (b[d] = !0), a && (c[d++] = a); - } - d < c.length && (c.length = d); - return 1 < d ? c : c[0]; -} -t.append = function(a, b) { - return this.add(a, b, !0); -}; -t.update = function(a, b) { - return this.remove(a).add(a, b); -}; -t.remove = function(a) { - O(a) && (a = xa(a, this.key)); - for (var b = w(this.index.values()), c = b.next(); !c.done; c = b.next()) { - c.value.remove(a, !0); - } - if (this.reg.has(a)) { - if (this.tag && !this.fastupdate) { - for (b = w(this.tag.values()), c = b.next(); !c.done; c = b.next()) { - c = c.value; - for (var d = w(c), e = d.next(); !e.done; e = d.next()) { - var g = e.value; - e = g[0]; - g = g[1]; - var f = g.indexOf(a); - -1 < f && (1 < g.length ? g.splice(f, 1) : c.delete(e)); - } - } - } - this.store && this.store.delete(a); - this.reg.delete(a); - } - this.cache && this.cache.remove(a); - return this; -}; -t.clear = function() { - for (var a = w(this.index.values()), b = a.next(); !b.done; b = a.next()) { - b.value.clear(); - } - if (this.tag) { - for (a = w(this.tag.values()), b = a.next(); !b.done; b = a.next()) { - b.value.clear(); - } - } - this.store && this.store.clear(); - return this; -}; -t.contain = function(a) { - return this.db ? this.index.get(this.field[0]).db.has(a) : this.reg.has(a); -}; -t.cleanup = function() { - for (var a = w(this.index.values()), b = a.next(); !b.done; b = a.next()) { - b.value.cleanup(); - } - return this; -}; -t.get = function(a) { - return this.db ? this.index.get(this.field[0]).db.enrich(a).then(function(b) { - return b[0] && b[0].doc; - }) : this.store.get(a); -}; -t.set = function(a, b) { - this.store.set(a, b); - return this; -}; -t.searchCache = Ha; -t.export = function(a, b, c, d, e, g) { - var f; - "undefined" === typeof g && (f = new Promise(function(k) { - g = k; - })); - e || (e = 0); - d || (d = 0); - if (d < this.field.length) { - c = this.field[d]; - var h = this.index[c]; - b = this; - h.export(a, b, e ? c : "", d, e++, g) || (d++, b.export(a, b, c, d, 1, g)); - } else { - switch(e) { - case 1: - b = "tag"; - h = this.A; - c = null; - break; - case 2: - b = "store"; - h = this.store; - c = null; - break; - default: - g(); - return; - } - Xa(a, this, c, b, d, e, h, g); - } - return f; -}; -t.import = function(a, b) { - if (b) { - switch(N(b) && (b = JSON.parse(b)), a) { - case "tag": - this.A = b; - break; - case "reg": - this.fastupdate = !1; - this.reg = b; - a = 0; - for (var c; a < this.field.length; a++) { - c = this.index[this.field[a]], c.reg = b, c.fastupdate = !1; - } - break; - case "store": - this.store = b; - break; - default: - a = a.split("."), c = a[0], a = a[1], c && a && this.index[c].import(a, b); - } - } -}; -Za(Z.prototype); +Ma(R.prototype); var Eb = "undefined" !== typeof window && (window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB), Fb = ["map", "ctx", "tag", "reg", "cfg"]; function Gb(a, b) { b = void 0 === b ? {} : b; @@ -3304,14 +3304,14 @@ t.commit = function(a, b, c) { return function() { var x = this.result, y; if (x && x.length) { - for (var v = Math.max(x.length, r.P.length), z = 0, B; z < v; z++) { - if ((B = r.P[z]) && B.length) { + for (var v = Math.max(x.length, r.P.length), z = 0, A; z < v; z++) { + if ((A = r.P[z]) && A.length) { if ((y = x[z]) && y.length) { - for (var D = 0; D < B.length; D++) { - y.push(B[D]); + for (var D = 0; D < A.length; D++) { + y.push(A[D]); } } else { - x[z] = B; + x[z] = A; } y = 1; } @@ -3366,7 +3366,7 @@ t.commit = function(a, b, c) { } }); }; -function Ib(a, b, c) { +function Kb(a, b, c) { for (var d = a.value, e, g, f = 0, h = 0, k; h < d.length; h++) { if (k = c ? d : d[h]) { for (var l = 0, m, n; l < b.length; l++) { @@ -3393,17 +3393,17 @@ t.remove = function(a) { return Promise.all([this.transaction("map", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Ib(c, a); + c && Kb(c, a); }; }), this.transaction("ctx", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Ib(c, a); + c && Kb(c, a); }; }), this.transaction("tag", "readwrite", function(b) { b.openCursor().onsuccess = function() { var c = this.result; - c && Ib(c, a, !0); + c && Kb(c, a, !0); }; }), this.transaction("reg", "readwrite", function(b) { for (var c = 0; c < a.length; c++) { @@ -3423,8 +3423,8 @@ function Hb(a) { a = null; }); } -;var Jb = {Index:V, Charset:Qa, Encoder:Fa, Document:Z, Worker:tb, Resolver:X, IndexedDB:Gb, Language:{}}, Kb = self, Nb; -(Nb = Kb.define) && Nb.amd ? Nb([], function() { - return Jb; -}) : "object" === typeof Kb.exports ? Kb.exports = Jb : Kb.FlexSearch = Jb; +;var Lb = {Index:R, Charset:pb, Encoder:Fa, Document:V, Worker:Ja, Resolver:Y, IndexedDB:Gb, Language:{}}, Mb = self, Nb; +(Nb = Mb.define) && Nb.amd ? Nb([], function() { + return Lb; +}) : "object" === typeof Mb.exports ? Mb.exports = Lb : Mb.FlexSearch = Lb; }(this||self)); diff --git a/dist/flexsearch.es5.min.js b/dist/flexsearch.es5.min.js index 5de56c6..fa6354d 100644 --- a/dist/flexsearch.es5.min.js +++ b/dist/flexsearch.es5.min.js @@ -6,18 +6,18 @@ * https://github.com/nextapps-de/flexsearch */ (function _f(self){'use strict';if(typeof module!=='undefined')self=module;else if(typeof process !== 'undefined')self=process;self._factory=_f;var t;function aa(a){var b=0;return function(){return b>>0)+"_",e=0;return b}); -C("Symbol.iterator",function(a){if(a)return a;a=Symbol("Symbol.iterator");for(var b="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),c=0;cc&&(c=Math.max(c+e,0));cc&&(c=Math.max(c+e,0));cthis.L&&(this.S.clear(),this.A=this.A/1.1|0));f&&d.push(f)}this.finalize&&(d=this.finalize(d)||d);this.cache&&a.length<=this.h&&(this.N.set(a,d),this.N.size>this.L&&(this.N.clear(),this.h=this.h/1.1|0));return d};function Ga(a){a.U=null;a.N.clear();a.S.clear()};function Ha(a,b,c){a=("object"===typeof a?""+a.query:a).toLowerCase();var d=this.cache.get(a);if(!d){d=this.search(a,b,c);if(d.then){var e=this;d.then(function(h){e.cache.set(a,h);return h})}this.cache.set(a,d)}return d}function R(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.h=""}R.prototype.set=function(a,b){this.cache.set(this.h=a,b);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)}; -R.prototype.get=function(a){var b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};R.prototype.remove=function(a){for(var b=w(this.cache),c=b.next();!c.done;c=b.next()){c=c.value;var d=c[0];c[1].includes(a)&&this.cache.delete(d)}};R.prototype.clear=function(){this.cache.clear();this.h=""};var Ia={normalize:function(a){return a.toLowerCase()},dedupe:!1};var Ja=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);var Ka=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),La=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];var Ma={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var Na=/[\x00-\x7F]+/g;var Oa=/[\x00-\x7F]+/g;var Pa=/[\x00-\x7F]+/g;var Qa={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:Ia,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:Ja},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:Ja,replacer:La,matcher:Ka},LatinExtra:{normalize:!0,dedupe:!0,mapper:Ja,replacer:La.concat([/(?!^)[aeoy]/g,""]),matcher:Ka},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(var b=0;b=f.length)b-=f.length;else{b=f[d?"splice":"slice"](b,c);if(f=b.length)if(e=e.length?e.concat(b):b,c-=f,d&&(a.length-=f),!c)break;b=0}return e} +this.replacer[k+1]);this.cache&&g.length<=this.A&&(this.S.set(g,f),this.S.size>this.L&&(this.S.clear(),this.A=this.A/1.1|0));f&&d.push(f)}this.finalize&&(d=this.finalize(d)||d);this.cache&&a.length<=this.h&&(this.N.set(a,d),this.N.size>this.L&&(this.N.clear(),this.h=this.h/1.1|0));return d};function Ga(a){a.U=null;a.N.clear();a.S.clear()};function Ha(a){var b,c,d,e,h,f,g,k;return I(function(l){a=a.data;b=self._index;c=a.args;d=a.task;switch(d){case "init":e=a.options||{};(h=e.config)&&(e=(await import(h))["default"]);(f=a.factory)?(Function("return "+f)()(self),self._index=new self.FlexSearch.Index(e),delete self.FlexSearch):self._index=new R(e);postMessage({id:a.id});break;default:g=a.id,k=b[d].apply(b,c),postMessage("search"===d?{id:g,msg:k}:{id:g})}l.h=0})};var Ia=0; +function Ja(a){function b(f){function g(k){k=k.data||k;var l=k.id,m=l&&e.h[l];m&&(m(k.msg),delete e.h[l])}this.worker=f;this.h=M();if(this.worker){d?this.worker.on("message",g):this.worker.onmessage=g;if(a.config)return new Promise(function(k){e.h[++Ia]=function(){k(e)};e.worker.postMessage({id:Ia,task:"init",factory:c,options:a})});this.worker.postMessage({task:"init",factory:c,options:a});return this}}a=void 0===a?{}:a;if(!this)return new Ja(a);var c="undefined"!==typeof self?self._factory:"undefined"!== +typeof window?window._factory:null;c&&(c=c.toString());var d="undefined"===typeof window,e=this,h=Ka(c,d,a.worker);return h.then?h.then(function(f){return b.call(e,f)}):b.call(this,h)}La("add");La("append");La("search");La("update");La("remove"); +function La(a){Ja.prototype[a]=Ja.prototype[a+"Async"]=function(){var b=this,c=arguments,d,e,h,f,g;return I(function(k){d=b;e=[].slice.call(c);h=e[e.length-1];"function"===typeof h&&(f=h,e.splice(e.length-1,1));g=new Promise(function(l){d.h[++Ia]=l;d.worker.postMessage({task:a,id:Ia,args:e})});return f?(g.then(f),k.return(b)):k.return(g)})}} +function Ka(a,b,c){return b?"undefined"!==typeof module?new (require("worker_threads")["Worker"])(__dirname + "/node/node.js"):import("worker_threads").then(function(worker){ return new worker["Worker"]((1,eval)("import.meta.dirname") + "/node/node.mjs"); }):a?new window.Worker(URL.createObjectURL(new Blob(["onmessage="+Ha.toString()],{type:"text/javascript"}))):new window.Worker(N(c)?c:(0,eval)("import.meta.url").replace("/worker.js","/worker/worker.js").replace("flexsearch.bundle.module.min.js", +"module/worker/worker.js"),{type:"module"})};function Ma(a){Na.call(a,"add");Na.call(a,"append");Na.call(a,"search");Na.call(a,"update");Na.call(a,"remove")}function Na(a){this[a+"Async"]=function(){var b=arguments,c=b[b.length-1];if("function"===typeof c){var d=c;delete b[b.length-1]}b=this[a].apply(this,b);d&&(b.then?b.then(d):d(b));return b}};function Oa(a,b,c,d,e,h,f,g){(d=a(c?c+"."+d:d,JSON.stringify(f)))&&d.then?d.then(function(){b.export(a,b,c,e,h+1,g)}):b.export(a,b,c,e,h+1,g)};function Pa(a,b,c,d){for(var e=[],h=0,f;h=f.length)b-=f.length;else{b=f[d?"splice":"slice"](b,c);if(f=b.length)if(e=e.length?e.concat(b):b,c-=f,d&&(a.length-=f),!c)break;b=0}return e} function S(a){if(!this)return new S(a);this.index=a?[a]:[];this.length=a?a.length:0;var b=this;return new Proxy([],{get:function(c,d){if("length"===d)return b.length;if("push"===d)return function(e){b.index[b.index.length-1].push(e);b.length++};if("pop"===d)return function(){if(b.length)return b.length--,b.index[b.index.length-1].pop()};if("indexOf"===d)return function(e){for(var h=0,f=0,g,k;fn;q--){p=l.substring(n,q);var r=this.score?this.score(b,l,k,p,n):ab(g,d,k,m,n);bb(this,h,p,r,a,c)}break}case "reverse":if(1< -m){for(q=m-1;0p?0:1),d,k,q-1,r-1),x=this.bidirectional&&l>n;bb(this,e,x?n:l,v,a,c,x?l:n)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& -(b||this.commit_task.push({del:a}),this.da&&cb(this));return this}; -function bb(a,b,c,d,e,h,f){var g=f?a.ctx:a.map,k;if(!b[c]||!f||!(k=b[c])[f])if(f?(b=k||(b[c]=M()),b[f]=1,(k=g.get(f))?g=k:g.set(f,g=new Map)):b[c]=1,(k=g.get(c))?g=k:g.set(c,g=k=[]),g=g[d]||(g[d]=[]),!h||!g.includes(e)){if(g.length===Math.pow(2,31)-1){b=new S(g);if(a.fastupdate)for(c=w(a.reg.values()),h=c.next();!h.done;h=c.next())h=h.value,h.includes(g)&&(h[h.indexOf(g)]=b);k[d]=g=b}g.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(g):a.reg.set(e,[g]))}} -function ab(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?db(a):a;for(var e=[],h=0,f=void 0,g=void 0;h=g){c-=g;continue}cb&&(f=f.slice(0,b),g=f.length),e.push(f);else{if(g>=b)return g>b&&(f=f.slice(0,b)),d?db(f):f;e=[f]}b-=g;if(!b)break}if(!e.length)return e;e=1c||d)k=k.slice(d,c+d)}else{e=[];for(f=0;fd)d-=g.length;else{if(g.length>c||d)g=g.slice(d, +d)return function(e){for(var h=0;hc||d)k=k.slice(d,c+d)}else{e=[];for(f=0;fd)d-=g.length;else{if(g.length>c||d)g=g.slice(d, c+d),c-=g.length,d&&(d-=g.length);e.push(g);if(!c)break}return 1a.length?e?W(a[0],b,c,d):a[0]:fb(a,c,b,e,h)};X.prototype.and=function(){if(this.result.length){var a=this,b=arguments,c=b[0];if(c.then)return c.then(function(){return a.and.apply(a,b)});if(c[0]&&c[0].index)return this.and.apply(this,c);var d=[];c=[];for(var e=0,h=0,f,g,k=0,l=void 0;ka.length)return[];var f=[];M();var g=ya(a);return g?eb(a,g,b,c,h,e,d):f};X.prototype.xor=function(){var a=this,b=arguments,c=b[0];if(c.then)return c.then(function(){return a.xor.apply(a,b)});if(c[0]&&c[0].index)return this.xor.apply(this,c);var d=[];c=[];for(var e=0,h=0,f,g,k=0,l=void 0;ka.length)return e?W(a[0],b,c,d):a[0];d=[];for(var f=M(),g=0,k=0,l;kc);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,h,f,g):a.db.get(b,"",d,e,h,f,g);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};V.prototype.remove=function(a,b){var c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(var d=0,e;de.length)e.pop();else{var h=e.indexOf(a);h===c.length-1?e.pop():e.splice(h,1)}}else pb(this.map,a),this.depth&&pb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.da&&cb(this));this.cache&&this.cache.remove(a);return this}; -function pb(a,b){var c=0;if(a.constructor===Array)for(var d=0,e=void 0,h;dc||d)a=a.slice(d,d+c);e&&(a=bb.call(this,a));return a}}function bb(a){for(var b=Array(a.length),c=0,d;cthis.limit&&this.cache.delete(this.cache.keys().next().value)}; +W.prototype.get=function(a){var b=this.cache.get(a);b&&this.h!==a&&(this.cache.delete(a),this.cache.set(this.h=a,b));return b};W.prototype.remove=function(a){for(var b=w(this.cache),c=b.next();!c.done;c=b.next()){c=c.value;var d=c[0];c[1].includes(a)&&this.cache.delete(d)}};W.prototype.clear=function(){this.cache.clear();this.h=""};var hb={normalize:function(a){return a.toLowerCase()},dedupe:!1};var ib=new Map([["b","p"],["v","f"],["w","f"],["z","s"],["x","s"],["d","t"],["n","m"],["c","k"],["g","k"],["j","k"],["q","k"],["i","e"],["y","e"],["u","o"]]);var jb=new Map([["ai","ei"],["ae","a"],["oe","o"],["ue","u"],["sh","s"],["ch","c"],["th","t"],["ph","f"],["pf","f"]]),kb=[/([^aeo])h([aeo$])/g,"$1$2",/([aeo])h([^aeo]|$)/g,"$1$2"];var lb={a:"",e:"",i:"",o:"",u:"",y:"",b:1,f:1,p:1,v:1,c:2,g:2,j:2,k:2,q:2,s:2,x:2,z:2,"\u00df":2,d:3,t:3,l:4,m:5,n:5,r:6};var mb=/[\x00-\x7F]+/g;var nb=/[\x00-\x7F]+/g;var ob=/[\x00-\x7F]+/g;var pb={LatinExact:{normalize:!1,dedupe:!1},LatinDefault:hb,LatinSimple:{normalize:!0,dedupe:!0},LatinBalance:{normalize:!0,dedupe:!0,mapper:ib},LatinAdvanced:{normalize:!0,dedupe:!0,mapper:ib,replacer:kb,matcher:jb},LatinExtra:{normalize:!0,dedupe:!0,mapper:ib,replacer:kb.concat([/(?!^)[aeoy]/g,""]),matcher:jb},LatinSoundex:{normalize:!0,dedupe:!1,include:{letter:!0},finalize:function(a){for(var b=0;bn;q--){p=l.substring(n,q);var r=this.score?this.score(b,l,k,p,n):rb(g,d,k,m,n);sb(this,h,p,r,a,c)}break}case "reverse":if(1< +m){for(q=m-1;0p?0:1),d,k,q-1,r-1),x=this.bidirectional&&l>n;sb(this,e,x?n:l,v,a,c,x?l:n)}}}}this.fastupdate||this.reg.add(a)}else b=""}this.db&& +(b||this.commit_task.push({del:a}),this.da&&tb(this));return this}; +function sb(a,b,c,d,e,h,f){var g=f?a.ctx:a.map,k;if(!b[c]||f&&!(k=b[c])[f])if(f?(b=k||(b[c]=M()),b[f]=1,(k=g.get(f))?g=k:g.set(f,g=new Map)):b[c]=1,(k=g.get(c))?g=k:g.set(c,g=k=[]),g=g[d]||(g[d]=[]),!h||!g.includes(e)){if(g.length===Math.pow(2,31)-1){b=new S(g);if(a.fastupdate)for(c=w(a.reg.values()),h=c.next();!h.done;h=c.next())h=h.value,h.includes(g)&&(h[h.indexOf(g)]=b);k[d]=g=b}g.push(e);a.fastupdate&&((d=a.reg.get(e))?d.push(g):a.reg.set(e,[g]))}} +function rb(a,b,c,d,e){return c&&1b?b?a.slice(c,c+b):a.slice(c):a,d?ub(a):a;for(var e=[],h=0,f=void 0,g=void 0;h=g){c-=g;continue}cb&&(f=f.slice(0,b),g=f.length),e.push(f);else{if(g>=b)return g>b&&(f=f.slice(0,b)),d?ub(f):f;e=[f]}b-=g;if(!b)break}if(!e.length)return e;e=1a.length?e?X(a[0],b,c,d):a[0]:Ya(a,c,b,e,h)};Y.prototype.and=function(){if(this.result.length){var a=this,b=arguments,c=b[0];if(c.then)return c.then(function(){return a.and.apply(a,b)});if(c[0]&&c[0].index)return this.and.apply(this,c);var d=[];c=[];for(var e=0,h=0,f,g,k=0,l=void 0;ka.length)return[];var f=[];M();var g=ya(a);return g?Xa(a,g,b,c,h,e,d):f};Y.prototype.xor=function(){var a=this,b=arguments,c=b[0];if(c.then)return c.then(function(){return a.xor.apply(a,b)});if(c[0]&&c[0].index)return this.xor.apply(this,c);var d=[];c=[];for(var e=0,h=0,f,g,k=0,l=void 0;ka.length)return e?X(a[0],b,c,d):a[0];d=[];for(var f=M(),g=0,k=0,l;kc);if(a.db)return c?a.db.get(k?c:b,k?b:c,d,e,h,f,g):a.db.get(b,"",d,e,h,f,g);a=c?(a=a.ctx.get(k?b:c))&&a.get(k?c:b):a.map.get(b);return a};R.prototype.remove=function(a,b){var c=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(c){if(this.fastupdate)for(var d=0,e;de.length)e.pop();else{var h=e.indexOf(a);h===c.length-1?e.pop():e.splice(h,1)}}else Cb(this.map,a),this.depth&&Cb(this.ctx,a);b||this.reg.delete(a)}this.db&&(this.commit_task.push({del:a}),this.da&&tb(this));this.cache&&this.cache.remove(a);return this}; +function Cb(a,b){var c=0;if(a.constructor===Array)for(var d=0,e=void 0,h;dc||d)a=a.slice(d,d+c);e&&(a=zb.call(this,a));return a}}function zb(a){for(var b=Array(a.length),c=0,d;c=m.length)d-=m.length;else{for(var n=c?d+Math.min(m.length-d,c):m.length,p=d;p=h.length)return[];if(!b&&!c)return h;h=h.slice(c,c+b);return d?e.enrich(h):h})}; -t.enrich=function(a){"object"!==typeof a&&(a=[a]);for(var b=this.db.transaction("reg","readonly").objectStore("reg"),c=[],d=0;d=m.length)d-=m.length;else{for(var n=c?d+Math.min(m.length-d,c):m.length,p=d;p=h.length)return[];if(!b&&!c)return h;h=h.slice(c,c+b);return d?e.enrich(h):h})}; +t.enrich=function(a){"object"!==typeof a&&(a=[a]);for(var b=this.db.transaction("reg","readonly").objectStore("reg"),c=[],d=0;dm&&!h&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(h=1),0<=m)if(e=1,1m&&!h&&"string"===typeof n&&!isNaN(n)&&(m=k.indexOf(parseInt(n,10)))&&(h=1),0<=m)if(e=1,1this.v&&(this.i.clear(),this.l=this.l/1.1|0));f&&b.push(f)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.g&&(this.h.set(a,b),this.h.size>this.v&&(this.h.clear(),this.g=this.g/1.1|0));return b};function D(a){a.j=null;a.h.clear();a.i.clear()};function E(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.g=""}E.prototype.set=function(a,c){this.cache.set(this.g=a,c);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};E.prototype.get=function(a){const c=this.cache.get(a);c&&this.g!==a&&(this.cache.delete(a),this.cache.set(this.g=a,c));return c};E.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}}; E.prototype.clear=function(){this.cache.clear();this.g=""};const F={normalize:function(a){return a.toLowerCase()},dedupe:!1};const G={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};u();H.prototype.add=function(a,c,b,d){if(c&&(a||0===a)){if(!d&&!b&&this.reg.has(a))return this.update(a,c);c=this.encoder.encode(c);if(d=c.length){const q=u(),p=u(),m=this.depth,r=this.resolution;for(let l=0;lg;h--){f=n.substring(g,h);var k=this.score?this.score(c,n,l,f,g):I(r,d,l,e,g);J(this,p,f,k,a,b)}break}case "reverse":if(1< e){for(h=e-1;0f?0:1),d,l,h-1,k-1),K=this.bidirectional&&n>g;J(this,q,K?g:n,A,a,b,K?n:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function J(a,c,b,d,e,g,f){let h=f?a.ctx:a.map,k;c[b]&&f&&(k=c[b])[f]||(f?(c=k||(c[b]=u()),c[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[d]||(h[d]=[]),g&&h.includes(e)||(h.push(e),a.fastupdate&&((c=a.reg.get(e))?c.push(h):a.reg.set(e,[h]))))}function I(a,c,b,d,e){return b&&1c?c?a.slice(b,b+c):a.slice(b):a;let d=[];for(let e=0,g,f;e=f){b-=f;continue}bc&&(g=g.slice(0,c),f=g.length),d.push(g);else{if(f>=c)return f>c&&(g=g.slice(0,c)),g;d=[g]}c-=f;if(!c)break}return d.length?d=1c?c?a.slice(b,b+c):a.slice(b):a;let d=[];for(let e=0,g,f;e=f){b-=f;continue}bc&&(g=g.slice(0,c),f=g.length),d.push(g);else{if(f>=c)return f>c&&(g=g.slice(0,c)),g;d=[g]}c-=f;if(!c)break}return d.length?d=1c||e)b=b.slice(e,c+e)}d=b}return d}; function M(a,c,b,d){return(a=N(this,a,c))&&a.length?L(a,b,d):[]}function O(a,c,b,d){let e=[];if(a){d=Math.min(a.length,d);for(let g=0,f;gb);a=b?(a=a.ctx.get(d?c:b))&&a.get(d?b:c):a.map.get(c);return a};H.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const g=e.indexOf(a);g===b.length-1?e.pop():e.splice(g,1)}}else P(this.map,a),this.depth&&P(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; diff --git a/dist/flexsearch.light.module.debug.js b/dist/flexsearch.light.module.debug.js index a958626..a9a8497 100644 --- a/dist/flexsearch.light.module.debug.js +++ b/dist/flexsearch.light.module.debug.js @@ -271,7 +271,9 @@ H.prototype.add = function(a, c, b, d) { }; function K(a, c, b, d, e, g, f) { let h = f ? a.ctx : a.map, k; - c[b] && f && (k = c[b])[f] || (f ? (c = k || (c[b] = u()), c[f] = 1, (k = h.get(f)) ? h = k : h.set(f, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[d] || (h[d] = []), g && h.includes(e) || (h.push(e), a.fastupdate && ((c = a.reg.get(e)) ? c.push(h) : a.reg.set(e, [h])))); + if (!c[b] || f && !(k = c[b])[f]) { + f ? (c = k || (c[b] = u()), c[f] = 1, (k = h.get(f)) ? h = k : h.set(f, h = new Map())) : c[b] = 1, (k = h.get(b)) ? h = k : h.set(b, h = []), h = h[d] || (h[d] = []), g && h.includes(e) || (h.push(e), a.fastupdate && ((c = a.reg.get(e)) ? c.push(h) : a.reg.set(e, [h]))); + } } function J(a, c, b, d, e) { return b && 1 < a ? c + (d || 0) <= a ? b + (e || 0) : (a - 1) / (c + (d || 0)) * (b + (e || 0)) + 1 | 0 : 0; diff --git a/dist/flexsearch.light.module.min.js b/dist/flexsearch.light.module.min.js index 11be7ab..9a3840d 100644 --- a/dist/flexsearch.light.module.min.js +++ b/dist/flexsearch.light.module.min.js @@ -15,7 +15,7 @@ C.prototype.encode=function(a){if(this.cache&&a.length<=this.g)if(this.j){if(thi h.length<=this.l&&(this.i.set(h,f),this.i.size>this.v&&(this.i.clear(),this.l=this.l/1.1|0));f&&b.push(f)}this.finalize&&(b=this.finalize(b)||b);this.cache&&a.length<=this.g&&(this.h.set(a,b),this.h.size>this.v&&(this.h.clear(),this.g=this.g/1.1|0));return b};function D(a){a.j=null;a.h.clear();a.i.clear()};function E(a){this.limit=a&&!0!==a?a:1E3;this.cache=new Map;this.g=""}E.prototype.set=function(a,c){this.cache.set(this.g=a,c);this.cache.size>this.limit&&this.cache.delete(this.cache.keys().next().value)};E.prototype.get=function(a){const c=this.cache.get(a);c&&this.g!==a&&(this.cache.delete(a),this.cache.set(this.g=a,c));return c};E.prototype.remove=function(a){for(const c of this.cache){const b=c[0];c[1].includes(a)&&this.cache.delete(b)}}; E.prototype.clear=function(){this.cache.clear();this.g=""};const F={normalize:function(a){return a.toLowerCase()},dedupe:!1};const G={memory:{resolution:1},performance:{resolution:6,fastupdate:!0,context:{depth:1,resolution:3}},match:{tokenize:"forward"},score:{resolution:9,context:{depth:2,resolution:9}}};u();I.prototype.add=function(a,c,b,d){if(c&&(a||0===a)){if(!d&&!b&&this.reg.has(a))return this.update(a,c);c=this.encoder.encode(c);if(d=c.length){const q=u(),p=u(),m=this.depth,r=this.resolution;for(let l=0;lg;h--){f=n.substring(g,h);var k=this.score?this.score(c,n,l,f,g):J(r,d,l,e,g);K(this,p,f,k,a,b)}break}case "reverse":if(1< e){for(h=e-1;0f?0:1),d,l,h-1,k-1),H=this.bidirectional&&n>g;K(this,q,H?g:n,A,a,b,H?n:g)}}}}this.fastupdate||this.reg.add(a)}}return this}; -function K(a,c,b,d,e,g,f){let h=f?a.ctx:a.map,k;c[b]&&f&&(k=c[b])[f]||(f?(c=k||(c[b]=u()),c[f]=1,(k=h.get(f))?h=k:h.set(f,h=new Map)):c[b]=1,(k=h.get(b))?h=k:h.set(b,h=[]),h=h[d]||(h[d]=[]),g&&h.includes(e)||(h.push(e),a.fastupdate&&((c=a.reg.get(e))?c.push(h):a.reg.set(e,[h]))))}function J(a,c,b,d,e){return b&&1c?c?a.slice(b,b+c):a.slice(b):a;let d=[];for(let e=0,g,f;e=f){b-=f;continue}bc&&(g=g.slice(0,c),f=g.length),d.push(g);else{if(f>=c)return f>c&&(g=g.slice(0,c)),g;d=[g]}c-=f;if(!c)break}return d.length?d=1c?c?a.slice(b,b+c):a.slice(b):a;let d=[];for(let e=0,g,f;e=f){b-=f;continue}bc&&(g=g.slice(0,c),f=g.length),d.push(g);else{if(f>=c)return f>c&&(g=g.slice(0,c)),g;d=[g]}c-=f;if(!c)break}return d.length?d=1c||e)b=b.slice(e,c+e)}d=b}return d}; function M(a,c,b,d){return(a=N(this,a,c))&&a.length?L(a,b,d):[]}function O(a,c,b,d){let e=[];if(a){d=Math.min(a.length,d);for(let g=0,f;gb);a=b?(a=a.ctx.get(d?c:b))&&a.get(d?b:c):a.map.get(c);return a};I.prototype.remove=function(a,c){const b=this.reg.size&&(this.fastupdate?this.reg.get(a):this.reg.has(a));if(b){if(this.fastupdate)for(let d=0,e;de.length)e.pop();else{const g=e.indexOf(a);g===b.length-1?e.pop():e.splice(g,1)}}else P(this.map,a),this.depth&&P(this.ctx,a);c||this.reg.delete(a)}this.cache&&this.cache.remove(a);return this}; diff --git a/dist/module-debug/charset/arabic/default.js b/dist/module-debug/charset/arabic/default.js index 028abbd..3071aff 100644 --- a/dist/module-debug/charset/arabic/default.js +++ b/dist/module-debug/charset/arabic/default.js @@ -12,31 +12,4 @@ const regex = /[\x00-\x7F]+/g, /** @type EncoderOptions */ -export default options; - -// import { pipeline } from "../../lang.js"; -// -// export const rtl = true; -// export const tokenize = ""; -// export default { -// encode: encode, -// rtl: rtl -// } -// -// -// -// /** -// * @param {string|number} str -// */ -// -// export function encode(str){ -// -// return pipeline.call( -// -// this, -// /* string: */ ("" + str).replace(regex, " "), -// /* normalize: */ false, -// /* split: */ split, -// /* collapse: */ false -// ); -// } \ No newline at end of file +export default options; \ No newline at end of file diff --git a/dist/module-debug/charset/cjk/default.js b/dist/module-debug/charset/cjk/default.js index c4caf70..9f95137 100644 --- a/dist/module-debug/charset/cjk/default.js +++ b/dist/module-debug/charset/cjk/default.js @@ -11,32 +11,4 @@ const regex = /[\x00-\x7F]+/g, /** @type EncoderOptions */ -export default options; - -// import { pipeline } from "../../lang.js"; -// -// export const rtl = false; -// export const tokenize = "strict"; -// export default { -// encode: encode, -// rtl: rtl, -// tokenize: tokenize -// } -// -// const regex = /[\x00-\x7F]+/g; -// -// /** -// * @param {string|number} str -// */ -// -// export function encode(str){ -// -// return pipeline.call( -// -// this, -// /* string: */ ("" + str).replace(regex, ""), -// /* normalize: */ false, -// /* split: */ "", -// /* collapse: */ false -// ); -// } \ No newline at end of file +export default options; \ No newline at end of file diff --git a/dist/module-debug/charset/cyrillic/default.js b/dist/module-debug/charset/cyrillic/default.js index 6de8b9a..85b2ac6 100644 --- a/dist/module-debug/charset/cyrillic/default.js +++ b/dist/module-debug/charset/cyrillic/default.js @@ -10,32 +10,4 @@ const regex = /[\x00-\x7F]+/g, /** @type EncoderOptions */ -export default options; - -// import { pipeline } from "../../lang.js"; -// -// export const rtl = false; -// export const tokenize = ""; -// export default { -// encode: encode, -// rtl: rtl -// } -// -// const regex = /[\x00-\x7F]+/g; -// const split = /\s+/; -// -// /** -// * @param {string|number} str -// */ -// -// export function encode(str){ -// -// return pipeline.call( -// -// this, -// /* string: */ ("" + str).replace(regex, " "), -// /* normalize: */ false, -// /* split: */ split, -// /* collapse: */ false -// ); -// } \ No newline at end of file +export default options; \ No newline at end of file diff --git a/dist/module-debug/charset/latin/advanced.js b/dist/module-debug/charset/latin/advanced.js index 9d30352..937424e 100644 --- a/dist/module-debug/charset/latin/advanced.js +++ b/dist/module-debug/charset/latin/advanced.js @@ -1,44 +1,6 @@ import { EncoderOptions } from "../../type.js"; import { soundex } from "./balance.js"; -// const soundex = new Map([ -// ["b", "p"], -// //["p", "p"], -// -// //["f", "f"], -// ["v", "f"], -// ["w", "f"], -// -// //["s", "s"], -// ["z", "s"], -// ["x", "s"], -// -// ["d", "t"], -// //["t", "t"], -// -// //["m", "m"], -// ["n", "m"], -// -// //["k", "k"], -// ["c", "k"], -// ["g", "k"], -// ["j", "k"], -// ["q", "k"], -// -// //["r", "r"], -// //["h", "h"], -// //["l", "l"], -// -// //["a", "a"], -// -// //["e", "e"], -// ["i", "e"], -// ["y", "e"], -// -// //["o", "o"], -// ["u", "o"] -// ]); - export const matcher = new Map([["ai", "ei"], ["ae", "a"], ["oe", "o"], ["ue", "u"], ["sh", "s"], ["ch", "c"], ["th", "t"], ["ph", "f"], ["pf", "f"]]); export const replacer = [/([^aeo])h([aeo$])/g, "$1$2", /([aeo])h([^aeo]|$)/g, "$1$2"]; @@ -51,95 +13,4 @@ const options = { replacer: replacer, matcher: matcher }; -export default options; - -// import { regex, replace, collapse } from "../../lang.js"; -// import { encode as encode_balance } from "./balance.js"; -// -// export const rtl = false; -// export const tokenize = ""; -// export default { -// encode: encode, -// rtl: rtl, -// tokenize: tokenize -// } -// -// // Phonetic Normalization -// -// const regex_ae = regex("ae"), -// //regex_ai = regex("ai"), -// //regex_ay = regex("ay"), -// //regex_ey = regex("ey"), -// regex_oe = regex("oe"), -// //regex_ue = regex("ue"), -// //regex_ie = regex("ie"), -// //regex_sz = regex("sz"), -// //regex_zs = regex("zs"), -// //regex_ck = regex("ck"), -// //regex_cc = regex("cc"), -// regex_sh = regex("sh"), -// regex_th = regex("th"), -// //regex_dt = regex("dt"), -// regex_ph = regex("ph"), -// regex_pf = regex("pf"); -// //regex_ou = regex("ou"), -// //regex_uo = regex("uo"); -// -// const pairs = [ -// regex_ae, "a", -// // regex_ai, "ei", -// // regex_ay, "ei", -// // regex_ey, "ei", -// regex_oe, "o", -// // regex_ue, "u", -// // regex_ie, "i", -// // regex_sz, "s", -// // regex_zs, "s", -// regex_sh, "s", -// // regex_ck, "k", -// // regex_cc, "k", -// regex_th, "t", -// // regex_dt, "t", -// regex_ph, "f", -// regex_pf, "f", -// // regex_ou, "o", -// // regex_uo, "u" -// -// // regex("(?![aeiouy])h(?![aeiouy])"), "", -// // regex("(?!^[aeiouy])h(?!^[aeiouy])"), "" -// regex("(?![aeo])h(?![aeo])"), "", -// regex("(?!^[aeo])h(?!^[aeo])"), "" -// ]; -// -// /** -// * @param {string|number} str -// * @param {boolean=} _skip_postprocessing -// */ -// -// export function encode(str, _skip_postprocessing){ -// -// if(str){ -// -// str = encode_balance.call(this, str).join(" "); -// -// if(str.length > 2){ -// -// str = replace(str, pairs); -// } -// -// if(!_skip_postprocessing){ -// -// if(str.length > 1){ -// -// str = collapse(str); -// } -// -// if(str){ -// -// str = str.split(" "); -// } -// } -// } -// -// return str || []; -// } \ No newline at end of file +export default options; \ No newline at end of file diff --git a/dist/module-debug/charset/latin/balance.js b/dist/module-debug/charset/latin/balance.js index f6791e8..dae9967 100644 --- a/dist/module-debug/charset/latin/balance.js +++ b/dist/module-debug/charset/latin/balance.js @@ -34,247 +34,4 @@ const options = { dedupe: !0, mapper: soundex }; -export default options; - -// //import { encode as encode_simple } from "./simple.js"; -// import { pipeline } from "../../lang.js"; -// -// // custom soundex implementation -// -// export const rtl = false; -// export const tokenize = ""; -// export default { -// encode: encode, -// rtl: rtl, -// tokenize: tokenize -// } -// -// //const regex_whitespace = /[\W_]+/g; -// const whitespace = /[\p{Z}\p{S}\p{P}\p{C}]+/u; -// const normalize = "".normalize && /[\u0300-\u036f]/g; -// //const regex_strip = /[^a-z0-9]+/; -// -// // const pairs = [ -// // regex_whitespace, " ", -// // regex_strip, "" -// // ]; -// -// // modified -// const pairs = new Map([ -// -// ["b", "p"], -// //["p", "p"], -// -// //["f", "f"], -// ["v", "f"], -// ["w", "f"], -// -// //["s", "s"], -// ["ß", "s"], -// ["z", "s"], -// ["x", "s"], -// -// ["d", "t"], -// //["t", "t"], -// -// //["m", "m"], -// ["n", "m"], -// ["ñ", "m"], -// -// //["k", "k"], -// ["c", "k"], -// ["ç", "k"], -// ["g", "k"], -// ["j", "k"], -// ["q", "k"], -// -// //["r", "r"], -// //["h", "h"], -// //["l", "l"], -// -// //["a", "a"], -// ["à", "a"], -// ["á", "a"], -// ["â", "a"], -// ["ã", "a"], -// ["ä", "a"], -// ["å", "a"], -// -// //["e", "e"], -// ["è", "e"], -// ["é", "e"], -// ["ê", "e"], -// ["ë", "e"], -// ["i", "e"], -// ["ì", "e"], -// ["í", "e"], -// ["î", "e"], -// ["ï", "e"], -// ["y", "e"], -// ["ý", "e"], -// ["ŷ", "e"], -// ["ÿ", "e"], -// -// //["o", "o"], -// ["ò", "o"], -// ["ó", "o"], -// ["ô", "o"], -// ["õ", "o"], -// ["ö", "o"], -// ["ő", "o"], -// ["u", "o"], -// ["ù", "o"], -// ["ú", "o"], -// ["û", "o"], -// ["ü", "o"], -// ["ű", "o"], -// ]); -// -// const map_soundex = new Map([ -// ["b", "p"], -// //["p", "p"], -// -// //["f", "f"], -// ["v", "f"], -// ["w", "f"], -// -// //["s", "s"], -// ["z", "s"], -// ["x", "s"], -// -// ["d", "t"], -// //["t", "t"], -// -// //["m", "m"], -// ["n", "m"], -// -// //["k", "k"], -// ["c", "k"], -// ["g", "k"], -// ["j", "k"], -// ["q", "k"], -// -// //["r", "r"], -// //["h", "h"], -// //["l", "l"], -// -// //["a", "a"], -// -// //["e", "e"], -// ["i", "e"], -// ["y", "e"], -// -// //["o", "o"], -// ["u", "o"] -// ]); -// // const soundex = { -// // -// // "b": "p", -// // //"p": "p", -// // -// // //"f": "f", -// // "v": "f", -// // "w": "f", -// // -// // //"s": "s", -// // "z": "s", -// // "x": "s", -// // "ß": "s", -// // -// // "d": "t", -// // //"t": "t", -// // -// // //"l": "l", -// // -// // //"m": "m", -// // "n": "m", -// // -// // "c": "k", -// // "g": "k", -// // "j": "k", -// // //"k": "k", -// // "q": "k", -// // -// // //"r": "r", -// // //"h": "h", -// // //"a": "a", -// // -// // //"e": "e", -// // "i": "e", -// // "y": "e", -// // -// // //"o": "o", -// // "u": "o" -// // }; -// -// /** -// * @param {string|number} str -// */ -// -// export function encode(str){ -// -// return pipeline.call( -// this, -// /* string: */ ("" + str).normalize("NFD").replace(normalize, "").toLowerCase(), -// /* normalize: */ map_soundex, -// /* split: */ whitespace, -// ///* collapse: */ false -// ); -// -// // return pipeline.call( -// // this, -// // /* string: */ ("" + str).toLowerCase(), -// // /* normalize: */ /*pairs*/ new Map(), -// // /* split: */ whitespace, -// // ///* collapse: */ false -// // ); -// -// // str = encode_simple.call(this, str).join(" "); -// // -// // // str = this.pipeline( -// // // -// // // /* string: */ normalize("" + str).toLowerCase(), -// // // /* normalize: */ false, -// // // /* split: */ false, -// // // /* collapse: */ false -// // // ); -// // -// // const result = []; -// // -// // if(str){ -// // -// // const words = str.split(regex_strip); -// // const length = words.length; -// // -// // for(let x = 0, tmp, count = 0; x < length; x++){ -// // -// // if((str = words[x]) /*&& (str.length > 2)*/ && (!this.filter || !this.filter.has(str))){ -// // -// // tmp = str[0]; -// // let code = soundex[tmp] || tmp; //str[0]; -// // let previous = code; //soundex[code] || code; -// // -// // for(let i = 1; i < str.length; i++){ -// // -// // tmp = str[i]; -// // const current = soundex[tmp] || tmp; -// // -// // if(current && (current !== previous)){ -// // -// // code += current; -// // previous = current; -// // -// // // if(code.length === 7){ -// // // -// // // break; -// // // } -// // } -// // } -// // -// // result[count++] = code; //(code + "0000").substring(0, 4); -// // } -// // } -// // } -// // -// // return result; -// } \ No newline at end of file +export default options; \ No newline at end of file diff --git a/dist/module-debug/charset/latin/default.js b/dist/module-debug/charset/latin/default.js index 5501ee9..37d1df4 100644 --- a/dist/module-debug/charset/latin/default.js +++ b/dist/module-debug/charset/latin/default.js @@ -7,32 +7,4 @@ const options = { }, dedupe: !1 }; -export default options; - -// import { pipeline } from "../../lang.js"; -// -// const whitespace = /[\p{Z}\p{S}\p{P}\p{C}]+/u; -// -// export const rtl = false; -// export const tokenize = ""; -// export default { -// encode: encode, -// rtl: rtl, -// tokenize: tokenize -// } -// -// /** -// * @param {string|number} str -// */ -// -// export function encode(str){ -// -// return pipeline.call( -// -// this, -// /* string: */ ("" + str).toLowerCase(), -// /* normalize: */ false, -// /* split: */ whitespace, -// /* collapse: */ false -// ); -// } \ No newline at end of file +export default options; \ No newline at end of file diff --git a/dist/module-debug/charset/latin/extra.js b/dist/module-debug/charset/latin/extra.js index d1368bd..d64f7f4 100644 --- a/dist/module-debug/charset/latin/extra.js +++ b/dist/module-debug/charset/latin/extra.js @@ -13,71 +13,4 @@ const options = { replacer: replacer.concat(compact), matcher: matcher }; -export default options; - -// import { regex, replace, collapse } from "../../lang.js"; -// import { encode as encode_advanced } from "./advanced.js"; -// -// export const rtl = false; -// export const tokenize = ""; -// export default { -// encode: encode, -// rtl: rtl, -// tokenize: tokenize -// } -// -// // Soundex Normalization -// -// const prefix = "(?!\\b)"; -// const //soundex_b = regex(prefix + "p"), -// // soundex_s = regex(prefix + "z"), -// // soundex_k = regex(prefix + "[cgq]"), -// // soundex_m = regex(prefix + "n"), -// // soundex_t = regex(prefix + "d"), -// // soundex_f = regex(prefix + "[vw]"), -// //regex_vowel = regex(prefix + "[aeiouy]"); -// regex_vowel = regex(prefix + "[aeo]"); -// -// const pairs = [ -// -// // soundex_b, "b", -// // soundex_s, "s", -// // soundex_k, "k", -// // soundex_m, "m", -// // soundex_t, "t", -// // soundex_f, "f", -// // regex("(?![aeiouy])h(?![aeiouy])"), "", -// // regex("(?!^[aeiouy])h(?!^[aeiouy])"), "", -// regex_vowel, "" -// ]; -// -// /** -// * @param {string|number} str -// */ -// -// export function encode(str){ -// -// if(str){ -// -// str = encode_advanced.call(this, str, /* skip post-processing: */ true); -// -// if(str.length > 1){ -// -// //str = replace(str, pairs); -// //str = str.replace(regex_vowel, ""); -// str = str.charAt(0) + str.substring(1).replace(regex_vowel, ""); -// } -// -// if(str.length > 1){ -// -// str = collapse(str); -// } -// -// if(str){ -// -// str = str.split(" "); -// } -// } -// -// return str || []; -// } \ No newline at end of file +export default options; \ No newline at end of file diff --git a/dist/module-debug/charset/latin/simple.js b/dist/module-debug/charset/latin/simple.js index 3ee046c..be96c47 100644 --- a/dist/module-debug/charset/latin/simple.js +++ b/dist/module-debug/charset/latin/simple.js @@ -5,340 +5,4 @@ const options = { normalize: !0, dedupe: !0 }; -export default options; - -// import { pipeline, regex } from "../../lang.js"; -// -// export const rtl = false; -// export const tokenize = ""; -// export default { -// encode: encode, -// rtl: rtl, -// tokenize: tokenize -// } -// -// // p{Z} = whitespaces -// // p{S} = symbols (emotes) -// // p{P} = special chars -// // p{C} = controls (linebreak, tabulator) -// const whitespace = /[\p{Z}\p{S}\p{P}\p{C}]+/u; -// const normalize = "".normalize && /[\u0300-\u036f]/g; -// const pairs = !normalize && new Map([ -// -// // Charset Normalization -// // String.normalize("NFKD").replace(/[\u0300-\u036f]/g, "") -// -// ["ª","a"], -// ["²","2"], -// ["³","3"], -// ["¹","1"], -// ["º","o"], -// ["¼","1⁄4"], -// ["½","1⁄2"], -// ["¾","3⁄4"], -// ["à","a"], -// ["á","a"], -// ["â","a"], -// ["ã","a"], -// ["ä","a"], -// ["å","a"], -// ["ç","c"], -// ["è","e"], -// ["é","e"], -// ["ê","e"], -// ["ë","e"], -// ["ì","i"], -// ["í","i"], -// ["î","i"], -// ["ï","i"], -// ["ñ","n"], -// ["ò","o"], -// ["ó","o"], -// ["ô","o"], -// ["õ","o"], -// ["ö","o"], -// ["ù","u"], -// ["ú","u"], -// ["û","u"], -// ["ü","u"], -// ["ý","y"], -// ["ÿ","y"], -// ["ā","a"], -// ["ă","a"], -// ["ą","a"], -// ["ć","c"], -// ["ĉ","c"], -// ["ċ","c"], -// ["č","c"], -// ["ď","d"], -// ["ē","e"], -// ["ĕ","e"], -// ["ė","e"], -// ["ę","e"], -// ["ě","e"], -// ["ĝ","g"], -// ["ğ","g"], -// ["ġ","g"], -// ["ģ","g"], -// ["ĥ","h"], -// ["ĩ","i"], -// ["ī","i"], -// ["ĭ","i"], -// ["į","i"], -// ["ij","ij"], -// ["ĵ","j"], -// ["ķ","k"], -// ["ĺ","l"], -// ["ļ","l"], -// ["ľ","l"], -// ["ŀ","l"], -// ["ń","n"], -// ["ņ","n"], -// ["ň","n"], -// ["ʼn","n"], -// ["ō","o"], -// ["ŏ","o"], -// ["ő","o"], -// ["ŕ","r"], -// ["ŗ","r"], -// ["ř","r"], -// ["ś","s"], -// ["ŝ","s"], -// ["ş","s"], -// ["š","s"], -// ["ţ","t"], -// ["ť","t"], -// ["ũ","u"], -// ["ū","u"], -// ["ŭ","u"], -// ["ů","u"], -// ["ű","u"], -// ["ų","u"], -// ["ŵ","w"], -// ["ŷ","y"], -// ["ź","z"], -// ["ż","z"], -// ["ž","z"], -// ["ſ","s"], -// ["ơ","o"], -// ["ư","u"], -// ["dž","dz"], -// ["lj","lj"], -// ["nj","nj"], -// ["ǎ","a"], -// ["ǐ","i"], -// ["ǒ","o"], -// ["ǔ","u"], -// ["ǖ","u"], -// ["ǘ","u"], -// ["ǚ","u"], -// ["ǜ","u"], -// ["ǟ","a"], -// ["ǡ","a"], -// ["ǣ","ae"], -// ["æ","ae"], -// ["ǽ","ae"], -// ["ǧ","g"], -// ["ǩ","k"], -// ["ǫ","o"], -// ["ǭ","o"], -// ["ǯ","ʒ"], -// ["ǰ","j"], -// ["dz","dz"], -// ["ǵ","g"], -// ["ǹ","n"], -// ["ǻ","a"], -// ["ǿ","ø"], -// ["ȁ","a"], -// ["ȃ","a"], -// ["ȅ","e"], -// ["ȇ","e"], -// ["ȉ","i"], -// ["ȋ","i"], -// ["ȍ","o"], -// ["ȏ","o"], -// ["ȑ","r"], -// ["ȓ","r"], -// ["ȕ","u"], -// ["ȗ","u"], -// ["ș","s"], -// ["ț","t"], -// ["ȟ","h"], -// ["ȧ","a"], -// ["ȩ","e"], -// ["ȫ","o"], -// ["ȭ","o"], -// ["ȯ","o"], -// ["ȱ","o"], -// ["ȳ","y"], -// ["ʰ","h"], -// ["ʱ","h"], -// ["ɦ","h"], -// ["ʲ","j"], -// ["ʳ","r"], -// ["ʴ","ɹ"], -// ["ʵ","ɻ"], -// ["ʶ","ʁ"], -// ["ʷ","w"], -// ["ʸ","y"], -// ["ˠ","ɣ"], -// ["ˡ","l"], -// ["ˢ","s"], -// ["ˣ","x"], -// ["ˤ","ʕ"], -// ["ΐ","ι"], -// ["ά","α"], -// ["έ","ε"], -// ["ή","η"], -// ["ί","ι"], -// ["ΰ","υ"], -// ["ϊ","ι"], -// ["ϋ","υ"], -// ["ό","ο"], -// ["ύ","υ"], -// ["ώ","ω"], -// ["ϐ","β"], -// ["ϑ","θ"], -// ["ϒ","Υ"], -// ["ϓ","Υ"], -// ["ϔ","Υ"], -// ["ϕ","φ"], -// ["ϖ","π"], -// ["ϰ","κ"], -// ["ϱ","ρ"], -// ["ϲ","ς"], -// ["ϵ","ε"], -// ["й","и"], -// ["ѐ","е"], -// ["ё","е"], -// ["ѓ","г"], -// ["ї","і"], -// ["ќ","к"], -// ["ѝ","и"], -// ["ў","у"], -// ["ѷ","ѵ"], -// ["ӂ","ж"], -// ["ӑ","а"], -// ["ӓ","а"], -// ["ӗ","е"], -// ["ӛ","ә"], -// ["ӝ","ж"], -// ["ӟ","з"], -// ["ӣ","и"], -// ["ӥ","и"], -// ["ӧ","о"], -// ["ӫ","ө"], -// ["ӭ","э"], -// ["ӯ","у"], -// ["ӱ","у"], -// ["ӳ","у"], -// ["ӵ","ч"] -// -// // Charset Normalization -// -// // ["à", "a"], -// // ["á", "a"], -// // ["â", "a"], -// // ["ã", "a"], -// // ["ä", "a"], -// // ["å", "a"], -// // -// // ["è", "e"], -// // ["é", "e"], -// // ["ê", "e"], -// // ["ë", "e"], -// // -// // ["ì", "i"], -// // ["í", "i"], -// // ["î", "i"], -// // ["ï", "i"], -// // -// // ["ò", "o"], -// // ["ó", "o"], -// // ["ô", "o"], -// // ["õ", "o"], -// // ["ö", "o"], -// // ["ő", "o"], -// // -// // ["ù", "u"], -// // ["ú", "u"], -// // ["û", "u"], -// // ["ü", "u"], -// // ["ű", "u"], -// // -// // ["ý", "y"], -// // ["ŷ", "y"], -// // ["ÿ", "y"], -// // -// // ["ñ", "n"], -// // ["ç", "c"], -// // ["ß", "s"] -// -// // Special Chars Removal -// -// // [",", ""], -// // [".", ""], -// // ["'", ""] -// -// // Non-Whitespace Separators -// -// // split by default p{P} -// // ["-", " "], -// // [":", " "], -// // ["_", " "], -// // ["|", " "], -// // ["/", " "], -// // ["\\", " "] -// ]); -// -// // let pairs; -// // -// // if(!normalize){ -// // -// // // Charset Normalization -// // -// // const regex_a = regex("[àáâãäå]"), -// // regex_e = regex("[èéêë]"), -// // regex_i = regex("[ìíîï]"), -// // regex_o = regex("[òóôõöő]"), -// // regex_u = regex("[ùúûüű]"), -// // regex_y = regex("[ýŷÿ]"), -// // regex_n = regex("ñ"), -// // //regex_c = regex("[çc]"), -// // regex_c = regex("ç"), -// // regex_s = regex("ß"), -// // //regex_and = regex(" & "), -// // regex_and = regex("&"); -// // -// // pairs = [ -// // regex_a, "a", -// // regex_e, "e", -// // regex_i, "i", -// // regex_o, "o", -// // regex_u, "u", -// // regex_y, "y", -// // regex_n, "n", -// // //regex_c, "k", -// // regex_c, "c", -// // regex_s, "s", -// // regex_and, " and " -// // ]; -// // } -// -// /** -// * @param {string|number} str -// */ -// -// export function encode(str){ -// -// //str = "" + str; -// -// return pipeline.call( -// -// this, -// /* string: */ (/*normalize ? str.normalize("NFD").replace(normalize, "") :*/ "" + str).toLowerCase(), -// /* normalize: */ pairs, -// /* split: */ whitespace, -// ///* collapse: */ false -// ); -// } \ No newline at end of file +export default options; \ No newline at end of file diff --git a/dist/module-debug/index/add.js b/dist/module-debug/index/add.js index 0f47234..387a1bd 100644 --- a/dist/module-debug/index/add.js +++ b/dist/module-debug/index/add.js @@ -174,7 +174,7 @@ Index.prototype.push_index = function (dupes, term, score, id, append, keyword) tmp; - if (!dupes[term] || !keyword || !(tmp = dupes[term])[keyword]) { + if (!dupes[term] || keyword && !(tmp = dupes[term])[keyword]) { if (keyword) { diff --git a/dist/module-debug/resolve/and.js b/dist/module-debug/resolve/and.js index 775c109..40e09cd 100644 --- a/dist/module-debug/resolve/and.js +++ b/dist/module-debug/resolve/and.js @@ -1,6 +1,7 @@ import Resolver from "../resolver.js"; import { create_object, get_max_len } from "../common.js"; import { intersect as _intersect } from "../intersect.js"; +import { ResolverOptions } from "../type.js"; Resolver.prototype.and = function () { if (this.result.length) { @@ -33,7 +34,10 @@ Resolver.prototype.and = function () { for (let i = 0, query; i < args.length; i++) { - if (query = args[i]) { + + query = /** @type {string|ResolverOptions} */args[i]; + + if (query) { limit = query.limit || 0; offset = query.offset || 0; diff --git a/dist/module-debug/resolve/not.js b/dist/module-debug/resolve/not.js index 5515d5b..fd78a3a 100644 --- a/dist/module-debug/resolve/not.js +++ b/dist/module-debug/resolve/not.js @@ -1,9 +1,5 @@ import Resolver from "../resolver.js"; -import default_resolver from "./default.js"; -import { create_object } from "../common.js"; -// import or from "./or.js"; -// import and from "./and.js"; -// import xor from "./xor.js"; +import { ResolverOptions } from "../type.js"; Resolver.prototype.not = function () { const self = this; @@ -32,7 +28,10 @@ Resolver.prototype.not = function () { for (let i = 0, query; i < args.length; i++) { - if (query = args[i]) { + + query = /** @type {string|ResolverOptions} */args[i]; + + if (query) { limit = query.limit || 0; offset = query.offset || 0; diff --git a/dist/module-debug/resolve/or.js b/dist/module-debug/resolve/or.js index e56c519..b23a87b 100644 --- a/dist/module-debug/resolve/or.js +++ b/dist/module-debug/resolve/or.js @@ -1,7 +1,7 @@ import Resolver from "../resolver.js"; import default_resolver from "./default.js"; -import { create_object, get_max_len } from "../common.js"; import { union as _union } from "../intersect.js"; +import { ResolverOptions } from "../type.js"; Resolver.prototype.or = function () { @@ -23,31 +23,6 @@ Resolver.prototype.or = function () { } } - // for(let i = 0; i < args.length; i++){ - // if(args[i].result instanceof Promise){ - // return; - // } - // } - - // if(args.length < 2){ - // if(first_argument.index){ - // first_argument.resolve = false; - // const result = first_argument.index.search(first_argument); - // if(result instanceof Promise){ - // result.then(function(result){ - // final = self.result.concat(result); - // self.result = resolver(final, limit, offset, enrich, !resolve); - // return resolve ? self.result : self; - // }); - // } - // else{ - // final = this.result.concat(result); - // this.result = resolver(final, limit, offset, enrich, !resolve); - // return resolve ? this.result : this; - // } - // } - // } - let final = [], promises = [], limit = 0, @@ -57,7 +32,10 @@ Resolver.prototype.or = function () { for (let i = 0, query; i < args.length; i++) { - if (query = args[i]) { + + query = /** @type {string|ResolverOptions} */args[i]; + + if (query) { limit = query.limit || 0; offset = query.offset || 0; diff --git a/dist/module-debug/resolve/xor.js b/dist/module-debug/resolve/xor.js index 538a7f4..9026feb 100644 --- a/dist/module-debug/resolve/xor.js +++ b/dist/module-debug/resolve/xor.js @@ -1,9 +1,7 @@ import Resolver from "../resolver.js"; import default_resolver from "./default.js"; import { create_object } from "../common.js"; -// import or from "./or.js"; -// import and from "./and.js"; -// import not from "./not.js"; +import { ResolverOptions } from "../type.js"; Resolver.prototype.xor = function () { const self = this; @@ -33,7 +31,10 @@ Resolver.prototype.xor = function () { for (let i = 0, query; i < args.length; i++) { - if (query = args[i]) { + + query = /** @type {string|ResolverOptions} */args[i]; + + if (query) { limit = query.limit || 0; offset = query.offset || 0; diff --git a/dist/module-debug/resolver.js b/dist/module-debug/resolver.js index 8a82beb..3c3890d 100644 --- a/dist/module-debug/resolver.js +++ b/dist/module-debug/resolver.js @@ -1,12 +1,13 @@ import default_resolver from "./resolve/default.js"; import { set_resolve } from "./index/search.js"; +import { ResolverOptions } from "./type.js"; import "./resolve/or.js"; import "./resolve/and.js"; import "./resolve/xor.js"; import "./resolve/not.js"; /** - * @param result + * @param {Array|ResolverOptions=} result * @constructor */ @@ -73,6 +74,12 @@ Resolver.prototype.boost = function (boost) { return this; }; +/** + * @param {number|ResolverOptions=} limit + * @param {number=} offset + * @param {boolean=} enrich + */ + Resolver.prototype.resolve = function (limit, offset, enrich) { set_resolve(1); const result = this.result; diff --git a/dist/module-debug/type.js b/dist/module-debug/type.js index 1ce14ce..a13ad73 100644 --- a/dist/module-debug/type.js +++ b/dist/module-debug/type.js @@ -1,5 +1,6 @@ // When you are looking for type definitions which fully describes the usage take a look into the index.d.ts file. // Some of the types here aren't supposed to be used as public, they might be defined just for internal state. +import Index from "./index.js"; import Encoder from "./encoder.js"; import StorageInterface from "./db/interface.js"; @@ -23,7 +24,7 @@ import StorageInterface from "./db/interface.js"; * config: string|undefined * }} */ -export let IndexOptions = {}; +export const IndexOptions = {}; /** * @typedef DocumentIndexOptions {{ @@ -46,7 +47,7 @@ export let IndexOptions = {}; * custom: Function|undefined * }} */ -export let DocumentIndexOptions = {}; +export const DocumentIndexOptions = {}; /** * @typedef DocumentOptions {{ @@ -66,7 +67,7 @@ export let DocumentIndexOptions = {}; * worker: boolean|string|undefined * }} */ -export let DocumentOptions = {}; +export const DocumentOptions = {}; /** * @typedef ContextOptions {{ @@ -75,7 +76,7 @@ export let DocumentOptions = {}; * resolution: number|undefined * }} */ -export let ContextOptions = {}; +export const ContextOptions = {}; /** * @typedef DocumentDescriptor {{ @@ -86,7 +87,7 @@ export let ContextOptions = {}; * store: StoreOptions|Array|undefined * }} */ -export let DocumentDescriptor = {}; +export const DocumentDescriptor = {}; /** * @typedef TagOptions {{ @@ -99,7 +100,7 @@ export let DocumentDescriptor = {}; * config: string|undefined * }} */ -export let TagOptions = {}; +export const TagOptions = {}; /** * @typedef StoreOptions {{ @@ -109,7 +110,7 @@ export let TagOptions = {}; * config: string|undefined * }} */ -export let StoreOptions = {}; +export const StoreOptions = {}; /** * @typedef SearchOptions {{ @@ -122,7 +123,7 @@ export let StoreOptions = {}; * enrich: [boolean=false] * }} */ -export let SearchOptions = {}; +export const SearchOptions = {}; // tag: Array|undefined /** @@ -140,7 +141,7 @@ export let SearchOptions = {}; * merge: [boolean=false] * }} */ -export let DocumentSearchOptions = {}; +export const DocumentSearchOptions = {}; /** * @typedef DocumentSearchResults Array<{{ @@ -149,7 +150,7 @@ export let DocumentSearchOptions = {}; * result: Array * }}> */ -export let DocumentSearchResults = {}; +export const DocumentSearchResults = {}; /** * @typedef EnrichedDocumentSearchResults Array<{{ @@ -161,7 +162,7 @@ export let DocumentSearchResults = {}; * }}> * }}> */ -export let EnrichedDocumentSearchResults = {}; +export const EnrichedDocumentSearchResults = {}; /** * @typedef MergedDocumentSearchResults Array<{{ @@ -170,7 +171,7 @@ export let EnrichedDocumentSearchResults = {}; * field: Array * }}> */ -export let MergedDocumentSearchResults = {}; +export const MergedDocumentSearchResults = {}; /** * @typedef EncoderOptions {{ @@ -191,7 +192,7 @@ export let MergedDocumentSearchResults = {}; * cache: boolean=true, * }} */ -export let EncoderOptions = {}; +export const EncoderOptions = {}; /** * @typedef EncoderSplitOptions {{ @@ -203,7 +204,7 @@ export let EncoderOptions = {}; * char: string|Array|undefined, * }} */ -export let EncoderSplitOptions = {}; +export const EncoderSplitOptions = {}; /** * @typedef PersistentOptions {{ @@ -213,4 +214,17 @@ export let EncoderSplitOptions = {}; * db: *|undefined * }} */ -export let PersistentOptions = {}; \ No newline at end of file +export const PersistentOptions = {}; + +/** + * @typedef ResolverOptions {{ + * index: Index|undefined, + * query: string, + * limit: [number=0], + * offset: [number=0], + * enrich: boolean=false, + * resolve: boolean=false, + * suggest: boolean=false + * }} + */ +export const ResolverOptions = {}; \ No newline at end of file diff --git a/dist/module-debug/webpack.js b/dist/module-debug/webpack.js index e3f9974..14b8528 100644 --- a/dist/module-debug/webpack.js +++ b/dist/module-debug/webpack.js @@ -1,5 +1,5 @@ -import { SearchOptions, ContextOptions, DocumentDescriptor, DocumentSearchOptions, DocumentIndexOptions, IndexOptions, DocumentOptions, TagOptions, StoreOptions, EncoderOptions, EncoderSplitOptions, PersistentOptions } from "./type.js"; +import { SearchOptions, ContextOptions, DocumentDescriptor, DocumentSearchOptions, DocumentIndexOptions, IndexOptions, DocumentOptions, TagOptions, StoreOptions, EncoderOptions, EncoderSplitOptions, PersistentOptions, ResolverOptions } from "./type.js"; import StorageInterface from "./db/interface.js"; import Document from "./document.js"; import Index from "./index.js"; @@ -223,6 +223,14 @@ import Charset from "./charset.js"; /** @export */PersistentOptions.type; /** @export */PersistentOptions.db; +/** @export */ResolverOptions.index; +/** @export */ResolverOptions.query; +/** @export */ResolverOptions.limit; +/** @export */ResolverOptions.offset; +/** @export */ResolverOptions.enrich; +/** @export */ResolverOptions.resolve; +/** @export */ResolverOptions.suggest; + const FlexSearch = { Index: Index, Charset: Charset, diff --git a/dist/module-min/index/add.js b/dist/module-min/index/add.js index 1e04541..61e4087 100644 --- a/dist/module-min/index/add.js +++ b/dist/module-min/index/add.js @@ -1 +1 @@ -import{create_object}from"../common.js";import Index,{autoCommit}from"../index.js";import default_compress from"../compress.js";import{KeystoreArray}from"../keystore.js";Index.prototype.add=function(a,b,c,d){if(b&&(a||0===a)){if(!d&&!c&&this.reg.has(a))return this.update(a,b);b=this.encoder.encode(b);const e=b.length;if(e){const d=create_object(),f=create_object(),g=this.depth,h=this.resolution;for(let j=0;jd;g--){m=i.substring(d,g);const l=this.score?this.score(b,i,j,m,d):get_score(h,e,j,k,d);this.push_index(f,m,l,a,c)}break}case"reverse":if(1h?0:1),e,j,l-1,g-1),n=this.bidirectional&&i>k;this.push_index(d,n?k:i,m,a,c,n?i:k)}}}}}this.fastupdate||this.reg.add(a)}else b=""}return this.db&&(b||this.commit_task.push({del:a}),this.commit_auto&&autoCommit(this)),this},Index.prototype.push_index=function(a,b,c,d,e,f){let g,h=f?this.ctx:this.map;if((!a[b]||!f||!(g=a[b])[f])&&(f?(a=g||(a[b]=create_object()),a[f]=1,this.compress&&(f=default_compress(f)),g=h.get(f),g?h=g:h.set(f,h=new Map)):a[b]=1,this.compress&&(b=default_compress(b)),g=h.get(b),g?h=g:h.set(b,h=g=[]),h=h[c]||(h[c]=[]),!e||!h.includes(d))){if(2147483647===h.length){const a=new KeystoreArray(h);if(this.fastupdate)for(let b of this.reg.values())b.includes(h)&&(b[b.indexOf(h)]=a);g[c]=h=a}if(h.push(d),this.fastupdate){const a=this.reg.get(d);a?a.push(h):this.reg.set(d,[h])}}};function get_score(a,b,c,d,e){return c&&1d;g--){m=i.substring(d,g);const l=this.score?this.score(b,i,j,m,d):get_score(h,e,j,k,d);this.push_index(f,m,l,a,c)}break}case"reverse":if(1h?0:1),e,j,l-1,g-1),n=this.bidirectional&&i>k;this.push_index(d,n?k:i,m,a,c,n?i:k)}}}}}this.fastupdate||this.reg.add(a)}else b=""}return this.db&&(b||this.commit_task.push({del:a}),this.commit_auto&&autoCommit(this)),this},Index.prototype.push_index=function(a,b,c,d,e,f){let g,h=f?this.ctx:this.map;if((!a[b]||f&&!(g=a[b])[f])&&(f?(a=g||(a[b]=create_object()),a[f]=1,this.compress&&(f=default_compress(f)),g=h.get(f),g?h=g:h.set(f,h=new Map)):a[b]=1,this.compress&&(b=default_compress(b)),g=h.get(b),g?h=g:h.set(b,h=g=[]),h=h[c]||(h[c]=[]),!e||!h.includes(d))){if(2147483647===h.length){const a=new KeystoreArray(h);if(this.fastupdate)for(let b of this.reg.values())b.includes(h)&&(b[b.indexOf(h)]=a);g[c]=h=a}if(h.push(d),this.fastupdate){const a=this.reg.get(d);a?a.push(h):this.reg.set(d,[h])}}};function get_score(a,b,c,d,e){return c&&1a.length)return[];let h=create_object(),i=get_max_len(a);return i?_intersect(a,i,b,c,g,f,e):[]} \ No newline at end of file +import Resolver from"../resolver.js";import{create_object,get_max_len}from"../common.js";import{intersect as _intersect}from"../intersect.js";import{ResolverOptions}from"../type.js";Resolver.prototype.and=function(){if(this.result.length){const a=this;let b=arguments,c=b[0];if(c.then)return c.then(function(){return a.and.apply(a,b)});if(c[0]&&c[0].index)return this.and.apply(this,c);let d,e,f,g=[],h=[],j=0,k=0;for(let a,c=0;ca.length)return[];let h=create_object(),i=get_max_len(a);return i?_intersect(a,i,b,c,g,f,e):[]} \ No newline at end of file diff --git a/dist/module-min/resolve/not.js b/dist/module-min/resolve/not.js index 22f6797..d544eff 100644 --- a/dist/module-min/resolve/not.js +++ b/dist/module-min/resolve/not.js @@ -1 +1 @@ -import Resolver from"../resolver.js";import default_resolver from"./default.js";import{create_object}from"../common.js";Resolver.prototype.not=function(){const a=this;let b=arguments,c=b[0];if(c.then)return c.then(function(){return a.not.apply(a,b)});if(c[0]&&c[0].index)return this.not.apply(this,c);let d,e,f=[],g=[],h=0,j=0;for(let a,c=0;ca.length?e?default_resolver(a[0],b,c,d):a[0]:_union(a,c,b,e,f)):a} \ No newline at end of file +import Resolver from"../resolver.js";import default_resolver from"./default.js";import{union as _union}from"../intersect.js";import{ResolverOptions}from"../type.js";Resolver.prototype.or=function(){const a=this;let b=arguments,c=b[0];if(c.then)return c.then(function(){return a.or.apply(a,b)});if(c[0]&&c[0].index)return this.or.apply(this,c);let d,e,f=[],g=[],h=0,j=0;for(let a,c=0;ca.length?e?default_resolver(a[0],b,c,d):a[0]:_union(a,c,b,e,f)):a} \ No newline at end of file diff --git a/dist/module-min/resolve/xor.js b/dist/module-min/resolve/xor.js index 1be2f20..868b711 100644 --- a/dist/module-min/resolve/xor.js +++ b/dist/module-min/resolve/xor.js @@ -1 +1 @@ -import Resolver from"../resolver.js";import default_resolver from"./default.js";import{create_object}from"../common.js";Resolver.prototype.xor=function(){const a=this;let b=arguments,c=b[0];if(c.then)return c.then(function(){return a.xor.apply(a,b)});if(c[0]&&c[0].index)return this.xor.apply(this,c);let d,e,f=[],g=[],h=0,j=0;for(let a,c=0;ca.length)return e?default_resolver(a[0],b,c,d):a[0];const g=[],h=create_object();let i=0;for(let g,j=0;ja.length)return e?default_resolver(a[0],b,c,d):a[0];const g=[],h=create_object();let i=0;for(let g,j=0;j 2){ -// -// str = replace(str, pairs); -// } -// -// if(!_skip_postprocessing){ -// -// if(str.length > 1){ -// -// str = collapse(str); -// } -// -// if(str){ -// -// str = str.split(" "); -// } -// } -// } -// -// return str || []; -// } \ No newline at end of file +export default options; \ No newline at end of file diff --git a/dist/module/charset/latin/balance.js b/dist/module/charset/latin/balance.js index f6791e8..dae9967 100644 --- a/dist/module/charset/latin/balance.js +++ b/dist/module/charset/latin/balance.js @@ -34,247 +34,4 @@ const options = { dedupe: !0, mapper: soundex }; -export default options; - -// //import { encode as encode_simple } from "./simple.js"; -// import { pipeline } from "../../lang.js"; -// -// // custom soundex implementation -// -// export const rtl = false; -// export const tokenize = ""; -// export default { -// encode: encode, -// rtl: rtl, -// tokenize: tokenize -// } -// -// //const regex_whitespace = /[\W_]+/g; -// const whitespace = /[\p{Z}\p{S}\p{P}\p{C}]+/u; -// const normalize = "".normalize && /[\u0300-\u036f]/g; -// //const regex_strip = /[^a-z0-9]+/; -// -// // const pairs = [ -// // regex_whitespace, " ", -// // regex_strip, "" -// // ]; -// -// // modified -// const pairs = new Map([ -// -// ["b", "p"], -// //["p", "p"], -// -// //["f", "f"], -// ["v", "f"], -// ["w", "f"], -// -// //["s", "s"], -// ["ß", "s"], -// ["z", "s"], -// ["x", "s"], -// -// ["d", "t"], -// //["t", "t"], -// -// //["m", "m"], -// ["n", "m"], -// ["ñ", "m"], -// -// //["k", "k"], -// ["c", "k"], -// ["ç", "k"], -// ["g", "k"], -// ["j", "k"], -// ["q", "k"], -// -// //["r", "r"], -// //["h", "h"], -// //["l", "l"], -// -// //["a", "a"], -// ["à", "a"], -// ["á", "a"], -// ["â", "a"], -// ["ã", "a"], -// ["ä", "a"], -// ["å", "a"], -// -// //["e", "e"], -// ["è", "e"], -// ["é", "e"], -// ["ê", "e"], -// ["ë", "e"], -// ["i", "e"], -// ["ì", "e"], -// ["í", "e"], -// ["î", "e"], -// ["ï", "e"], -// ["y", "e"], -// ["ý", "e"], -// ["ŷ", "e"], -// ["ÿ", "e"], -// -// //["o", "o"], -// ["ò", "o"], -// ["ó", "o"], -// ["ô", "o"], -// ["õ", "o"], -// ["ö", "o"], -// ["ő", "o"], -// ["u", "o"], -// ["ù", "o"], -// ["ú", "o"], -// ["û", "o"], -// ["ü", "o"], -// ["ű", "o"], -// ]); -// -// const map_soundex = new Map([ -// ["b", "p"], -// //["p", "p"], -// -// //["f", "f"], -// ["v", "f"], -// ["w", "f"], -// -// //["s", "s"], -// ["z", "s"], -// ["x", "s"], -// -// ["d", "t"], -// //["t", "t"], -// -// //["m", "m"], -// ["n", "m"], -// -// //["k", "k"], -// ["c", "k"], -// ["g", "k"], -// ["j", "k"], -// ["q", "k"], -// -// //["r", "r"], -// //["h", "h"], -// //["l", "l"], -// -// //["a", "a"], -// -// //["e", "e"], -// ["i", "e"], -// ["y", "e"], -// -// //["o", "o"], -// ["u", "o"] -// ]); -// // const soundex = { -// // -// // "b": "p", -// // //"p": "p", -// // -// // //"f": "f", -// // "v": "f", -// // "w": "f", -// // -// // //"s": "s", -// // "z": "s", -// // "x": "s", -// // "ß": "s", -// // -// // "d": "t", -// // //"t": "t", -// // -// // //"l": "l", -// // -// // //"m": "m", -// // "n": "m", -// // -// // "c": "k", -// // "g": "k", -// // "j": "k", -// // //"k": "k", -// // "q": "k", -// // -// // //"r": "r", -// // //"h": "h", -// // //"a": "a", -// // -// // //"e": "e", -// // "i": "e", -// // "y": "e", -// // -// // //"o": "o", -// // "u": "o" -// // }; -// -// /** -// * @param {string|number} str -// */ -// -// export function encode(str){ -// -// return pipeline.call( -// this, -// /* string: */ ("" + str).normalize("NFD").replace(normalize, "").toLowerCase(), -// /* normalize: */ map_soundex, -// /* split: */ whitespace, -// ///* collapse: */ false -// ); -// -// // return pipeline.call( -// // this, -// // /* string: */ ("" + str).toLowerCase(), -// // /* normalize: */ /*pairs*/ new Map(), -// // /* split: */ whitespace, -// // ///* collapse: */ false -// // ); -// -// // str = encode_simple.call(this, str).join(" "); -// // -// // // str = this.pipeline( -// // // -// // // /* string: */ normalize("" + str).toLowerCase(), -// // // /* normalize: */ false, -// // // /* split: */ false, -// // // /* collapse: */ false -// // // ); -// // -// // const result = []; -// // -// // if(str){ -// // -// // const words = str.split(regex_strip); -// // const length = words.length; -// // -// // for(let x = 0, tmp, count = 0; x < length; x++){ -// // -// // if((str = words[x]) /*&& (str.length > 2)*/ && (!this.filter || !this.filter.has(str))){ -// // -// // tmp = str[0]; -// // let code = soundex[tmp] || tmp; //str[0]; -// // let previous = code; //soundex[code] || code; -// // -// // for(let i = 1; i < str.length; i++){ -// // -// // tmp = str[i]; -// // const current = soundex[tmp] || tmp; -// // -// // if(current && (current !== previous)){ -// // -// // code += current; -// // previous = current; -// // -// // // if(code.length === 7){ -// // // -// // // break; -// // // } -// // } -// // } -// // -// // result[count++] = code; //(code + "0000").substring(0, 4); -// // } -// // } -// // } -// // -// // return result; -// } \ No newline at end of file +export default options; \ No newline at end of file diff --git a/dist/module/charset/latin/default.js b/dist/module/charset/latin/default.js index 5501ee9..37d1df4 100644 --- a/dist/module/charset/latin/default.js +++ b/dist/module/charset/latin/default.js @@ -7,32 +7,4 @@ const options = { }, dedupe: !1 }; -export default options; - -// import { pipeline } from "../../lang.js"; -// -// const whitespace = /[\p{Z}\p{S}\p{P}\p{C}]+/u; -// -// export const rtl = false; -// export const tokenize = ""; -// export default { -// encode: encode, -// rtl: rtl, -// tokenize: tokenize -// } -// -// /** -// * @param {string|number} str -// */ -// -// export function encode(str){ -// -// return pipeline.call( -// -// this, -// /* string: */ ("" + str).toLowerCase(), -// /* normalize: */ false, -// /* split: */ whitespace, -// /* collapse: */ false -// ); -// } \ No newline at end of file +export default options; \ No newline at end of file diff --git a/dist/module/charset/latin/extra.js b/dist/module/charset/latin/extra.js index d1368bd..d64f7f4 100644 --- a/dist/module/charset/latin/extra.js +++ b/dist/module/charset/latin/extra.js @@ -13,71 +13,4 @@ const options = { replacer: replacer.concat(compact), matcher: matcher }; -export default options; - -// import { regex, replace, collapse } from "../../lang.js"; -// import { encode as encode_advanced } from "./advanced.js"; -// -// export const rtl = false; -// export const tokenize = ""; -// export default { -// encode: encode, -// rtl: rtl, -// tokenize: tokenize -// } -// -// // Soundex Normalization -// -// const prefix = "(?!\\b)"; -// const //soundex_b = regex(prefix + "p"), -// // soundex_s = regex(prefix + "z"), -// // soundex_k = regex(prefix + "[cgq]"), -// // soundex_m = regex(prefix + "n"), -// // soundex_t = regex(prefix + "d"), -// // soundex_f = regex(prefix + "[vw]"), -// //regex_vowel = regex(prefix + "[aeiouy]"); -// regex_vowel = regex(prefix + "[aeo]"); -// -// const pairs = [ -// -// // soundex_b, "b", -// // soundex_s, "s", -// // soundex_k, "k", -// // soundex_m, "m", -// // soundex_t, "t", -// // soundex_f, "f", -// // regex("(?![aeiouy])h(?![aeiouy])"), "", -// // regex("(?!^[aeiouy])h(?!^[aeiouy])"), "", -// regex_vowel, "" -// ]; -// -// /** -// * @param {string|number} str -// */ -// -// export function encode(str){ -// -// if(str){ -// -// str = encode_advanced.call(this, str, /* skip post-processing: */ true); -// -// if(str.length > 1){ -// -// //str = replace(str, pairs); -// //str = str.replace(regex_vowel, ""); -// str = str.charAt(0) + str.substring(1).replace(regex_vowel, ""); -// } -// -// if(str.length > 1){ -// -// str = collapse(str); -// } -// -// if(str){ -// -// str = str.split(" "); -// } -// } -// -// return str || []; -// } \ No newline at end of file +export default options; \ No newline at end of file diff --git a/dist/module/charset/latin/simple.js b/dist/module/charset/latin/simple.js index 3ee046c..be96c47 100644 --- a/dist/module/charset/latin/simple.js +++ b/dist/module/charset/latin/simple.js @@ -5,340 +5,4 @@ const options = { normalize: !0, dedupe: !0 }; -export default options; - -// import { pipeline, regex } from "../../lang.js"; -// -// export const rtl = false; -// export const tokenize = ""; -// export default { -// encode: encode, -// rtl: rtl, -// tokenize: tokenize -// } -// -// // p{Z} = whitespaces -// // p{S} = symbols (emotes) -// // p{P} = special chars -// // p{C} = controls (linebreak, tabulator) -// const whitespace = /[\p{Z}\p{S}\p{P}\p{C}]+/u; -// const normalize = "".normalize && /[\u0300-\u036f]/g; -// const pairs = !normalize && new Map([ -// -// // Charset Normalization -// // String.normalize("NFKD").replace(/[\u0300-\u036f]/g, "") -// -// ["ª","a"], -// ["²","2"], -// ["³","3"], -// ["¹","1"], -// ["º","o"], -// ["¼","1⁄4"], -// ["½","1⁄2"], -// ["¾","3⁄4"], -// ["à","a"], -// ["á","a"], -// ["â","a"], -// ["ã","a"], -// ["ä","a"], -// ["å","a"], -// ["ç","c"], -// ["è","e"], -// ["é","e"], -// ["ê","e"], -// ["ë","e"], -// ["ì","i"], -// ["í","i"], -// ["î","i"], -// ["ï","i"], -// ["ñ","n"], -// ["ò","o"], -// ["ó","o"], -// ["ô","o"], -// ["õ","o"], -// ["ö","o"], -// ["ù","u"], -// ["ú","u"], -// ["û","u"], -// ["ü","u"], -// ["ý","y"], -// ["ÿ","y"], -// ["ā","a"], -// ["ă","a"], -// ["ą","a"], -// ["ć","c"], -// ["ĉ","c"], -// ["ċ","c"], -// ["č","c"], -// ["ď","d"], -// ["ē","e"], -// ["ĕ","e"], -// ["ė","e"], -// ["ę","e"], -// ["ě","e"], -// ["ĝ","g"], -// ["ğ","g"], -// ["ġ","g"], -// ["ģ","g"], -// ["ĥ","h"], -// ["ĩ","i"], -// ["ī","i"], -// ["ĭ","i"], -// ["į","i"], -// ["ij","ij"], -// ["ĵ","j"], -// ["ķ","k"], -// ["ĺ","l"], -// ["ļ","l"], -// ["ľ","l"], -// ["ŀ","l"], -// ["ń","n"], -// ["ņ","n"], -// ["ň","n"], -// ["ʼn","n"], -// ["ō","o"], -// ["ŏ","o"], -// ["ő","o"], -// ["ŕ","r"], -// ["ŗ","r"], -// ["ř","r"], -// ["ś","s"], -// ["ŝ","s"], -// ["ş","s"], -// ["š","s"], -// ["ţ","t"], -// ["ť","t"], -// ["ũ","u"], -// ["ū","u"], -// ["ŭ","u"], -// ["ů","u"], -// ["ű","u"], -// ["ų","u"], -// ["ŵ","w"], -// ["ŷ","y"], -// ["ź","z"], -// ["ż","z"], -// ["ž","z"], -// ["ſ","s"], -// ["ơ","o"], -// ["ư","u"], -// ["dž","dz"], -// ["lj","lj"], -// ["nj","nj"], -// ["ǎ","a"], -// ["ǐ","i"], -// ["ǒ","o"], -// ["ǔ","u"], -// ["ǖ","u"], -// ["ǘ","u"], -// ["ǚ","u"], -// ["ǜ","u"], -// ["ǟ","a"], -// ["ǡ","a"], -// ["ǣ","ae"], -// ["æ","ae"], -// ["ǽ","ae"], -// ["ǧ","g"], -// ["ǩ","k"], -// ["ǫ","o"], -// ["ǭ","o"], -// ["ǯ","ʒ"], -// ["ǰ","j"], -// ["dz","dz"], -// ["ǵ","g"], -// ["ǹ","n"], -// ["ǻ","a"], -// ["ǿ","ø"], -// ["ȁ","a"], -// ["ȃ","a"], -// ["ȅ","e"], -// ["ȇ","e"], -// ["ȉ","i"], -// ["ȋ","i"], -// ["ȍ","o"], -// ["ȏ","o"], -// ["ȑ","r"], -// ["ȓ","r"], -// ["ȕ","u"], -// ["ȗ","u"], -// ["ș","s"], -// ["ț","t"], -// ["ȟ","h"], -// ["ȧ","a"], -// ["ȩ","e"], -// ["ȫ","o"], -// ["ȭ","o"], -// ["ȯ","o"], -// ["ȱ","o"], -// ["ȳ","y"], -// ["ʰ","h"], -// ["ʱ","h"], -// ["ɦ","h"], -// ["ʲ","j"], -// ["ʳ","r"], -// ["ʴ","ɹ"], -// ["ʵ","ɻ"], -// ["ʶ","ʁ"], -// ["ʷ","w"], -// ["ʸ","y"], -// ["ˠ","ɣ"], -// ["ˡ","l"], -// ["ˢ","s"], -// ["ˣ","x"], -// ["ˤ","ʕ"], -// ["ΐ","ι"], -// ["ά","α"], -// ["έ","ε"], -// ["ή","η"], -// ["ί","ι"], -// ["ΰ","υ"], -// ["ϊ","ι"], -// ["ϋ","υ"], -// ["ό","ο"], -// ["ύ","υ"], -// ["ώ","ω"], -// ["ϐ","β"], -// ["ϑ","θ"], -// ["ϒ","Υ"], -// ["ϓ","Υ"], -// ["ϔ","Υ"], -// ["ϕ","φ"], -// ["ϖ","π"], -// ["ϰ","κ"], -// ["ϱ","ρ"], -// ["ϲ","ς"], -// ["ϵ","ε"], -// ["й","и"], -// ["ѐ","е"], -// ["ё","е"], -// ["ѓ","г"], -// ["ї","і"], -// ["ќ","к"], -// ["ѝ","и"], -// ["ў","у"], -// ["ѷ","ѵ"], -// ["ӂ","ж"], -// ["ӑ","а"], -// ["ӓ","а"], -// ["ӗ","е"], -// ["ӛ","ә"], -// ["ӝ","ж"], -// ["ӟ","з"], -// ["ӣ","и"], -// ["ӥ","и"], -// ["ӧ","о"], -// ["ӫ","ө"], -// ["ӭ","э"], -// ["ӯ","у"], -// ["ӱ","у"], -// ["ӳ","у"], -// ["ӵ","ч"] -// -// // Charset Normalization -// -// // ["à", "a"], -// // ["á", "a"], -// // ["â", "a"], -// // ["ã", "a"], -// // ["ä", "a"], -// // ["å", "a"], -// // -// // ["è", "e"], -// // ["é", "e"], -// // ["ê", "e"], -// // ["ë", "e"], -// // -// // ["ì", "i"], -// // ["í", "i"], -// // ["î", "i"], -// // ["ï", "i"], -// // -// // ["ò", "o"], -// // ["ó", "o"], -// // ["ô", "o"], -// // ["õ", "o"], -// // ["ö", "o"], -// // ["ő", "o"], -// // -// // ["ù", "u"], -// // ["ú", "u"], -// // ["û", "u"], -// // ["ü", "u"], -// // ["ű", "u"], -// // -// // ["ý", "y"], -// // ["ŷ", "y"], -// // ["ÿ", "y"], -// // -// // ["ñ", "n"], -// // ["ç", "c"], -// // ["ß", "s"] -// -// // Special Chars Removal -// -// // [",", ""], -// // [".", ""], -// // ["'", ""] -// -// // Non-Whitespace Separators -// -// // split by default p{P} -// // ["-", " "], -// // [":", " "], -// // ["_", " "], -// // ["|", " "], -// // ["/", " "], -// // ["\\", " "] -// ]); -// -// // let pairs; -// // -// // if(!normalize){ -// // -// // // Charset Normalization -// // -// // const regex_a = regex("[àáâãäå]"), -// // regex_e = regex("[èéêë]"), -// // regex_i = regex("[ìíîï]"), -// // regex_o = regex("[òóôõöő]"), -// // regex_u = regex("[ùúûüű]"), -// // regex_y = regex("[ýŷÿ]"), -// // regex_n = regex("ñ"), -// // //regex_c = regex("[çc]"), -// // regex_c = regex("ç"), -// // regex_s = regex("ß"), -// // //regex_and = regex(" & "), -// // regex_and = regex("&"); -// // -// // pairs = [ -// // regex_a, "a", -// // regex_e, "e", -// // regex_i, "i", -// // regex_o, "o", -// // regex_u, "u", -// // regex_y, "y", -// // regex_n, "n", -// // //regex_c, "k", -// // regex_c, "c", -// // regex_s, "s", -// // regex_and, " and " -// // ]; -// // } -// -// /** -// * @param {string|number} str -// */ -// -// export function encode(str){ -// -// //str = "" + str; -// -// return pipeline.call( -// -// this, -// /* string: */ (/*normalize ? str.normalize("NFD").replace(normalize, "") :*/ "" + str).toLowerCase(), -// /* normalize: */ pairs, -// /* split: */ whitespace, -// ///* collapse: */ false -// ); -// } \ No newline at end of file +export default options; \ No newline at end of file diff --git a/dist/module/index/add.js b/dist/module/index/add.js index 0f47234..387a1bd 100644 --- a/dist/module/index/add.js +++ b/dist/module/index/add.js @@ -174,7 +174,7 @@ Index.prototype.push_index = function (dupes, term, score, id, append, keyword) tmp; - if (!dupes[term] || !keyword || !(tmp = dupes[term])[keyword]) { + if (!dupes[term] || keyword && !(tmp = dupes[term])[keyword]) { if (keyword) { diff --git a/dist/module/resolve/and.js b/dist/module/resolve/and.js index 775c109..40e09cd 100644 --- a/dist/module/resolve/and.js +++ b/dist/module/resolve/and.js @@ -1,6 +1,7 @@ import Resolver from "../resolver.js"; import { create_object, get_max_len } from "../common.js"; import { intersect as _intersect } from "../intersect.js"; +import { ResolverOptions } from "../type.js"; Resolver.prototype.and = function () { if (this.result.length) { @@ -33,7 +34,10 @@ Resolver.prototype.and = function () { for (let i = 0, query; i < args.length; i++) { - if (query = args[i]) { + + query = /** @type {string|ResolverOptions} */args[i]; + + if (query) { limit = query.limit || 0; offset = query.offset || 0; diff --git a/dist/module/resolve/not.js b/dist/module/resolve/not.js index 5515d5b..fd78a3a 100644 --- a/dist/module/resolve/not.js +++ b/dist/module/resolve/not.js @@ -1,9 +1,5 @@ import Resolver from "../resolver.js"; -import default_resolver from "./default.js"; -import { create_object } from "../common.js"; -// import or from "./or.js"; -// import and from "./and.js"; -// import xor from "./xor.js"; +import { ResolverOptions } from "../type.js"; Resolver.prototype.not = function () { const self = this; @@ -32,7 +28,10 @@ Resolver.prototype.not = function () { for (let i = 0, query; i < args.length; i++) { - if (query = args[i]) { + + query = /** @type {string|ResolverOptions} */args[i]; + + if (query) { limit = query.limit || 0; offset = query.offset || 0; diff --git a/dist/module/resolve/or.js b/dist/module/resolve/or.js index e56c519..b23a87b 100644 --- a/dist/module/resolve/or.js +++ b/dist/module/resolve/or.js @@ -1,7 +1,7 @@ import Resolver from "../resolver.js"; import default_resolver from "./default.js"; -import { create_object, get_max_len } from "../common.js"; import { union as _union } from "../intersect.js"; +import { ResolverOptions } from "../type.js"; Resolver.prototype.or = function () { @@ -23,31 +23,6 @@ Resolver.prototype.or = function () { } } - // for(let i = 0; i < args.length; i++){ - // if(args[i].result instanceof Promise){ - // return; - // } - // } - - // if(args.length < 2){ - // if(first_argument.index){ - // first_argument.resolve = false; - // const result = first_argument.index.search(first_argument); - // if(result instanceof Promise){ - // result.then(function(result){ - // final = self.result.concat(result); - // self.result = resolver(final, limit, offset, enrich, !resolve); - // return resolve ? self.result : self; - // }); - // } - // else{ - // final = this.result.concat(result); - // this.result = resolver(final, limit, offset, enrich, !resolve); - // return resolve ? this.result : this; - // } - // } - // } - let final = [], promises = [], limit = 0, @@ -57,7 +32,10 @@ Resolver.prototype.or = function () { for (let i = 0, query; i < args.length; i++) { - if (query = args[i]) { + + query = /** @type {string|ResolverOptions} */args[i]; + + if (query) { limit = query.limit || 0; offset = query.offset || 0; diff --git a/dist/module/resolve/xor.js b/dist/module/resolve/xor.js index 538a7f4..9026feb 100644 --- a/dist/module/resolve/xor.js +++ b/dist/module/resolve/xor.js @@ -1,9 +1,7 @@ import Resolver from "../resolver.js"; import default_resolver from "./default.js"; import { create_object } from "../common.js"; -// import or from "./or.js"; -// import and from "./and.js"; -// import not from "./not.js"; +import { ResolverOptions } from "../type.js"; Resolver.prototype.xor = function () { const self = this; @@ -33,7 +31,10 @@ Resolver.prototype.xor = function () { for (let i = 0, query; i < args.length; i++) { - if (query = args[i]) { + + query = /** @type {string|ResolverOptions} */args[i]; + + if (query) { limit = query.limit || 0; offset = query.offset || 0; diff --git a/dist/module/resolver.js b/dist/module/resolver.js index 8a82beb..3c3890d 100644 --- a/dist/module/resolver.js +++ b/dist/module/resolver.js @@ -1,12 +1,13 @@ import default_resolver from "./resolve/default.js"; import { set_resolve } from "./index/search.js"; +import { ResolverOptions } from "./type.js"; import "./resolve/or.js"; import "./resolve/and.js"; import "./resolve/xor.js"; import "./resolve/not.js"; /** - * @param result + * @param {Array|ResolverOptions=} result * @constructor */ @@ -73,6 +74,12 @@ Resolver.prototype.boost = function (boost) { return this; }; +/** + * @param {number|ResolverOptions=} limit + * @param {number=} offset + * @param {boolean=} enrich + */ + Resolver.prototype.resolve = function (limit, offset, enrich) { set_resolve(1); const result = this.result; diff --git a/dist/module/type.js b/dist/module/type.js index 1ce14ce..a13ad73 100644 --- a/dist/module/type.js +++ b/dist/module/type.js @@ -1,5 +1,6 @@ // When you are looking for type definitions which fully describes the usage take a look into the index.d.ts file. // Some of the types here aren't supposed to be used as public, they might be defined just for internal state. +import Index from "./index.js"; import Encoder from "./encoder.js"; import StorageInterface from "./db/interface.js"; @@ -23,7 +24,7 @@ import StorageInterface from "./db/interface.js"; * config: string|undefined * }} */ -export let IndexOptions = {}; +export const IndexOptions = {}; /** * @typedef DocumentIndexOptions {{ @@ -46,7 +47,7 @@ export let IndexOptions = {}; * custom: Function|undefined * }} */ -export let DocumentIndexOptions = {}; +export const DocumentIndexOptions = {}; /** * @typedef DocumentOptions {{ @@ -66,7 +67,7 @@ export let DocumentIndexOptions = {}; * worker: boolean|string|undefined * }} */ -export let DocumentOptions = {}; +export const DocumentOptions = {}; /** * @typedef ContextOptions {{ @@ -75,7 +76,7 @@ export let DocumentOptions = {}; * resolution: number|undefined * }} */ -export let ContextOptions = {}; +export const ContextOptions = {}; /** * @typedef DocumentDescriptor {{ @@ -86,7 +87,7 @@ export let ContextOptions = {}; * store: StoreOptions|Array|undefined * }} */ -export let DocumentDescriptor = {}; +export const DocumentDescriptor = {}; /** * @typedef TagOptions {{ @@ -99,7 +100,7 @@ export let DocumentDescriptor = {}; * config: string|undefined * }} */ -export let TagOptions = {}; +export const TagOptions = {}; /** * @typedef StoreOptions {{ @@ -109,7 +110,7 @@ export let TagOptions = {}; * config: string|undefined * }} */ -export let StoreOptions = {}; +export const StoreOptions = {}; /** * @typedef SearchOptions {{ @@ -122,7 +123,7 @@ export let StoreOptions = {}; * enrich: [boolean=false] * }} */ -export let SearchOptions = {}; +export const SearchOptions = {}; // tag: Array|undefined /** @@ -140,7 +141,7 @@ export let SearchOptions = {}; * merge: [boolean=false] * }} */ -export let DocumentSearchOptions = {}; +export const DocumentSearchOptions = {}; /** * @typedef DocumentSearchResults Array<{{ @@ -149,7 +150,7 @@ export let DocumentSearchOptions = {}; * result: Array * }}> */ -export let DocumentSearchResults = {}; +export const DocumentSearchResults = {}; /** * @typedef EnrichedDocumentSearchResults Array<{{ @@ -161,7 +162,7 @@ export let DocumentSearchResults = {}; * }}> * }}> */ -export let EnrichedDocumentSearchResults = {}; +export const EnrichedDocumentSearchResults = {}; /** * @typedef MergedDocumentSearchResults Array<{{ @@ -170,7 +171,7 @@ export let EnrichedDocumentSearchResults = {}; * field: Array * }}> */ -export let MergedDocumentSearchResults = {}; +export const MergedDocumentSearchResults = {}; /** * @typedef EncoderOptions {{ @@ -191,7 +192,7 @@ export let MergedDocumentSearchResults = {}; * cache: boolean=true, * }} */ -export let EncoderOptions = {}; +export const EncoderOptions = {}; /** * @typedef EncoderSplitOptions {{ @@ -203,7 +204,7 @@ export let EncoderOptions = {}; * char: string|Array|undefined, * }} */ -export let EncoderSplitOptions = {}; +export const EncoderSplitOptions = {}; /** * @typedef PersistentOptions {{ @@ -213,4 +214,17 @@ export let EncoderSplitOptions = {}; * db: *|undefined * }} */ -export let PersistentOptions = {}; \ No newline at end of file +export const PersistentOptions = {}; + +/** + * @typedef ResolverOptions {{ + * index: Index|undefined, + * query: string, + * limit: [number=0], + * offset: [number=0], + * enrich: boolean=false, + * resolve: boolean=false, + * suggest: boolean=false + * }} + */ +export const ResolverOptions = {}; \ No newline at end of file diff --git a/dist/module/webpack.js b/dist/module/webpack.js index e3f9974..14b8528 100644 --- a/dist/module/webpack.js +++ b/dist/module/webpack.js @@ -1,5 +1,5 @@ -import { SearchOptions, ContextOptions, DocumentDescriptor, DocumentSearchOptions, DocumentIndexOptions, IndexOptions, DocumentOptions, TagOptions, StoreOptions, EncoderOptions, EncoderSplitOptions, PersistentOptions } from "./type.js"; +import { SearchOptions, ContextOptions, DocumentDescriptor, DocumentSearchOptions, DocumentIndexOptions, IndexOptions, DocumentOptions, TagOptions, StoreOptions, EncoderOptions, EncoderSplitOptions, PersistentOptions, ResolverOptions } from "./type.js"; import StorageInterface from "./db/interface.js"; import Document from "./document.js"; import Index from "./index.js"; @@ -223,6 +223,14 @@ import Charset from "./charset.js"; /** @export */PersistentOptions.type; /** @export */PersistentOptions.db; +/** @export */ResolverOptions.index; +/** @export */ResolverOptions.query; +/** @export */ResolverOptions.limit; +/** @export */ResolverOptions.offset; +/** @export */ResolverOptions.enrich; +/** @export */ResolverOptions.resolve; +/** @export */ResolverOptions.suggest; + const FlexSearch = { Index: Index, Charset: Charset, diff --git a/package.json b/package.json index e2cf965..9b5c8ff 100644 --- a/package.json +++ b/package.json @@ -73,11 +73,11 @@ "build:module:min": "node task/babel RELEASE=min && exit 0", "build:module:bundle": "node task/build RELEASE=bundle.module DEBUG=false PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=true SUPPORT_RESOLVER=true SUPPORT_KEYSTORE=true SUPPORT_COMPRESSION=false", "build:module:bundle:debug": "node task/build RELEASE=bundle.module DEBUG=true PROFILER=false SUPPORT_WORKER=true SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=true SUPPORT_RESOLVER=true SUPPORT_KEYSTORE=true SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT", - "build:module:compact": "node task/build RELEASE=compact.module DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=false SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=false SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false", - "build:module:compact:debug": "node task/build RELEASE=compact.module DEBUG=true PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=false SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=false SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT", - "build:module:light": "node task/build RELEASE=light.module DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=false SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=false SUPPORT_STORE=false SUPPORT_TAGS=false SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=false SUPPORT_DOCUMENT=false POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false", - "build:module:light:debug": "node task/build RELEASE=light.module DEBUG=true PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=false SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=false SUPPORT_STORE=false SUPPORT_TAGS=false SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=false SUPPORT_DOCUMENT=false POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT", - "build:all": "npm run build:bundle && npm run build:bundle:debug && npm run build:light && npm run build:light:debug && npm run build:compact && npm run build:compact:debug && npm run build:module && npm run build:module:debug && npm run build:module:min && npm run build:module:bundle && npm run build:module:bundle:debug && npm run build:module:light && npm run build:module:light:debug && npm run build:module:compact && npm run build:module:compact:debug && npm run build:lang && npm run build:es5 && npm run build:es5:debug", + "build:module:compact": "node task/build RELEASE=compact.module DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false", + "build:module:compact:debug": "node task/build RELEASE=compact.module DEBUG=true PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=true SUPPORT_CACHE=true SUPPORT_ASYNC=true SUPPORT_STORE=true SUPPORT_TAGS=true SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=true SUPPORT_DOCUMENT=true POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT", + "build:module:light": "node task/build RELEASE=light.module DEBUG=false PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=false SUPPORT_CACHE=true SUPPORT_ASYNC=false SUPPORT_STORE=false SUPPORT_TAGS=false SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=false SUPPORT_DOCUMENT=false POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false", + "build:module:light:debug": "node task/build RELEASE=light.module DEBUG=true PROFILER=false SUPPORT_WORKER=false SUPPORT_ENCODER=true SUPPORT_CHARSET=false SUPPORT_CACHE=true SUPPORT_ASYNC=false SUPPORT_STORE=false SUPPORT_TAGS=false SUPPORT_SUGGESTION=true SUPPORT_SERIALIZE=false SUPPORT_DOCUMENT=false POLYFILL=false SUPPORT_PERSISTENT=false SUPPORT_RESOLVER=false SUPPORT_KEYSTORE=false SUPPORT_COMPRESSION=false FORMATTING=PRETTY_PRINT", + "build:all": "npm run build:bundle && npm run build:bundle:debug && npm run build:light && npm run build:light:debug && npm run build:compact && npm run build:compact:debug && npm run build:module && npm run build:module:debug && npm run build:module:min && npm run build:module:bundle && npm run build:module:bundle:debug && npm run build:module:light && npm run build:module:light:debug && npm run build:module:compact && npm run build:module:compact:debug && npm run build:lang && npm run build:es5 && npm run build:es5:debug && npm run build:db", "build:custom": "node task/build RELEASE=custom", "test": "cd test && npm install && npm run test" }, diff --git a/src/charset/arabic/default.js b/src/charset/arabic/default.js index 7ef9bc2..107a8a8 100644 --- a/src/charset/arabic/default.js +++ b/src/charset/arabic/default.js @@ -12,30 +12,3 @@ const options = { } }; export default options; - -// import { pipeline } from "../../lang.js"; -// -// export const rtl = true; -// export const tokenize = ""; -// export default { -// encode: encode, -// rtl: rtl -// } -// -// -// -// /** -// * @param {string|number} str -// */ -// -// export function encode(str){ -// -// return pipeline.call( -// -// this, -// /* string: */ ("" + str).replace(regex, " "), -// /* normalize: */ false, -// /* split: */ split, -// /* collapse: */ false -// ); -// } diff --git a/src/charset/cjk/default.js b/src/charset/cjk/default.js index 9bfb87d..90f5183 100644 --- a/src/charset/cjk/default.js +++ b/src/charset/cjk/default.js @@ -11,31 +11,3 @@ const options = { } }; export default options; - -// import { pipeline } from "../../lang.js"; -// -// export const rtl = false; -// export const tokenize = "strict"; -// export default { -// encode: encode, -// rtl: rtl, -// tokenize: tokenize -// } -// -// const regex = /[\x00-\x7F]+/g; -// -// /** -// * @param {string|number} str -// */ -// -// export function encode(str){ -// -// return pipeline.call( -// -// this, -// /* string: */ ("" + str).replace(regex, ""), -// /* normalize: */ false, -// /* split: */ "", -// /* collapse: */ false -// ); -// } diff --git a/src/charset/cyrillic/default.js b/src/charset/cyrillic/default.js index ce26c16..699b40f 100644 --- a/src/charset/cyrillic/default.js +++ b/src/charset/cyrillic/default.js @@ -10,31 +10,3 @@ const options = { } }; export default options; - -// import { pipeline } from "../../lang.js"; -// -// export const rtl = false; -// export const tokenize = ""; -// export default { -// encode: encode, -// rtl: rtl -// } -// -// const regex = /[\x00-\x7F]+/g; -// const split = /\s+/; -// -// /** -// * @param {string|number} str -// */ -// -// export function encode(str){ -// -// return pipeline.call( -// -// this, -// /* string: */ ("" + str).replace(regex, " "), -// /* normalize: */ false, -// /* split: */ split, -// /* collapse: */ false -// ); -// } diff --git a/src/charset/latin/advanced.js b/src/charset/latin/advanced.js index df6db83..a8c38e1 100644 --- a/src/charset/latin/advanced.js +++ b/src/charset/latin/advanced.js @@ -1,44 +1,6 @@ import { EncoderOptions } from "../../type.js"; import { soundex } from "./balance.js"; -// const soundex = new Map([ -// ["b", "p"], -// //["p", "p"], -// -// //["f", "f"], -// ["v", "f"], -// ["w", "f"], -// -// //["s", "s"], -// ["z", "s"], -// ["x", "s"], -// -// ["d", "t"], -// //["t", "t"], -// -// //["m", "m"], -// ["n", "m"], -// -// //["k", "k"], -// ["c", "k"], -// ["g", "k"], -// ["j", "k"], -// ["q", "k"], -// -// //["r", "r"], -// //["h", "h"], -// //["l", "l"], -// -// //["a", "a"], -// -// //["e", "e"], -// ["i", "e"], -// ["y", "e"], -// -// //["o", "o"], -// ["u", "o"] -// ]); - export const matcher = new Map([ ["ai", "ei"], ["ae", "a"], @@ -65,94 +27,3 @@ const options = { matcher: matcher }; export default options; - -// import { regex, replace, collapse } from "../../lang.js"; -// import { encode as encode_balance } from "./balance.js"; -// -// export const rtl = false; -// export const tokenize = ""; -// export default { -// encode: encode, -// rtl: rtl, -// tokenize: tokenize -// } -// -// // Phonetic Normalization -// -// const regex_ae = regex("ae"), -// //regex_ai = regex("ai"), -// //regex_ay = regex("ay"), -// //regex_ey = regex("ey"), -// regex_oe = regex("oe"), -// //regex_ue = regex("ue"), -// //regex_ie = regex("ie"), -// //regex_sz = regex("sz"), -// //regex_zs = regex("zs"), -// //regex_ck = regex("ck"), -// //regex_cc = regex("cc"), -// regex_sh = regex("sh"), -// regex_th = regex("th"), -// //regex_dt = regex("dt"), -// regex_ph = regex("ph"), -// regex_pf = regex("pf"); -// //regex_ou = regex("ou"), -// //regex_uo = regex("uo"); -// -// const pairs = [ -// regex_ae, "a", -// // regex_ai, "ei", -// // regex_ay, "ei", -// // regex_ey, "ei", -// regex_oe, "o", -// // regex_ue, "u", -// // regex_ie, "i", -// // regex_sz, "s", -// // regex_zs, "s", -// regex_sh, "s", -// // regex_ck, "k", -// // regex_cc, "k", -// regex_th, "t", -// // regex_dt, "t", -// regex_ph, "f", -// regex_pf, "f", -// // regex_ou, "o", -// // regex_uo, "u" -// -// // regex("(?![aeiouy])h(?![aeiouy])"), "", -// // regex("(?!^[aeiouy])h(?!^[aeiouy])"), "" -// regex("(?![aeo])h(?![aeo])"), "", -// regex("(?!^[aeo])h(?!^[aeo])"), "" -// ]; -// -// /** -// * @param {string|number} str -// * @param {boolean=} _skip_postprocessing -// */ -// -// export function encode(str, _skip_postprocessing){ -// -// if(str){ -// -// str = encode_balance.call(this, str).join(" "); -// -// if(str.length > 2){ -// -// str = replace(str, pairs); -// } -// -// if(!_skip_postprocessing){ -// -// if(str.length > 1){ -// -// str = collapse(str); -// } -// -// if(str){ -// -// str = str.split(" "); -// } -// } -// } -// -// return str || []; -// } diff --git a/src/charset/latin/balance.js b/src/charset/latin/balance.js index 35369a2..c6e24b6 100644 --- a/src/charset/latin/balance.js +++ b/src/charset/latin/balance.js @@ -45,246 +45,3 @@ const options = { mapper: soundex }; export default options; - -// //import { encode as encode_simple } from "./simple.js"; -// import { pipeline } from "../../lang.js"; -// -// // custom soundex implementation -// -// export const rtl = false; -// export const tokenize = ""; -// export default { -// encode: encode, -// rtl: rtl, -// tokenize: tokenize -// } -// -// //const regex_whitespace = /[\W_]+/g; -// const whitespace = /[\p{Z}\p{S}\p{P}\p{C}]+/u; -// const normalize = "".normalize && /[\u0300-\u036f]/g; -// //const regex_strip = /[^a-z0-9]+/; -// -// // const pairs = [ -// // regex_whitespace, " ", -// // regex_strip, "" -// // ]; -// -// // modified -// const pairs = new Map([ -// -// ["b", "p"], -// //["p", "p"], -// -// //["f", "f"], -// ["v", "f"], -// ["w", "f"], -// -// //["s", "s"], -// ["ß", "s"], -// ["z", "s"], -// ["x", "s"], -// -// ["d", "t"], -// //["t", "t"], -// -// //["m", "m"], -// ["n", "m"], -// ["ñ", "m"], -// -// //["k", "k"], -// ["c", "k"], -// ["ç", "k"], -// ["g", "k"], -// ["j", "k"], -// ["q", "k"], -// -// //["r", "r"], -// //["h", "h"], -// //["l", "l"], -// -// //["a", "a"], -// ["à", "a"], -// ["á", "a"], -// ["â", "a"], -// ["ã", "a"], -// ["ä", "a"], -// ["å", "a"], -// -// //["e", "e"], -// ["è", "e"], -// ["é", "e"], -// ["ê", "e"], -// ["ë", "e"], -// ["i", "e"], -// ["ì", "e"], -// ["í", "e"], -// ["î", "e"], -// ["ï", "e"], -// ["y", "e"], -// ["ý", "e"], -// ["ŷ", "e"], -// ["ÿ", "e"], -// -// //["o", "o"], -// ["ò", "o"], -// ["ó", "o"], -// ["ô", "o"], -// ["õ", "o"], -// ["ö", "o"], -// ["ő", "o"], -// ["u", "o"], -// ["ù", "o"], -// ["ú", "o"], -// ["û", "o"], -// ["ü", "o"], -// ["ű", "o"], -// ]); -// -// const map_soundex = new Map([ -// ["b", "p"], -// //["p", "p"], -// -// //["f", "f"], -// ["v", "f"], -// ["w", "f"], -// -// //["s", "s"], -// ["z", "s"], -// ["x", "s"], -// -// ["d", "t"], -// //["t", "t"], -// -// //["m", "m"], -// ["n", "m"], -// -// //["k", "k"], -// ["c", "k"], -// ["g", "k"], -// ["j", "k"], -// ["q", "k"], -// -// //["r", "r"], -// //["h", "h"], -// //["l", "l"], -// -// //["a", "a"], -// -// //["e", "e"], -// ["i", "e"], -// ["y", "e"], -// -// //["o", "o"], -// ["u", "o"] -// ]); -// // const soundex = { -// // -// // "b": "p", -// // //"p": "p", -// // -// // //"f": "f", -// // "v": "f", -// // "w": "f", -// // -// // //"s": "s", -// // "z": "s", -// // "x": "s", -// // "ß": "s", -// // -// // "d": "t", -// // //"t": "t", -// // -// // //"l": "l", -// // -// // //"m": "m", -// // "n": "m", -// // -// // "c": "k", -// // "g": "k", -// // "j": "k", -// // //"k": "k", -// // "q": "k", -// // -// // //"r": "r", -// // //"h": "h", -// // //"a": "a", -// // -// // //"e": "e", -// // "i": "e", -// // "y": "e", -// // -// // //"o": "o", -// // "u": "o" -// // }; -// -// /** -// * @param {string|number} str -// */ -// -// export function encode(str){ -// -// return pipeline.call( -// this, -// /* string: */ ("" + str).normalize("NFD").replace(normalize, "").toLowerCase(), -// /* normalize: */ map_soundex, -// /* split: */ whitespace, -// ///* collapse: */ false -// ); -// -// // return pipeline.call( -// // this, -// // /* string: */ ("" + str).toLowerCase(), -// // /* normalize: */ /*pairs*/ new Map(), -// // /* split: */ whitespace, -// // ///* collapse: */ false -// // ); -// -// // str = encode_simple.call(this, str).join(" "); -// // -// // // str = this.pipeline( -// // // -// // // /* string: */ normalize("" + str).toLowerCase(), -// // // /* normalize: */ false, -// // // /* split: */ false, -// // // /* collapse: */ false -// // // ); -// // -// // const result = []; -// // -// // if(str){ -// // -// // const words = str.split(regex_strip); -// // const length = words.length; -// // -// // for(let x = 0, tmp, count = 0; x < length; x++){ -// // -// // if((str = words[x]) /*&& (str.length > 2)*/ && (!this.filter || !this.filter.has(str))){ -// // -// // tmp = str[0]; -// // let code = soundex[tmp] || tmp; //str[0]; -// // let previous = code; //soundex[code] || code; -// // -// // for(let i = 1; i < str.length; i++){ -// // -// // tmp = str[i]; -// // const current = soundex[tmp] || tmp; -// // -// // if(current && (current !== previous)){ -// // -// // code += current; -// // previous = current; -// // -// // // if(code.length === 7){ -// // // -// // // break; -// // // } -// // } -// // } -// // -// // result[count++] = code; //(code + "0000").substring(0, 4); -// // } -// // } -// // } -// // -// // return result; -// } diff --git a/src/charset/latin/default.js b/src/charset/latin/default.js index 87b0a74..d1b2a3e 100644 --- a/src/charset/latin/default.js +++ b/src/charset/latin/default.js @@ -8,31 +8,3 @@ const options = { dedupe: false }; export default options; - -// import { pipeline } from "../../lang.js"; -// -// const whitespace = /[\p{Z}\p{S}\p{P}\p{C}]+/u; -// -// export const rtl = false; -// export const tokenize = ""; -// export default { -// encode: encode, -// rtl: rtl, -// tokenize: tokenize -// } -// -// /** -// * @param {string|number} str -// */ -// -// export function encode(str){ -// -// return pipeline.call( -// -// this, -// /* string: */ ("" + str).toLowerCase(), -// /* normalize: */ false, -// /* split: */ whitespace, -// /* collapse: */ false -// ); -// } diff --git a/src/charset/latin/extra.js b/src/charset/latin/extra.js index 0d8b589..450c8ca 100644 --- a/src/charset/latin/extra.js +++ b/src/charset/latin/extra.js @@ -15,70 +15,3 @@ const options = { matcher: matcher }; export default options; - -// import { regex, replace, collapse } from "../../lang.js"; -// import { encode as encode_advanced } from "./advanced.js"; -// -// export const rtl = false; -// export const tokenize = ""; -// export default { -// encode: encode, -// rtl: rtl, -// tokenize: tokenize -// } -// -// // Soundex Normalization -// -// const prefix = "(?!\\b)"; -// const //soundex_b = regex(prefix + "p"), -// // soundex_s = regex(prefix + "z"), -// // soundex_k = regex(prefix + "[cgq]"), -// // soundex_m = regex(prefix + "n"), -// // soundex_t = regex(prefix + "d"), -// // soundex_f = regex(prefix + "[vw]"), -// //regex_vowel = regex(prefix + "[aeiouy]"); -// regex_vowel = regex(prefix + "[aeo]"); -// -// const pairs = [ -// -// // soundex_b, "b", -// // soundex_s, "s", -// // soundex_k, "k", -// // soundex_m, "m", -// // soundex_t, "t", -// // soundex_f, "f", -// // regex("(?![aeiouy])h(?![aeiouy])"), "", -// // regex("(?!^[aeiouy])h(?!^[aeiouy])"), "", -// regex_vowel, "" -// ]; -// -// /** -// * @param {string|number} str -// */ -// -// export function encode(str){ -// -// if(str){ -// -// str = encode_advanced.call(this, str, /* skip post-processing: */ true); -// -// if(str.length > 1){ -// -// //str = replace(str, pairs); -// //str = str.replace(regex_vowel, ""); -// str = str.charAt(0) + str.substring(1).replace(regex_vowel, ""); -// } -// -// if(str.length > 1){ -// -// str = collapse(str); -// } -// -// if(str){ -// -// str = str.split(" "); -// } -// } -// -// return str || []; -// } diff --git a/src/charset/latin/simple.js b/src/charset/latin/simple.js index d310495..92e463f 100644 --- a/src/charset/latin/simple.js +++ b/src/charset/latin/simple.js @@ -6,339 +6,3 @@ const options = { dedupe: true }; export default options; - -// import { pipeline, regex } from "../../lang.js"; -// -// export const rtl = false; -// export const tokenize = ""; -// export default { -// encode: encode, -// rtl: rtl, -// tokenize: tokenize -// } -// -// // p{Z} = whitespaces -// // p{S} = symbols (emotes) -// // p{P} = special chars -// // p{C} = controls (linebreak, tabulator) -// const whitespace = /[\p{Z}\p{S}\p{P}\p{C}]+/u; -// const normalize = "".normalize && /[\u0300-\u036f]/g; -// const pairs = !normalize && new Map([ -// -// // Charset Normalization -// // String.normalize("NFKD").replace(/[\u0300-\u036f]/g, "") -// -// ["ª","a"], -// ["²","2"], -// ["³","3"], -// ["¹","1"], -// ["º","o"], -// ["¼","1⁄4"], -// ["½","1⁄2"], -// ["¾","3⁄4"], -// ["à","a"], -// ["á","a"], -// ["â","a"], -// ["ã","a"], -// ["ä","a"], -// ["å","a"], -// ["ç","c"], -// ["è","e"], -// ["é","e"], -// ["ê","e"], -// ["ë","e"], -// ["ì","i"], -// ["í","i"], -// ["î","i"], -// ["ï","i"], -// ["ñ","n"], -// ["ò","o"], -// ["ó","o"], -// ["ô","o"], -// ["õ","o"], -// ["ö","o"], -// ["ù","u"], -// ["ú","u"], -// ["û","u"], -// ["ü","u"], -// ["ý","y"], -// ["ÿ","y"], -// ["ā","a"], -// ["ă","a"], -// ["ą","a"], -// ["ć","c"], -// ["ĉ","c"], -// ["ċ","c"], -// ["č","c"], -// ["ď","d"], -// ["ē","e"], -// ["ĕ","e"], -// ["ė","e"], -// ["ę","e"], -// ["ě","e"], -// ["ĝ","g"], -// ["ğ","g"], -// ["ġ","g"], -// ["ģ","g"], -// ["ĥ","h"], -// ["ĩ","i"], -// ["ī","i"], -// ["ĭ","i"], -// ["į","i"], -// ["ij","ij"], -// ["ĵ","j"], -// ["ķ","k"], -// ["ĺ","l"], -// ["ļ","l"], -// ["ľ","l"], -// ["ŀ","l"], -// ["ń","n"], -// ["ņ","n"], -// ["ň","n"], -// ["ʼn","n"], -// ["ō","o"], -// ["ŏ","o"], -// ["ő","o"], -// ["ŕ","r"], -// ["ŗ","r"], -// ["ř","r"], -// ["ś","s"], -// ["ŝ","s"], -// ["ş","s"], -// ["š","s"], -// ["ţ","t"], -// ["ť","t"], -// ["ũ","u"], -// ["ū","u"], -// ["ŭ","u"], -// ["ů","u"], -// ["ű","u"], -// ["ų","u"], -// ["ŵ","w"], -// ["ŷ","y"], -// ["ź","z"], -// ["ż","z"], -// ["ž","z"], -// ["ſ","s"], -// ["ơ","o"], -// ["ư","u"], -// ["dž","dz"], -// ["lj","lj"], -// ["nj","nj"], -// ["ǎ","a"], -// ["ǐ","i"], -// ["ǒ","o"], -// ["ǔ","u"], -// ["ǖ","u"], -// ["ǘ","u"], -// ["ǚ","u"], -// ["ǜ","u"], -// ["ǟ","a"], -// ["ǡ","a"], -// ["ǣ","ae"], -// ["æ","ae"], -// ["ǽ","ae"], -// ["ǧ","g"], -// ["ǩ","k"], -// ["ǫ","o"], -// ["ǭ","o"], -// ["ǯ","ʒ"], -// ["ǰ","j"], -// ["dz","dz"], -// ["ǵ","g"], -// ["ǹ","n"], -// ["ǻ","a"], -// ["ǿ","ø"], -// ["ȁ","a"], -// ["ȃ","a"], -// ["ȅ","e"], -// ["ȇ","e"], -// ["ȉ","i"], -// ["ȋ","i"], -// ["ȍ","o"], -// ["ȏ","o"], -// ["ȑ","r"], -// ["ȓ","r"], -// ["ȕ","u"], -// ["ȗ","u"], -// ["ș","s"], -// ["ț","t"], -// ["ȟ","h"], -// ["ȧ","a"], -// ["ȩ","e"], -// ["ȫ","o"], -// ["ȭ","o"], -// ["ȯ","o"], -// ["ȱ","o"], -// ["ȳ","y"], -// ["ʰ","h"], -// ["ʱ","h"], -// ["ɦ","h"], -// ["ʲ","j"], -// ["ʳ","r"], -// ["ʴ","ɹ"], -// ["ʵ","ɻ"], -// ["ʶ","ʁ"], -// ["ʷ","w"], -// ["ʸ","y"], -// ["ˠ","ɣ"], -// ["ˡ","l"], -// ["ˢ","s"], -// ["ˣ","x"], -// ["ˤ","ʕ"], -// ["ΐ","ι"], -// ["ά","α"], -// ["έ","ε"], -// ["ή","η"], -// ["ί","ι"], -// ["ΰ","υ"], -// ["ϊ","ι"], -// ["ϋ","υ"], -// ["ό","ο"], -// ["ύ","υ"], -// ["ώ","ω"], -// ["ϐ","β"], -// ["ϑ","θ"], -// ["ϒ","Υ"], -// ["ϓ","Υ"], -// ["ϔ","Υ"], -// ["ϕ","φ"], -// ["ϖ","π"], -// ["ϰ","κ"], -// ["ϱ","ρ"], -// ["ϲ","ς"], -// ["ϵ","ε"], -// ["й","и"], -// ["ѐ","е"], -// ["ё","е"], -// ["ѓ","г"], -// ["ї","і"], -// ["ќ","к"], -// ["ѝ","и"], -// ["ў","у"], -// ["ѷ","ѵ"], -// ["ӂ","ж"], -// ["ӑ","а"], -// ["ӓ","а"], -// ["ӗ","е"], -// ["ӛ","ә"], -// ["ӝ","ж"], -// ["ӟ","з"], -// ["ӣ","и"], -// ["ӥ","и"], -// ["ӧ","о"], -// ["ӫ","ө"], -// ["ӭ","э"], -// ["ӯ","у"], -// ["ӱ","у"], -// ["ӳ","у"], -// ["ӵ","ч"] -// -// // Charset Normalization -// -// // ["à", "a"], -// // ["á", "a"], -// // ["â", "a"], -// // ["ã", "a"], -// // ["ä", "a"], -// // ["å", "a"], -// // -// // ["è", "e"], -// // ["é", "e"], -// // ["ê", "e"], -// // ["ë", "e"], -// // -// // ["ì", "i"], -// // ["í", "i"], -// // ["î", "i"], -// // ["ï", "i"], -// // -// // ["ò", "o"], -// // ["ó", "o"], -// // ["ô", "o"], -// // ["õ", "o"], -// // ["ö", "o"], -// // ["ő", "o"], -// // -// // ["ù", "u"], -// // ["ú", "u"], -// // ["û", "u"], -// // ["ü", "u"], -// // ["ű", "u"], -// // -// // ["ý", "y"], -// // ["ŷ", "y"], -// // ["ÿ", "y"], -// // -// // ["ñ", "n"], -// // ["ç", "c"], -// // ["ß", "s"] -// -// // Special Chars Removal -// -// // [",", ""], -// // [".", ""], -// // ["'", ""] -// -// // Non-Whitespace Separators -// -// // split by default p{P} -// // ["-", " "], -// // [":", " "], -// // ["_", " "], -// // ["|", " "], -// // ["/", " "], -// // ["\\", " "] -// ]); -// -// // let pairs; -// // -// // if(!normalize){ -// // -// // // Charset Normalization -// // -// // const regex_a = regex("[àáâãäå]"), -// // regex_e = regex("[èéêë]"), -// // regex_i = regex("[ìíîï]"), -// // regex_o = regex("[òóôõöő]"), -// // regex_u = regex("[ùúûüű]"), -// // regex_y = regex("[ýŷÿ]"), -// // regex_n = regex("ñ"), -// // //regex_c = regex("[çc]"), -// // regex_c = regex("ç"), -// // regex_s = regex("ß"), -// // //regex_and = regex(" & "), -// // regex_and = regex("&"); -// // -// // pairs = [ -// // regex_a, "a", -// // regex_e, "e", -// // regex_i, "i", -// // regex_o, "o", -// // regex_u, "u", -// // regex_y, "y", -// // regex_n, "n", -// // //regex_c, "k", -// // regex_c, "c", -// // regex_s, "s", -// // regex_and, " and " -// // ]; -// // } -// -// /** -// * @param {string|number} str -// */ -// -// export function encode(str){ -// -// //str = "" + str; -// -// return pipeline.call( -// -// this, -// /* string: */ (/*normalize ? str.normalize("NFD").replace(normalize, "") :*/ "" + str).toLowerCase(), -// /* normalize: */ pairs, -// /* split: */ whitespace, -// ///* collapse: */ false -// ); -// } diff --git a/src/index/add.js b/src/index/add.js index 07ea41a..cbd799f 100644 --- a/src/index/add.js +++ b/src/index/add.js @@ -186,7 +186,7 @@ Index.prototype.push_index = function(dupes, term, score, id, append, keyword){ let arr = keyword ? this.ctx : this.map; let tmp; - if(!dupes[term] || !keyword || !(tmp = dupes[term])[keyword]){ + if(!dupes[term] || (keyword && !(tmp = dupes[term])[keyword])){ if(keyword){ diff --git a/src/resolve/and.js b/src/resolve/and.js index 2026f44..b4a39d4 100644 --- a/src/resolve/and.js +++ b/src/resolve/and.js @@ -1,6 +1,7 @@ import Resolver from "../resolver.js"; import { create_object, get_max_len } from "../common.js"; import { intersect as _intersect } from "../intersect.js"; +import { ResolverOptions } from "../type.js"; Resolver.prototype.and = function(){ if(this.result.length){ @@ -27,7 +28,12 @@ Resolver.prototype.and = function(){ let limit = 0, offset = 0, enrich, resolve, suggest; for(let i = 0, query; i < args.length; i++){ - if((query = args[i])){ + + query = /** @type {string|ResolverOptions} */ ( + args[i] + ); + + if(query){ limit = query.limit || 0; offset = query.offset || 0; diff --git a/src/resolve/not.js b/src/resolve/not.js index e8d50cd..6c30f35 100644 --- a/src/resolve/not.js +++ b/src/resolve/not.js @@ -1,9 +1,5 @@ import Resolver from "../resolver.js"; -import default_resolver from "./default.js"; -import { create_object } from "../common.js"; -// import or from "./or.js"; -// import and from "./and.js"; -// import xor from "./xor.js"; +import { ResolverOptions } from "../type.js"; Resolver.prototype.not = function(){ const self = this; @@ -28,7 +24,12 @@ Resolver.prototype.not = function(){ let limit = 0, offset = 0, enrich, resolve; for(let i = 0, query; i < args.length; i++){ - if((query = args[i])){ + + query = /** @type {string|ResolverOptions} */ ( + args[i] + ); + + if(query){ limit = query.limit || 0; offset = query.offset || 0; diff --git a/src/resolve/xor.js b/src/resolve/xor.js index 18d0dab..63519ab 100644 --- a/src/resolve/xor.js +++ b/src/resolve/xor.js @@ -1,9 +1,7 @@ import Resolver from "../resolver.js"; import default_resolver from "./default.js"; import { create_object } from "../common.js"; -// import or from "./or.js"; -// import and from "./and.js"; -// import not from "./not.js"; +import { ResolverOptions } from "../type.js";; Resolver.prototype.xor = function(){ const self = this; @@ -28,7 +26,12 @@ Resolver.prototype.xor = function(){ let limit = 0, offset = 0, enrich, resolve; for(let i = 0, query; i < args.length; i++){ - if((query = args[i])){ + + query = /** @type {string|ResolverOptions} */ ( + args[i] + ); + + if(query){ limit = query.limit || 0; offset = query.offset || 0; diff --git a/src/type.js b/src/type.js index 1ce14ce..a13ad73 100644 --- a/src/type.js +++ b/src/type.js @@ -1,5 +1,6 @@ // When you are looking for type definitions which fully describes the usage take a look into the index.d.ts file. // Some of the types here aren't supposed to be used as public, they might be defined just for internal state. +import Index from "./index.js"; import Encoder from "./encoder.js"; import StorageInterface from "./db/interface.js"; @@ -23,7 +24,7 @@ import StorageInterface from "./db/interface.js"; * config: string|undefined * }} */ -export let IndexOptions = {}; +export const IndexOptions = {}; /** * @typedef DocumentIndexOptions {{ @@ -46,7 +47,7 @@ export let IndexOptions = {}; * custom: Function|undefined * }} */ -export let DocumentIndexOptions = {}; +export const DocumentIndexOptions = {}; /** * @typedef DocumentOptions {{ @@ -66,7 +67,7 @@ export let DocumentIndexOptions = {}; * worker: boolean|string|undefined * }} */ -export let DocumentOptions = {}; +export const DocumentOptions = {}; /** * @typedef ContextOptions {{ @@ -75,7 +76,7 @@ export let DocumentOptions = {}; * resolution: number|undefined * }} */ -export let ContextOptions = {}; +export const ContextOptions = {}; /** * @typedef DocumentDescriptor {{ @@ -86,7 +87,7 @@ export let ContextOptions = {}; * store: StoreOptions|Array|undefined * }} */ -export let DocumentDescriptor = {}; +export const DocumentDescriptor = {}; /** * @typedef TagOptions {{ @@ -99,7 +100,7 @@ export let DocumentDescriptor = {}; * config: string|undefined * }} */ -export let TagOptions = {}; +export const TagOptions = {}; /** * @typedef StoreOptions {{ @@ -109,7 +110,7 @@ export let TagOptions = {}; * config: string|undefined * }} */ -export let StoreOptions = {}; +export const StoreOptions = {}; /** * @typedef SearchOptions {{ @@ -122,7 +123,7 @@ export let StoreOptions = {}; * enrich: [boolean=false] * }} */ -export let SearchOptions = {}; +export const SearchOptions = {}; // tag: Array|undefined /** @@ -140,7 +141,7 @@ export let SearchOptions = {}; * merge: [boolean=false] * }} */ -export let DocumentSearchOptions = {}; +export const DocumentSearchOptions = {}; /** * @typedef DocumentSearchResults Array<{{ @@ -149,7 +150,7 @@ export let DocumentSearchOptions = {}; * result: Array * }}> */ -export let DocumentSearchResults = {}; +export const DocumentSearchResults = {}; /** * @typedef EnrichedDocumentSearchResults Array<{{ @@ -161,7 +162,7 @@ export let DocumentSearchResults = {}; * }}> * }}> */ -export let EnrichedDocumentSearchResults = {}; +export const EnrichedDocumentSearchResults = {}; /** * @typedef MergedDocumentSearchResults Array<{{ @@ -170,7 +171,7 @@ export let EnrichedDocumentSearchResults = {}; * field: Array * }}> */ -export let MergedDocumentSearchResults = {}; +export const MergedDocumentSearchResults = {}; /** * @typedef EncoderOptions {{ @@ -191,7 +192,7 @@ export let MergedDocumentSearchResults = {}; * cache: boolean=true, * }} */ -export let EncoderOptions = {}; +export const EncoderOptions = {}; /** * @typedef EncoderSplitOptions {{ @@ -203,7 +204,7 @@ export let EncoderOptions = {}; * char: string|Array|undefined, * }} */ -export let EncoderSplitOptions = {}; +export const EncoderSplitOptions = {}; /** * @typedef PersistentOptions {{ @@ -213,4 +214,17 @@ export let EncoderSplitOptions = {}; * db: *|undefined * }} */ -export let PersistentOptions = {}; \ No newline at end of file +export const PersistentOptions = {}; + +/** + * @typedef ResolverOptions {{ + * index: Index|undefined, + * query: string, + * limit: [number=0], + * offset: [number=0], + * enrich: boolean=false, + * resolve: boolean=false, + * suggest: boolean=false + * }} + */ +export const ResolverOptions = {}; \ No newline at end of file diff --git a/src/webpack.js b/src/webpack.js index dd300b2..dc55933 100644 --- a/src/webpack.js +++ b/src/webpack.js @@ -22,7 +22,8 @@ import { StoreOptions, EncoderOptions, EncoderSplitOptions, - PersistentOptions + PersistentOptions, + ResolverOptions } from "./type.js"; import StorageInterface from "./db/interface.js"; import Document from "./document.js"; @@ -251,6 +252,14 @@ if(SUPPORT_PERSISTENT){ /** @export */ PersistentOptions.type; /** @export */ PersistentOptions.db; +/** @export */ ResolverOptions.index; +/** @export */ ResolverOptions.query; +/** @export */ ResolverOptions.limit; +/** @export */ ResolverOptions.offset; +/** @export */ ResolverOptions.enrich; +/** @export */ ResolverOptions.resolve; +/** @export */ ResolverOptions.suggest; + const FlexSearch = { "Index": Index, "Charset": SUPPORT_CHARSET ? Charset : null,