@wcs-colab/plugin-qps 3.1.16-custom.10 → 3.1.16-custom.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.cjs +1 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.global.js +5 -5
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +1 -11
- package/dist/index.js.map +1 -1
- package/package.json +53 -46
package/dist/index.global.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
"use strict";var orama=orama||{};orama.plugin=orama.plugin||{};orama.plugin.qps=(()=>{var
|
|
2
|
-
- `),
|
|
1
|
+
"use strict";var orama=orama||{};orama.plugin=orama.plugin||{};orama.plugin.qps=(()=>{var Z=Object.defineProperty;var $e=Object.getOwnPropertyDescriptor;var Ge=Object.getOwnPropertyNames;var Ke=Object.prototype.hasOwnProperty;var je=(i,e,t)=>e in i?Z(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var v=(i,e)=>{for(var t in e)Z(i,t,{get:e[t],enumerable:!0})},Ye=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ge(e))!Ke.call(i,o)&&o!==t&&Z(i,o,{get:()=>e[o],enumerable:!(n=$e(e,o))||n.enumerable});return i};var He=i=>Ye(Z({},"__esModule",{value:!0}),i);var y=(i,e,t)=>(je(i,typeof e!="symbol"?e+"":e,t),t);var Nt={};v(Nt,{pluginQPS:()=>wt});var Qe={arabic:"ar",armenian:"am",bulgarian:"bg",czech:"cz",danish:"dk",dutch:"nl",english:"en",finnish:"fi",french:"fr",german:"de",greek:"gr",hungarian:"hu",indian:"in",indonesian:"id",irish:"ie",italian:"it",lithuanian:"lt",nepali:"np",norwegian:"no",portuguese:"pt",romanian:"ro",russian:"ru",serbian:"rs",slovenian:"ru",spanish:"es",swedish:"se",tamil:"ta",turkish:"tr",ukrainian:"uk",sanskrit:"sk"};var ue=Object.keys(Qe);var Et=Date.now().toString().slice(5);var _t=BigInt(1e3),vt=BigInt(1e6),Lt=BigInt(1e9);function Te(i,...e){return i.replace(/%(?:(?<position>\d+)\$)?(?<width>-?\d*\.?\d*)(?<type>[dfs])/g,function(...t){let n=t[t.length-1],{width:o,type:s,position:r}=n,a=r?e[Number.parseInt(r)-1]:e.shift(),c=o===""?0:Number.parseInt(o);switch(s){case"d":return a.toString().padStart(c,"0");case"f":{let l=a,[u,d]=o.split(".").map(f=>Number.parseFloat(f));return typeof d=="number"&&d>=0&&(l=l.toFixed(d)),typeof u=="number"&&u>=0?l.toString().padStart(c,"0"):l.toString()}case"s":return c<0?a.toString().padEnd(-c," "):a.toString().padStart(c," ");default:return a}})}function ee(i,e){return Object.hasOwn===void 0?Object.prototype.hasOwnProperty.call(i,e)?i[e]:void 0:Object.hasOwn(i,e)?i[e]:void 0}var qe={cm:.01,m:1,km:1e3,ft:.3048,yd:.9144,mi:1609.344};function te(i,e){let t=qe[e];if(t===void 0)throw new Error(w("INVALID_DISTANCE_SUFFIX",i).message);return i*t}var be="intersection"in new Set;function C(...i){if(i.length===0)return new Set;if(i.length===1)return i[0];if(i.length===2){let n=i[0],o=i[1];if(be)return n.intersection(o);let s=new Set,r=n.size<o.size?n:o,a=r===n?o:n;for(let c of r)a.has(c)&&s.add(c);return s}let e={index:0,size:i[0].size};for(let n=1;n<i.length;n++)i[n].size<e.size&&(e.index=n,e.size=i[n].size);if(be){let n=i[e.index];for(let o=0;o<i.length;o++)o!==e.index&&(n=n.intersection(i[o]));return n}let t=i[e.index];for(let n=0;n<i.length;n++){if(n===e.index)continue;let o=i[n];for(let s of t)o.has(s)||t.delete(s)}return t}var Xe="union"in new Set;function V(i,e){return Xe?i?i.union(e):e:i?new Set([...i,...e]):new Set(e)}function fe(i,e){let t=new Set;for(let n of i)e.has(n)||t.add(n);return t}var Ze=ue.join(`
|
|
2
|
+
- `),et={NO_LANGUAGE_WITH_CUSTOM_TOKENIZER:"Do not pass the language option to create when using a custom tokenizer.",LANGUAGE_NOT_SUPPORTED:`Language "%s" is not supported.
|
|
3
3
|
Supported languages are:
|
|
4
|
-
- ${
|
|
5
|
-
Input vectors must be of the size declared in the schema, as calculating similarity between vectors of different sizes can lead to unexpected results.`,WRONG_SEARCH_PROPERTY_TYPE:'Property "%s" is not searchable. Only "string" properties are searchable.',FACET_NOT_SUPPORTED:`Facet doens't support the type "%s".`,INVALID_DISTANCE_SUFFIX:'Invalid distance suffix "%s". Valid suffixes are: cm, m, km, mi, yd, ft.',INVALID_SEARCH_MODE:'Invalid search mode "%s". Valid modes are: "fulltext", "vector", "hybrid".',MISSING_VECTOR_AND_SECURE_PROXY:"No vector was provided and no secure proxy was configured. Please provide a vector or configure an Orama Secure Proxy to perform hybrid search.",MISSING_TERM:'"term" is a required parameter when performing hybrid search. Please provide a search term.',INVALID_VECTOR_INPUT:'Invalid "vector" property. Expected an object with "value" and "property" properties, but got "%s" instead.',PLUGIN_CRASHED:"A plugin crashed during initialization. Please check the error message for more information:",PLUGIN_SECURE_PROXY_NOT_FOUND:`Could not find '@
|
|
4
|
+
- ${Ze}`,INVALID_STEMMER_FUNCTION_TYPE:"config.stemmer property must be a function.",MISSING_STEMMER:'As of version 1.0.0 @wcs-colab/orama does not ship non English stemmers by default. To solve this, please explicitly import and specify the "%s" stemmer from the package @orama/stemmers. See https://docs.orama.com/docs/orama-js/text-analysis/stemming for more information.',CUSTOM_STOP_WORDS_MUST_BE_FUNCTION_OR_ARRAY:"Custom stop words array must only contain strings.",UNSUPPORTED_COMPONENT:'Unsupported component "%s".',COMPONENT_MUST_BE_FUNCTION:'The component "%s" must be a function.',COMPONENT_MUST_BE_FUNCTION_OR_ARRAY_FUNCTIONS:'The component "%s" must be a function or an array of functions.',INVALID_SCHEMA_TYPE:'Unsupported schema type "%s" at "%s". Expected "string", "boolean" or "number" or array of them.',DOCUMENT_ID_MUST_BE_STRING:'Document id must be of type "string". Got "%s" instead.',DOCUMENT_ALREADY_EXISTS:'A document with id "%s" already exists.',DOCUMENT_DOES_NOT_EXIST:'A document with id "%s" does not exists.',MISSING_DOCUMENT_PROPERTY:'Missing searchable property "%s".',INVALID_DOCUMENT_PROPERTY:'Invalid document property "%s": expected "%s", got "%s"',UNKNOWN_INDEX:'Invalid property name "%s". Expected a wildcard string ("*") or array containing one of the following properties: %s',INVALID_BOOST_VALUE:"Boost value must be a number greater than, or less than 0.",INVALID_FILTER_OPERATION:"You can only use one operation per filter, you requested %d.",SCHEMA_VALIDATION_FAILURE:'Cannot insert document due schema validation failure on "%s" property.',INVALID_SORT_SCHEMA_TYPE:'Unsupported sort schema type "%s" at "%s". Expected "string" or "number".',CANNOT_SORT_BY_ARRAY:'Cannot configure sort for "%s" because it is an array (%s).',UNABLE_TO_SORT_ON_UNKNOWN_FIELD:'Unable to sort on unknown field "%s". Allowed fields: %s',SORT_DISABLED:"Sort is disabled. Please read the documentation at https://docs.orama.com/docs/orama-js for more information.",UNKNOWN_GROUP_BY_PROPERTY:'Unknown groupBy property "%s".',INVALID_GROUP_BY_PROPERTY:'Invalid groupBy property "%s". Allowed types: "%s", but given "%s".',UNKNOWN_FILTER_PROPERTY:'Unknown filter property "%s".',UNKNOWN_VECTOR_PROPERTY:'Unknown vector property "%s". Make sure the property exists in the schema and is configured as a vector.',INVALID_VECTOR_SIZE:'Vector size must be a number greater than 0. Got "%s" instead.',INVALID_VECTOR_VALUE:'Vector value must be a number greater than 0. Got "%s" instead.',INVALID_INPUT_VECTOR:`Property "%s" was declared as a %s-dimensional vector, but got a %s-dimensional vector instead.
|
|
5
|
+
Input vectors must be of the size declared in the schema, as calculating similarity between vectors of different sizes can lead to unexpected results.`,WRONG_SEARCH_PROPERTY_TYPE:'Property "%s" is not searchable. Only "string" properties are searchable.',FACET_NOT_SUPPORTED:`Facet doens't support the type "%s".`,INVALID_DISTANCE_SUFFIX:'Invalid distance suffix "%s". Valid suffixes are: cm, m, km, mi, yd, ft.',INVALID_SEARCH_MODE:'Invalid search mode "%s". Valid modes are: "fulltext", "vector", "hybrid".',MISSING_VECTOR_AND_SECURE_PROXY:"No vector was provided and no secure proxy was configured. Please provide a vector or configure an Orama Secure Proxy to perform hybrid search.",MISSING_TERM:'"term" is a required parameter when performing hybrid search. Please provide a search term.',INVALID_VECTOR_INPUT:'Invalid "vector" property. Expected an object with "value" and "property" properties, but got "%s" instead.',PLUGIN_CRASHED:"A plugin crashed during initialization. Please check the error message for more information:",PLUGIN_SECURE_PROXY_NOT_FOUND:`Could not find '@wcs-colab/plugin-secure-proxy' installed in your Orama instance.
|
|
6
6
|
Please install it before proceeding with creating an answer session.
|
|
7
7
|
Read more at https://docs.orama.com/docs/orama-js/plugins/plugin-secure-proxy#plugin-secure-proxy
|
|
8
8
|
`,PLUGIN_SECURE_PROXY_MISSING_CHAT_MODEL:`Could not find a chat model defined in the secure proxy plugin configuration.
|
|
9
9
|
Please provide a chat model before proceeding with creating an answer session.
|
|
10
10
|
Read more at https://docs.orama.com/docs/orama-js/plugins/plugin-secure-proxy#plugin-secure-proxy
|
|
11
|
-
`,ANSWER_SESSION_LAST_MESSAGE_IS_NOT_ASSISTANT:"The last message in the session is not an assistant message. Cannot regenerate non-assistant messages.",PLUGIN_COMPONENT_CONFLICT:'The component "%s" is already defined. The plugin "%s" is trying to redefine it.'};function w(i,...e){let t=new Error(be(Ze[i]??`Unsupported Orama Error code: ${i}`,...e));return t.code=i,"captureStackTrace"in Error.prototype&&Error.captureStackTrace(t),t}var nt={string:!1,number:!1,boolean:!1,enum:!1,geopoint:!1,"string[]":!0,"number[]":!0,"boolean[]":!0,"enum[]":!0},rt={"string[]":"string","number[]":"number","boolean[]":"boolean","enum[]":"enum"};function z(i){return typeof i=="string"&&/^vector\[\d+\]$/.test(i)}function fe(i){return typeof i=="string"&&nt[i]}function Te(i){return rt[i]}function te(i){let e=Number(i.slice(7,-1));switch(!0){case isNaN(e):throw w("INVALID_VECTOR_VALUE",i);case e<=0:throw w("INVALID_VECTOR_SIZE",i);default:return e}}function B(i,e){if(typeof e=="string"){let t=i.idToInternalId.get(e);if(t)return t;let n=i.idToInternalId.size+1;return i.idToInternalId.set(e,n),i.internalIdToId.push(e),n}return e>i.internalIdToId.length?B(i,e.toString()):e}var E={};_(E,{calculateResultScores:()=>me,create:()=>pe,createIndex:()=>lt,getSearchableProperties:()=>Me,getSearchablePropertiesWithTypes:()=>Ce,insert:()=>Ee,insertDocumentScoreParameters:()=>Ae,insertTokenScoreParameters:()=>ke,insertVector:()=>ve,load:()=>ze,remove:()=>_e,removeDocumentScoreParameters:()=>Pe,removeTokenScoreParameters:()=>Re,save:()=>Be,search:()=>Le,searchByGeoWhereClause:()=>ft,searchByWhereClause:()=>H});var ne={};_(ne,{AVLNode:()=>L,AVLTree:()=>J});var L=class i{constructor(e,t){y(this,"k");y(this,"v");y(this,"l",null);y(this,"r",null);y(this,"h",1);this.k=e,this.v=new Set(t)}updateHeight(){this.h=Math.max(i.getHeight(this.l),i.getHeight(this.r))+1}static getHeight(e){return e?e.h:0}getBalanceFactor(){return i.getHeight(this.l)-i.getHeight(this.r)}rotateLeft(){let e=this.r;return this.r=e.l,e.l=this,this.updateHeight(),e.updateHeight(),e}rotateRight(){let e=this.l;return this.l=e.r,e.r=this,this.updateHeight(),e.updateHeight(),e}toJSON(){return{k:this.k,v:Array.from(this.v),l:this.l?this.l.toJSON():null,r:this.r?this.r.toJSON():null,h:this.h}}static fromJSON(e){let t=new i(e.k,e.v);return t.l=e.l?i.fromJSON(e.l):null,t.r=e.r?i.fromJSON(e.r):null,t.h=e.h,t}},J=class i{constructor(e,t){y(this,"root",null);y(this,"insertCount",0);e!==void 0&&t!==void 0&&(this.root=new L(e,t))}insert(e,t,n=1e3){this.root=this.insertNode(this.root,e,t,n)}insertMultiple(e,t,n=1e3){for(let o of t)this.insert(e,o,n)}rebalance(){this.root&&(this.root=this.rebalanceNode(this.root))}toJSON(){return{root:this.root?this.root.toJSON():null,insertCount:this.insertCount}}static fromJSON(e){let t=new i;return t.root=e.root?L.fromJSON(e.root):null,t.insertCount=e.insertCount||0,t}insertNode(e,t,n,o){if(e===null)return new L(t,[n]);let s=[],r=e,c=null;for(;r!==null;)if(s.push({parent:c,node:r}),t<r.k)if(r.l===null){r.l=new L(t,[n]),s.push({parent:r,node:r.l});break}else c=r,r=r.l;else if(t>r.k)if(r.r===null){r.r=new L(t,[n]),s.push({parent:r,node:r.r});break}else c=r,r=r.r;else return r.v.add(n),e;let a=!1;this.insertCount++%o===0&&(a=!0);for(let l=s.length-1;l>=0;l--){let{parent:u,node:d}=s[l];if(d.updateHeight(),a){let f=this.rebalanceNode(d);u?u.l===d?u.l=f:u.r===d&&(u.r=f):e=f}}return e}rebalanceNode(e){let t=e.getBalanceFactor();if(t>1){if(e.l&&e.l.getBalanceFactor()>=0)return e.rotateRight();if(e.l)return e.l=e.l.rotateLeft(),e.rotateRight()}if(t<-1){if(e.r&&e.r.getBalanceFactor()<=0)return e.rotateLeft();if(e.r)return e.r=e.r.rotateRight(),e.rotateLeft()}return e}find(e){let t=this.findNodeByKey(e);return t?t.v:null}contains(e){return this.find(e)!==null}getSize(){let e=0,t=[],n=this.root;for(;n||t.length>0;){for(;n;)t.push(n),n=n.l;n=t.pop(),e++,n=n.r}return e}isBalanced(){if(!this.root)return!0;let e=[this.root];for(;e.length>0;){let t=e.pop(),n=t.getBalanceFactor();if(Math.abs(n)>1)return!1;t.l&&e.push(t.l),t.r&&e.push(t.r)}return!0}remove(e){this.root=this.removeNode(this.root,e)}removeDocument(e,t){let n=this.findNodeByKey(e);n&&(n.v.size===1?this.root=this.removeNode(this.root,e):n.v=new Set([...n.v.values()].filter(o=>o!==t)))}findNodeByKey(e){let t=this.root;for(;t;)if(e<t.k)t=t.l;else if(e>t.k)t=t.r;else return t;return null}removeNode(e,t){if(e===null)return null;let n=[],o=e;for(;o!==null&&o.k!==t;)n.push(o),t<o.k?o=o.l:o=o.r;if(o===null)return e;if(o.l===null||o.r===null){let s=o.l?o.l:o.r;if(n.length===0)e=s;else{let r=n[n.length-1];r.l===o?r.l=s:r.r=s}}else{let s=o,r=o.r;for(;r.l!==null;)s=r,r=r.l;o.k=r.k,o.v=r.v,s.l===r?s.l=r.r:s.r=r.r,o=s}n.push(o);for(let s=n.length-1;s>=0;s--){let r=n[s];r.updateHeight();let c=this.rebalanceNode(r);if(s>0){let a=n[s-1];a.l===r?a.l=c:a.r===r&&(a.r=c)}else e=c}return e}rangeSearch(e,t){let n=new Set,o=[],s=this.root;for(;s||o.length>0;){for(;s;)o.push(s),s=s.l;if(s=o.pop(),s.k>=e&&s.k<=t)for(let r of s.v)n.add(r);if(s.k>t)break;s=s.r}return n}greaterThan(e,t=!1){let n=new Set,o=[],s=this.root;for(;s||o.length>0;){for(;s;)o.push(s),s=s.r;if(s=o.pop(),t&&s.k>=e||!t&&s.k>e)for(let r of s.v)n.add(r);else if(s.k<=e)break;s=s.l}return n}lessThan(e,t=!1){let n=new Set,o=[],s=this.root;for(;s||o.length>0;){for(;s;)o.push(s),s=s.l;if(s=o.pop(),t&&s.k<=e||!t&&s.k<e)for(let r of s.v)n.add(r);else if(s.k>e)break;s=s.r}return n}};var re={};_(re,{FlatTree:()=>$});var $=class i{constructor(){y(this,"numberToDocumentId");this.numberToDocumentId=new Map}insert(e,t){this.numberToDocumentId.has(e)?this.numberToDocumentId.get(e).add(t):this.numberToDocumentId.set(e,new Set([t]))}find(e){let t=this.numberToDocumentId.get(e);return t?Array.from(t):null}remove(e){this.numberToDocumentId.delete(e)}removeDocument(e,t){let n=this.numberToDocumentId.get(t);n&&(n.delete(e),n.size===0&&this.numberToDocumentId.delete(t))}contains(e){return this.numberToDocumentId.has(e)}getSize(){let e=0;for(let t of this.numberToDocumentId.values())e+=t.size;return e}filter(e){let t=Object.keys(e);if(t.length!==1)throw new Error("Invalid operation");let n=t[0];switch(n){case"eq":{let o=e[n],s=this.numberToDocumentId.get(o);return s?Array.from(s):[]}case"in":{let o=e[n],s=new Set;for(let r of o){let c=this.numberToDocumentId.get(r);if(c)for(let a of c)s.add(a)}return Array.from(s)}case"nin":{let o=new Set(e[n]),s=new Set;for(let[r,c]of this.numberToDocumentId.entries())if(!o.has(r))for(let a of c)s.add(a);return Array.from(s)}default:throw new Error("Invalid operation")}}filterArr(e){let t=Object.keys(e);if(t.length!==1)throw new Error("Invalid operation");let n=t[0];switch(n){case"containsAll":{let s=e[n].map(c=>this.numberToDocumentId.get(c)??new Set);if(s.length===0)return[];let r=s.reduce((c,a)=>new Set([...c].filter(l=>a.has(l))));return Array.from(r)}case"containsAny":{let s=e[n].map(c=>this.numberToDocumentId.get(c)??new Set);if(s.length===0)return[];let r=s.reduce((c,a)=>new Set([...c,...a]));return Array.from(r)}default:throw new Error("Invalid operation")}}static fromJSON(e){if(!e.numberToDocumentId)throw new Error("Invalid Flat Tree JSON");let t=new i;for(let[n,o]of e.numberToDocumentId)t.numberToDocumentId.set(n,new Set(o));return t}toJSON(){return{numberToDocumentId:Array.from(this.numberToDocumentId.entries()).map(([e,t])=>[e,Array.from(t)])}}};var U={};_(U,{RadixNode:()=>Q,RadixTree:()=>K});function it(i,e,t){if(t<0)return-1;if(i===e)return 0;let n=i.length,o=e.length;if(n===0)return o<=t?o:-1;if(o===0)return n<=t?n:-1;let s=Math.abs(n-o);if(i.startsWith(e))return s<=t?s:-1;if(e.startsWith(i))return 0;if(s>t)return-1;let r=[];for(let c=0;c<=n;c++){r[c]=[c];for(let a=1;a<=o;a++)r[c][a]=c===0?a:0}for(let c=1;c<=n;c++){let a=1/0;for(let l=1;l<=o;l++)i[c-1]===e[l-1]?r[c][l]=r[c-1][l-1]:r[c][l]=Math.min(r[c-1][l]+1,r[c][l-1]+1,r[c-1][l-1]+1),a=Math.min(a,r[c][l]);if(a>t)return-1}return r[n][o]<=t?r[n][o]:-1}function de(i,e,t){let n=it(i,e,t);return{distance:n,isBounded:n>=0}}var Q=class i{constructor(e,t,n){y(this,"k");y(this,"s");y(this,"c",new Map);y(this,"d",new Set);y(this,"e");y(this,"w","");this.k=e,this.s=t,this.e=n}updateParent(e){this.w=e.w+this.s}addDocument(e){this.d.add(e)}removeDocument(e){return this.d.delete(e)}findAllWords(e,t,n,o){let s=[this];for(;s.length>0;){let r=s.pop();if(r.e){let{w:c,d:a}=r;if(n&&c!==t)continue;if(Z(e,c)!==null)if(o)if(Math.abs(t.length-c.length)<=o&&de(t,c,o).isBounded)e[c]=[];else continue;else e[c]=[];if(Z(e,c)!=null&&a.size>0){let l=e[c];for(let u of a)l.includes(u)||l.push(u)}}r.c.size>0&&s.push(...r.c.values())}return e}insert(e,t){let n=this,o=0,s=e.length;for(;o<s;){let r=e[o],c=n.c.get(r);if(c){let a=c.s,l=a.length,u=0;for(;u<l&&o+u<s&&a[u]===e[o+u];)u++;if(u===l){if(n=c,o+=u,o===s){c.e||(c.e=!0),c.addDocument(t);return}continue}let d=a.slice(0,u),f=a.slice(u),h=e.slice(o+u),p=new i(d[0],d,!1);if(n.c.set(d[0],p),p.updateParent(n),c.s=f,c.k=f[0],p.c.set(f[0],c),c.updateParent(p),h){let m=new i(h[0],h,!0);m.addDocument(t),p.c.set(h[0],m),m.updateParent(p)}else p.e=!0,p.addDocument(t);return}else{let a=new i(r,e.slice(o),!0);a.addDocument(t),n.c.set(r,a),a.updateParent(n);return}}n.e||(n.e=!0),n.addDocument(t)}_findLevenshtein(e,t,n,o,s){let r=[{node:this,index:t,tolerance:n}];for(;r.length>0;){let{node:c,index:a,tolerance:l}=r.pop();if(c.w.startsWith(e)&&c.w!==e){console.log("[RADIX FIX] Prefix optimization triggered for:",c.w,"term:",e),c.findAllWords(s,e,!1,0);continue}if(c.w.startsWith(e)&&c.w===e&&console.log("[RADIX FIX] Exact match excluded from prefix optimization:",e),l<0)continue;if(c.e){let{w:d,d:f}=c;if(d&&(de(e,d,o).isBounded&&(s[d]=[]),Z(s,d)!==void 0&&f.size>0)){let h=new Set(s[d]);for(let p of f)h.add(p);s[d]=Array.from(h)}}if(a>=e.length)continue;let u=e[a];if(c.c.has(u)){let d=c.c.get(u);r.push({node:d,index:a+1,tolerance:l})}r.push({node:c,index:a+1,tolerance:l-1});for(let[d,f]of c.c)r.push({node:f,index:a,tolerance:l-1}),d!==u&&r.push({node:f,index:a+1,tolerance:l-1})}}find(e){let{term:t,exact:n,tolerance:o}=e;if(o&&!n){let s={};return this._findLevenshtein(t,0,o,o,s),s}else{let s=this,r=0,c=t.length;for(;r<c;){let l=t[r],u=s.c.get(l);if(u){let d=u.s,f=d.length,h=0;for(;h<f&&r+h<c&&d[h]===t[r+h];)h++;if(h===f)s=u,r+=h;else if(r+h===c)if(h===c-r){if(n)return{};{let p={};return u.findAllWords(p,t,n,o),p}}else return{};else return{}}else return{}}let a={};return s.findAllWords(a,t,n,o),a}}contains(e){let t=this,n=0,o=e.length;for(;n<o;){let s=e[n],r=t.c.get(s);if(r){let c=r.s,a=c.length,l=0;for(;l<a&&n+l<o&&c[l]===e[n+l];)l++;if(l<a)return!1;n+=a,t=r}else return!1}return!0}removeWord(e){if(!e)return!1;let t=this,n=e.length,o=[];for(let s=0;s<n;s++){let r=e[s];if(t.c.has(r)){let c=t.c.get(r);o.push({parent:t,character:r}),s+=c.s.length-1,t=c}else return!1}for(t.d.clear(),t.e=!1;o.length>0&&t.c.size===0&&!t.e&&t.d.size===0;){let{parent:s,character:r}=o.pop();s.c.delete(r),t=s}return!0}removeDocumentByWord(e,t,n=!0){if(!e)return!0;let o=this,s=e.length;for(let r=0;r<s;r++){let c=e[r];if(o.c.has(c)){let a=o.c.get(c);r+=a.s.length-1,o=a,n&&o.w!==e||o.removeDocument(t)}else return!1}return!0}static getCommonPrefix(e,t){let n=Math.min(e.length,t.length),o=0;for(;o<n&&e.charCodeAt(o)===t.charCodeAt(o);)o++;return e.slice(0,o)}toJSON(){return{w:this.w,s:this.s,e:this.e,k:this.k,d:Array.from(this.d),c:Array.from(this.c?.entries())?.map(([e,t])=>[e,t.toJSON()])}}static fromJSON(e){let t=new i(e.k,e.s,e.e);return t.w=e.w,t.d=new Set(e.d),t.c=new Map(e?.c?.map(([n,o])=>[n,i.fromJSON(o)])||[]),t}},K=class i extends Q{constructor(){super("","",!1)}static fromJSON(e){let t=new i;return t.w=e.w,t.s=e.s,t.e=e.e,t.k=e.k,t.d=new Set(e.d),t.c=new Map(e?.c?.map(([n,o])=>[n,Q.fromJSON(o)])||[]),t}toJSON(){return super.toJSON()}};var se={};_(se,{BKDTree:()=>R});var oe=class i{constructor(e,t){y(this,"point");y(this,"docIDs");y(this,"left");y(this,"right");y(this,"parent");this.point=e,this.docIDs=new Set(t),this.left=null,this.right=null,this.parent=null}toJSON(){return{point:this.point,docIDs:Array.from(this.docIDs),left:this.left?this.left.toJSON():null,right:this.right?this.right.toJSON():null}}static fromJSON(e,t=null){let n=new i(e.point,e.docIDs);return n.parent=t,e.left&&(n.left=i.fromJSON(e.left,n)),e.right&&(n.right=i.fromJSON(e.right,n)),n}},R=class i{constructor(){y(this,"root");y(this,"nodeMap");this.root=null,this.nodeMap=new Map}getPointKey(e){return`${e.lon},${e.lat}`}insert(e,t){let n=this.getPointKey(e),o=this.nodeMap.get(n);if(o){t.forEach(a=>o.docIDs.add(a));return}let s=new oe(e,t);if(this.nodeMap.set(n,s),this.root==null){this.root=s;return}let r=this.root,c=0;for(;;){if(c%2===0)if(e.lon<r.point.lon){if(r.left==null){r.left=s,s.parent=r;return}r=r.left}else{if(r.right==null){r.right=s,s.parent=r;return}r=r.right}else if(e.lat<r.point.lat){if(r.left==null){r.left=s,s.parent=r;return}r=r.left}else{if(r.right==null){r.right=s,s.parent=r;return}r=r.right}c++}}contains(e){let t=this.getPointKey(e);return this.nodeMap.has(t)}getDocIDsByCoordinates(e){let t=this.getPointKey(e),n=this.nodeMap.get(t);return n?Array.from(n.docIDs):null}removeDocByID(e,t){let n=this.getPointKey(e),o=this.nodeMap.get(n);o&&(o.docIDs.delete(t),o.docIDs.size===0&&(this.nodeMap.delete(n),this.deleteNode(o)))}deleteNode(e){let t=e.parent,n=e.left?e.left:e.right;n&&(n.parent=t),t?t.left===e?t.left=n:t.right===e&&(t.right=n):(this.root=n,this.root&&(this.root.parent=null))}searchByRadius(e,t,n=!0,o="asc",s=!1){let r=s?i.vincentyDistance:i.haversineDistance,c=[{node:this.root,depth:0}],a=[];for(;c.length>0;){let{node:l,depth:u}=c.pop();if(l==null)continue;let d=r(e,l.point);(n?d<=t:d>t)&&a.push({point:l.point,docIDs:Array.from(l.docIDs)}),l.left!=null&&c.push({node:l.left,depth:u+1}),l.right!=null&&c.push({node:l.right,depth:u+1})}return o&&a.sort((l,u)=>{let d=r(e,l.point),f=r(e,u.point);return o.toLowerCase()==="asc"?d-f:f-d}),a}searchByPolygon(e,t=!0,n=null,o=!1){let s=[{node:this.root,depth:0}],r=[];for(;s.length>0;){let{node:a,depth:l}=s.pop();if(a==null)continue;a.left!=null&&s.push({node:a.left,depth:l+1}),a.right!=null&&s.push({node:a.right,depth:l+1});let u=i.isPointInPolygon(e,a.point);(u&&t||!u&&!t)&&r.push({point:a.point,docIDs:Array.from(a.docIDs)})}let c=i.calculatePolygonCentroid(e);if(n){let a=o?i.vincentyDistance:i.haversineDistance;r.sort((l,u)=>{let d=a(c,l.point),f=a(c,u.point);return n.toLowerCase()==="asc"?d-f:f-d})}return r}toJSON(){return{root:this.root?this.root.toJSON():null}}static fromJSON(e){let t=new i;return e.root&&(t.root=oe.fromJSON(e.root),t.buildNodeMap(t.root)),t}buildNodeMap(e){if(e==null)return;let t=this.getPointKey(e.point);this.nodeMap.set(t,e),e.left&&this.buildNodeMap(e.left),e.right&&this.buildNodeMap(e.right)}static calculatePolygonCentroid(e){let t=0,n=0,o=0,s=e.length;for(let c=0,a=s-1;c<s;a=c++){let l=e[c].lon,u=e[c].lat,d=e[a].lon,f=e[a].lat,h=l*f-d*u;t+=h,n+=(l+d)*h,o+=(u+f)*h}t/=2;let r=6*t;return n/=r,o/=r,{lon:n,lat:o}}static isPointInPolygon(e,t){let n=!1,o=t.lon,s=t.lat,r=e.length;for(let c=0,a=r-1;c<r;a=c++){let l=e[c].lon,u=e[c].lat,d=e[a].lon,f=e[a].lat;u>s!=f>s&&o<(d-l)*(s-u)/(f-u)+l&&(n=!n)}return n}static haversineDistance(e,t){let n=Math.PI/180,o=e.lat*n,s=t.lat*n,r=(t.lat-e.lat)*n,c=(t.lon-e.lon)*n,a=Math.sin(r/2)*Math.sin(r/2)+Math.cos(o)*Math.cos(s)*Math.sin(c/2)*Math.sin(c/2);return 6371e3*(2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a)))}static vincentyDistance(e,t){let o=.0033528106647474805,s=(1-o)*6378137,r=Math.PI/180,c=e.lat*r,a=t.lat*r,l=(t.lon-e.lon)*r,u=Math.atan((1-o)*Math.tan(c)),d=Math.atan((1-o)*Math.tan(a)),f=Math.sin(u),h=Math.cos(u),p=Math.sin(d),m=Math.cos(d),b=l,S,I=1e3,g,T,x,D,k,O;do{let W=Math.sin(b),Y=Math.cos(b);if(g=Math.sqrt(m*W*(m*W)+(h*p-f*m*Y)*(h*p-f*m*Y)),g===0)return 0;T=f*p+h*m*Y,x=Math.atan2(g,T),D=h*m*W/g,k=1-D*D,O=T-2*f*p/k,isNaN(O)&&(O=0);let ae=o/16*k*(4+o*(4-3*k));S=b,b=l+(1-ae)*o*D*(x+ae*g*(O+ae*T*(-1+2*O*O)))}while(Math.abs(b-S)>1e-12&&--I>0);if(I===0)return NaN;let N=k*(6378137*6378137-s*s)/(s*s),v=1+N/16384*(4096+N*(-768+N*(320-175*N))),A=N/1024*(256+N*(-128+N*(74-47*N))),P=A*g*(O+A/4*(T*(-1+2*O*O)-A/6*O*(-3+4*g*g)*(-3+4*O*O)));return s*v*(x-P)}};var ie={};_(ie,{BoolNode:()=>G});var G=class i{constructor(){y(this,"true");y(this,"false");this.true=new Set,this.false=new Set}insert(e,t){t?this.true.add(e):this.false.add(e)}delete(e,t){t?this.true.delete(e):this.false.delete(e)}getSize(){return this.true.size+this.false.size}toJSON(){return{true:Array.from(this.true),false:Array.from(this.false)}}static fromJSON(e){let t=new i;return t.true=new Set(e.true),t.false=new Set(e.false),t}};function xe(i,e,t,n,o,{k:s,b:r,d:c}){return Math.log(1+(t-e+.5)/(e+.5))*(c+i*(s+1))/(i+s*(1-r+r*n/o))}var ce={};_(ce,{DEFAULT_SIMILARITY:()=>ct,VectorIndex:()=>j,findSimilarVectors:()=>De,getMagnitude:()=>he});var ct=.8,j=class i{constructor(e){y(this,"size");y(this,"vectors",new Map);this.size=e}add(e,t){t instanceof Float32Array||(t=new Float32Array(t));let n=he(t,this.size);this.vectors.set(e,[n,t])}remove(e){this.vectors.delete(e)}find(e,t,n){return e instanceof Float32Array||(e=new Float32Array(e)),De(e,n,this.vectors,this.size,t)}toJSON(){let e=[];for(let[t,[n,o]]of this.vectors)e.push([t,[n,Array.from(o)]]);return{size:this.size,vectors:e}}static fromJSON(e){let t=e,n=new i(t.size);for(let[o,[s,r]]of t.vectors)n.vectors.set(o,[s,new Float32Array(r)]);return n}};function he(i,e){let t=0;for(let n=0;n<e;n++)t+=i[n]*i[n];return Math.sqrt(t)}function De(i,e,t,n,o){let s=he(i,n),r=[],c=e||t.keys();for(let a of c){let l=t.get(a);if(!l)continue;let u=l[0],d=l[1],f=0;for(let p=0;p<n;p++)f+=i[p]*d[p];let h=f/(s*u);h>=o&&r.push([a,h])}return r}function Ae(i,e,t,n,o){let s=B(i.sharedInternalDocumentStore,t);i.avgFieldLength[e]=((i.avgFieldLength[e]??0)*(o-1)+n.length)/o,i.fieldLengths[e][s]=n.length,i.frequencies[e][s]={}}function ke(i,e,t,n,o){let s=0;for(let a of n)a===o&&s++;let r=B(i.sharedInternalDocumentStore,t),c=s/n.length;i.frequencies[e][r][o]=c,o in i.tokenOccurrences[e]||(i.tokenOccurrences[e][o]=0),i.tokenOccurrences[e][o]=(i.tokenOccurrences[e][o]??0)+1}function Pe(i,e,t,n){let o=B(i.sharedInternalDocumentStore,t);n>1?i.avgFieldLength[e]=(i.avgFieldLength[e]*n-i.fieldLengths[e][o])/(n-1):i.avgFieldLength[e]=void 0,i.fieldLengths[e][o]=void 0,i.frequencies[e][o]=void 0}function Re(i,e,t){i.tokenOccurrences[e][t]--}function pe(i,e,t,n,o=""){n||(n={sharedInternalDocumentStore:e,indexes:{},vectorIndexes:{},searchableProperties:[],searchablePropertiesWithTypes:{},frequencies:{},tokenOccurrences:{},avgFieldLength:{},fieldLengths:{}});for(let[s,r]of Object.entries(t)){let c=`${o}${o?".":""}${s}`;if(typeof r=="object"&&!Array.isArray(r)){pe(i,e,r,n,c);continue}if(z(r))n.searchableProperties.push(c),n.searchablePropertiesWithTypes[c]=r,n.vectorIndexes[c]={type:"Vector",node:new j(te(r)),isArray:!1};else{let a=/\[/.test(r);switch(r){case"boolean":case"boolean[]":n.indexes[c]={type:"Bool",node:new G,isArray:a};break;case"number":case"number[]":n.indexes[c]={type:"AVL",node:new J(0,[]),isArray:a};break;case"string":case"string[]":n.indexes[c]={type:"Radix",node:new K,isArray:a},n.avgFieldLength[c]=0,n.frequencies[c]={},n.tokenOccurrences[c]={},n.fieldLengths[c]={};break;case"enum":case"enum[]":n.indexes[c]={type:"Flat",node:new $,isArray:a};break;case"geopoint":n.indexes[c]={type:"BKD",node:new R,isArray:a};break;default:throw w("INVALID_SCHEMA_TYPE",Array.isArray(r)?"array":r,c)}n.searchableProperties.push(c),n.searchablePropertiesWithTypes[c]=r}}return n}function at(i,e,t,n,o,s,r,c){return a=>{let{type:l,node:u}=e.indexes[t];switch(l){case"Bool":{u[a?"true":"false"].add(n);break}case"AVL":{let d=c?.avlRebalanceThreshold??1;u.insert(a,n,d);break}case"Radix":{let d=s.tokenize(a,o,t,!1);i.insertDocumentScoreParameters(e,t,n,d,r);for(let f of d)i.insertTokenScoreParameters(e,t,n,d,f),u.insert(f,n);break}case"Flat":{u.insert(a,n);break}case"BKD":{u.insert(a,[n]);break}}}}function Ee(i,e,t,n,o,s,r,c,a,l,u){if(z(r))return ve(e,t,s,n,o);let d=at(i,e,t,o,c,a,l,u);if(!fe(r))return d(s);let f=s,h=f.length;for(let p=0;p<h;p++)d(f[p])}function ve(i,e,t,n,o){i.vectorIndexes[e].node.add(o,t)}function Oe(i,e,t,n,o,s,r,c,a,l){if(z(r))return e.vectorIndexes[t].node.remove(o),!0;let{type:u,node:d}=e.indexes[t];switch(u){case"AVL":return d.removeDocument(s,o),!0;case"Bool":return d[s?"true":"false"].delete(o),!0;case"Radix":{let f=a.tokenize(s,c,t);i.removeDocumentScoreParameters(e,t,n,l);for(let h of f)i.removeTokenScoreParameters(e,t,h),d.removeDocumentByWord(h,o);return!0}case"Flat":return d.removeDocument(o,s),!0;case"BKD":return d.removeDocByID(s,o),!1}}function _e(i,e,t,n,o,s,r,c,a,l){if(!fe(r))return Oe(i,e,t,n,o,s,r,c,a,l);let u=Te(r),d=s,f=d.length;for(let h=0;h<f;h++)Oe(i,e,t,n,o,d[h],u,c,a,l);return!0}function me(i,e,t,n,o,s,r,c,a,l){let u=Array.from(n),d=i.avgFieldLength[e],f=i.fieldLengths[e],h=i.tokenOccurrences[e],p=i.frequencies[e],m=typeof h[t]=="number"?h[t]??0:0,b=u.length;for(let S=0;S<b;S++){let I=u[S];if(a&&!a.has(I))continue;l.has(I)||l.set(I,new Map);let g=l.get(I);g.set(e,(g.get(e)||0)+1);let T=p?.[I]?.[t]??0,x=xe(T,m,o,f[I],d,s);r.has(I)?r.set(I,r.get(I)+x*c):r.set(I,x*c)}}function Le(i,e,t,n,o,s,r,c,a,l,u,d=0){let f=t.tokenize(e,n),h=f.length||1,p=new Map,m=new Map,b=new Map;for(let g of o){if(!(g in i.indexes))continue;let T=i.indexes[g],{type:x}=T;if(x!=="Radix")throw w("WRONG_SEARCH_PROPERTY_TYPE",g);let D=c[g]??1;if(D<=0)throw w("INVALID_BOOST_VALUE",D);f.length===0&&!e&&f.push("");let k=f.length;for(let O=0;O<k;O++){let N=f[O],v=T.node.find({term:N,exact:s,tolerance:r}),A=Object.keys(v);A.length>0&&m.set(N,!0);let P=A.length;for(let F=0;F<P;F++){let W=A[F],Y=v[W];me(i,g,W,Y,l,a,b,D,u,p)}}}let S=Array.from(b.entries()).map(([g,T])=>[g,T]).sort((g,T)=>T[1]-g[1]);if(S.length===0)return[];if(d===1)return S;if(d===0){if(h===1)return S;for(let T of f)if(!m.get(T))return[];return S.filter(([T])=>{let x=p.get(T);return x?Array.from(x.values()).some(D=>D===h):!1})}let I=S.filter(([g])=>{let T=p.get(g);return T?Array.from(T.values()).some(x=>x===h):!1});if(I.length>0){let g=S.filter(([x])=>!I.some(([D])=>D===x)),T=Math.ceil(g.length*d);return[...I,...g.slice(0,T)]}return S}function H(i,e,t,n){if("and"in t&&t.and&&Array.isArray(t.and)){let r=t.and;if(r.length===0)return new Set;let c=r.map(a=>H(i,e,a,n));return C(...c)}if("or"in t&&t.or&&Array.isArray(t.or)){let r=t.or;return r.length===0?new Set:r.map(a=>H(i,e,a,n)).reduce((a,l)=>V(a,l),new Set)}if("not"in t&&t.not){let r=t.not,c=new Set,a=i.sharedInternalDocumentStore;for(let u=1;u<=a.internalIdToId.length;u++)c.add(u);let l=H(i,e,r,n);return ue(c,l)}let o=Object.keys(t),s=o.reduce((r,c)=>({[c]:new Set,...r}),{});for(let r of o){let c=t[r];if(typeof i.indexes[r]>"u")throw w("UNKNOWN_FILTER_PROPERTY",r);let{node:a,type:l,isArray:u}=i.indexes[r];if(l==="Bool"){let f=a,h=c?f.true:f.false;s[r]=V(s[r],h);continue}if(l==="BKD"){let f;if("radius"in c)f="radius";else if("polygon"in c)f="polygon";else throw new Error(`Invalid operation ${c}`);if(f==="radius"){let{value:h,coordinates:p,unit:m="m",inside:b=!0,highPrecision:S=!1}=c[f],I=ee(h,m),g=a.searchByRadius(p,I,b,void 0,S);s[r]=we(s[r],g)}else{let{coordinates:h,inside:p=!0,highPrecision:m=!1}=c[f],b=a.searchByPolygon(h,p,void 0,m);s[r]=we(s[r],b)}continue}if(l==="Radix"&&(typeof c=="string"||Array.isArray(c))){for(let f of[c].flat()){let h=e.tokenize(f,n,r);for(let p of h){let m=a.find({term:p,exact:!0});s[r]=dt(s[r],m)}}continue}let d=Object.keys(c);if(d.length>1)throw w("INVALID_FILTER_OPERATION",d.length);if(l==="Flat"){let f=new Set(u?a.filterArr(c):a.filter(c));s[r]=V(s[r],f);continue}if(l==="AVL"){let f=d[0],h=c[f],p;switch(f){case"gt":{p=a.greaterThan(h,!1);break}case"gte":{p=a.greaterThan(h,!0);break}case"lt":{p=a.lessThan(h,!1);break}case"lte":{p=a.lessThan(h,!0);break}case"eq":{p=a.find(h)??new Set;break}case"between":{let[m,b]=h;p=a.rangeSearch(m,b);break}default:throw w("INVALID_FILTER_OPERATION",f)}s[r]=V(s[r],p)}}return C(...Object.values(s))}function Me(i){return i.searchableProperties}function Ce(i){return i.searchablePropertiesWithTypes}function ze(i,e){let{indexes:t,vectorIndexes:n,searchableProperties:o,searchablePropertiesWithTypes:s,frequencies:r,tokenOccurrences:c,avgFieldLength:a,fieldLengths:l}=e,u={},d={};for(let f of Object.keys(t)){let{node:h,type:p,isArray:m}=t[f];switch(p){case"Radix":u[f]={type:"Radix",node:K.fromJSON(h),isArray:m};break;case"Flat":u[f]={type:"Flat",node:$.fromJSON(h),isArray:m};break;case"AVL":u[f]={type:"AVL",node:J.fromJSON(h),isArray:m};break;case"BKD":u[f]={type:"BKD",node:R.fromJSON(h),isArray:m};break;case"Bool":u[f]={type:"Bool",node:G.fromJSON(h),isArray:m};break;default:u[f]=t[f]}}for(let f of Object.keys(n))d[f]={type:"Vector",isArray:!1,node:j.fromJSON(n[f])};return{sharedInternalDocumentStore:i,indexes:u,vectorIndexes:d,searchableProperties:o,searchablePropertiesWithTypes:s,frequencies:r,tokenOccurrences:c,avgFieldLength:a,fieldLengths:l}}function Be(i){let{indexes:e,vectorIndexes:t,searchableProperties:n,searchablePropertiesWithTypes:o,frequencies:s,tokenOccurrences:r,avgFieldLength:c,fieldLengths:a}=i,l={};for(let d of Object.keys(t))l[d]=t[d].node.toJSON();let u={};for(let d of Object.keys(e)){let{type:f,node:h,isArray:p}=e[d];f==="Flat"||f==="Radix"||f==="AVL"||f==="BKD"||f==="Bool"?u[d]={type:f,node:h.toJSON(),isArray:p}:(u[d]=e[d],u[d].node=u[d].node.toJSON())}return{indexes:u,vectorIndexes:l,searchableProperties:n,searchablePropertiesWithTypes:o,frequencies:s,tokenOccurrences:r,avgFieldLength:c,fieldLengths:a}}function lt(){return{create:pe,insert:Ee,remove:_e,insertDocumentScoreParameters:Ae,insertTokenScoreParameters:ke,removeDocumentScoreParameters:Pe,removeTokenScoreParameters:Re,calculateResultScores:me,search:Le,searchByWhereClause:H,getSearchableProperties:Me,getSearchablePropertiesWithTypes:Ce,load:ze,save:Be}}function we(i,e){i||(i=new Set);let t=e.length;for(let n=0;n<t;n++){let o=e[n].docIDs,s=o.length;for(let r=0;r<s;r++)i.add(o[r])}return i}function Ne(i,e,t=!1){let n=t?R.vincentyDistance:R.haversineDistance,o=[],s=[];for(let{point:a}of i)s.push(n(e,a));let r=Math.max(...s),c=0;for(let{docIDs:a}of i){let l=s[c],u=r-l+1;for(let d of a)o.push([d,u]);c++}return o.sort((a,l)=>l[1]-a[1]),o}function ut(i,e){let t=Object.keys(i);if(t.length!==1)return{isGeoOnly:!1};let n=t[0],o=i[n];if(typeof e.indexes[n]>"u")return{isGeoOnly:!1};let{type:s}=e.indexes[n];return s==="BKD"&&o&&("radius"in o||"polygon"in o)?{isGeoOnly:!0,geoProperty:n,geoOperation:o}:{isGeoOnly:!1}}function ft(i,e){let t=i,n=ut(e,t);if(!n.isGeoOnly||!n.geoProperty||!n.geoOperation)return null;let{node:o}=t.indexes[n.geoProperty],s=n.geoOperation,r=o,c;if("radius"in s){let{value:a,coordinates:l,unit:u="m",inside:d=!0,highPrecision:f=!1}=s.radius,h=l,p=ee(a,u);return c=r.searchByRadius(h,p,d,"asc",f),Ne(c,h,f)}else if("polygon"in s){let{coordinates:a,inside:l=!0,highPrecision:u=!1}=s.polygon;c=r.searchByPolygon(a,l,"asc",u);let d=R.calculatePolygonCentroid(a);return Ne(c,d,u)}return null}function dt(i,e){i||(i=new Set);let t=Object.keys(e),n=t.length;for(let o=0;o<n;o++){let s=e[t[o]],r=s.length;for(let c=0;c<r;c++)i.add(s[c])}return i}var ht="[^aeiou]",Ue="[aeiouy]",M=ht+"[^aeiouy]*",q=Ue+"[aeiou]*",pn="^("+M+")?"+q+M,mn="^("+M+")?"+q+M+"("+q+")?$",gn="^("+M+")?"+q+M+q+M,Sn="^("+M+")?"+Ue;function ge(i,e,t){for(let n of Object.entries(e)){let o=n[0],s=n[1],r=`${t}${t?".":""}${o}`;if(typeof s=="object"&&!Array.isArray(s)){ge(i,s,r);continue}if(z(s))i.searchableProperties.push(r),i.searchablePropertiesWithTypes[r]=s,i.vectorIndexes[r]={type:"Vector",node:new ce.VectorIndex(te(s)),isArray:!1};else{let c=/\[/.test(s);switch(s){case"boolean":case"boolean[]":i.indexes[r]={type:"Bool",node:new ie.BoolNode,isArray:c};break;case"number":case"number[]":i.indexes[r]={type:"AVL",node:new ne.AVLTree(0,[]),isArray:c};break;case"string":case"string[]":i.indexes[r]={type:"Radix",node:new U.RadixTree,isArray:c};break;case"enum":case"enum[]":i.indexes[r]={type:"Flat",node:new re.FlatTree,isArray:c};break;case"geopoint":i.indexes[r]={type:"BKD",node:new se.BKDTree,isArray:c};break;default:throw new Error("INVALID_SCHEMA_TYPE: "+r)}i.searchableProperties.push(r),i.searchablePropertiesWithTypes[r]=s}}}var It=1048575;function yt(i,e){let t=Ve(i),o=We(i)|1<<e;return t+1<<20|o}function Se(i,e,t,n,o,s,r){let c=i.split(/\.|\?|!/),a=0,l=0;for(let u of c){let d=r.tokenize(u,s,n);for(let f of d){l++,t[f]||(t[f]=0);let h=Math.min(a,20);t.tokenQuantums[o][f]=yt(t.tokenQuantums[o][f],h),e.insert(f,o)}d.length>1&&a++}t.tokensLength.set(o,l)}function Fe(i){let e=i.tokens,t=i.radixNode,n=i.exact,o=i.tolerance,s=i.stats,r=i.boostPerProp,c=i.resultMap,a=i.whereFiltersIDs,l=s.tokensLength,u=s.tokenQuantums,d={term:"",exact:n,tolerance:o},f={},h=e.length;for(let b=0;b<h;b++){let S=e[b];d.term=S;let I=t.find(d);f={...f,...I}}let p=Object.keys(f),m=p.length;for(let b=0;b<m;b++){let S=p[b],I=f[S],g=I.length,T=e.includes(S);for(let x=0;x<g;x++){let D=I[x];if(a&&!a.has(D))continue;let k=l.get(D),O=u[D][S],N=Ve(O),v=We(O),A=(N*N/k+(T?1:0))*r;if(!c.has(D)){c.set(D,[A,v]);continue}let P=c.get(D),F=P[0]+bt(P[1]&v)*2+A;P[0]=F,P[1]=P[1]|v}}}function We(i){return i&It}function Ve(i){return i>>20}function bt(i){let e=0;do i&1&&++e;while(i>>=1);return e}function Ie(i,e,t,n,o,s,r){let c=r.tokensLength,a=r.tokenQuantums,l=o.tokenize(i,s,t);for(let u of l)e.removeDocumentByWord(u,n,!0);c.delete(n),delete a[n]}var Tt=new U.RadixNode("","",!1),xt={tokenQuantums:{},tokensLength:new Map};function Dt(i,e,t,n,o,s,r,c,a,l,u){let d=new Map,f={tokens:t.tokenize(e,n),radixNode:Tt,exact:s,tolerance:r,stats:xt,boostPerProp:0,all:d,resultMap:d,whereFiltersIDs:u},h=o.length;for(let S=0;S<h;S++){let I=o[S],g=i.stats[I],T=c[I]??1;f.radixNode=i.indexes[I].node,f.stats=g,f.boostPerProp=T,Fe(f)}let p=Array.from(d),m=p.length,b=[];for(let S=0;S<m;S++){let I=p[S],g=I[0],T=I[1][0];b.push([g,T])}return b}function Ot(){return{name:"qps",getComponents(i){return wt(i)}}}function wt(i){return{index:{create:function(){let t={indexes:{},vectorIndexes:{},searchableProperties:[],searchablePropertiesWithTypes:{},stats:{}};return ge(t,i,""),t},insert:function(t,n,o,s,r,c,a,l,u,d){if(!(a==="string"||a==="string[]"))return E.insert(t,n,o,s,r,c,a,l,u,d);n.stats[o]||(n.stats[o]={tokenQuantums:{},tokensLength:new Map});let f=n.stats[o],h=n.indexes[o].node;if(f.tokenQuantums[r]={},Array.isArray(c))for(let p of c)Se(p,h,f,o,r,l,u);else Se(c,h,f,o,r,l,u)},remove:function(t,n,o,s,r,c,a,l,u,d){if(!(a==="string"||a==="string[]"))return E.remove(t,n,o,s,r,c,a,l,u,d);let f=n.stats[o],h=n.indexes[o].node;if(Array.isArray(c))for(let p of c)Ie(p,h,o,r,u,l,f);else Ie(c,h,o,r,u,l,f)},insertDocumentScoreParameters:()=>{throw new Error},insertTokenScoreParameters:()=>{throw new Error},removeDocumentScoreParameters:()=>{throw new Error},removeTokenScoreParameters:()=>{throw new Error},calculateResultScores:()=>{throw new Error},search:Dt,searchByWhereClause:function(t,n,o,s){let r=Object.entries(o).filter(([u])=>t.indexes[u].type==="Radix");if(r.length===0)return E.searchByWhereClause(t,n,o,s);let c;for(let[u,d]of r){let f=[];if(Array.isArray(d))for(let m of d){let b=n.tokenize(m,s)?.[0];f.push(b)}else f=n.tokenize(d,s);let h=t.indexes[u].node,p=new Set;for(let m of f){let S=h.find({term:m,exact:!0})[m];if(S)for(let I of S)p.add(I)}c?c=C(c,p):c=p}if(Object.entries(o).filter(([u])=>t.indexes[u].type!=="Radix").length===0)return c;let l=E.searchByWhereClause(t,n,o,s);return C(c,l)},getSearchableProperties:function(t){return t.searchableProperties},getSearchablePropertiesWithTypes:function(e){return e.searchablePropertiesWithTypes},load:function(t,n){let o=E.load(t,n[0]),s=n[1],r={...o.indexes,...Object.fromEntries(s.radixTrees.map(([c,a,l,u])=>[c,{node:U.RadixNode.fromJSON(u),isArray:a,type:l}]))};return{...o,indexes:r,stats:Object.fromEntries(s.stats.map(([c,{tokenQuantums:a,tokensLength:l}])=>[c,{tokenQuantums:a,tokensLength:new Map(l)}]))}},save:function(t){let n=t,o=Object.entries(n.indexes).filter(([,{type:a}])=>a!=="Radix"),s=E.save({...n,indexes:Object.fromEntries(o)}),c={radixTrees:Object.entries(n.indexes).filter(([,{type:a}])=>a==="Radix").map(([a,{node:l,isArray:u,type:d}])=>[a,u,d,l.toJSON()]),stats:Object.entries(t.stats).map(([a,{tokenQuantums:l,tokensLength:u}])=>[a,{tokenQuantums:l,tokensLength:Array.from(u.entries())}])};return[s,c]}}}}return Ye(Nt);})();
|
|
11
|
+
`,ANSWER_SESSION_LAST_MESSAGE_IS_NOT_ASSISTANT:"The last message in the session is not an assistant message. Cannot regenerate non-assistant messages.",PLUGIN_COMPONENT_CONFLICT:'The component "%s" is already defined. The plugin "%s" is trying to redefine it.'};function w(i,...e){let t=new Error(Te(et[i]??`Unsupported Orama Error code: ${i}`,...e));return t.code=i,"captureStackTrace"in Error.prototype&&Error.captureStackTrace(t),t}var rt={string:!1,number:!1,boolean:!1,enum:!1,geopoint:!1,"string[]":!0,"number[]":!0,"boolean[]":!0,"enum[]":!0},ot={"string[]":"string","number[]":"number","boolean[]":"boolean","enum[]":"enum"};function z(i){return typeof i=="string"&&/^vector\[\d+\]$/.test(i)}function de(i){return typeof i=="string"&&rt[i]}function xe(i){return ot[i]}function ne(i){let e=Number(i.slice(7,-1));switch(!0){case isNaN(e):throw w("INVALID_VECTOR_VALUE",i);case e<=0:throw w("INVALID_VECTOR_SIZE",i);default:return e}}function B(i,e){if(typeof e=="string"){let t=i.idToInternalId.get(e);if(t)return t;let n=i.idToInternalId.size+1;return i.idToInternalId.set(e,n),i.internalIdToId.push(e),n}return e>i.internalIdToId.length?B(i,e.toString()):e}var E={};v(E,{calculateResultScores:()=>ge,create:()=>me,createIndex:()=>ut,getSearchableProperties:()=>Ce,getSearchablePropertiesWithTypes:()=>ze,insert:()=>_e,insertDocumentScoreParameters:()=>ke,insertTokenScoreParameters:()=>Pe,insertVector:()=>ve,load:()=>Be,remove:()=>Le,removeDocumentScoreParameters:()=>Re,removeTokenScoreParameters:()=>Ee,save:()=>Fe,search:()=>Me,searchByGeoWhereClause:()=>dt,searchByWhereClause:()=>q});var re={};v(re,{AVLNode:()=>L,AVLTree:()=>J});var L=class i{constructor(e,t){y(this,"k");y(this,"v");y(this,"l",null);y(this,"r",null);y(this,"h",1);this.k=e,this.v=new Set(t)}updateHeight(){this.h=Math.max(i.getHeight(this.l),i.getHeight(this.r))+1}static getHeight(e){return e?e.h:0}getBalanceFactor(){return i.getHeight(this.l)-i.getHeight(this.r)}rotateLeft(){let e=this.r;return this.r=e.l,e.l=this,this.updateHeight(),e.updateHeight(),e}rotateRight(){let e=this.l;return this.l=e.r,e.r=this,this.updateHeight(),e.updateHeight(),e}toJSON(){return{k:this.k,v:Array.from(this.v),l:this.l?this.l.toJSON():null,r:this.r?this.r.toJSON():null,h:this.h}}static fromJSON(e){let t=new i(e.k,e.v);return t.l=e.l?i.fromJSON(e.l):null,t.r=e.r?i.fromJSON(e.r):null,t.h=e.h,t}},J=class i{constructor(e,t){y(this,"root",null);y(this,"insertCount",0);e!==void 0&&t!==void 0&&(this.root=new L(e,t))}insert(e,t,n=1e3){this.root=this.insertNode(this.root,e,t,n)}insertMultiple(e,t,n=1e3){for(let o of t)this.insert(e,o,n)}rebalance(){this.root&&(this.root=this.rebalanceNode(this.root))}toJSON(){return{root:this.root?this.root.toJSON():null,insertCount:this.insertCount}}static fromJSON(e){let t=new i;return t.root=e.root?L.fromJSON(e.root):null,t.insertCount=e.insertCount||0,t}insertNode(e,t,n,o){if(e===null)return new L(t,[n]);let s=[],r=e,a=null;for(;r!==null;)if(s.push({parent:a,node:r}),t<r.k)if(r.l===null){r.l=new L(t,[n]),s.push({parent:r,node:r.l});break}else a=r,r=r.l;else if(t>r.k)if(r.r===null){r.r=new L(t,[n]),s.push({parent:r,node:r.r});break}else a=r,r=r.r;else return r.v.add(n),e;let c=!1;this.insertCount++%o===0&&(c=!0);for(let l=s.length-1;l>=0;l--){let{parent:u,node:d}=s[l];if(d.updateHeight(),c){let f=this.rebalanceNode(d);u?u.l===d?u.l=f:u.r===d&&(u.r=f):e=f}}return e}rebalanceNode(e){let t=e.getBalanceFactor();if(t>1){if(e.l&&e.l.getBalanceFactor()>=0)return e.rotateRight();if(e.l)return e.l=e.l.rotateLeft(),e.rotateRight()}if(t<-1){if(e.r&&e.r.getBalanceFactor()<=0)return e.rotateLeft();if(e.r)return e.r=e.r.rotateRight(),e.rotateLeft()}return e}find(e){let t=this.findNodeByKey(e);return t?t.v:null}contains(e){return this.find(e)!==null}getSize(){let e=0,t=[],n=this.root;for(;n||t.length>0;){for(;n;)t.push(n),n=n.l;n=t.pop(),e++,n=n.r}return e}isBalanced(){if(!this.root)return!0;let e=[this.root];for(;e.length>0;){let t=e.pop(),n=t.getBalanceFactor();if(Math.abs(n)>1)return!1;t.l&&e.push(t.l),t.r&&e.push(t.r)}return!0}remove(e){this.root=this.removeNode(this.root,e)}removeDocument(e,t){let n=this.findNodeByKey(e);n&&(n.v.size===1?this.root=this.removeNode(this.root,e):n.v=new Set([...n.v.values()].filter(o=>o!==t)))}findNodeByKey(e){let t=this.root;for(;t;)if(e<t.k)t=t.l;else if(e>t.k)t=t.r;else return t;return null}removeNode(e,t){if(e===null)return null;let n=[],o=e;for(;o!==null&&o.k!==t;)n.push(o),t<o.k?o=o.l:o=o.r;if(o===null)return e;if(o.l===null||o.r===null){let s=o.l?o.l:o.r;if(n.length===0)e=s;else{let r=n[n.length-1];r.l===o?r.l=s:r.r=s}}else{let s=o,r=o.r;for(;r.l!==null;)s=r,r=r.l;o.k=r.k,o.v=r.v,s.l===r?s.l=r.r:s.r=r.r,o=s}n.push(o);for(let s=n.length-1;s>=0;s--){let r=n[s];r.updateHeight();let a=this.rebalanceNode(r);if(s>0){let c=n[s-1];c.l===r?c.l=a:c.r===r&&(c.r=a)}else e=a}return e}rangeSearch(e,t){let n=new Set,o=[],s=this.root;for(;s||o.length>0;){for(;s;)o.push(s),s=s.l;if(s=o.pop(),s.k>=e&&s.k<=t)for(let r of s.v)n.add(r);if(s.k>t)break;s=s.r}return n}greaterThan(e,t=!1){let n=new Set,o=[],s=this.root;for(;s||o.length>0;){for(;s;)o.push(s),s=s.r;if(s=o.pop(),t&&s.k>=e||!t&&s.k>e)for(let r of s.v)n.add(r);else if(s.k<=e)break;s=s.l}return n}lessThan(e,t=!1){let n=new Set,o=[],s=this.root;for(;s||o.length>0;){for(;s;)o.push(s),s=s.l;if(s=o.pop(),t&&s.k<=e||!t&&s.k<e)for(let r of s.v)n.add(r);else if(s.k>e)break;s=s.r}return n}};var oe={};v(oe,{FlatTree:()=>$});var $=class i{constructor(){y(this,"numberToDocumentId");this.numberToDocumentId=new Map}insert(e,t){this.numberToDocumentId.has(e)?this.numberToDocumentId.get(e).add(t):this.numberToDocumentId.set(e,new Set([t]))}find(e){let t=this.numberToDocumentId.get(e);return t?Array.from(t):null}remove(e){this.numberToDocumentId.delete(e)}removeDocument(e,t){let n=this.numberToDocumentId.get(t);n&&(n.delete(e),n.size===0&&this.numberToDocumentId.delete(t))}contains(e){return this.numberToDocumentId.has(e)}getSize(){let e=0;for(let t of this.numberToDocumentId.values())e+=t.size;return e}filter(e){let t=Object.keys(e);if(t.length!==1)throw new Error("Invalid operation");let n=t[0];switch(n){case"eq":{let o=e[n],s=this.numberToDocumentId.get(o);return s?Array.from(s):[]}case"in":{let o=e[n],s=new Set;for(let r of o){let a=this.numberToDocumentId.get(r);if(a)for(let c of a)s.add(c)}return Array.from(s)}case"nin":{let o=new Set(e[n]),s=new Set;for(let[r,a]of this.numberToDocumentId.entries())if(!o.has(r))for(let c of a)s.add(c);return Array.from(s)}default:throw new Error("Invalid operation")}}filterArr(e){let t=Object.keys(e);if(t.length!==1)throw new Error("Invalid operation");let n=t[0];switch(n){case"containsAll":{let s=e[n].map(a=>this.numberToDocumentId.get(a)??new Set);if(s.length===0)return[];let r=s.reduce((a,c)=>new Set([...a].filter(l=>c.has(l))));return Array.from(r)}case"containsAny":{let s=e[n].map(a=>this.numberToDocumentId.get(a)??new Set);if(s.length===0)return[];let r=s.reduce((a,c)=>new Set([...a,...c]));return Array.from(r)}default:throw new Error("Invalid operation")}}static fromJSON(e){if(!e.numberToDocumentId)throw new Error("Invalid Flat Tree JSON");let t=new i;for(let[n,o]of e.numberToDocumentId)t.numberToDocumentId.set(n,new Set(o));return t}toJSON(){return{numberToDocumentId:Array.from(this.numberToDocumentId.entries()).map(([e,t])=>[e,Array.from(t)])}}};var F={};v(F,{RadixNode:()=>Q,RadixTree:()=>G});var H=!1;function at(i,e,t){if(t<0)return-1;if(i===e)return 0;let n=i.length,o=e.length;if(n===0)return o<=t?o:-1;if(o===0)return n<=t?n:-1;let s=Math.abs(n-o);if(H){if(i.startsWith(e))return s<=t?s:-1;if(e.startsWith(i))return 0}if(s>t)return-1;let r=[];for(let a=0;a<=n;a++){r[a]=[a];for(let c=1;c<=o;c++)r[a][c]=a===0?c:0}for(let a=1;a<=n;a++){let c=1/0;for(let l=1;l<=o;l++)i[a-1]===e[l-1]?r[a][l]=r[a-1][l-1]:r[a][l]=Math.min(r[a-1][l]+1,r[a][l-1]+1,r[a-1][l-1]+1),c=Math.min(c,r[a][l]);if(c>t)return-1}return r[n][o]<=t?r[n][o]:-1}function he(i,e,t){let n=at(i,e,t);return{distance:n,isBounded:n>=0}}var Q=class i{constructor(e,t,n){y(this,"k");y(this,"s");y(this,"c",new Map);y(this,"d",new Set);y(this,"e");y(this,"w","");this.k=e,this.s=t,this.e=n}updateParent(e){this.w=e.w+this.s}addDocument(e){this.d.add(e)}removeDocument(e){return this.d.delete(e)}findAllWords(e,t,n,o){let s=[this];for(;s.length>0;){let r=s.pop();if(r.e){let{w:a,d:c}=r;if(n&&a!==t)continue;if(ee(e,a)!==null)if(o)if(Math.abs(t.length-a.length)<=o&&he(t,a,o).isBounded)e[a]=[];else continue;else e[a]=[];if(ee(e,a)!=null&&c.size>0){let l=e[a];for(let u of c)l.includes(u)||l.push(u)}}r.c.size>0&&s.push(...r.c.values())}return e}insert(e,t){let n=this,o=0,s=e.length;for(;o<s;){let r=e[o],a=n.c.get(r);if(a){let c=a.s,l=c.length,u=0;for(;u<l&&o+u<s&&c[u]===e[o+u];)u++;if(u===l){if(n=a,o+=u,o===s){a.e||(a.e=!0),a.addDocument(t);return}continue}let d=c.slice(0,u),f=c.slice(u),h=e.slice(o+u),p=new i(d[0],d,!1);if(n.c.set(d[0],p),p.updateParent(n),a.s=f,a.k=f[0],p.c.set(f[0],a),a.updateParent(p),h){let m=new i(h[0],h,!0);m.addDocument(t),p.c.set(h[0],m),m.updateParent(p)}else p.e=!0,p.addDocument(t);return}else{let c=new i(r,e.slice(o),!0);c.addDocument(t),n.c.set(r,c),c.updateParent(n);return}}n.e||(n.e=!0),n.addDocument(t)}_findLevenshtein(e,t,n,o,s){let r=[{node:this,index:t,tolerance:n}];for(;r.length>0;){let{node:a,index:c,tolerance:l}=r.pop();if(H&&a.w.startsWith(e)&&a.w!==e){console.log("[RADIX FIX] Prefix optimization triggered for:",a.w,"term:",e),a.findAllWords(s,e,!1,0);continue}if(H&&a.w.startsWith(e)&&a.w===e&&console.log("[RADIX FIX] Exact match excluded from prefix optimization:",e),l<0)continue;if(a.e){let{w:d,d:f}=a;if(d&&(he(e,d,o).isBounded&&(s[d]=[]),ee(s,d)!==void 0&&f.size>0)){let h=new Set(s[d]);for(let p of f)h.add(p);s[d]=Array.from(h)}}if(c>=e.length)continue;let u=e[c];if(a.c.has(u)){let d=a.c.get(u);r.push({node:d,index:c+1,tolerance:l})}r.push({node:a,index:c+1,tolerance:l-1});for(let[d,f]of a.c)r.push({node:f,index:c,tolerance:l-1}),d!==u&&r.push({node:f,index:c+1,tolerance:l-1})}}find(e){let{term:t,exact:n,tolerance:o}=e;if(o&&!n){let s={};return this._findLevenshtein(t,0,o,o,s),s}else{let s=this,r=0,a=t.length;for(;r<a;){let l=t[r],u=s.c.get(l);if(u){let d=u.s,f=d.length,h=0;for(;h<f&&r+h<a&&d[h]===t[r+h];)h++;if(h===f)s=u,r+=h;else if(r+h===a)if(h===a-r){if(n)return{};{let p={};return u.findAllWords(p,t,n,o),p}}else return{};else return{}}else return{}}let c={};return s.findAllWords(c,t,n,o),c}}contains(e){let t=this,n=0,o=e.length;for(;n<o;){let s=e[n],r=t.c.get(s);if(r){let a=r.s,c=a.length,l=0;for(;l<c&&n+l<o&&a[l]===e[n+l];)l++;if(l<c)return!1;n+=c,t=r}else return!1}return!0}removeWord(e){if(!e)return!1;let t=this,n=e.length,o=[];for(let s=0;s<n;s++){let r=e[s];if(t.c.has(r)){let a=t.c.get(r);o.push({parent:t,character:r}),s+=a.s.length-1,t=a}else return!1}for(t.d.clear(),t.e=!1;o.length>0&&t.c.size===0&&!t.e&&t.d.size===0;){let{parent:s,character:r}=o.pop();s.c.delete(r),t=s}return!0}removeDocumentByWord(e,t,n=!0){if(!e)return!0;let o=this,s=e.length;for(let r=0;r<s;r++){let a=e[r];if(o.c.has(a)){let c=o.c.get(a);r+=c.s.length-1,o=c,n&&o.w!==e||o.removeDocument(t)}else return!1}return!0}static getCommonPrefix(e,t){let n=Math.min(e.length,t.length),o=0;for(;o<n&&e.charCodeAt(o)===t.charCodeAt(o);)o++;return e.slice(0,o)}toJSON(){return{w:this.w,s:this.s,e:this.e,k:this.k,d:Array.from(this.d),c:Array.from(this.c?.entries())?.map(([e,t])=>[e,t.toJSON()])}}static fromJSON(e){let t=new i(e.k,e.s,e.e);return t.w=e.w,t.d=new Set(e.d),t.c=new Map(e?.c?.map(([n,o])=>[n,i.fromJSON(o)])||[]),t}},G=class i extends Q{constructor(){super("","",!1)}static fromJSON(e){let t=new i;return t.w=e.w,t.s=e.s,t.e=e.e,t.k=e.k,t.d=new Set(e.d),t.c=new Map(e?.c?.map(([n,o])=>[n,Q.fromJSON(o)])||[]),t}toJSON(){return super.toJSON()}};var ie={};v(ie,{BKDTree:()=>R});var se=class i{constructor(e,t){y(this,"point");y(this,"docIDs");y(this,"left");y(this,"right");y(this,"parent");this.point=e,this.docIDs=new Set(t),this.left=null,this.right=null,this.parent=null}toJSON(){return{point:this.point,docIDs:Array.from(this.docIDs),left:this.left?this.left.toJSON():null,right:this.right?this.right.toJSON():null}}static fromJSON(e,t=null){let n=new i(e.point,e.docIDs);return n.parent=t,e.left&&(n.left=i.fromJSON(e.left,n)),e.right&&(n.right=i.fromJSON(e.right,n)),n}},R=class i{constructor(){y(this,"root");y(this,"nodeMap");this.root=null,this.nodeMap=new Map}getPointKey(e){return`${e.lon},${e.lat}`}insert(e,t){let n=this.getPointKey(e),o=this.nodeMap.get(n);if(o){t.forEach(c=>o.docIDs.add(c));return}let s=new se(e,t);if(this.nodeMap.set(n,s),this.root==null){this.root=s;return}let r=this.root,a=0;for(;;){if(a%2===0)if(e.lon<r.point.lon){if(r.left==null){r.left=s,s.parent=r;return}r=r.left}else{if(r.right==null){r.right=s,s.parent=r;return}r=r.right}else if(e.lat<r.point.lat){if(r.left==null){r.left=s,s.parent=r;return}r=r.left}else{if(r.right==null){r.right=s,s.parent=r;return}r=r.right}a++}}contains(e){let t=this.getPointKey(e);return this.nodeMap.has(t)}getDocIDsByCoordinates(e){let t=this.getPointKey(e),n=this.nodeMap.get(t);return n?Array.from(n.docIDs):null}removeDocByID(e,t){let n=this.getPointKey(e),o=this.nodeMap.get(n);o&&(o.docIDs.delete(t),o.docIDs.size===0&&(this.nodeMap.delete(n),this.deleteNode(o)))}deleteNode(e){let t=e.parent,n=e.left?e.left:e.right;n&&(n.parent=t),t?t.left===e?t.left=n:t.right===e&&(t.right=n):(this.root=n,this.root&&(this.root.parent=null))}searchByRadius(e,t,n=!0,o="asc",s=!1){let r=s?i.vincentyDistance:i.haversineDistance,a=[{node:this.root,depth:0}],c=[];for(;a.length>0;){let{node:l,depth:u}=a.pop();if(l==null)continue;let d=r(e,l.point);(n?d<=t:d>t)&&c.push({point:l.point,docIDs:Array.from(l.docIDs)}),l.left!=null&&a.push({node:l.left,depth:u+1}),l.right!=null&&a.push({node:l.right,depth:u+1})}return o&&c.sort((l,u)=>{let d=r(e,l.point),f=r(e,u.point);return o.toLowerCase()==="asc"?d-f:f-d}),c}searchByPolygon(e,t=!0,n=null,o=!1){let s=[{node:this.root,depth:0}],r=[];for(;s.length>0;){let{node:c,depth:l}=s.pop();if(c==null)continue;c.left!=null&&s.push({node:c.left,depth:l+1}),c.right!=null&&s.push({node:c.right,depth:l+1});let u=i.isPointInPolygon(e,c.point);(u&&t||!u&&!t)&&r.push({point:c.point,docIDs:Array.from(c.docIDs)})}let a=i.calculatePolygonCentroid(e);if(n){let c=o?i.vincentyDistance:i.haversineDistance;r.sort((l,u)=>{let d=c(a,l.point),f=c(a,u.point);return n.toLowerCase()==="asc"?d-f:f-d})}return r}toJSON(){return{root:this.root?this.root.toJSON():null}}static fromJSON(e){let t=new i;return e.root&&(t.root=se.fromJSON(e.root),t.buildNodeMap(t.root)),t}buildNodeMap(e){if(e==null)return;let t=this.getPointKey(e.point);this.nodeMap.set(t,e),e.left&&this.buildNodeMap(e.left),e.right&&this.buildNodeMap(e.right)}static calculatePolygonCentroid(e){let t=0,n=0,o=0,s=e.length;for(let a=0,c=s-1;a<s;c=a++){let l=e[a].lon,u=e[a].lat,d=e[c].lon,f=e[c].lat,h=l*f-d*u;t+=h,n+=(l+d)*h,o+=(u+f)*h}t/=2;let r=6*t;return n/=r,o/=r,{lon:n,lat:o}}static isPointInPolygon(e,t){let n=!1,o=t.lon,s=t.lat,r=e.length;for(let a=0,c=r-1;a<r;c=a++){let l=e[a].lon,u=e[a].lat,d=e[c].lon,f=e[c].lat;u>s!=f>s&&o<(d-l)*(s-u)/(f-u)+l&&(n=!n)}return n}static haversineDistance(e,t){let n=Math.PI/180,o=e.lat*n,s=t.lat*n,r=(t.lat-e.lat)*n,a=(t.lon-e.lon)*n,c=Math.sin(r/2)*Math.sin(r/2)+Math.cos(o)*Math.cos(s)*Math.sin(a/2)*Math.sin(a/2);return 6371e3*(2*Math.atan2(Math.sqrt(c),Math.sqrt(1-c)))}static vincentyDistance(e,t){let o=.0033528106647474805,s=(1-o)*6378137,r=Math.PI/180,a=e.lat*r,c=t.lat*r,l=(t.lon-e.lon)*r,u=Math.atan((1-o)*Math.tan(a)),d=Math.atan((1-o)*Math.tan(c)),f=Math.sin(u),h=Math.cos(u),p=Math.sin(d),m=Math.cos(d),b=l,S,I=1e3,g,T,x,D,k,O;do{let W=Math.sin(b),Y=Math.cos(b);if(g=Math.sqrt(m*W*(m*W)+(h*p-f*m*Y)*(h*p-f*m*Y)),g===0)return 0;T=f*p+h*m*Y,x=Math.atan2(g,T),D=h*m*W/g,k=1-D*D,O=T-2*f*p/k,isNaN(O)&&(O=0);let le=o/16*k*(4+o*(4-3*k));S=b,b=l+(1-le)*o*D*(x+le*g*(O+le*T*(-1+2*O*O)))}while(Math.abs(b-S)>1e-12&&--I>0);if(I===0)return NaN;let A=k*(6378137*6378137-s*s)/(s*s),_=1+A/16384*(4096+A*(-768+A*(320-175*A))),N=A/1024*(256+A*(-128+A*(74-47*A))),P=N*g*(O+N/4*(T*(-1+2*O*O)-N/6*O*(-3+4*g*g)*(-3+4*O*O)));return s*_*(x-P)}};var ae={};v(ae,{BoolNode:()=>K});var K=class i{constructor(){y(this,"true");y(this,"false");this.true=new Set,this.false=new Set}insert(e,t){t?this.true.add(e):this.false.add(e)}delete(e,t){t?this.true.delete(e):this.false.delete(e)}getSize(){return this.true.size+this.false.size}toJSON(){return{true:Array.from(this.true),false:Array.from(this.false)}}static fromJSON(e){let t=new i;return t.true=new Set(e.true),t.false=new Set(e.false),t}};function De(i,e,t,n,o,{k:s,b:r,d:a}){return Math.log(1+(t-e+.5)/(e+.5))*(a+i*(s+1))/(i+s*(1-r+r*n/o))}var ce={};v(ce,{DEFAULT_SIMILARITY:()=>ct,VectorIndex:()=>j,findSimilarVectors:()=>Oe,getMagnitude:()=>pe});var ct=.8,j=class i{constructor(e){y(this,"size");y(this,"vectors",new Map);this.size=e}add(e,t){t instanceof Float32Array||(t=new Float32Array(t));let n=pe(t,this.size);this.vectors.set(e,[n,t])}remove(e){this.vectors.delete(e)}find(e,t,n){return e instanceof Float32Array||(e=new Float32Array(e)),Oe(e,n,this.vectors,this.size,t)}toJSON(){let e=[];for(let[t,[n,o]]of this.vectors)e.push([t,[n,Array.from(o)]]);return{size:this.size,vectors:e}}static fromJSON(e){let t=e,n=new i(t.size);for(let[o,[s,r]]of t.vectors)n.vectors.set(o,[s,new Float32Array(r)]);return n}};function pe(i,e){let t=0;for(let n=0;n<e;n++)t+=i[n]*i[n];return Math.sqrt(t)}function Oe(i,e,t,n,o){let s=pe(i,n),r=[],a=e||t.keys();for(let c of a){let l=t.get(c);if(!l)continue;let u=l[0],d=l[1],f=0;for(let p=0;p<n;p++)f+=i[p]*d[p];let h=f/(s*u);h>=o&&r.push([c,h])}return r}function ke(i,e,t,n,o){let s=B(i.sharedInternalDocumentStore,t);i.avgFieldLength[e]=((i.avgFieldLength[e]??0)*(o-1)+n.length)/o,i.fieldLengths[e][s]=n.length,i.frequencies[e][s]={}}function Pe(i,e,t,n,o){let s=0;for(let c of n)c===o&&s++;let r=B(i.sharedInternalDocumentStore,t),a=s/n.length;i.frequencies[e][r][o]=a,o in i.tokenOccurrences[e]||(i.tokenOccurrences[e][o]=0),i.tokenOccurrences[e][o]=(i.tokenOccurrences[e][o]??0)+1}function Re(i,e,t,n){let o=B(i.sharedInternalDocumentStore,t);n>1?i.avgFieldLength[e]=(i.avgFieldLength[e]*n-i.fieldLengths[e][o])/(n-1):i.avgFieldLength[e]=void 0,i.fieldLengths[e][o]=void 0,i.frequencies[e][o]=void 0}function Ee(i,e,t){i.tokenOccurrences[e][t]--}function me(i,e,t,n,o=""){n||(n={sharedInternalDocumentStore:e,indexes:{},vectorIndexes:{},searchableProperties:[],searchablePropertiesWithTypes:{},frequencies:{},tokenOccurrences:{},avgFieldLength:{},fieldLengths:{}});for(let[s,r]of Object.entries(t)){let a=`${o}${o?".":""}${s}`;if(typeof r=="object"&&!Array.isArray(r)){me(i,e,r,n,a);continue}if(z(r))n.searchableProperties.push(a),n.searchablePropertiesWithTypes[a]=r,n.vectorIndexes[a]={type:"Vector",node:new j(ne(r)),isArray:!1};else{let c=/\[/.test(r);switch(r){case"boolean":case"boolean[]":n.indexes[a]={type:"Bool",node:new K,isArray:c};break;case"number":case"number[]":n.indexes[a]={type:"AVL",node:new J(0,[]),isArray:c};break;case"string":case"string[]":n.indexes[a]={type:"Radix",node:new G,isArray:c},n.avgFieldLength[a]=0,n.frequencies[a]={},n.tokenOccurrences[a]={},n.fieldLengths[a]={};break;case"enum":case"enum[]":n.indexes[a]={type:"Flat",node:new $,isArray:c};break;case"geopoint":n.indexes[a]={type:"BKD",node:new R,isArray:c};break;default:throw w("INVALID_SCHEMA_TYPE",Array.isArray(r)?"array":r,a)}n.searchableProperties.push(a),n.searchablePropertiesWithTypes[a]=r}}return n}function lt(i,e,t,n,o,s,r,a){return c=>{let{type:l,node:u}=e.indexes[t];switch(l){case"Bool":{u[c?"true":"false"].add(n);break}case"AVL":{let d=a?.avlRebalanceThreshold??1;u.insert(c,n,d);break}case"Radix":{let d=s.tokenize(c,o,t,!1);i.insertDocumentScoreParameters(e,t,n,d,r);for(let f of d)i.insertTokenScoreParameters(e,t,n,d,f),u.insert(f,n);break}case"Flat":{u.insert(c,n);break}case"BKD":{u.insert(c,[n]);break}}}}function _e(i,e,t,n,o,s,r,a,c,l,u){if(z(r))return ve(e,t,s,n,o);let d=lt(i,e,t,o,a,c,l,u);if(!de(r))return d(s);let f=s,h=f.length;for(let p=0;p<h;p++)d(f[p])}function ve(i,e,t,n,o){i.vectorIndexes[e].node.add(o,t)}function we(i,e,t,n,o,s,r,a,c,l){if(z(r))return e.vectorIndexes[t].node.remove(o),!0;let{type:u,node:d}=e.indexes[t];switch(u){case"AVL":return d.removeDocument(s,o),!0;case"Bool":return d[s?"true":"false"].delete(o),!0;case"Radix":{let f=c.tokenize(s,a,t);i.removeDocumentScoreParameters(e,t,n,l);for(let h of f)i.removeTokenScoreParameters(e,t,h),d.removeDocumentByWord(h,o);return!0}case"Flat":return d.removeDocument(o,s),!0;case"BKD":return d.removeDocByID(s,o),!1}}function Le(i,e,t,n,o,s,r,a,c,l){if(!de(r))return we(i,e,t,n,o,s,r,a,c,l);let u=xe(r),d=s,f=d.length;for(let h=0;h<f;h++)we(i,e,t,n,o,d[h],u,a,c,l);return!0}function ge(i,e,t,n,o,s,r,a,c,l){let u=Array.from(n),d=i.avgFieldLength[e],f=i.fieldLengths[e],h=i.tokenOccurrences[e],p=i.frequencies[e],m=typeof h[t]=="number"?h[t]??0:0,b=u.length;for(let S=0;S<b;S++){let I=u[S];if(c&&!c.has(I))continue;l.has(I)||l.set(I,new Map);let g=l.get(I);g.set(e,(g.get(e)||0)+1);let T=p?.[I]?.[t]??0,x=De(T,m,o,f[I],d,s);r.has(I)?r.set(I,r.get(I)+x*a):r.set(I,x*a)}}function Me(i,e,t,n,o,s,r,a,c,l,u,d=0){let f=t.tokenize(e,n),h=f.length||1,p=new Map,m=new Map,b=new Map;for(let g of o){if(!(g in i.indexes))continue;let T=i.indexes[g],{type:x}=T;if(x!=="Radix")throw w("WRONG_SEARCH_PROPERTY_TYPE",g);let D=a[g]??1;if(D<=0)throw w("INVALID_BOOST_VALUE",D);f.length===0&&!e&&f.push("");let k=f.length;for(let O=0;O<k;O++){let A=f[O],_=T.node.find({term:A,exact:s,tolerance:r}),N=Object.keys(_);N.length>0&&m.set(A,!0);let P=N.length;for(let U=0;U<P;U++){let W=N[U],Y=_[W];ge(i,g,W,Y,l,c,b,D,u,p)}}}let S=Array.from(b.entries()).map(([g,T])=>[g,T]).sort((g,T)=>T[1]-g[1]);if(S.length===0)return[];if(d===1)return S;if(d===0){if(h===1)return S;for(let T of f)if(!m.get(T))return[];return S.filter(([T])=>{let x=p.get(T);return x?Array.from(x.values()).some(D=>D===h):!1})}let I=S.filter(([g])=>{let T=p.get(g);return T?Array.from(T.values()).some(x=>x===h):!1});if(I.length>0){let g=S.filter(([x])=>!I.some(([D])=>D===x)),T=Math.ceil(g.length*d);return[...I,...g.slice(0,T)]}return S}function q(i,e,t,n){if("and"in t&&t.and&&Array.isArray(t.and)){let r=t.and;if(r.length===0)return new Set;let a=r.map(c=>q(i,e,c,n));return C(...a)}if("or"in t&&t.or&&Array.isArray(t.or)){let r=t.or;return r.length===0?new Set:r.map(c=>q(i,e,c,n)).reduce((c,l)=>V(c,l),new Set)}if("not"in t&&t.not){let r=t.not,a=new Set,c=i.sharedInternalDocumentStore;for(let u=1;u<=c.internalIdToId.length;u++)a.add(u);let l=q(i,e,r,n);return fe(a,l)}let o=Object.keys(t),s=o.reduce((r,a)=>({[a]:new Set,...r}),{});for(let r of o){let a=t[r];if(typeof i.indexes[r]>"u")throw w("UNKNOWN_FILTER_PROPERTY",r);let{node:c,type:l,isArray:u}=i.indexes[r];if(l==="Bool"){let f=c,h=a?f.true:f.false;s[r]=V(s[r],h);continue}if(l==="BKD"){let f;if("radius"in a)f="radius";else if("polygon"in a)f="polygon";else throw new Error(`Invalid operation ${a}`);if(f==="radius"){let{value:h,coordinates:p,unit:m="m",inside:b=!0,highPrecision:S=!1}=a[f],I=te(h,m),g=c.searchByRadius(p,I,b,void 0,S);s[r]=Ae(s[r],g)}else{let{coordinates:h,inside:p=!0,highPrecision:m=!1}=a[f],b=c.searchByPolygon(h,p,void 0,m);s[r]=Ae(s[r],b)}continue}if(l==="Radix"&&(typeof a=="string"||Array.isArray(a))){for(let f of[a].flat()){let h=e.tokenize(f,n,r);for(let p of h){let m=c.find({term:p,exact:!0});s[r]=ht(s[r],m)}}continue}let d=Object.keys(a);if(d.length>1)throw w("INVALID_FILTER_OPERATION",d.length);if(l==="Flat"){let f=new Set(u?c.filterArr(a):c.filter(a));s[r]=V(s[r],f);continue}if(l==="AVL"){let f=d[0],h=a[f],p;switch(f){case"gt":{p=c.greaterThan(h,!1);break}case"gte":{p=c.greaterThan(h,!0);break}case"lt":{p=c.lessThan(h,!1);break}case"lte":{p=c.lessThan(h,!0);break}case"eq":{p=c.find(h)??new Set;break}case"between":{let[m,b]=h;p=c.rangeSearch(m,b);break}default:throw w("INVALID_FILTER_OPERATION",f)}s[r]=V(s[r],p)}}return C(...Object.values(s))}function Ce(i){return i.searchableProperties}function ze(i){return i.searchablePropertiesWithTypes}function Be(i,e){let{indexes:t,vectorIndexes:n,searchableProperties:o,searchablePropertiesWithTypes:s,frequencies:r,tokenOccurrences:a,avgFieldLength:c,fieldLengths:l}=e,u={},d={};for(let f of Object.keys(t)){let{node:h,type:p,isArray:m}=t[f];switch(p){case"Radix":u[f]={type:"Radix",node:G.fromJSON(h),isArray:m};break;case"Flat":u[f]={type:"Flat",node:$.fromJSON(h),isArray:m};break;case"AVL":u[f]={type:"AVL",node:J.fromJSON(h),isArray:m};break;case"BKD":u[f]={type:"BKD",node:R.fromJSON(h),isArray:m};break;case"Bool":u[f]={type:"Bool",node:K.fromJSON(h),isArray:m};break;default:u[f]=t[f]}}for(let f of Object.keys(n))d[f]={type:"Vector",isArray:!1,node:j.fromJSON(n[f])};return{sharedInternalDocumentStore:i,indexes:u,vectorIndexes:d,searchableProperties:o,searchablePropertiesWithTypes:s,frequencies:r,tokenOccurrences:a,avgFieldLength:c,fieldLengths:l}}function Fe(i){let{indexes:e,vectorIndexes:t,searchableProperties:n,searchablePropertiesWithTypes:o,frequencies:s,tokenOccurrences:r,avgFieldLength:a,fieldLengths:c}=i,l={};for(let d of Object.keys(t))l[d]=t[d].node.toJSON();let u={};for(let d of Object.keys(e)){let{type:f,node:h,isArray:p}=e[d];f==="Flat"||f==="Radix"||f==="AVL"||f==="BKD"||f==="Bool"?u[d]={type:f,node:h.toJSON(),isArray:p}:(u[d]=e[d],u[d].node=u[d].node.toJSON())}return{indexes:u,vectorIndexes:l,searchableProperties:n,searchablePropertiesWithTypes:o,frequencies:s,tokenOccurrences:r,avgFieldLength:a,fieldLengths:c}}function ut(){return{create:me,insert:_e,remove:Le,insertDocumentScoreParameters:ke,insertTokenScoreParameters:Pe,removeDocumentScoreParameters:Re,removeTokenScoreParameters:Ee,calculateResultScores:ge,search:Me,searchByWhereClause:q,getSearchableProperties:Ce,getSearchablePropertiesWithTypes:ze,load:Be,save:Fe}}function Ae(i,e){i||(i=new Set);let t=e.length;for(let n=0;n<t;n++){let o=e[n].docIDs,s=o.length;for(let r=0;r<s;r++)i.add(o[r])}return i}function Ne(i,e,t=!1){let n=t?R.vincentyDistance:R.haversineDistance,o=[],s=[];for(let{point:c}of i)s.push(n(e,c));let r=Math.max(...s),a=0;for(let{docIDs:c}of i){let l=s[a],u=r-l+1;for(let d of c)o.push([d,u]);a++}return o.sort((c,l)=>l[1]-c[1]),o}function ft(i,e){let t=Object.keys(i);if(t.length!==1)return{isGeoOnly:!1};let n=t[0],o=i[n];if(typeof e.indexes[n]>"u")return{isGeoOnly:!1};let{type:s}=e.indexes[n];return s==="BKD"&&o&&("radius"in o||"polygon"in o)?{isGeoOnly:!0,geoProperty:n,geoOperation:o}:{isGeoOnly:!1}}function dt(i,e){let t=i,n=ft(e,t);if(!n.isGeoOnly||!n.geoProperty||!n.geoOperation)return null;let{node:o}=t.indexes[n.geoProperty],s=n.geoOperation,r=o,a;if("radius"in s){let{value:c,coordinates:l,unit:u="m",inside:d=!0,highPrecision:f=!1}=s.radius,h=l,p=te(c,u);return a=r.searchByRadius(h,p,d,"asc",f),Ne(a,h,f)}else if("polygon"in s){let{coordinates:c,inside:l=!0,highPrecision:u=!1}=s.polygon;a=r.searchByPolygon(c,l,"asc",u);let d=R.calculatePolygonCentroid(c);return Ne(a,d,u)}return null}function ht(i,e){i||(i=new Set);let t=Object.keys(e),n=t.length;for(let o=0;o<n;o++){let s=e[t[o]],r=s.length;for(let a=0;a<r;a++)i.add(s[a])}return i}var pt="[^aeiou]",Ue="[aeiouy]",M=pt+"[^aeiouy]*",X=Ue+"[aeiou]*",mn="^("+M+")?"+X+M,gn="^("+M+")?"+X+M+"("+X+")?$",Sn="^("+M+")?"+X+M+X+M,In="^("+M+")?"+Ue;function Se(i,e,t){for(let n of Object.entries(e)){let o=n[0],s=n[1],r=`${t}${t?".":""}${o}`;if(typeof s=="object"&&!Array.isArray(s)){Se(i,s,r);continue}if(z(s))i.searchableProperties.push(r),i.searchablePropertiesWithTypes[r]=s,i.vectorIndexes[r]={type:"Vector",node:new ce.VectorIndex(ne(s)),isArray:!1};else{let a=/\[/.test(s);switch(s){case"boolean":case"boolean[]":i.indexes[r]={type:"Bool",node:new ae.BoolNode,isArray:a};break;case"number":case"number[]":i.indexes[r]={type:"AVL",node:new re.AVLTree(0,[]),isArray:a};break;case"string":case"string[]":i.indexes[r]={type:"Radix",node:new F.RadixTree,isArray:a};break;case"enum":case"enum[]":i.indexes[r]={type:"Flat",node:new oe.FlatTree,isArray:a};break;case"geopoint":i.indexes[r]={type:"BKD",node:new ie.BKDTree,isArray:a};break;default:throw new Error("INVALID_SCHEMA_TYPE: "+r)}i.searchableProperties.push(r),i.searchablePropertiesWithTypes[r]=s}}}var yt=1048575;function bt(i,e){let t=Je(i),o=Ve(i)|1<<e;return t+1<<20|o}function Ie(i,e,t,n,o,s,r){let a=i.split(/\.|\?|!/),c=0,l=0;for(let u of a){let d=r.tokenize(u,s,n);for(let f of d){l++,t[f]||(t[f]=0);let h=Math.min(c,20);t.tokenQuantums[o][f]=bt(t.tokenQuantums[o][f],h),e.insert(f,o)}d.length>1&&c++}t.tokensLength.set(o,l)}function We(i){let e=i.tokens,t=i.radixNode,n=i.exact,o=i.tolerance,s=i.stats,r=i.boostPerProp,a=i.resultMap,c=i.whereFiltersIDs,l=s.tokensLength,u=s.tokenQuantums,d={term:"",exact:n,tolerance:o},f={},h=e.length;for(let b=0;b<h;b++){let S=e[b];d.term=S;let I=t.find(d);f={...f,...I}}let p=Object.keys(f),m=p.length;for(let b=0;b<m;b++){let S=p[b],I=f[S],g=I.length,T=e.includes(S);for(let x=0;x<g;x++){let D=I[x];if(c&&!c.has(D))continue;let k=l.get(D),O=u[D][S],A=Je(O),_=Ve(O),N=(A*A/k+(T?1:0))*r;if(!a.has(D)){a.set(D,[N,_]);continue}let P=a.get(D),U=P[0]+Tt(P[1]&_)*2+N;P[0]=U,P[1]=P[1]|_}}}function Ve(i){return i&yt}function Je(i){return i>>20}function Tt(i){let e=0;do i&1&&++e;while(i>>=1);return e}function ye(i,e,t,n,o,s,r){let a=r.tokensLength,c=r.tokenQuantums,l=o.tokenize(i,s,t);for(let u of l)e.removeDocumentByWord(u,n,!0);a.delete(n),delete c[n]}var xt=new F.RadixNode("","",!1),Dt={tokenQuantums:{},tokensLength:new Map};function Ot(i,e,t,n,o,s,r,a,c,l,u){let d=new Map,f={tokens:t.tokenize(e,n),radixNode:xt,exact:s,tolerance:r,stats:Dt,boostPerProp:0,all:d,resultMap:d,whereFiltersIDs:u},h=o.length;for(let S=0;S<h;S++){let I=o[S],g=i.stats[I],T=a[I]??1;f.radixNode=i.indexes[I].node,f.stats=g,f.boostPerProp=T,We(f)}let p=Array.from(d),m=p.length,b=[];for(let S=0;S<m;S++){let I=p[S],g=I[0],T=I[1][0];b.push([g,T])}return b}function wt(){return{name:"qps",getComponents(i){return At(i)}}}function At(i){return{index:{create:function(){let t={indexes:{},vectorIndexes:{},searchableProperties:[],searchablePropertiesWithTypes:{},stats:{}};return Se(t,i,""),t},insert:function(t,n,o,s,r,a,c,l,u,d){if(!(c==="string"||c==="string[]"))return E.insert(t,n,o,s,r,a,c,l,u,d);n.stats[o]||(n.stats[o]={tokenQuantums:{},tokensLength:new Map});let f=n.stats[o],h=n.indexes[o].node;if(f.tokenQuantums[r]={},Array.isArray(a))for(let p of a)Ie(p,h,f,o,r,l,u);else Ie(a,h,f,o,r,l,u)},remove:function(t,n,o,s,r,a,c,l,u,d){if(!(c==="string"||c==="string[]"))return E.remove(t,n,o,s,r,a,c,l,u,d);let f=n.stats[o],h=n.indexes[o].node;if(Array.isArray(a))for(let p of a)ye(p,h,o,r,u,l,f);else ye(a,h,o,r,u,l,f)},insertDocumentScoreParameters:()=>{throw new Error},insertTokenScoreParameters:()=>{throw new Error},removeDocumentScoreParameters:()=>{throw new Error},removeTokenScoreParameters:()=>{throw new Error},calculateResultScores:()=>{throw new Error},search:Ot,searchByWhereClause:function(t,n,o,s){let r=Object.entries(o).filter(([u])=>t.indexes[u].type==="Radix");if(r.length===0)return E.searchByWhereClause(t,n,o,s);let a;for(let[u,d]of r){let f=[];if(Array.isArray(d))for(let m of d){let b=n.tokenize(m,s)?.[0];f.push(b)}else f=n.tokenize(d,s);let h=t.indexes[u].node,p=new Set;for(let m of f){let S=h.find({term:m,exact:!0})[m];if(S)for(let I of S)p.add(I)}a?a=C(a,p):a=p}if(Object.entries(o).filter(([u])=>t.indexes[u].type!=="Radix").length===0)return a;let l=E.searchByWhereClause(t,n,o,s);return C(a,l)},getSearchableProperties:function(t){return t.searchableProperties},getSearchablePropertiesWithTypes:function(e){return e.searchablePropertiesWithTypes},load:function(t,n){let o=E.load(t,n[0]),s=n[1],r={...o.indexes,...Object.fromEntries(s.radixTrees.map(([a,c,l,u])=>[a,{node:F.RadixNode.fromJSON(u),isArray:c,type:l}]))};return{...o,indexes:r,stats:Object.fromEntries(s.stats.map(([a,{tokenQuantums:c,tokensLength:l}])=>[a,{tokenQuantums:c,tokensLength:new Map(l)}]))}},save:function(t){let n=t,o=Object.entries(n.indexes).filter(([,{type:c}])=>c!=="Radix"),s=E.save({...n,indexes:Object.fromEntries(o)}),a={radixTrees:Object.entries(n.indexes).filter(([,{type:c}])=>c==="Radix").map(([c,{node:l,isArray:u,type:d}])=>[c,u,d,l.toJSON()]),stats:Object.entries(t.stats).map(([c,{tokenQuantums:l,tokensLength:u}])=>[c,{tokenQuantums:l,tokensLength:Array.from(u.entries())}])};return[s,a]}}}}return He(Nt);})();
|
|
12
12
|
//# sourceMappingURL=index.global.js.map
|