1import{x as it,B as ct}from"./main-LbiaU7L9.js";import{c as ze}from"./index-BqU5Saav.js";import{r as at}from"./remove-undefined-CzMSKybq-D-34gD0A.js";import"./react-vendor-DoblKRta.js";import"./search-default-CHEEfRln.js";const Be={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"},lt={dutch:/[^A-Za-zà èéìòóù0-9_'-]+/gim,english:/[^A-Za-zà èéìòóù0-9_'-]+/gim,french:/[^a-z0-9äâà éèëêïîöôùüûÅç-]+/gim,italian:/[^A-Za-zà èéìòóù0-9_'-]+/gim,norwegian:/[^a-z0-9_æøåÃÃÃ
äÃöÃüÃ]+/gim,portuguese:/[^a-z0-9à -úÃ-Ã]/gim,russian:/[^a-z0-9а-ÑÐ-ЯÑÐ]+/gim,spanish:/[^a-z0-9A-Zá-úÃ-ÃñÃüÃ]+/gim,swedish:/[^a-z0-9_Ã¥Ã
äÃöÃüÃ-]+/gim,german:/[^a-z0-9A-ZäöüÃÃÃÃ]+/gim,finnish:/[^a-z0-9äöÃÃ]+/gim,danish:/[^a-z0-9æøåÃÃÃ
]+/gim,hungarian:/[^a-z0-9áéÃóöÅúüűÃÃÃÃÃÅÃÃŰ]+/gim,romanian:/[^a-z0-9ÄâîÈÈÄÃÃÈÈ]+/gim,serbian:/[^a-z0-9ÄÄžšÄÄÄŽŠÄ]+/gim,turkish:/[^a-z0-9çÃÄÄıİöÃÅÅüÃ]+/gim,lithuanian:/[^a-z0-9Ä
ÄÄÄįšųūžÄÄÄÄĮŠŲŪŽ]+/gim,arabic:/[^a-z0-9Ø£-Ù]+/gim,nepali:/[^a-z0-9à¤
-ह]+/gim,irish:/[^a-z0-9áéÃóúÃÃÃÃÃ]+/gim,indian:/[^a-z0-9à¤
-ह]+/gim,armenian:/[^a-z0-9Õ¡-Ö]+/gim,greek:/[^a-z0-9α-Ïά-Ï]+/gim,indonesian:/[^a-z0-9]+/gim,ukrainian:/[^a-z0-9а-ÑÐ-ЯÑÑÑÐÐÐ]+/gim,slovenian:/[^a-z0-9ÄžšÄŽŠ]+/gim,bulgarian:/[^a-z0-9а-ÑÐ-Я]+/gim,tamil:/[^a-z0-9à®
-ஹ]+/gim,sanskrit:/[^a-z0-9A-ZÄīūá¹á¸·á¹á¹á¸¥Åá¹£á¹á¸á¹á¹
ñḻḹá¹]+/gim,czech:/[^A-Z0-9a-zÄÅ¡ÄÅžýáÃéúůóťÄÄÅ ÄÅŽÃÃÃÃÃÃŮŤÄ-]+/gim},se=Object.keys(Be);function ut(t){return t!==void 0&&se.includes(t)?Be[t]:void 0}const ft=Date.now().toString().slice(5);let dt=0;const ge=BigInt(1e3),me=BigInt(1e6),ye=BigInt(1e9),ee=65535;function Fe(t,e){if(e.length<ee)Array.prototype.push.apply(t,e);else{const n=e.length;for(let r=0;r<n;r+=ee)Array.prototype.push.apply(t,e.slice(r,r+ee))}}function ht(t,...e){return t.replace(/%(?:(?<position>\d+)\$)?(?<width>-?\d*\.?\d*)(?<type>[dfs])/g,function(...n){const r=n[n.length-1],{width:o,type:s,position:i}=r,c=i?e[Number.parseInt(i)-1]:e.shift(),a=o===""?0:Number.parseInt(o);switch(s){case"d":return c.toString().padStart(a,"0");case"f":{let l=c;const[f,u]=o.split(".").map(d=>Number.parseFloat(d));return typeof u=="number"&&u>=0&&(l=l.toFixed(u)),typeof f=="number"&&f>=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 pt(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}function gt(){return typeof process<"u"&&process.release&&process.release.name==="node"}function Se(){return BigInt(Math.floor(performance.now()*1e6))}function ie(t){return typeof t=="number"&&(t=BigInt(t)),t<ge?`${t}ns`:t<me?`${t/ge}μs`:t<ye?`${t/me}ms`:`${t/ye}s`}function C(){return pt()?Se():gt()||typeof process<"u"&&typeof process?.hrtime?.bigint=="function"?process.hrtime.bigint():typeof performance<"u"?Se():BigInt(0)}function Ve(){return`${ft}-${dt++}`}function te(t,e){return Object.hasOwn===void 0?Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0:Object.hasOwn(t,e)?t[e]:void 0}function We(t,e){return e[1]===t[1]?t[0]-e[0]:e[1]-t[1]}function mt(t){if(t.length===0)return[];if(t.length===1)return t[0];for(let n=1;n<t.length;n++)if(t[n].length<t[0].length){const r=t[0];t[0]=t[n],t[n]=r}const e=new Map;for(const n of t[0])e.set(n,1);for(let n=1;n<t.length;n++){let r=0;for(const o of t[n]){const s=e.get(o);s===n&&(e.set(o,s+1),r++)}if(r===0)return[]}return t[0].filter(n=>{const r=e.get(n);return r!==void 0&&e.set(n,0),r===t.length})}function $e(t,e){const n={},r=e.length;for(let o=0;o<r;o++){const s=e[o],i=s.split(".");let c=t;const a=i.length;for(let l=0;l<a;l++)if(c=c[i[l]],typeof c=="object"){if(c!==null&&"lat"in c&&"lon"in c&&typeof c.lat=="number"&&typeof c.lon=="number"){c=n[s]=c;break}else if(!Array.isArray(c)&&c!==null&&l===a-1){c=void 0;break}}else if((c===null||typeof c!="object")&&l<a-1){c=void 0;break}typeof c<"u"&&(n[s]=c)}return n}function ce(t,e){return $e(t,[e])[e]}const yt={cm:.01,m:1,km:1e3,ft:.3048,yd:.9144,mi:1609.344};function Ge(t,e){const n=yt[e];if(n===void 0)throw new Error(O("INVALID_DISTANCE_SUFFIX",t).message);return t*n}function je(t,e){t.hits=t.hits.map(n=>({...n,document:{...n.document,...e.reduce((r,o)=>{const s=o.split("."),i=s.pop();let c=r;for(const a of s)c[a]=c[a]??{},c=c[a];return c[i]=null,r},n.document)}}))}function j(t){return Array.isArray(t)?t.some(e=>j(e)):t?.constructor?.name==="AsyncFunction"}const be="intersection"in new Set;function Ie(...t){if(t.length===0)return new Set;if(t.length===1)return t[0];if(t.length===2){const r=t[0],o=t[1];if(be)return r.intersection(o);const s=new Set,i=r.size<o.size?r:o,c=i===r?o:r;for(const a of i)c.has(a)&&s.add(a);return s}const e={index:0,size:t[0].size};for(let r=1;r<t.length;
1r++)t[r].size<e.size&&(e.index=r,e.size=t[r].size);if(be){let r=t[e.index];for(let o=0;o<t.length;o++)o!==e.index&&(r=r.intersection(t[o]));return r}const n=t[e.index];for(let r=0;r<t.length;r++){if(r===e.index)continue;const o=t[r];for(const s of n)o.has(s)||n.delete(s)}return n}const St="union"in new Set;function V(t,e){return St?t?t.union(e):e:t?new Set([...t,...e]):new Set(e)}function bt(t,e){const n=new Set;for(const r of t)e.has(r)||n.add(r);return n}const It=se.join(` 2 - `),Tt={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. 3Supported languages are: 4 - ${It}`,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. 5Input 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. 6Please install it before proceeding with creating an answer session. 7Read 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. 9Please provide a chat model before proceeding with creating an answer session. 10Read 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 O(t,...e){const n=new Error(ht(Tt[t]??`Unsupported Orama Error c
11ode: ${t}`,...e));return n.code=t,"captureStackTrace"in Error.prototype&&Error.captureStackTrace(n),n}function Ot(t){return{raw:Number(t),formatted:ie(t)}}function Nt(t){if(t.id){if(typeof t.id!="string")throw O("DOCUMENT_ID_MUST_BE_STRING",typeof t.id);return t.id}return Ve()}function Je(t,e){for(const[n,r]of Object.entries(e)){const o=t[n];if(!(typeof o>"u")&&!(r==="geopoint"&&typeof o=="object"&&typeof o.lon=="number"&&typeof o.lat=="number")&&!(r==="enum"&&(typeof o=="string"||typeof o=="number"))){if(r==="enum[]"&&Array.isArray(o)){const s=o.length;for(let i=0;i<s;i++)if(typeof o[i]!="string"&&typeof o[i]!="number")return n+"."+i;continue}if(z(r)){const s=He(r);if(!Array.isArray(o)||o.length!==s)throw O("INVALID_INPUT_VECTOR",n,s,o.length);continue}if(ae(r)){if(!Array.isArray(o))return n;const s=Ye(r),i=o.length;for(let c=0;c<i;c++)if(typeof o[c]!==s)return n+"."+c;continue}if(typeof r=="object"){if(!o||typeof o!="object")return n;const s=Je(o,r);if(s)return n+"."+s;continue}if(typeof o!==r)return n}}}const Dt={string:!1,number:!1,boolean:!1,enum:!1,geopoint:!1,"string[]":!0,"number[]":!0,"boolean[]":!0,"enum[]":!0},wt={"string[]":"string","number[]":"number","boolean[]":"boolean","enum[]":"enum"};function z(t){return typeof t=="string"&&/^vector\[\d+\]$/.test(t)}function ae(t){return typeof t=="string"&&Dt[t]}function Ye(t){return wt[t]}function He(t){const e=Number(t.slice(7,-1));switch(!0){case isNaN(e):throw O("INVALID_VECTOR_VALUE",t);case e<=0:throw O("INVALID_VECTOR_SIZE",t);default:return e}}function At(){return{idToInternalId:new Map,internalIdToId:[],save:Et,load:_t}}function Et(t){return{internalIdToId:t.internalIdToId}}function _t(t,e){const{internalIdToId:n}=e;t.internalDocumentIDStore.idToInternalId.clear(),t.internalDocumentIDStore.internalIdToId=[];const r=n.length;for(let o=0;o<r;o++){const s=n[o];t.internalDocumentIDStore.idToInternalId.set(s,o+1),t.internalDocumentIDStore.internalIdToId.push(s)}}function P(t,e){if(typeof e=="string"){const n=t.idToInternalId.get(e);if(n)return n;const r=t.idToInternalId.size+1;return t.idToInternalId.set(e,r),t.internalIdToId.push(e),r}return e>t.internalIdToId.length?P(t,e.toString()):e}function J(t,e){if(t.internalIdToId.length<e)throw new Error(`Invalid internalId ${e}`);return t.internalIdToId[e-1]}function Pt(t,e){return{sharedInternalDocumentStore:e,docs:{},count:0}}function Rt(t,e){const n=P(t.sharedInternalDocumentStore,e);return t.docs[n]}function vt(t,e){const n=e.length,r=Array.from({length:n});for(let o=0;o<n;o++){const s=P(t.sharedInternalDocumentStore,e[o]);r[o]=t.docs[s]}return r}function kt(t){return t.docs}function Mt(t,e,n,r){return typeof t.docs[n]<"u"?!1:(t.docs[n]=r,t.count++,!0)}function Lt(t,e){const n=P(t.sharedInternalDocumentStore,e);return typeof t.docs[n]>"u"?!1:(delete t.docs[n],t.count--,!0)}function Ct(t){return t.count}function xt(t,e){const n=e;return{docs:n.docs,count:n.count,sharedInternalDocumentStore:t}}function Ut(t){return{docs:t.docs,count:t.count}}function zt(){return{create:Pt,get:Rt,getMultiple:vt,getAll:kt,store:Mt,remove:Lt,count:Ct,load:xt,save:Ut}}const Bt=["beforeInsert","afterInsert","beforeRemove","afterRemove","beforeUpdate","afterUpdate","beforeUpsert","afterUpsert","beforeSearch","afterSearch","beforeInsertMultiple","afterInsertMultiple","beforeRemoveMultiple","afterRemoveMultiple","beforeUpdateMultiple","afterUpdateMultiple","beforeUpsertMultiple","afterUpsertMultiple","beforeLoad","afterLoad","afterCreate"];function Ft(t,e){const n=[],r=t.plugins?.length;if(!r)return n;for(let o=0;o<r;o++)try{const s=t.plugins[o];typeof s[e]=="function"&&n.push(s[e])}catch(s){throw console.error("Caught error in getAllPluginsByHook:",s),O("PLUGIN_CRASHED")}return n}const Vt=["tokenizer","index","documentsStore","sorter","pinning"],Te=["validateSchema","getDocumentIndexId","getDocumentProperties","formatElapsedTime"];function le(t,e,n,r,o){if(t.some(j))return(async()=>{for(const i of t)await i(e,n,r,o)})();for(const i of t)i(e,n,r,o)}function ue(t,e,n,r){if(t.some(j))return(async()=>{for(const s of t)await s(e,n,r)})();for(const s of t)s(e,n,r)}function Wt(t,e){if(t.some(j))return(async()=>{for(const r of t)await r(e)})();for(const r of t)r(e)}class E{k;v;l=null;r=null;h=1;constructor(e,n){this.k=e,this.v=new Set(n)}updateHeight(){this.h=Math.max(E.getHeight(this.l),E.getHeight(this.r))+1}static getHeight(e){return e?e.h:0}getBalanceFactor(){return E.getHeight(this.l)-E.getHeight(this.r)}rotateLeft(){const e=this.r;return this.r=e.l,e.l=this,this.updateHeight(),e.updateHeight(),e}rotateRight(){const 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){const n=new E(e.k,e.v);return n.l=e.l?E.fromJSON(e.l):null,n.r=e.r?E.fromJSON(e.r):null,n.h=e.h,n}}class Y{root=null;insertCount=0;constructor(e,n){e!==void 0&&n!==void 0&&(this.root=new E(e,n))}insert(e,n,r=1e3){this.root=this.insertNode(this.root,e,n,r)}insertMultiple(e,n,r=1e3){for(const o of n)this.insert(e,o,r)}rebalance(){this.root&&(this.root=this.rebalanceNode(this.root))}toJSON(){return{root:this.root?this.root.toJSON():null,insertCount:this.insertCount}}static fromJSON(e){const n=new Y;return n.root=e.root?E.fromJSON(e.root):null,n.insertCount=e.insertCount||0,n}insertNode(e,n,r,o){if(e===null)return new E(n,[r]);const s=[];let i=e,c=null;for(;i!==null;)if(s.push({parent:c,node:i}),n<i.k)if(i.l===null){i.l=new E(n,[r]),s.push({parent:i,node:i.l});break}else c=i,i=i.l;else if(n>i.k)if(i.r===null){i.r=new E(n,[r]),s.push({parent:i,node:i.r});break}else c=i,i=i.r;else return i.v.add(r),e;let a=!1;this.insertCount++%o===0&&(a=!0);for(let l=s.length-1;l>=0;l--){const{parent:f,node:u}=s[l];if(u.updateHeight(),a){const d=this.rebalanceNode(u);f?f.l===u?f.l=d:f.r===u&&(f.r=d):e=d}}return e}rebalanceNode(e){const n=e.getBalanceFactor();if(n>
111){if(e.l&&e.l.getBalanceFactor()>=0)return e.rotateRight();if(e.l)return e.l=e.l.rotateLeft(),e.rotateRight()}if(n<-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){const n=this.findNodeByKey(e);return n?n.v:null}contains(e){return this.find(e)!==null}getSize(){let e=0;const n=[];let r=this.root;for(;r||n.length>0;){for(;r;)n.push(r),r=r.l;r=n.pop(),e++,r=r.r}return e}isBalanced(){if(!this.root)return!0;const e=[this.root];for(;e.length>0;){const n=e.pop(),r=n.getBalanceFactor();if(Math.abs(r)>1)return!1;n.l&&e.push(n.l),n.r&&e.push(n.r)}return!0}remove(e){this.root=this.removeNode(this.root,e)}removeDocument(e,n){const r=this.findNodeByKey(e);r&&(r.v.size===1?this.root=this.removeNode(this.root,e):r.v=new Set([...r.v.values()].filter(o=>o!==n)))}findNodeByKey(e){let n=this.root;for(;n;)if(e<n.k)n=n.l;else if(e>n.k)n=n.r;else return n;return null}removeNode(e,n){if(e===null)return null;const r=[];let o=e;for(;o!==null&&o.k!==n;)r.push(o),n<o.k?o=o.l:o=o.r;if(o===null)return e;if(o.l===null||o.r===null){const s=o.l?o.l:o.r;if(r.length===0)e=s;else{const i=r[r.length-1];i.l===o?i.l=s:i.r=s}}else{let s=o,i=o.r;for(;i.l!==null;)s=i,i=i.l;o.k=i.k,o.v=i.v,s.l===i?s.l=i.r:s.r=i.r,o=s}r.push(o);for(let s=r.length-1;s>=0;s--){const i=r[s];i.updateHeight();const c=this.rebalanceNode(i);if(s>0){const a=r[s-1];a.l===i?a.l=c:a.r===i&&(a.r=c)}else e=c}return e}rangeSearch(e,n){const r=new Set,o=[];let 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<=n)for(const i of s.v)r.add(i);if(s.k>n)break;s=s.r}return r}greaterThan(e,n=!1){const r=new Set,o=[];let s=this.root;for(;s||o.length>0;){for(;s;)o.push(s),s=s.r;if(s=o.pop(),n&&s.k>=e||!n&&s.k>e)for(const i of s.v)r.add(i);else if(s.k<=e)break;s=s.l}return r}lessThan(e,n=!1){const r=new Set,o=[];let s=this.root;for(;s||o.length>0;){for(;s;)o.push(s),s=s.l;if(s=o.pop(),n&&s.k<=e||!n&&s.k<e)for(const i of s.v)r.add(i);else if(s.k>e)break;s=s.r}return r}}class H{numberToDocumentId;constructor(){this.numberToDocumentId=new Map}insert(e,n){this.numberToDocumentId.has(e)?this.numberToDocumentId.get(e).add(n):this.numberToDocumentId.set(e,new Set([n]))}find(e){const n=this.numberToDocumentId.get(e);return n?Array.from(n):null}remove(e){this.numberToDocumentId.delete(e)}removeDocument(e,n){const r=this.numberToDocumentId.get(n);r&&(r.delete(e),r.size===0&&this.numberToDocumentId.delete(n))}contains(e){return this.numberToDocumentId.has(e)}getSize(){let e=0;for(const n of this.numberToDocumentId.values())e+=n.size;return e}filter(e){const n=Object.keys(e);if(n.length!==1)throw new Error("Invalid operation");const r=n[0];switch(r){case"eq":{const o=e[r],s=this.numberToDocumentId.get(o);return s?Array.from(s):[]}case"in":{const o=e[r],s=new Set;for(const i of o){const c=this.numberToDocumentId.get(i);if(c)for(const a of c)s.add(a)}return Array.from(s)}case"nin":{const o=new Set(e[r]),s=new Set;for(const[i,c]of this.numberToDocumentId.entries())if(!o.has(i))for(const a of c)s.add(a);return Array.from(s)}default:throw new Error("Invalid operation")}}filterArr(e){const n=Object.keys(e);if(n.length!==1)throw new Error("Invalid operation");const r=n[0];switch(r){case"containsAll":{const s=e[r].map(c=>this.numberToDocumentId.get(c)??new Set);if(s.length===0)return[];const i=s.reduce((c,a)=>new Set([...c].filter(l=>a.has(l))));return Array.from(i)}case"containsAny":{const s=e[r].map(c=>this.numberToDocumentId.get(c)??new Set);if(s.length===0)return[];const i=s.reduce((c,a)=>new Set([...c,...a]));return Array.from(i)}default:throw new Error("Invalid operation")}}static fromJSON(e){if(!e.numberToDocumentId)throw new Error("Invalid Flat Tree JSON");const n=new H;for(const[r,o]of e.numberToDocumentId)n.numberToDocumentId.set(r,new Set(o));return n}toJSON(){return{numberToDocumentId:Array.from(this.numberToDocumentId.entries()).map(([e,n])=>[e,Array.from(n)])}}}function $t(t,e,n){if(n<0)return-1;if(t===e)return 0;const r=t.length,o=e.length;if(r===0)return o<=n?o:-1;if(o===0)return r<=n?r:-1;const s=Math.abs(r-o);if(t.startsWith(e))return s<=n?s:-1;if(e.startsWith(t))return 0;if(s>n)return-1;const i=[];for(let c=0;c<=r;c++){i[c]=[c];for(let a=1;a<=o;a++)i[c][a]=c===0?a:0}for(let c=1;c<=r;c++){let a=1/0;for(let l=1;l<=o;l++)t[c-1]===e[l-1]?i[c][l]=i[c-1][l-1]:i[c][l]=Math.min(i[c-1][l]+1,i[c][l-1]+1,i[c-1][l-1]+1),a=Math.min(a,i[c][l]);if(a>n)return-1}return i[r][o]<=n?i[r][o]:-1}function Oe(t,e,n){const r=$t(t,e,n);return{distance:r,isBounded:r>=0}}class v{k;s;c=new Map;d=new Set;e;w="";constructor(e,n,r){this.k=e,this.s=n,this.e=r}updateParent(e){this.w=e.w+this.s}addDocument(e){this.d.add(e)}removeDocument(e){return this.d.delete(e)}findAllWords(e,n,r,o){const s=[this];for(;s.length>0;){const i=s.pop();if(i.e){const{w:c,d:a}=i;if(r&&c!==n)continue;if(te(e,c)!==null)if(o)if(Math.abs(n.length-c.length)<=o&&Oe(n,c,o).isBounded)e[c]=[];else continue;else e[c]=[];if(te(e,c)!=null&&a.size>0){const l=e[c];for(const f of a)l.includes(f)||l.push(f)}}i.c.size>0&&s.push(...i.c.values())}return e}insert(e,n){let r=this,o=0;const s=e.length;for(;o<s;){const i=e[o],c=r.c.get(i);if(c){const a=c.s,l=a.length;let f=0;for(;f<l&&o+f<s&&a[f]===e[o+f];)f++;if(f===l){if(r=c,o+=f,o===s){c.e||(c.e=!0),c.addDocument(n);return}continue}const u=a.slice(0,f),d=a.slice(f),h=e.slice(o+f),p=new v(u[0],u,!1);
11if(r.c.set(u[0],p),p.updateParent(r),c.s=d,c.k=d[0],p.c.set(d[0],c),c.updateParent(p),h){const y=new v(h[0],h,!0);y.addDocument(n),p.c.set(h[0],y),y.updateParent(p)}else p.e=!0,p.addDocument(n);return}else{const a=new v(i,e.slice(o),!0);a.addDocument(n),r.c.set(i,a),a.updateParent(r);return}}r.e||(r.e=!0),r.addDocument(n)}_findLevenshtein(e,n,r,o,s){const i=[{node:this,index:n,tolerance:r}];for(;i.length>0;){const{node:c,index:a,tolerance:l}=i.pop();if(c.w.startsWith(e)){c.findAllWords(s,e,!1,0);continue}if(l<0)continue;if(c.e){const{w:u,d}=c;if(u&&(Oe(e,u,o).isBounded&&(s[u]=[]),te(s,u)!==void 0&&d.size>0)){const h=new Set(s[u]);for(const p of d)h.add(p);s[u]=Array.from(h)}}if(a>=e.length)continue;const f=e[a];if(c.c.has(f)){const u=c.c.get(f);i.push({node:u,index:a+1,tolerance:l})}i.push({node:c,index:a+1,tolerance:l-1});for(const[u,d]of c.c)i.push({node:d,index:a,tolerance:l-1}),u!==f&&i.push({node:d,index:a+1,tolerance:l-1})}}find(e){const{term:n,exact:r,tolerance:o}=e;if(o&&!r){const s={};return this._findLevenshtein(n,0,o,o,s),s}else{let s=this,i=0;const c=n.length;for(;i<c;){const l=n[i],f=s.c.get(l);if(f){const u=f.s,d=u.length;let h=0;for(;h<d&&i+h<c&&u[h]===n[i+h];)h++;if(h===d)s=f,i+=h;else if(i+h===c)if(h===c-i){if(r)return{};{const p={};return f.findAllWords(p,n,r,o),p}}else return{};else return{}}else return{}}const a={};return s.findAllWords(a,n,r,o),a}}contains(e){let n=this,r=0;const o=e.length;for(;r<o;){const s=e[r],i=n.c.get(s);if(i){const c=i.s,a=c.length;let l=0;for(;l<a&&r+l<o&&c[l]===e[r+l];)l++;if(l<a)return!1;r+=a,n=i}else return!1}return!0}removeWord(e){if(!e)return!1;let n=this;const r=e.length,o=[];for(let s=0;s<r;s++){const i=e[s];if(n.c.has(i)){const c=n.c.get(i);o.push({parent:n,character:i}),s+=c.s.length-1,n=c}else return!1}for(n.d.clear(),n.e=!1;o.length>0&&n.c.size===0&&!n.e&&n.d.size===0;){const{parent:s,character:i}=o.pop();s.c.delete(i),n=s}return!0}removeDocumentByWord(e,n,r=!0){if(!e)return!0;let o=this;const s=e.length;for(let i=0;i<s;i++){const c=e[i];if(o.c.has(c)){const a=o.c.get(c);i+=a.s.length-1,o=a,r&&o.w!==e||o.removeDocument(n)}else return!1}return!0}static getCommonPrefix(e,n){const r=Math.min(e.length,n.length);let o=0;for(;o<r&&e.charCodeAt(o)===n.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,n])=>[e,n.toJSON()])}}static fromJSON(e){const n=new v(e.k,e.s,e.e);return n.w=e.w,n.d=new Set(e.d),n.c=new Map(e?.c?.map(([r,o])=>[r,v.fromJSON(o)])||[]),n}}class K extends v{constructor(){super("","",!1)}static fromJSON(e){const n=new K;return n.w=e.w,n.s=e.s,n.e=e.e,n.k=e.k,n.d=new Set(e.d),n.c=new Map(e?.c?.map(([r,o])=>[r,v.fromJSON(o)])||[]),n}toJSON(){return super.toJSON()}}const Gt=2,jt=6371e3;class L{point;docIDs;left;right;parent;constructor(e,n){this.point=e,this.docIDs=new Set(n),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,n=null){const r=new L(e.point,e.docIDs);return r.parent=n,e.left&&(r.left=L.fromJSON(e.left,r)),e.right&&(r.right=L.fromJSON(e.right,r)),r}}class _{root;nodeMap;constructor(){this.root=null,this.nodeMap=new Map}getPointKey(e){return`${e.lon},${e.lat}`}insert(e,n){const r=this.getPointKey(e),o=this.nodeMap.get(r);if(o){n.forEach(a=>o.docIDs.add(a));return}const s=new L(e,n);if(this.nodeMap.set(r,s),this.root==null){this.root=s;return}let i=this.root,c=0;for(;;){if(c%Gt===0)if(e.lon<i.point.lon){if(i.left==null){i.left=s,s.parent=i;return}i=i.left}else{if(i.right==null){i.right=s,s.parent=i;return}i=i.right}else if(e.lat<i.point.lat){if(i.left==null){i.left=s,s.parent=i;return}i=i.left}else{if(i.right==null){i.right=s,s.parent=i;return}i=i.right}c++}}contains(e){const n=this.getPointKey(e);return this.nodeMap.has(n)}getDocIDsByCoordinates(e){const n=this.getPointKey(e),r=this.nodeMap.get(n);return r?Array.from(r.docIDs):null}removeDocByID(e,n){const r=this.getPointKey(e),o=this.nodeMap.get(r);
11o&&(o.docIDs.delete(n),o.docIDs.size===0&&(this.nodeMap.delete(r),this.deleteNode(o)))}deleteNode(e){const n=e.parent,r=e.left?e.left:e.right;r&&(r.parent=n),n?n.left===e?n.left=r:n.right===e&&(n.right=r):(this.root=r,this.root&&(this.root.parent=null))}searchByRadius(e,n,r=!0,o="asc",s=!1){const i=s?_.vincentyDistance:_.haversineDistance,c=[{node:this.root,depth:0}],a=[];for(;c.length>0;){const{node:l,depth:f}=c.pop();if(l==null)continue;const u=i(e,l.point);(r?u<=n:u>n)&&a.push({point:l.point,docIDs:Array.from(l.docIDs)}),l.left!=null&&c.push({node:l.left,depth:f+1}),l.right!=null&&c.push({node:l.right,depth:f+1})}return o&&a.sort((l,f)=>{const u=i(e,l.point),d=i(e,f.point);return o.toLowerCase()==="asc"?u-d:d-u}),a}searchByPolygon(e,n=!0,r=null,o=!1){const s=[{node:this.root,depth:0}],i=[];for(;s.length>0;){const{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});const f=_.isPointInPolygon(e,a.point);(f&&n||!f&&!n)&&i.push({point:a.point,docIDs:Array.from(a.docIDs)})}const c=_.calculatePolygonCentroid(e);if(r){const a=o?_.vincentyDistance:_.haversineDistance;i.sort((l,f)=>{const u=a(c,l.point),d=a(c,f.point);return r.toLowerCase()==="asc"?u-d:d-u})}return i}toJSON(){return{root:this.root?this.root.toJSON():null}}static fromJSON(e){const n=new _;return e.root&&(n.root=L.fromJSON(e.root),n.buildNodeMap(n.root)),n}buildNodeMap(e){if(e==null)return;const n=this.getPointKey(e.point);this.nodeMap.set(n,e),e.left&&this.buildNodeMap(e.left),e.right&&this.buildNodeMap(e.right)}static calculatePolygonCentroid(e){let n=0,r=0,o=0;const s=e.length;for(let c=0,a=s-1;c<s;a=c++){const l=e[c].lon,f=e[c].lat,u=e[a].lon,d=e[a].lat,h=l*d-u*f;n+=h,r+=(l+u)*h,o+=(f+d)*h}n/=2;const i=6*n;return r/=i,o/=i,{lon:r,lat:o}}static isPointInPolygon(e,n){let r=!1;const o=n.lon,s=n.lat,i=e.length;for(let c=0,a=i-1;c<i;a=c++){const l=e[c].lon,f=e[c].lat,u=e[a].lon,d=e[a].lat;f>s!=d>s&&o<(u-l)*(s-f)/(d-f)+l&&(r=!r)}return r}static haversineDistance(e,n){const r=Math.PI/180,o=e.lat*r,s=n.lat*r,i=(n.lat-e.lat)*r,c=(n.lon-e.lon)*r,a=Math.sin(i/2)*Math.sin(i/2)+Math.cos(o)*Math.cos(s)*Math.sin(c/2)*Math.sin(c/2),l=2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a));return jt*l}static vincentyDistance(e,n){const o=.0033528106647474805,s=(1-o)*6378137,i=Math.PI/180,c=e.lat*i,a=n.lat*i,l=(n.lon-e.lon)*i,f=Math.atan((1-o)*Math.tan(c)),u=Math.atan((1-o)*Math.tan(a)),d=Math.sin(f),h=Math.cos(f),p=Math.sin(u),y=Math.cos(u);let g=l,m,S=1e3,b,I,T,D,w,N;do{const M=Math.sin(g),x=Math.cos(g);if(b=Math.sqrt(y*M*(y*M)+(h*p-d*y*x)*(h*p-d*y*x)),b===0)return 0;I=d*p+h*y*x,T=Math.atan2(b,I),D=h*y*M/b,w=1-D*D,N=I-2*d*p/w,isNaN(N)&&(N=0);const Q=o/16*w*(4+o*(4-3*w));m=g,g=l+(1-Q)*o*D*(T+Q*b*(N+Q*I*(-1+2*N*N)))}while(Math.abs(g-m)>1e-12&&--S>0);if(S===0)return NaN;const A=w*(6378137*6378137-s*s)/(s*s),B=1+A/16384*(4096+A*(-768+A*(320-175*A))),k=A/1024*(256+A*(-128+A*(74-47*A))),Z=k*b*(N+k/4*(I*(-1+2*N*N)-k/6*N*(-3+4*b*b)*(-3+4*N*N)));return s*B*(T-Z)}}class q{true;false;constructor(){this.true=new Set,this.false=new Set}insert(e,n){n?this.true.add(e):this.false.add(e)}delete(e,n){n?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){const n=new q;return n.true=new Set(e.true),n.false=new Set(e.false),n}}function Jt(t,e,n,r,o,{k:s,b:i,d:c}){return Math.log(1+(n-e+.5)/(e+.5))*(c+t*(s+1))/(t+s*(1-i+i*r/o))}const Yt=.8;class X{size;vectors=new Map;constructor(e){this.size=e}add(e,n){n instanceof Float32Array||(n=new Float32Array(n));const r=Ke(n,this.size);this.vectors.set(e,[r,n])}remove(e){this.vectors.delete(e)}find(e,n,r){return e instanceof Float32Array||(e=new Float32Array(e)),Ht(e,r,this.vectors,this.size,n)}toJSON(){const e=[];for(const[n,[r,o]]of this.vectors)e.push([n,[r,Array.from(o)]]);return{size:this.size,vectors:e}}static fromJSON(e){const n=e,r=new X(n.size);for(const[o,[s,i]]of n.vectors)r.vectors.set(o,[s,new Float32Array(i)]);return r}}function Ke(t,e){let n=0;for(let r=0;r<e;r++)n+=t[r]*t[r];return Math.sqrt(n)}function Ht(t,e,n,r,o){const s=Ke(t,r),i=[],c=e||n.keys();for(const a of c){const l=n.get(a);if(!l)continue;const f=l[0],u=l[1];let d=0;for(let p=0;p<r;p++)d+=t[p]*u[p];const h=d/(s*f);h>=o&&i.push([a,h])}return i}
11function Kt(t,e,n,r,o){const s=P(t.sharedInternalDocumentStore,n);t.avgFieldLength[e]=((t.avgFieldLength[e]??0)*(o-1)+r.length)/o,t.fieldLengths[e][s]=r.length,t.frequencies[e][s]={}}function qt(t,e,n,r,o){let s=0;for(const a of r)a===o&&s++;const i=P(t.sharedInternalDocumentStore,n),c=s/r.length;t.frequencies[e][i][o]=c,o in t.tokenOccurrences[e]||(t.tokenOccurrences[e][o]=0),t.tokenOccurrences[e][o]=(t.tokenOccurrences[e][o]??0)+1}function Xt(t,e,n,r){const o=P(t.sharedInternalDocumentStore,n);r>1?t.avgFieldLength[e]=(t.avgFieldLength[e]*r-t.fieldLengths[e][o])/(r-1):t.avgFieldLength[e]=void 0,t.fieldLengths[e][o]=void 0,t.frequencies[e][o]=void 0}function Zt(t,e,n){t.tokenOccurrences[e][n]--}function qe(t,e,n,r,o=""){r||(r={sharedInternalDocumentStore:e,indexes:{},vectorIndexes:{},searchableProperties:[],searchablePropertiesWithTypes:{},frequencies:{},tokenOccurrences:{},avgFieldLength:{},fieldLengths:{}});for(const[s,i]of Object.entries(n)){const c=`${o}${o?".":""}${s}`;if(typeof i=="object"&&!Array.isArray(i)){qe(t,e,i,r,c);continue}if(z(i))r.searchableProperties.push(c),r.searchablePropertiesWithTypes[c]=i,r.vectorIndexes[c]={type:"Vector",node:new X(He(i)),isArray:!1};else{const a=/\[/.test(i);switch(i){case"boolean":case"boolean[]":r.indexes[c]={type:"Bool",node:new q,isArray:a};break;case"number":case"number[]":r.indexes[c]={type:"AVL",node:new Y(0,[]),isArray:a};break;case"string":case"string[]":r.indexes[c]={type:"Radix",node:new K,isArray:a},r.avgFieldLength[c]=0,r.frequencies[c]={},r.tokenOccurrences[c]={},r.fieldLengths[c]={};break;case"enum":case"enum[]":r.indexes[c]={type:"Flat",node:new H,isArray:a};break;case"geopoint":r.indexes[c]={type:"BKD",node:new _,isArray:a};break;default:throw O("INVALID_SCHEMA_TYPE",Array.isArray(i)?"array":i,c)}r.searchableProperties.push(c),r.searchablePropertiesWithTypes[c]=i}}return r}function Qt(t,e,n,r,o,s,i,c){return a=>{const{type:l,node:f}=e.indexes[n];switch(l){case"Bool":{f[a?"true":"false"].add(r);break}case"AVL":{const u=c?.avlRebalanceThreshold??1;f.insert(a,r,u);break}case"Radix":{const u=s.tokenize(a,o,n,!1);t.insertDocumentScoreParameters(e,n,r,u,i);for(const d of u)t.insertTokenScoreParameters(e,n,r,u,d),f.insert(d,r);break}case"Flat":{f.insert(a,r);break}case"BKD":{f.insert(a,[r]);break}}}}function en(t,e,n,r,o,s,i,c,a,l,f){if(z(i))return tn(e,n,s,r,o);const u=Qt(t,e,n,o,c,a,l,f);if(!ae(i))return u(s);const d=s,h=d.length;for(let p=0;p<h;p++)u(d[p])}function tn(t,e,n,r,o){t.vectorIndexes[e].node.add(o,n)}function Ne(t,e,n,r,o,s,i,c,a,l){if(z(i))return e.vectorIndexes[n].node.remove(o),!0;const{type:f,node:u}=e.indexes[n];switch(f){case"AVL":return u.removeDocument(s,o),!0;case"Bool":return u[s?"true":"false"].delete(o),!0;case"Radix":{const d=a.tokenize(s,c,n);t.removeDocumentScoreParameters(e,n,r,l);for(const h of d)t.removeTokenScoreParameters(e,n,h),u.removeDocumentByWord(h,o);return!0}case"Flat":return u.removeDocument(o,s),!0;case"BKD":return u.removeDocByID(s,o),!1}}function nn(t,e,n,r,o,s,i,c,a,l){if(!ae(i))return Ne(t,e,n,r,o,s,i,c,a,l);const f=Ye(i),u=s,d=u.length;for(let h=0;h<d;h++)Ne(t,e,n,r,o,u[h],f,c,a,l);return!0}function Xe(t,e,n,r,o,s,i,c,a,l){const f=Array.from(r),u=t.avgFieldLength[e],d=t.fieldLengths[e],h=t.tokenOccurrences[e],p=t.frequencies[e],y=typeof h[n]=="number"?h[n]??0:0,g=f.length;for(let m=0;m<g;m++){const S=f[m];if(a&&!a.has(S))continue;l.has(S)||l.set(S,new Map);const b=l.get(S);b.set(e,(b.get(e)||0)+1);const I=p?.[S]?.[n]??0,T=Jt(I,y,o,d[S],u,s);i.has(S)?i.set(S,i.get(S)+T*c):i.set(S,T*c)}}function rn(t,e,n,r,o,s,i,c,a,l,f,u=0){const d=n.tokenize(e,r),h=d.length||1,p=new Map,y=new Map,g=new Map;for(const b of o){if(!(b in t.indexes))continue;const I=t.indexes[b],{type:T}=I;if(T!=="Radix")throw O("WRONG_SEARCH_PROPERTY_TYPE",b);const D=c[b]??1;if(D<=0)throw O("INVALID_BOOST_VALUE",D);d.length===0&&!e&&d.push("");const w=d.length;for(let N=0;N<w;N++){const A=d[N],B=I.node.find({term:A,exact:s,tolerance:i}),k=Object.keys(B);k.length>0&&y.set(A,!0);const Z=k.length;for(let F=0;F<Z;F++){const M=k[F],x=B[M];Xe(t,b,M,x,l,a,g,D,f,p)}}}const m=Array.from(g.entries()).map(([b,I])=>[b,I]).sort((b,I)=>I[1]-b[1]);if(m.length===0)return[];if(u===1)return m;if(u===0){if(h===1)return m;for(const I of d)if(!y.get(I))return[];return m.filter(([I])=>{const T=p.get(I);return T?Array.from(T.values()).some(D=>D===h):!1})}const S=m.filter(([b])=>{const I=p.get(b);return I?Array.from(I.values()).some(T=>T===h):!1});if(S.length>0){const b=m.filter(([T])=>!S.some(([D])=>D===T)),I=Math.ceil(b.length*u);return[...S,...b.slice(0,I)]}return m}function $(t,e,n,r){if("and"in n&&n.and&&Array.isArray(n.and)){const i=n.and;if(i.length===0)return new Set;const c=i.map(a=>$(t,e,a,r));return Ie(...c)}if("or"in n&&n.or&&Array.isArray(n.or)){const i=n.or;return i.length===0?new Set:i.map(a=>$(t,e,a,r)).reduce((a,l)=>V(a,l),new Set)}if("not"in n&&n.not){const i=n.not,c=new Set,a=t.sharedInternalDocumentStore;for(let f=1;f<=a.internalIdToId.length;f++)c.add(f);const l=$(t,e,i,r);return bt(c,l)}const o=Object.keys(n),s=o.reduce((i,c)=>({[c]:new Set,...i}),{});for(const i of o){const c=n[i];if(typeof t.indexes[i]>
11"u")throw O("UNKNOWN_FILTER_PROPERTY",i);const{node:a,type:l,isArray:f}=t.indexes[i];if(l==="Bool"){const d=a,h=c?d.true:d.false;s[i]=V(s[i],h);continue}if(l==="BKD"){let d;if("radius"in c)d="radius";else if("polygon"in c)d="polygon";else throw new Error(`Invalid operation ${c}`);if(d==="radius"){const{value:h,coordinates:p,unit:y="m",inside:g=!0,highPrecision:m=!1}=c[d],S=Ge(h,y),b=a.searchByRadius(p,S,g,void 0,m);s[i]=De(s[i],b)}else{const{coordinates:h,inside:p=!0,highPrecision:y=!1}=c[d],g=a.searchByPolygon(h,p,void 0,y);s[i]=De(s[i],g)}continue}if(l==="Radix"&&(typeof c=="string"||Array.isArray(c))){for(const d of[c].flat()){const h=e.tokenize(d,r,i);for(const p of h){const y=a.find({term:p,exact:!0});s[i]=dn(s[i],y)}}continue}const u=Object.keys(c);if(u.length>1)throw O("INVALID_FILTER_OPERATION",u.length);if(l==="Flat"){const d=new Set(f?a.filterArr(c):a.filter(c));s[i]=V(s[i],d);continue}if(l==="AVL"){const d=u[0],h=c[d];let p;switch(d){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":{const[y,g]=h;p=a.rangeSearch(y,g);break}default:throw O("INVALID_FILTER_OPERATION",d)}s[i]=V(s[i],p)}}return Ie(...Object.values(s))}function on(t){return t.searchableProperties}function sn(t){return t.searchablePropertiesWithTypes}function cn(t,e){const{indexes:n,vectorIndexes:r,searchableProperties:o,searchablePropertiesWithTypes:s,frequencies:i,tokenOccurrences:c,avgFieldLength:a,fieldLengths:l}=e,f={},u={};for(const d of Object.keys(n)){const{node:h,type:p,isArray:y}=n[d];switch(p){case"Radix":f[d]={type:"Radix",node:K.fromJSON(h),isArray:y};break;case"Flat":f[d]={type:"Flat",node:H.fromJSON(h),isArray:y};break;case"AVL":f[d]={type:"AVL",node:Y.fromJSON(h),isArray:y};break;case"BKD":f[d]={type:"BKD",node:_.fromJSON(h),isArray:y};break;case"Bool":f[d]={type:"Bool",node:q.fromJSON(h),isArray:y};break;default:f[d]=n[d]}}for(const d of Object.keys(r))u[d]={type:"Vector",isArray:!1,node:X.fromJSON(r[d])};return{sharedInternalDocumentStore:t,indexes:f,vectorIndexes:u,searchableProperties:o,searchablePropertiesWithTypes:s,frequencies:i,tokenOccurrences:c,avgFieldLength:a,fieldLengths:l}}function an(t){const{indexes:e,vectorIndexes:n,searchableProperties:r,searchablePropertiesWithTypes:o,frequencies:s,tokenOccurrences:i,avgFieldLength:c,fieldLengths:a}=t,l={};for(const u of Object.keys(n))l[u]=n[u].node.toJSON();const f={};for(const u of Object.keys(e)){const{type:d,node:h,isArray:p}=e[u];d==="Flat"||d==="Radix"||d==="AVL"||d==="BKD"||d==="Bool"?f[u]={type:d,node:h.toJSON(),isArray:p}:(f[u]=e[u],f[u].node=f[u].node.toJSON())}return{indexes:f,vectorIndexes:l,searchableProperties:r,searchablePropertiesWithTypes:o,frequencies:s,tokenOccurrences:i,avgFieldLength:c,fieldLengths:a}}function ln(){return{create:qe,insert:en,remove:nn,insertDocumentScoreParameters:Kt,insertTokenScoreParameters:qt,removeDocumentScoreParameters:Xt,removeTokenScoreParameters:Zt,calculateResultScores:Xe,search:rn,searchByWhereClause:$,getSearchableProperties:on,getSearchablePropertiesWithTypes:sn,load:cn,save:an}}function De(t,e){t||(t=new Set);const n=e.length;for(let r=0;r<n;r++){const o=e[r].docIDs,s=o.length;for(let i=0;i<s;i++)t.add(o[i])}return t}function we(t,e,n=!1){const r=n?_.vincentyDistance:_.haversineDistance,o=[],s=[];for(const{point:a}of t)s.push(r(e,a));const i=Math.max(...s);let c=0;for(const{docIDs:a}of t){const l=s[c],f=i-l+1;for(const u of a)o.push([u,f]);c++}return o.sort((a,l)=>l[1]-a[1]),o}function un(t,e){const n=Object.keys(t);if(n.length!==1)return{isGeoOnly:!1};const r=n[0],o=t[r];if(typeof e.indexes[r]>"u")return{isGeoOnly:!1};const{type:s}=e.indexes[r];return s==="BKD"&&o&&("radius"in o||"polygon"in o)?{isGeoOnly:!0,geoProperty:r,geoOperation:o}:{isGeoOnly:!1}}function fn(t,e){const n=t,r=un(e,n);if(!r.isGeoOnly||!r.geoProperty||!r.geoOperation)return null;const{node:o}=n.indexes[r.geoProperty],s=r.geoOperation,i=o;let c;if("radius"in s){const{value:a,coordinates:l,unit:f="m",inside:u=!0,highPrecision:d=!1}=s.radius,h=l,p=Ge(a,f);return c=i.searchByRadius(h,p,u,"asc",d),we(c,h,d)}else if("polygon"in s){const{coordinates:a,inside:l=!0,highPrecision:f=!1}=s.polygon;c=i.searchByPolygon(a,l,"asc",f);const u=_.calculatePolygonCentroid(a);return we(c,u,f)}return null}function dn(t,e){t||(t=new Set);const n=Object.keys(e),r=n.length;for(let o=0;o<r;o++){const s=e[n[o]],i=s.length;for(let c=0;c<i;c++)t.add(s[c])}return t}function Ze(t,e,n,r,o){const s={language:t.tokenizer.language,sharedInternalDocumentStore:e,enabled:!0,isSorted:!0,sortableProperties:[],sortablePropertiesWithTypes:{},sorts:{}};for(const[i,c]of Object.entries(n)){const a=`${o}${o?".":""}${i}`;if(!r.includes(a)){if(typeof c=="object"&&!Array.isArray(c)){const l=Ze(t,e,c,r,a);Fe(s.sortableProperties,l.sortableProperties),s.sorts={...s.sorts,...l.sorts},s.sortablePropertiesWithTypes={...s.sortablePropertiesWithTypes,...l.sortablePropertiesWithTypes};continue}if(!z(c))switch(c){case"boolean":case"number":case"string":s.sortableProperties.push(a),s.sortablePropertiesWithTypes[a]=c,s.sorts[a]={docs:new Map,orderedDocsToRemove:new Map,orderedDocs:[],type:c};break;case"geopoint":case"enum":continue;case"enum[]":case"boolean[]":case"number[]":case"string[]":continue;default:throw O("INVALID_SORT_SCHEMA_TYPE",Array.isArray(c)?"array":c,a)}}}return s}function hn(t,e,n,r){return r?.enabled!==!1?Ze(t,e,n,(r||{}).unsortableProperties||[],""):{disabled:!0}}function pn(t,e,n,r){if(!t.enabled)return;t.isSorted=!1;
11const o=P(t.sharedInternalDocumentStore,n),s=t.sorts[e];s.orderedDocsToRemove.has(o)&&fe(t,e),s.docs.set(o,s.orderedDocs.length),s.orderedDocs.push([o,r])}function Qe(t){if(t.isSorted||!t.enabled)return;const e=Object.keys(t.sorts);for(const n of e)Sn(t,n);t.isSorted=!0}function gn(t,e,n){return e[1].localeCompare(n[1],ut(t))}function mn(t,e){return t[1]-e[1]}function yn(t,e){return e[1]?-1:1}function Sn(t,e){const n=t.sorts[e];let r;switch(n.type){case"string":r=gn.bind(null,t.language);break;case"number":r=mn.bind(null);break;case"boolean":r=yn.bind(null);break}n.orderedDocs.sort(r);const o=n.orderedDocs.length;for(let s=0;s<o;s++){const i=n.orderedDocs[s][0];n.docs.set(i,s)}}function bn(t){const e=Object.keys(t.sorts);for(const n of e)fe(t,n)}function fe(t,e){const n=t.sorts[e];n.orderedDocsToRemove.size&&(n.orderedDocs=n.orderedDocs.filter(r=>!n.orderedDocsToRemove.has(r[0])),n.orderedDocsToRemove.clear())}function In(t,e,n){if(!t.enabled)return;const r=t.sorts[e],o=P(t.sharedInternalDocumentStore,n);r.docs.get(o)&&(r.docs.delete(o),r.orderedDocsToRemove.set(o,!0))}function Tn(t,e,n){if(!t.enabled)throw O("SORT_DISABLED");const r=n.property,o=n.order==="DESC",s=t.sorts[r];if(!s)throw O("UNABLE_TO_SORT_ON_UNKNOWN_FIELD",r,t.sortableProperties.join(", "));return fe(t,r),Qe(t),e.sort((i,c)=>{const a=s.docs.get(P(t.sharedInternalDocumentStore,i[0])),l=s.docs.get(P(t.sharedInternalDocumentStore,c[0])),f=typeof a<"u",u=typeof l<"u";return!f&&!u?0:f?u?o?l-a:a-l:-1:1}),e}function On(t){return t.enabled?t.sortableProperties:[]}function Nn(t){return t.enabled?t.sortablePropertiesWithTypes:{}}function Dn(t,e){const n=e;if(!n.enabled)return{enabled:!1};const r=Object.keys(n.sorts).reduce((o,s)=>{const{docs:i,orderedDocs:c,type:a}=n.sorts[s];return o[s]={docs:new Map(Object.entries(i).map(([l,f])=>[+l,f])),orderedDocsToRemove:new Map,orderedDocs:c,type:a},o},{});return{sharedInternalDocumentStore:t,language:n.language,sortableProperties:n.sortableProperties,sortablePropertiesWithTypes:n.sortablePropertiesWithTypes,sorts:r,enabled:!0,isSorted:n.isSorted}}function wn(t){if(!t.enabled)return{enabled:!1};bn(t),Qe(t);const e=Object.keys(t.sorts).reduce((n,r)=>{const{docs:o,orderedDocs:s,type:i}=t.sorts[r];return n[r]={docs:Object.fromEntries(o.entries()),orderedDocs:s,type:i},n},{});return{language:t.language,sortableProperties:t.sortableProperties,sortablePropertiesWithTypes:t.sortablePropertiesWithTypes,sorts:e,enabled:t.enabled,isSorted:t.isSorted}}function An(){return{create:hn,insert:pn,remove:In,save:wn,load:Dn,sortBy:Tn,getSortableProperties:On,getSortablePropertiesWithTypes:Nn}}const Ae=192,En=383,_n=[65,65,65,65,65,65,65,67,69,69,69,69,73,73,73,73,69,78,79,79,79,79,79,null,79,85,85,85,85,89,80,115,97,97,97,97,97,97,97,99,101,101,101,101,105,105,105,105,101,110,111,111,111,111,111,null,111,117,117,117,117,121,112,121,65,97,65,97,65,97,67,99,67,99,67,99,67,99,68,100,68,100,69,101,69,101,69,101,69,101,69,101,71,103,71,103,71,103,71,103,72,104,72,104,73,105,73,105,73,105,73,105,73,105,73,105,74,106,75,107,107,76,108,76,108,76,108,76,108,76,108,78,110,78,110,78,110,110,78,110,79,111,79,111,79,111,79,111,82,114,82,114,82,114,83,115,83,115,83,115,83,115,84,116,84,116,84,116,85,117,85,117,85,117,85,117,85,117,85,117,87,119,89,121,89,90,122,90,122,90,122,115];function Pn(t){return t<Ae||t>En?t:_n[t-Ae]||t}function Rn(t){const e=[];for(let n=0;n<t.length;n++)e[n]=Pn(t.charCodeAt(n));return String.fromCharCode(...e)}const vn={ational:"ate",tional:"tion",enci:"ence",anci:"ance",izer:"ize",bli:"ble",alli:"al",entli:"ent",eli:"e",ousli:"ous",ization:"ize",ation:"ate",ator:"ate",alism:"al",iveness:"ive",fulness:"ful",ousness:"ous",aliti:"al",iviti:"ive",biliti:"ble",logi:"log"},kn={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:""},Mn="[^aeiou]",G="[aeiouy]",R=Mn+"[^aeiouy]*",U=G+"[aeiou]*",ne="^("+R+")?"+U+R,Ln="^("+R+")?"+U+R+"("+U+")?$",W="^("+R+")?"+U+R+U+R,Ee="^("+R+")?"+G;function Cn(t){let e,n,r,o,s,i;if(t.length<3)return t;const c=t.substring(0,1);if(c=="y"&&(t=c.toUpperCase()+t.substring(1)),r=/^(.+?)(ss|i)es$/,o=/^(.+?)([^s])s$/,r.test(t)?t=t.replace(r,"$1$2"):o.test(t)&&(t=t.replace(o,"$1$2")),r=/^(.+?)eed$/,o=/^(.+?)(ed|ing)$/,r.test(t)){const a=r.exec(t);r=new RegExp(ne),r.test(a[1])&&(r=/.$/,t=t.replace(r,""))}else o.test(t)&&(e=o.exec(t)[1],o=new RegExp(Ee),o.test(e)&&(t=e,o=/(at|bl|iz)$/,s=new RegExp("([^aeiouylsz])\\1$"),i=new RegExp("^"+R+G+"[^aeiouwxy]$"),o.test(t)?t=t+"e":s.test(t)?(r=/.$/,t=t.replace(r,"")):i.test(t)&&(t=t+"e")));if(r=/^(.+?)y$/,r.test(t)&&(e=r.exec(t)?.[1],r=new RegExp(Ee),e&&r.test(e)&&(t=e+"i")),r=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,r.test(t)){const a=r.exec(t);e=a?.[1],n=a?.[2],r=new RegExp(ne),e&&r.test(e)&&(t=e+vn[n])}if(r=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,r.test(t)){const a=r.exec(t);e=a?.[1],n=a?.[2],r=new RegExp(ne),e&&r.test(e)&&(t=e+kn[n])}if(r=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,o=/^(.+?)(s|t)(ion)$/,r.test(t))e=r.exec(t)?.[1],r=new RegExp(W),e&&r.test(e)&&(t=e);else if(o.test(t)){const a=o.exec(t);e=a?.[1]??""+a?.[2]??"",o=new RegExp(W),o.test(e)&&(t=e)}return r=/^(.+?)e$/,r.test(t)&&(e=r.exec(t)?.[1],r=new RegExp(W),o=new RegExp(Ln),s=new RegExp("^"+R+G+"[^aeiouwxy]$"),e&&(r.test(e)||o.test(e)&&!s.test(e))&&(t=e)),r=/ll$/,o=new RegExp(W),r.test(t)&&o.test(t)&&(r=/.$/,t=t.replace(r,"")),c=="y"&&(t=c.toLowerCase()+t.substring(1)),t}function _e(t,e,n=!0){const r=`${this.language}:${t}:${e}`;return n&&this.normalizationCache.has(r)?this.normalizationCache.get(r):this.stopWords?.includes(e)?(n&&this.normalizationCache.set(r,""),""):(this.stemmer&&!this.stemmerSkipProperties.has(t)&&(e=this.stemmer(e)),e=Rn(e),n&&this.normalizationCache.set(r,e),e)}function xn(t){for(;t[t.length-1]==="";)t.pop();for(;t[0]==="";)t.shift();return t}function Pe(t,e,n,r=!0){if(e&&e!==this.language)throw O("LANGUAGE_NOT_SUPPORTED",e);if(typeof t!="string")return[t];const o=this.normalizeToken.bind(this,n??"");let s;if(n&&this.tokenizeSkipProperties.has(n))s=[o(t,r)];else{const c=lt[this.language];s=t.toLowerCase().split(c).map(a=>
11o(a,r)).filter(Boolean)}const i=xn(s);return this.allowDuplicates?i:Array.from(new Set(i))}function Re(t={}){if(!t.language)t.language="english";else if(!se.includes(t.language))throw O("LANGUAGE_NOT_SUPPORTED",t.language);let e;if(t.stemming||t.stemmer&&!("stemming"in t))if(t.stemmer){if(typeof t.stemmer!="function")throw O("INVALID_STEMMER_FUNCTION_TYPE");e=t.stemmer}else if(t.language==="english")e=Cn;else throw O("MISSING_STEMMER",t.language);let n;if(t.stopWords!==!1){if(n=[],Array.isArray(t.stopWords))n=t.stopWords;else if(typeof t.stopWords=="function")n=t.stopWords(n);else if(t.stopWords)throw O("CUSTOM_STOP_WORDS_MUST_BE_FUNCTION_OR_ARRAY");if(!Array.isArray(n))throw O("CUSTOM_STOP_WORDS_MUST_BE_FUNCTION_OR_ARRAY");for(const o of n)if(typeof o!="string")throw O("CUSTOM_STOP_WORDS_MUST_BE_FUNCTION_OR_ARRAY")}const r={tokenize:Pe,language:t.language,stemmer:e,stemmerSkipProperties:new Set(t.stemmerSkipProperties?[t.stemmerSkipProperties].flat():[]),tokenizeSkipProperties:new Set(t.tokenizeSkipProperties?[t.tokenizeSkipProperties].flat():[]),stopWords:n,allowDuplicates:!!t.allowDuplicates,normalizeToken:_e,normalizationCache:new Map};return r.tokenize=Pe.bind(r),r.normalizeToken=_e,r}function Un(t){return{sharedInternalDocumentStore:t,rules:new Map}}function zn(t,e){if(t.rules.has(e.id))throw new Error(`PINNING_RULE_ALREADY_EXISTS: A pinning rule with id "${e.id}" already exists. Use updateRule to modify it.`);t.rules.set(e.id,e)}function Bn(t,e){if(!t.rules.has(e.id))throw new Error(`PINNING_RULE_NOT_FOUND: Cannot update pinning rule with id "${e.id}" because it does not exist. Use addRule to create it.`);t.rules.set(e.id,e)}function Fn(t,e){return t.rules.delete(e)}function Vn(t,e){return t.rules.get(e)}function Wn(t){return Array.from(t.rules.values())}function $n(t,e){const n=t.toLowerCase().trim(),r=e.pattern.toLowerCase().trim();switch(e.anchoring){case"is":return n===r;case"starts_with":return n.startsWith(r);case"contains":return n.includes(r);default:return!1}}function Gn(t,e){return t?e.conditions.every(n=>$n(t,n)):!1}function et(t,e){if(!e)return[];const n=[];for(const r of t.rules.values())Gn(e,r)&&n.push(r);return n}function jn(t,e){const n=e;return{sharedInternalDocumentStore:t,rules:new Map(n?.rules??[])}}function Jn(t){return{rules:Array.from(t.rules.entries())}}function Yn(){return{create:Un,addRule:zn,updateRule:Bn,removeRule:Fn,getRule:Vn,getAllRules:Wn,getMatchingRules:et,load:jn,save:Jn}}function Hn(t){const e={formatElapsedTime:Ot,getDocumentIndexId:Nt,getDocumentProperties:$e,validateSchema:Je};for(const n of Te){const r=n;if(t[r]){if(typeof t[r]!="function")throw O("COMPONENT_MUST_BE_FUNCTION",r)}else t[r]=e[r]}for(const n of Object.keys(t))if(!Vt.includes(n)&&!Te.includes(n))throw O("UNSUPPORTED_COMPONENT",n)}function Kn({schema:t,sort:e,language:n,components:r,id:o,plugins:s}){r||(r={});for(const S of s??[]){if(!("getComponents"in S)||typeof S.getComponents!="function")continue;const b=S.getComponents(t),I=Object.keys(b);for(const T of I)if(r[T])throw O("PLUGIN_COMPONENT_CONFLICT",T,S.name);r={...r,...b}}o||(o=Ve());let i=r.tokenizer,c=r.index,a=r.documentsStore,l=r.sorter,f=r.pinning;if(i?i.tokenize?i=i:i=Re(i):i=Re({language:n??"english"}),r.tokenizer&&n)throw O("NO_LANGUAGE_WITH_CUSTOM_TOKENIZER");const u=At();c||=ln(),l||=An(),a||=zt(),f||=Yn(),Hn(r);const{getDocumentProperties:d,getDocumentIndexId:h,validateSchema:p,formatElapsedTime:y}=r,g={data:{},caches:{},schema:t,tokenizer:i,index:c,sorter:l,documentsStore:a,pinning:f,internalDocumentIDStore:u,getDocumentProperties:d,getDocumentIndexId:h,validateSchema:p,beforeInsert:[],afterInsert:[],beforeRemove:[],afterRemove:[],beforeUpdate:[],afterUpdate:[],beforeUpsert:[],afterUpsert:[],beforeSearch:[],afterSearch:[],beforeInsertMultiple:[],afterInsertMultiple:[],beforeRemoveMultiple:[],afterRemoveMultiple:[],beforeUpdateMultiple:[],afterUpdateMultiple:[],beforeUpsertMultiple:[],afterUpsertMultiple:[],afterCreate:[],formatElapsedTime:y,id:o,plugins:s,version:qn()};g.data={index:g.index.create(g,u,t),docs:g.documentsStore.create(g,u),sorting:g.sorter.create(g,u,t,e),pinning:g.pinning.create(u)};for(const S of Bt)g[S]=(g[S]??[]).concat(Ft(g,S));const m=g.afterCreate;return m&&Wt(m,g),g}function qn(){return"{{VERSION}}"}function Xn(t,e){return t.documentsStore.get(t.data.docs,e)}function Zn(t){return t.documentsStore.count(t.data.docs)}const ve="fulltext",Qn="hybrid",er="vector";function tr(t,e){return t[1]-e[1]}function nr(t,e){return e[1]-t[1]}function rr(t="desc"){return t.toLowerCase()==="asc"?tr:nr}function de(t,e,n){const r={},o=e.map(([l])=>l),s=t.documentsStore.getMultiple(t.data.docs,o),i=Object.keys(n),c=t.index.getSearchablePropertiesWithTypes(t.data.index);for(const l of i){let f;if(c[l]==="number"){const{ranges:u}=n[l],d=u.length,h=Array.from({length:d});for(let p=0;p<d;p++){const y=u[p];h[p]=[`${y.from}-${y.to}`,0]}f=Object.fromEntries(h)}r[l]={count:0,values:f??{}}}const a=s.length;for(let l=0;l<a;l++){const f=s[l];for(const u of i){const d=u.includes(".")?ce(f,u):f[u],h=c[u],p=r[u].values;switch(h){case"number":{const y=n[u].ranges;ke(y,p)(d);break}case"number[]":{const y=new Set,g=n[u].ranges,m=ke(g,p,y);for(const S of d)m(S);break}case"boolean":case"enum":case"string":{Me(p,h)(d);break}case"boolean[]":case"enum[]":case"string[]":{const m=Me(p,h==="boolean[]"?"boolean":"string",new Set);for(const S of d)m(S);break}default:throw O("FACET_NOT_SUPPORTED",h)}}}for(const l of i){const f=r[l];if(f.count=Object.keys(f.values).length,c[l]==="string"){const u=n[l],d=rr(u.sort);f.values=Object.fromEntries(Object.entries(f.values).sort(d).slice(u.offset??0,u.limit??10))}}return r}function ke(t,e,n){return r=>{for(const o of t){const s=`${o.from}-${o.to}`;n?.has(s)||r>=o.from&&r<=o.to&&(e[s]===void 0?e[s]=1:(e[s]++,n?.add(s)))}}}function Me(t,e,n){const r=e==="boolean"?"false":"";return o=>{const s=o?.toString()??r;n?.has(s)||(t[s]=(t[s]??0)+1,n?.add(s))}}const or={reducer:(t,e,n,r)=>(e[r]=n,e),getInitialValue:t=>Array.from({length:t})},Le=["string","number","boolean"];function he(t,e,n){const r=n.properties,o=r.length,s=t.index.getSearchablePropertiesWithTypes(t.data.index);for(let m=0;m<o;m++){const S=r[m];
11if(typeof s[S]>"u")throw O("UNKNOWN_GROUP_BY_PROPERTY",S);if(!Le.includes(s[S]))throw O("INVALID_GROUP_BY_PROPERTY",S,Le.join(", "),s[S])}const i=e.map(([m])=>J(t.internalDocumentIDStore,m)),c=t.documentsStore.getMultiple(t.data.docs,i),a=c.length,l=n.maxResult||Number.MAX_SAFE_INTEGER,f=[],u={};for(let m=0;m<o;m++){const S=r[m],b={property:S,perValue:{}},I=new Set;for(let T=0;T<a;T++){const D=c[T],w=ce(D,S);if(typeof w>"u")continue;const N=typeof w!="boolean"?w:""+w,A=b.perValue[N]??{indexes:[],count:0};A.count>=l||(A.indexes.push(T),A.count++,b.perValue[N]=A,I.add(w))}f.push(Array.from(I)),u[S]=b}const d=tt(f),h=d.length,p=[];for(let m=0;m<h;m++){const S=d[m],b=S.length,I={values:[],indexes:[]},T=[];for(let D=0;D<b;D++){const w=S[D],N=r[D];T.push(u[N].perValue[typeof w!="boolean"?w:""+w].indexes),I.values.push(w)}I.indexes=mt(T).sort((D,w)=>D-w),I.indexes.length!==0&&p.push(I)}const y=p.length,g=Array.from({length:y});for(let m=0;m<y;m++){const S=p[m],b=n.reduce||or,I=S.indexes.map(N=>({id:i[N],score:e[N][1],document:c[N]})),T=b.reducer.bind(null,S.values),D=b.getInitialValue(S.indexes.length),w=I.reduce(T,D);g[m]={values:S.values,result:w}}return g}function tt(t,e=0){if(e+1===t.length)return t[e].map(s=>[s]);const n=t[e],r=tt(t,e+1),o=[];for(const s of n)for(const i of r){const c=[s];Fe(c,i),o.push(c)}return o}function pe(t,e,n,r){const o=et(e,r);if(o.length===0)return n;const s=o.flatMap(g=>g.consequence.promote);s.sort((g,m)=>g.position-m.position);const i=new Set,c=new Map,a=new Set;for(const g of s){const m=P(t.internalDocumentIDStore,g.doc_id);if(m!==void 0){if(c.has(m)){const S=c.get(m);g.position<S&&c.set(m,g.position);continue}a.has(g.position)||(i.add(m),c.set(m,g.position),a.add(g.position))}}if(c.size===0)return n;const l=n.filter(([g])=>!i.has(g)),f=1e6,u=[];for(const[g,m]of c.entries())n.find(([b])=>b===g)?u.push([g,f-m]):t.documentsStore.get(t.data.docs,g)&&u.push([g,0]);u.sort((g,m)=>{const S=c.get(g[0])??1/0,b=c.get(m[0])??1/0;return S-b});const d=[],h=new Map;for(const g of u){const m=c.get(g[0]);h.set(m,g)}let p=0,y=0;for(;y<l.length+u.length;)if(h.has(y))d.push(h.get(y)),y++;else if(p<l.length)d.push(l[p]),p++,y++;else break;for(const[g,m]of h.entries())g>=d.length&&d.push(m);return d}function nt(t,e,n){const{term:r,properties:o}=e,s=t.data.index;let i=t.caches.propertiesToSearch;if(!i){const u=t.index.getSearchablePropertiesWithTypes(s);i=t.index.getSearchableProperties(s),i=i.filter(d=>u[d].startsWith("string")),t.caches.propertiesToSearch=i}if(o&&o!=="*"){for(const u of o)if(!i.includes(u))throw O("UNKNOWN_INDEX",u,i.join(", "));i=i.filter(u=>o.includes(u))}const c=Object.keys(e.where??{}).length>0;let a;c&&(a=t.index.searchByWhereClause(s,t.tokenizer,e.where,n));let l;const f=e.threshold!==void 0&&e.threshold!==null?e.threshold:1;if(r||o){const u=Zn(t);if(l=t.index.search(s,r||"",t.tokenizer,n,i,e.exact||!1,e.tolerance||0,e.boost||{},ar(e.relevance),u,a,f),e.exact&&r){const d=r.trim().split(/\s+/);l=l.filter(([h])=>{const p=t.documentsStore.get(t.data.docs,h);if(!p)return!1;for(const y of i){const g=ir(p,y);if(typeof g=="string"&&d.every(S=>new RegExp(`\\b${sr(S)}\\b`).test(g)))return!0}return!1})}}else if(c){const u=fn(s,e.where);u?l=u:l=(a?Array.from(a):[]).map(h=>[+h,0])}else l=Object.keys(t.documentsStore.getAll(t.data.docs)).map(d=>[+d,0]);return l}function sr(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ir(t,e){const n=e.split(".");let r=t;for(const o of n)if(r&&typeof r=="object"&&o in r)r=r[o];else return;return r}function cr(t,e,n){const r=C();function o(){const c=Object.keys(t.data.index.vectorIndexes),a=e.facets&&Object.keys(e.facets).length>0,{limit:l=10,offset:f=0,distinctOn:u,includeVectors:d=!1}=e,h=e.preflight===!0;let p=nt(t,e,n);if(e.sortBy)if(typeof e.sortBy=="function"){const m=p.map(([I])=>I),b=t.documentsStore.getMultiple(t.data.docs,m).map((I,T)=>[p[T][0],p[T][1],I]);b.sort(e.sortBy),p=b.map(([I,T])=>[I,T])}else p=t.sorter.sortBy(t.data.sorting,p,e.sortBy).map(([m,S])=>[P(t.internalDocumentIDStore,m),S]);else p=p.sort(We);p=pe(t,t.data.pinning,p,e.term);let y;h||(y=u?mr(t,p,f,l,u):st(t,p,f,l));const g={elapsed:{formatted:"",raw:0},hits:[],count:p.length};
11if(typeof y<"u"&&(g.hits=y.filter(Boolean),d||je(g,c)),a){const m=de(t,p,e.facets);g.facets=m}return e.groupBy&&(g.groups=he(t,p,e.groupBy)),g.elapsed=t.formatElapsedTime(C()-r),g}async function s(){t.beforeSearch&&await ue(t.beforeSearch,t,e,n);const c=o();return t.afterSearch&&await le(t.afterSearch,t,e,n,c),c}return t.beforeSearch?.length||t.afterSearch?.length?s():o()}const re={k:1.2,b:.75,d:.5};function ar(t){const e=t??{};return e.k=e.k??re.k,e.b=e.b??re.b,e.d=e.d??re.d,e}function rt(t,e,n){const r=e.vector;if(r&&(!("value"in r)||!("property"in r)))throw O("INVALID_VECTOR_INPUT",Object.keys(r).join(", "));const o=t.data.index.vectorIndexes[r.property];if(!o)throw O("UNKNOWN_VECTOR_PROPERTY",r.property);const s=o.node.size;if(r?.value.length!==s)throw r?.property===void 0||r?.value.length===void 0?O("INVALID_INPUT_VECTOR","undefined",s,"undefined"):O("INVALID_INPUT_VECTOR",r.property,s,r.value.length);const i=t.data.index;let c;return Object.keys(e.where??{}).length>0&&(c=t.index.searchByWhereClause(i,t.tokenizer,e.where,n)),o.node.find(r.value,e.similarity??Yt,c)}function lr(t,e,n="english"){const r=C();function o(){let c=rt(t,e,n).sort(We);c=pe(t,t.data.pinning,c,void 0);let a=[];e.facets&&Object.keys(e.facets).length>0&&(a=de(t,c,e.facets));const f=e.vector.property,u=e.includeVectors??!1,d=e.limit??10,h=e.offset??0,p=Array.from({length:d});for(let S=0;S<d;S++){const b=c[S+h];if(!b)break;const I=t.data.docs.docs[b[0]];if(I){u||(I[f]=null);const T={id:J(t.internalDocumentIDStore,b[0]),score:b[1],document:I};p[S]=T}}let y=[];e.groupBy&&(y=he(t,c,e.groupBy));const m=C()-r;return{count:c.length,hits:p.filter(Boolean),elapsed:{raw:Number(m),formatted:ie(m)},...a?{facets:a}:{},...y?{groups:y}:{}}}async function s(){t.beforeSearch&&await ue(t.beforeSearch,t,e,n);const c=o();return t.afterSearch&&await le(t.afterSearch,t,e,n,c),c}return t.beforeSearch?.length||t.afterSearch?.length?s():o()}function ur(t,e,n){const r=dr(nt(t,e,n)),o=rt(t,e,n),s=e.hybridWeights;return pr(r,o,e.term??"",s)}function fr(t,e,n){const r=C();function o(){let c=ur(t,e,n);c=pe(t,t.data.pinning,c,e.term);let a;e.facets&&Object.keys(e.facets).length>0&&(a=de(t,c,e.facets));let f;e.groupBy&&(f=he(t,c,e.groupBy));const u=e.offset??0,d=e.limit??10,h=st(t,c,u,d).filter(Boolean),p=C(),y={count:c.length,elapsed:{raw:Number(p-r),formatted:ie(p-r)},hits:h,...a?{facets:a}:{},...f?{groups:f}:{}};if(!(e.includeVectors??!1)){const m=Object.keys(t.data.index.vectorIndexes);je(y,m)}return y}async function s(){t.beforeSearch&&await ue(t.beforeSearch,t,e,n);const c=o();return t.afterSearch&&await le(t.afterSearch,t,e,n,c),c}return t.beforeSearch?.length||t.afterSearch?.length?s():o()}function oe(t){return t[1]}function dr(t){const e=Math.max.apply(Math,t.map(oe));return t.map(([n,r])=>[n,r/e])}function Ce(t,e){return t/e}function hr(t,e){return(n,r)=>n*t+r*e}function pr(t,e,n,r){const o=Math.max.apply(Math,t.map(oe)),s=Math.max.apply(Math,e.map(oe)),i=r&&r.text&&r.vector,{text:c,vector:a}=i?r:gr(),l=new Map,f=t.length,u=hr(c,a);for(let h=0;h<f;h++){const[p,y]=t[h],g=Ce(y,o),m=u(g,0);l.set(p,m)}const d=e.length;for(let h=0;h<d;h++){const[p,y]=e[h],g=Ce(y,s),m=l.get(p)??0;l.set(p,m+u(0,g))}return[...l].sort((h,p)=>p[1]-h[1])}function gr(t){return{text:.5,vector:.5}}function ot(t,e,n){const r=e.mode??ve;if(r===ve)return cr(t,e,n);if(r===er)return lr(t,e);if(r===Qn)return fr(t,e);throw O("INVALID_SEARCH_MODE",r)}function mr(t,e,n,r,o){const s=t.data.docs,i=new Map,c=[],a=new Set,l=e.length;let f=0;for(let u=0;u<l;u++){const d=e[u];if(typeof d>"u")continue;const[h,p]=d;if(a.has(h))continue;const y=t.documentsStore.get(s,h),g=ce(y,o);if(!(typeof g>"u"||i.has(g))&&(i.set(g,!0),f++,!(f<=n)&&(c.push({id:J(t.internalDocumentIDStore,h),score:p,document:y}),a.add(h),f>=n+r)))break}return c}function st(t,e,n,r){const o=t.data.docs,s=Array.from({length:r}),i=new Set;for(let c=n;c<r+n;c++){const a=e[c];if(typeof a>"u")break;const[l,f]=a;if(!i.has(l)){const u=t.documentsStore.get(o,l);s[c]={id:J(t.internalDocumentIDStore,l),score:f,document:u},i.add(l)}}return s}function xe(t,e){t.internalDocumentIDStore.load(t,e.internalDocumentIDStore),t.data.index=t.index.load(t.internalDocumentIDStore,e.index),t.data.docs=t.documentsStore.load(t.internalDocumentIDStore,e.docs),t.data.sorting=t.sorter.load(t.internalDocumentIDStore,e.sorting),t.data.pinning=t.pinning.load(t.internalDocumentIDStore,e.pinning),t.tokenizer.language=e.language}async function yr(t,e,n={}){const r=ze(e);return(await ot(t,{term:e,tolerance:1,...n,boost:{title:2,..."boost"in n?n.boost:void 0}})).hits.map(o=>({type:"page",content:r.highlightMarkdown(o.document.title),breadcrumbs:o.document.breadcrumbs,id:o.document.url,url:o.document.url}))}async function Sr(t,e,n=[],{mode:r="fulltext",...o}={}){typeof n=="string"&&(n=[n]);const s={limit:60,mode:r,...o,where:at({tags:n.length>0?{containsAll:n}:void 0,...o.where}),groupBy:{properties:["page_id"],maxResult:8,...o.groupBy},properties:r==="fulltext"?["content"]:["content","embeddings"]};e.length>0&&(s.term=e);const i=ze(e),c=await ot(t,s),a=[];for(const l of c.groups??[]){const f=l.values[0],u=Xn(t,f);if(u){a.push({id:f,type:"page",content:i.highlightMarkdown(u.content),breadcrumbs:u.breadcrumbs,url:u.url});for(const d of l.result)d.document.type!=="page"&&a.push({id:d.document.id.toString(),content:i.highlightMarkdown(d.document.content),breadcrumbs:d.document.breadcrumbs,type:d.document.type,url:d.document.url})}}return typeof s.limit=="number"&&a.length>s.limit?a.slice(0,s.limit):a}const Ue=new Map;async function br(t,e=n=>Kn({schema:{_:"string"},language:n})){const n=await fetch(t);if(!n.ok)throw new Error(`failed to fetch exported search indexes from ${t}, make sure the search database is exported and available for client.`);const r=await n.json(),o=new Map;if(r.type==="i18n")await Promise.all(Object.entries(r.data).map(async([s,i])=>{const c=await e(s);xe(c,i),o.set(s,{type:i.type,db:c})}));else{const s=await e();xe(s,r),o.set("",{type:r.type,db:s})}return o}function Ir({from:t=it(ct,"/api/search"),initOrama:e}){const n=t,r=Ue.get(n);if(r)return r;const o=br(t,e);return Ue.set(n,o),o}function Ar(t={}){const{tag:e,locale:n,search:r}=t;return{deps:[e,n],async search(o){const s=await Ir(t);let i=s.get(n??"");
11return i||(console.warn(`failed to find search data for "${n}", available: ${Array.from(s.keys())}.`),i=s.values().next().value),i?i.type==="simple"?yr(i,o,r):Sr(i.db,o,e,r):[]}}}export{Ar as oramaStaticClient};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.