UNPKG

@orama/plugin-match-highlight

Version:

Orama plugin for search match highlighting

12 lines 20.2 kB
"use strict";var orama=orama||{};orama.plugin=orama.plugin||{};orama.plugin.matchHighlight=(()=>{var Y=Object.defineProperty;var Re=Object.getOwnPropertyDescriptor;var _e=Object.getOwnPropertyNames;var Pe=Object.prototype.hasOwnProperty;var Me=(e,t)=>{for(var n in t)Y(e,n,{get:t[n],enumerable:!0})},ve=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of _e(t))!Pe.call(e,s)&&s!==n&&Y(e,s,{get:()=>t[s],enumerable:!(r=Re(t,s))||r.enumerable});return e};var Le=e=>ve(Y({},"__esModule",{value:!0}),e);var bt={};Me(bt,{afterInsert:()=>gt,loadWithHighlight:()=>It,saveWithHighlight:()=>St,searchWithHighlight:()=>yt});var Ue={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 K=Object.keys(Ue);var At=Date.now().toString().slice(5);var ue=BigInt(1e3),fe=BigInt(1e6),ae=BigInt(1e9);var J=65535;function F(e,t){if(t.length<J)Array.prototype.push.apply(e,t);else{let n=t.length;for(let r=0;r<n;r+=J)Array.prototype.push.apply(e,t.slice(r,r+J))}}function he(e,...t){return e.replace(/%(?:(?<position>\d+)\$)?(?<width>-?\d*\.?\d*)(?<type>[dfs])/g,function(...n){let r=n[n.length-1],{width:s,type:i,position:l}=r,o=l?t[Number.parseInt(l)-1]:t.shift(),u=s===""?0:Number.parseInt(s);switch(i){case"d":return o.toString().padStart(u,"0");case"f":{let c=o,[d,f]=s.split(".").map(g=>Number.parseFloat(g));return typeof f=="number"&&f>=0&&(c=c.toFixed(f)),typeof d=="number"&&d>=0?c.toString().padStart(u,"0"):c.toString()}case"s":return u<0?o.toString().padEnd(-u," "):o.toString().padStart(u," ");default:return o}})}function Ce(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}function ke(){return typeof process<"u"&&process.release&&process.release.name==="node"}function de(){return BigInt(Math.floor(performance.now()*1e6))}function P(e){return typeof e=="number"&&(e=BigInt(e)),e<ue?`${e}ns`:e<fe?`${e/ue}\u03BCs`:e<ae?`${e/fe}ms`:`${e/ae}s`}function N(){return Ce()?de():ke()||typeof process<"u"&&typeof process?.hrtime?.bigint=="function"?process.hrtime.bigint():typeof performance<"u"?de():BigInt(0)}function V(e,t){return t[1]===e[1]?e[0]-t[0]:t[1]-e[1]}function pe(e){if(e.length===0)return[];if(e.length===1)return e[0];for(let n=1;n<e.length;n++)if(e[n].length<e[0].length){let r=e[0];e[0]=e[n],e[n]=r}let t=new Map;for(let n of e[0])t.set(n,1);for(let n=1;n<e.length;n++){let r=0;for(let s of e[n]){let i=t.get(s);i===n&&(t.set(s,i+1),r++)}if(r===0)return[]}return e[0].filter(n=>{let r=t.get(n);return r!==void 0&&t.set(n,0),r===e.length})}function H(e,t){let n={},r=t.length;for(let s=0;s<r;s++){let i=t[s],l=i.split("."),o=e,u=l.length;for(let c=0;c<u;c++)if(o=o[l[c]],typeof o=="object"){if(o!==null&&"lat"in o&&"lon"in o&&typeof o.lat=="number"&&typeof o.lon=="number"){o=n[i]=o;break}else if(!Array.isArray(o)&&o!==null&&c===u-1){o=void 0;break}}else if((o===null||typeof o!="object")&&c<u-1){o=void 0;break}typeof o<"u"&&(n[i]=o)}return n}function M(e,t){return H(e,[t])[t]}function W(e,t){e.hits=e.hits.map(n=>({...n,document:{...n.document,...t.reduce((r,s)=>{let i=s.split("."),l=i.pop(),o=r;for(let u of i)o[u]=o[u]??{},o=o[u];return o[l]=null,r},n.document)}}))}function w(e){return Array.isArray(e)?e.some(t=>w(t)):e?.constructor?.name==="AsyncFunction"}var Nt="intersection"in new Set;var Ot="union"in new Set;var Be=K.join(` - `),ze={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. Supported languages are: - ${Be}`,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/open-source/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.oramasearch 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".',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. 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. Please install it before proceeding with creating an answer session. Read more at https://docs.orama.com/open-source/plugins/plugin-secure-proxy#plugin-secure-proxy `,PLUGIN_SECURE_PROXY_MISSING_CHAT_MODEL:`Could not find a chat model defined in the secure proxy plugin configuration. Please provide a chat model before proceeding with creating an answer session. Read more at https://docs.orama.com/open-source/plugins/plugin-secure-proxy#plugin-secure-proxy `,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 S(e,...t){let n=new Error(he(ze[e]??`Unsupported Orama Error code: ${e}`,...t));return n.code=e,"captureStackTrace"in Error.prototype&&Error.captureStackTrace(n),n}function E(e,t){if(typeof t=="string"){let n=e.idToInternalId.get(t);if(n)return n;let r=e.idToInternalId.size+1;return e.idToInternalId.set(t,r),e.internalIdToId.push(t),r}return t>e.internalIdToId.length?E(e,t.toString()):t}function R(e,t){if(e.internalIdToId.length<t)throw new Error(`Invalid internalId ${t}`);return e.internalIdToId[t-1]}function v(e,t,n,r,s){if(e.some(w))return(async()=>{for(let l of e)await l(t,n,r,s)})();for(let l of e)l(t,n,r,s)}function L(e,t,n,r){if(e.some(w))return(async()=>{for(let i of e)await i(t,n,r)})();for(let i of e)i(t,n,r)}function We(e,t,n){if(n<0)return-1;if(e===t)return 0;let r=e.length,s=t.length;if(r===0)return s<=n?s:-1;if(s===0)return r<=n?r:-1;let i=Math.abs(r-s);if(e.startsWith(t))return i<=n?i:-1;if(t.startsWith(e))return 0;if(i>n)return-1;let l=[];for(let o=0;o<=r;o++){l[o]=[o];for(let u=1;u<=s;u++)l[o][u]=o===0?u:0}for(let o=1;o<=r;o++){let u=1/0;for(let c=1;c<=s;c++)e[o-1]===t[c-1]?l[o][c]=l[o-1][c-1]:l[o][c]=Math.min(l[o-1][c]+1,l[o][c-1]+1,l[o-1][c-1]+1),u=Math.min(u,l[o][c]);if(u>n)return-1}return l[r][s]<=n?l[r][s]:-1}function q(e,t,n){let r=We(e,t,n);return{distance:r,isBounded:r>=0}}var He="[^aeiou]",Se="[aeiouy]",_=He+"[^aeiouy]*",B=Se+"[aeiou]*",Ln="^("+_+")?"+B+_,Un="^("+_+")?"+B+_+"("+B+")?$",Cn="^("+_+")?"+B+_+B+_,kn="^("+_+")?"+Se;function X(e){return e.documentsStore.count(e.data.docs)}var G="fulltext",ee="hybrid",te="vector";function Ze(e,t){return e[1]-t[1]}function Qe(e,t){return t[1]-e[1]}function et(e="desc"){return e.toLowerCase()==="asc"?Ze:Qe}function C(e,t,n){let r={},s=t.map(([c])=>c),i=e.documentsStore.getMultiple(e.data.docs,s),l=Object.keys(n),o=e.index.getSearchablePropertiesWithTypes(e.data.index);for(let c of l){let d;if(o[c]==="number"){let{ranges:f}=n[c],g=f.length,h=Array.from({length:g});for(let a=0;a<g;a++){let m=f[a];h[a]=[`${m.from}-${m.to}`,0]}d=Object.fromEntries(h)}r[c]={count:0,values:d??{}}}let u=i.length;for(let c=0;c<u;c++){let d=i[c];for(let f of l){let g=f.includes(".")?M(d,f):d[f],h=o[f],a=r[f].values;switch(h){case"number":{let m=n[f].ranges;Ie(m,a)(g);break}case"number[]":{let m=new Set,I=n[f].ranges,p=Ie(I,a,m);for(let y of g)p(y);break}case"boolean":case"enum":case"string":{be(a,h)(g);break}case"boolean[]":case"enum[]":case"string[]":{let p=be(a,h==="boolean[]"?"boolean":"string",new Set);for(let y of g)p(y);break}default:throw S("FACET_NOT_SUPPORTED",h)}}}for(let c of l){let d=r[c];if(d.count=Object.keys(d.values).length,o[c]==="string"){let f=n[c],g=et(f.sort);d.values=Object.fromEntries(Object.entries(d.values).sort(g).slice(f.offset??0,f.limit??10))}}return r}function Ie(e,t,n){return r=>{for(let s of e){let i=`${s.from}-${s.to}`;n?.has(i)||r>=s.from&&r<=s.to&&(t[i]===void 0?t[i]=1:(t[i]++,n?.add(i)))}}}function be(e,t,n){let r=t==="boolean"?"false":"";return s=>{let i=s?.toString()??r;n?.has(i)||(e[i]=(e[i]??0)+1,n?.add(i))}}var tt={reducer:(e,t,n,r)=>(t[r]=n,t),getInitialValue:e=>Array.from({length:e})},Te=["string","number","boolean"];function k(e,t,n){let r=n.properties,s=r.length,i=e.index.getSearchablePropertiesWithTypes(e.data.index);for(let p=0;p<s;p++){let y=r[p];if(typeof i[y]>"u")throw S("UNKNOWN_GROUP_BY_PROPERTY",y);if(!Te.includes(i[y]))throw S("INVALID_GROUP_BY_PROPERTY",y,Te.join(", "),i[y])}let l=t.map(([p])=>R(e.internalDocumentIDStore,p)),o=e.documentsStore.getMultiple(e.data.docs,l),u=o.length,c=n.maxResult||Number.MAX_SAFE_INTEGER,d=[],f={};for(let p=0;p<s;p++){let y=r[p],T={property:y,perValue:{}},b=new Set;for(let D=0;D<u;D++){let A=o[D],x=M(A,y);if(typeof x>"u")continue;let O=typeof x!="boolean"?x:""+x,z=T.perValue[O]??{indexes:[],count:0};z.count>=c||(z.indexes.push(D),z.count++,T.perValue[O]=z,b.add(x))}d.push(Array.from(b)),f[y]=T}let g=De(d),h=g.length,a=[];for(let p=0;p<h;p++){let y=g[p],T=y.length,b={values:[],indexes:[]},D=[];for(let A=0;A<T;A++){let x=y[A],O=r[A];D.push(f[O].perValue[typeof x!="boolean"?x:""+x].indexes),b.values.push(x)}b.indexes=pe(D).sort((A,x)=>A-x),b.indexes.length!==0&&a.push(b)}let m=a.length,I=Array.from({length:m});for(let p=0;p<m;p++){let y=a[p],T=n.reduce||tt,b=y.indexes.map(O=>({id:l[O],score:t[O][1],document:o[O]})),D=T.reducer.bind(null,y.values),A=T.getInitialValue(y.indexes.length),x=b.reduce(D,A);I[p]={values:y.values,result:x}}return I}function De(e,t=0){if(t+1===e.length)return e[t].map(i=>[i]);let n=e[t],r=De(e,t+1),s=[];for(let i of n)for(let l of r){let o=[i];F(o,l),s.push(o)}return s}function re(e,t,n){let{term:r,properties:s}=t,i=e.data.index,l=e.caches.propertiesToSearch;if(!l){let f=e.index.getSearchablePropertiesWithTypes(i);l=e.index.getSearchableProperties(i),l=l.filter(g=>f[g].startsWith("string")),e.caches.propertiesToSearch=l}if(s&&s!=="*"){for(let f of s)if(!l.includes(f))throw S("UNKNOWN_INDEX",f,l.join(", "));l=l.filter(f=>s.includes(f))}let o=Object.keys(t.where??{}).length>0,u;o&&(u=e.index.searchByWhereClause(i,e.tokenizer,t.where,n));let c,d=t.threshold!==void 0&&t.threshold!==null?t.threshold:1;if(r||s){let f=X(e);c=e.index.search(i,r||"",e.tokenizer,n,l,t.exact||!1,t.tolerance||0,t.boost||{},nt(t.relevance),f,u,d)}else c=(u?Array.from(u):Object.keys(e.documentsStore.getAll(e.data.docs))).map(g=>[+g,0]);return c}function xe(e,t,n){let r=N();function s(){let o=Object.keys(e.data.index.vectorIndexes),u=t.facets&&Object.keys(t.facets).length>0,{limit:c=10,offset:d=0,distinctOn:f,includeVectors:g=!1}=t,h=t.preflight===!0,a=re(e,t,n);if(t.sortBy)if(typeof t.sortBy=="function"){let p=a.map(([b])=>b),T=e.documentsStore.getMultiple(e.data.docs,p).map((b,D)=>[a[D][0],a[D][1],b]);T.sort(t.sortBy),a=T.map(([b,D])=>[b,D])}else a=e.sorter.sortBy(e.data.sorting,a,t.sortBy).map(([p,y])=>[E(e.internalDocumentIDStore,p),y]);else a=a.sort(V);let m;h||(m=f?Ae(e,a,d,c,f):j(e,a,d,c));let I={elapsed:{formatted:"",raw:0},hits:[],count:a.length};if(typeof m<"u"&&(I.hits=m.filter(Boolean),g||W(I,o)),u){let p=C(e,a,t.facets);I.facets=p}return t.groupBy&&(I.groups=k(e,a,t.groupBy)),I.elapsed=e.formatElapsedTime(N()-r),I}async function i(){e.beforeSearch&&await L(e.beforeSearch,e,t,n);let o=s();return e.afterSearch&&await v(e.afterSearch,e,t,n,o),o}return e.beforeSearch?.length||e.afterSearch?.length?i():s()}var ne={k:1.2,b:.75,d:.5};function nt(e){let t=e??{};return t.k=t.k??ne.k,t.b=t.b??ne.b,t.d=t.d??ne.d,t}function oe(e,t,n){let r=t.vector;if(r&&(!("value"in r)||!("property"in r)))throw S("INVALID_VECTOR_INPUT",Object.keys(r).join(", "));let s=e.data.index.vectorIndexes[r.property],i=s.node.size;if(r?.value.length!==i)throw r?.property===void 0||r?.value.length===void 0?S("INVALID_INPUT_VECTOR","undefined",i,"undefined"):S("INVALID_INPUT_VECTOR",r.property,i,r.value.length);let l=e.data.index,o;return Object.keys(t.where??{}).length>0&&(o=e.index.searchByWhereClause(l,e.tokenizer,t.where,n)),s.node.find(r.value,t.similarity??.8,o)}function se(e,t,n="english"){let r=N();function s(){let o=oe(e,t,n).sort(V),u=[];t.facets&&Object.keys(t.facets).length>0&&(u=C(e,o,t.facets));let d=t.vector.property,f=t.includeVectors??!1,g=t.limit??10,h=t.offset??0,a=Array.from({length:g});for(let y=0;y<g;y++){let T=o[y+h];if(!T)break;let b=e.data.docs.docs[T[0]];if(b){f||(b[d]=null);let D={id:R(e.internalDocumentIDStore,T[0]),score:T[1],document:b};a[y]=D}}let m=[];t.groupBy&&(m=k(e,o,t.groupBy));let p=N()-r;return{count:o.length,hits:a.filter(Boolean),elapsed:{raw:Number(p),formatted:P(p)},...u?{facets:u}:{},...m?{groups:m}:{}}}async function i(){e.beforeSearch&&await L(e.beforeSearch,e,t,n);let o=s();return e.afterSearch&&await v(e.afterSearch,e,t,n,o),o}return e.beforeSearch?.length||e.afterSearch?.length?i():s()}function ot(e,t,n){let r=st(re(e,t,n)),s=oe(e,t,n),i=t.hybridWeights;return ct(r,s,t.term??"",i)}function Oe(e,t,n){let r=N();function s(){let o=ot(e,t,n),u;t.facets&&Object.keys(t.facets).length>0&&(u=C(e,o,t.facets));let d;t.groupBy&&(d=k(e,o,t.groupBy));let f=t.offset??0,g=t.limit??10,h=j(e,o,f,g).filter(Boolean),a=N(),m={count:o.length,elapsed:{raw:Number(a-r),formatted:P(a-r)},hits:h,...u?{facets:u}:{},...d?{groups:d}:{}};if(!(t.includeVectors??!1)){let p=Object.keys(e.data.index.vectorIndexes);W(m,p)}return m}async function i(){e.beforeSearch&&await L(e.beforeSearch,e,t,n);let o=s();return e.afterSearch&&await v(e.afterSearch,e,t,n,o),o}return e.beforeSearch?.length||e.afterSearch?.length?i():s()}function ie(e){return e[1]}function st(e){let t=Math.max.apply(Math,e.map(ie));return e.map(([n,r])=>[n,r/t])}function Ne(e,t){return e/t}function it(e,t){return(n,r)=>n*e+r*t}function ct(e,t,n,r){let s=Math.max.apply(Math,e.map(ie)),i=Math.max.apply(Math,t.map(ie)),l=r&&r.text&&r.vector,{text:o,vector:u}=l?r:lt(n),c=new Map,d=e.length,f=it(o,u);for(let h=0;h<d;h++){let[a,m]=e[h],I=Ne(m,s),p=f(I,0);c.set(a,p)}let g=t.length;for(let h=0;h<g;h++){let[a,m]=t[h],I=Ne(m,i),p=c.get(a)??0;c.set(a,p+f(0,I))}return[...c].sort((h,a)=>a[1]-h[1])}function lt(e){return{text:.5,vector:.5}}function $(e,t,n){let r=t.mode??G;if(r===G)return xe(e,t,n);if(r===te)return se(e,t);if(r===ee)return Oe(e,t);throw S("INVALID_SEARCH_MODE",r)}function Ae(e,t,n,r,s){let i=e.data.docs,l=new Map,o=[],u=new Set,c=t.length,d=0;for(let f=0;f<c;f++){let g=t[f];if(typeof g>"u")continue;let[h,a]=g;if(u.has(h))continue;let m=e.documentsStore.get(i,h),I=M(m,s);if(!(typeof I>"u"||l.has(I))&&(l.set(I,!0),d++,!(d<=n)&&(o.push({id:R(e.internalDocumentIDStore,h),score:a,document:m}),u.add(h),d>=n+r)))break}return o}function j(e,t,n,r){let s=e.data.docs,i=Array.from({length:r}),l=new Set;for(let o=n;o<r+n;o++){let u=t[o];if(typeof u>"u")break;let[c,d]=u;if(!l.has(c)){let f=e.documentsStore.get(s,c);i[o]={id:R(e.internalDocumentIDStore,c),score:d,document:f},l.add(c)}}return i}function ce(e,t){e.internalDocumentIDStore.load(e,t.internalDocumentIDStore),e.data.index=e.index.load(e.internalDocumentIDStore,t.index),e.data.docs=e.documentsStore.load(e.internalDocumentIDStore,t.docs),e.data.sorting=e.sorter.load(e.internalDocumentIDStore,t.sorting),e.tokenizer.language=t.language}function le(e){return{internalDocumentIDStore:e.internalDocumentIDStore.save(e.internalDocumentIDStore),index:e.index.save(e.data.index),docs:e.documentsStore.save(e.data.docs),sorting:e.sorter.save(e.data.sorting),language:e.tokenizer.language}}var Uo=Symbol("orama.insertions"),Co=Symbol("orama.removals");async function gt(e,t){"positions"in e.data||Object.assign(e.data,{positions:{}}),await Ee(e,await e.documentsStore.get(e.data.docs,t),t)}var mt=/[\p{L}0-9_'-]+/gimu;async function Ee(e,t,n,r="",s=e.schema){e.data.positions[n]=Object.create(null);for(let i of Object.keys(t)){let l=typeof t[i]=="object",o=typeof s[i]=="object",u=`${r}${String(i)}`;if(l&&i in s&&o&&Ee(e,t[i],n,u+".",s[i]),!(typeof t[i]=="string"&&i in s&&!o))continue;e.data.positions[n][u]=Object.create(null);let c=t[i],d;for(;(d=mt.exec(c))!==null;){let f=d[0].toLowerCase(),g=`${e.tokenizer.language}:${f}`,h;e.tokenizer.normalizationCache.has(g)?h=e.tokenizer.normalizationCache.get(g):([h]=e.tokenizer.tokenize(f),e.tokenizer.normalizationCache.set(g,h)),Array.isArray(e.data.positions[n][u][h])||(e.data.positions[n][u][h]=[]);let a=d.index,m=d[0].length;e.data.positions[n][u][h].push({start:a,length:m})}}}async function yt(e,t,n){let r=await $(e,t,n),s=e.tokenizer.tokenize(t.term??"",n),i=[];for(let l of r.hits){let o=Object.entries(e.data.positions[l.id]),u=[];for(let[c,d]of o){let f=[],g=Object.entries(d);for(let h of g){let[a]=h;for(let m of s)if(t.tolerance){if(q(a,m,t.tolerance).isBounded){f.push(h);break}}else if(a.startsWith(m)){f.push(h);break}}u.push([c,Object.fromEntries(f)])}i.push(Object.assign(l,{positions:Object.fromEntries(u)}))}return r.hits=i,r}function St(e){return{...le(e),positions:e.data.positions}}function It(e,t){ce(e,t),e.data.positions=t.positions}return Le(bt);})(); //# sourceMappingURL=index.global.js.map