@wcs-colab/plugin-qps 3.1.16-custom.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ var Ie=Object.defineProperty;var Je=(i,e,t)=>e in i?Ie(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var M=(i,e)=>{for(var t in e)Ie(i,t,{get:e[t],enumerable:!0})};var y=(i,e,t)=>(Je(i,typeof e!="symbol"?e+"":e,t),t);var $e={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 ae=Object.keys($e);var Dt=Date.now().toString().slice(5);var Ot=BigInt(1e3),wt=BigInt(1e6),Nt=BigInt(1e9);function be(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,c=r?e[Number.parseInt(r)-1]:e.shift(),a=o===""?0:Number.parseInt(o);switch(s){case"d":return c.toString().padStart(a,"0");case"f":{let l=c,[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(a,"0"):l.toString()}case"s":return a<0?c.toString().padEnd(-a," "):c.toString().padStart(a," ");default:return c}})}function X(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 Ke={cm:.01,m:1,km:1e3,ft:.3048,yd:.9144,mi:1609.344};function Z(i,e){let t=Ke[e];if(t===void 0)throw new Error(w("INVALID_DISTANCE_SUFFIX",i).message);return i*t}var ye="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(ye)return n.intersection(o);let s=new Set,r=n.size<o.size?n:o,c=r===n?o:n;for(let a of r)c.has(a)&&s.add(a);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(ye){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 Ge="union"in new Set;function V(i,e){return Ge?i?i.union(e):e:i?new Set([...i,...e]):new Set(e)}function le(i,e){let t=new Set;for(let n of i)e.has(n)||t.add(n);return t}var je=ae.join(`
2
+ - `),Ye={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
+ Supported languages are:
4
+ - ${je}`,INVALID_STEMMER_FUNCTION_TYPE:"config.stemmer property must be a function.",MISSING_STEMMER:'As of version 1.0.0 @orama/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 '@orama/secure-proxy-plugin' installed in your Orama instance.
6
+ Please install it before proceeding with creating an answer session.
7
+ Read more at https://docs.orama.com/docs/orama-js/plugins/plugin-secure-proxy#plugin-secure-proxy
8
+ `,PLUGIN_SECURE_PROXY_MISSING_CHAT_MODEL:`Could not find a chat model defined in the secure proxy plugin configuration.
9
+ Please provide a chat model before proceeding with creating an answer session.
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(Ye[i]??`Unsupported Orama Error code: ${i}`,...e));return t.code=i,"captureStackTrace"in Error.prototype&&Error.captureStackTrace(t),t}var qe={string:!1,number:!1,boolean:!1,enum:!1,geopoint:!1,"string[]":!0,"number[]":!0,"boolean[]":!0,"enum[]":!0},Xe={"string[]":"string","number[]":"number","boolean[]":"boolean","enum[]":"enum"};function z(i){return typeof i=="string"&&/^vector\[\d+\]$/.test(i)}function ue(i){return typeof i=="string"&&qe[i]}function Te(i){return Xe[i]}function ee(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={};M(E,{calculateResultScores:()=>pe,create:()=>he,createIndex:()=>ot,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:()=>it,searchByWhereClause:()=>H});var te={};M(te,{AVLNode:()=>_,AVLTree:()=>J});var _=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 _(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?_.fromJSON(e.root):null,t.insertCount=e.insertCount||0,t}insertNode(e,t,n,o){if(e===null)return new _(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 _(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 _(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 ne={};M(ne,{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={};M(U,{RadixNode:()=>Q,RadixTree:()=>K});function tt(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 fe(i,e,t){let n=tt(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(X(e,c)!==null)if(o)if(Math.abs(t.length-c.length)<=o&&fe(t,c,o).isBounded)e[c]=[];else continue;else e[c]=[];if(X(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&&(fe(e,d,o).isBounded&&(s[d]=[]),X(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 oe={};M(oe,{BKDTree:()=>R});var re=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 re(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=re.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 ce=o/16*k*(4+o*(4-3*k));S=b,b=l+(1-ce)*o*D*(x+ce*g*(O+ce*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 se={};M(se,{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 ie={};M(ie,{DEFAULT_SIMILARITY:()=>nt,VectorIndex:()=>j,findSimilarVectors:()=>De,getMagnitude:()=>de});var nt=.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=de(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 de(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=de(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 he(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)){he(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(ee(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 rt(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=rt(i,e,t,o,c,a,l,u);if(!ue(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(!ue(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 pe(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];pe(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 le(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=Z(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]=ct(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 ot(){return{create:he,insert:Ee,remove:_e,insertDocumentScoreParameters:Ae,insertTokenScoreParameters:ke,removeDocumentScoreParameters:Pe,removeTokenScoreParameters:Re,calculateResultScores:pe,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 st(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 it(i,e){let t=i,n=st(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=Z(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 ct(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 at="[^aeiou]",Ue="[aeiouy]",L=at+"[^aeiouy]*",q=Ue+"[aeiou]*",cn="^("+L+")?"+q+L,an="^("+L+")?"+q+L+"("+q+")?$",ln="^("+L+")?"+q+L+q+L,un="^("+L+")?"+Ue;function me(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)){me(i,s,r);continue}if(z(s))i.searchableProperties.push(r),i.searchablePropertiesWithTypes[r]=s,i.vectorIndexes[r]={type:"Vector",node:new ie.VectorIndex(ee(s)),isArray:!1};else{let c=/\[/.test(s);switch(s){case"boolean":case"boolean[]":i.indexes[r]={type:"Bool",node:new se.BoolNode,isArray:c};break;case"number":case"number[]":i.indexes[r]={type:"AVL",node:new te.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 ne.FlatTree,isArray:c};break;case"geopoint":i.indexes[r]={type:"BKD",node:new oe.BKDTree,isArray:c};break;default:throw new Error("INVALID_SCHEMA_TYPE: "+r)}i.searchableProperties.push(r),i.searchablePropertiesWithTypes[r]=s}}}var ht=1048575;function pt(i,e){let t=Ve(i),o=We(i)|1<<e;return t+1<<20|o}function ge(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]=pt(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]+mt(P[1]&v)*2+A;P[0]=F,P[1]=P[1]|v}}}function We(i){return i&ht}function Ve(i){return i>>20}function mt(i){let e=0;do i&1&&++e;while(i>>=1);return e}function Se(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 gt=new U.RadixNode("","",!1),St={tokenQuantums:{},tokensLength:new Map};function It(i,e,t,n,o,s,r,c,a,l,u){let d=new Map,f={tokens:t.tokenize(e,n),radixNode:gt,exact:s,tolerance:r,stats:St,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 Yn(){return{name:"qps",getComponents(i){return yt(i)}}}function yt(i){return{index:{create:function(){let t={indexes:{},vectorIndexes:{},searchableProperties:[],searchablePropertiesWithTypes:{},stats:{}};return me(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)ge(p,h,f,o,r,l,u);else ge(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)Se(p,h,o,r,u,l,f);else Se(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:It,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]}}}}export{Yn as pluginQPS};
12
+ //# sourceMappingURL=index.js.map