murmur-rag 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -23
- package/dist/cdn/anthropic-ynz7717b.js +2 -0
- package/dist/cdn/chunk-hpx6rpea.js +1 -0
- package/dist/cdn/{embed-59r4jck6.js → embed-0m8xctqy.js} +3 -3
- package/dist/cdn/{embed-pnm9593k.js → embed-7pk91zq8.js} +2 -2
- package/dist/cdn/embed-dbkjhg16.js +83 -0
- package/dist/cdn/{embed-q6y6vgv1.js → embed-krrjjyf5.js} +4 -4
- package/dist/cdn/embed-n5nzhrf2.js +9 -0
- package/dist/cdn/{embed-hn0r8fmg.js → embed-rp9gb1qq.js} +2 -2
- package/dist/cdn/embed-xtkxyrpe.js +44 -0
- package/dist/cdn/google-k5kwa54v.js +14 -0
- package/dist/cdn/index-db4ne93m.js +1 -0
- package/dist/cdn/index-gyd02jvt.js +9 -0
- package/dist/cdn/index-qc8kgsdt.js +1 -0
- package/dist/cdn/index-t0qn2m4r.js +1 -0
- package/dist/cdn/index-y0faj89r.js +1 -0
- package/dist/cdn/mistral-p2qcnn42.js +3 -0
- package/dist/cdn/murmur-d6t6cjc7.js +5 -0
- package/dist/cdn/murmur.js +24 -5
- package/dist/cdn/openai-compatible-psnkrpxy.js +11 -0
- package/dist/cdn/openai-d3q1d6cz.js +18 -0
- package/dist/cdn/retriever-6qvn2maq.js +1 -0
- package/dist/cdn/transformers.web-xn16v7pz.js +46 -0
- package/dist/cli.js +2 -0
- package/dist/lib/chunks/{index-ynjdey8j.js → index-8h9c8ekq.js} +4 -2
- package/dist/lib/chunks/{index-6re28wc1.js → index-b77xqap3.js} +13 -1
- package/dist/lib/chunks/{index-10g918kt.js → index-p86sy3y4.js} +1 -1
- package/dist/lib/chunks/{index-4at214g0.js → index-y3v46yjp.js} +314 -27
- package/dist/lib/chunks/{murmur-c1c79eh8.js → murmur-t36hd4vt.js} +2 -2
- package/dist/lib/chunks/{retriever-h8nz6jsc.js → retriever-wxshtnm0.js} +1 -1
- package/dist/lib/embed.js +4 -2
- package/dist/lib/index.js +5 -3
- package/dist/lib/indexer/index.js +2 -0
- package/dist/lib/local/index.js +163 -0
- package/dist/lib/rag/index.js +13 -11
- package/dist/lib/widget/index.js +2 -2
- package/dist/types/local/index.d.ts +56 -0
- package/dist/types/rag/ground.d.ts +7 -0
- package/dist/types/rag/index.d.ts +1 -1
- package/dist/types/widget/element.d.ts +3 -0
- package/dist/types/widget/i18n.d.ts +14 -0
- package/dist/types/widget/session.d.ts +32 -1
- package/dist/types/widget/styles.d.ts +1 -1
- package/package.json +17 -3
- package/dist/cdn/anthropic-w7nkjk5e.js +0 -2
- package/dist/cdn/chunk-e0j28zmb.js +0 -1
- package/dist/cdn/embed-2xm309sb.js +0 -7
- package/dist/cdn/embed-n7jskdxd.js +0 -44
- package/dist/cdn/embed-sgjh2kg2.js +0 -83
- package/dist/cdn/google-qha5xyx4.js +0 -14
- package/dist/cdn/index-11c9cspb.js +0 -1
- package/dist/cdn/index-e5entetm.js +0 -1
- package/dist/cdn/index-hv290nbv.js +0 -9
- package/dist/cdn/index-kk9hgxdc.js +0 -1
- package/dist/cdn/mistral-16bekg8b.js +0 -3
- package/dist/cdn/murmur-bnm335nb.js +0 -5
- package/dist/cdn/openai-compatible-za7hc1fv.js +0 -11
- package/dist/cdn/openai-dhy4fp4c.js +0 -18
- package/dist/cdn/retriever-m8peqj5t.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Ye}from"./embed-2xm309sb.js";class L{constructor(t,e){let s=t._tree,n=Array.from(s.keys());this.set=t,this._type=e,this._path=n.length>0?[{node:s,keys:n}]:[]}next(){let t=this.dive();return this.backtrack(),t}dive(){if(this._path.length===0)return{done:!0,value:void 0};let{node:t,keys:e}=z(this._path);if(z(e)==="")return{done:!1,value:this.result()};let s=t.get(z(e));return this._path.push({node:s,keys:Array.from(s.keys())}),this.dive()}backtrack(){if(this._path.length===0)return;let t=z(this._path).keys;if(t.pop(),t.length>0)return;this._path.pop(),this.backtrack()}key(){return this.set._prefix+this._path.map(({keys:t})=>z(t)).filter((t)=>t!=="").join("")}value(){return z(this._path).node.get("")}result(){switch(this._type){case"VALUES":return this.value();case"KEYS":return this.key();default:return[this.key(),this.value()]}}[Symbol.iterator](){return this}}var z=(t)=>t[t.length-1],G=(t,e,s)=>{let n=new Map;if(e===void 0)return n;let i=e.length+1,r=i+s,c=new Uint8Array(r*i).fill(s+1);for(let o=0;o<i;++o)c[o]=o;for(let o=1;o<r;++o)c[o*i]=o;return U(t,e,s,n,c,1,i,""),n},U=(t,e,s,n,i,r,c,o)=>{let u=r*c;t:for(let d of t.keys())if(d===""){let a=i[u-1];if(a<=s)n.set(o,[t.get(d),a])}else{let a=r;for(let h=0;h<d.length;++h,++a){let f=d[h],m=c*a,g=m-c,l=i[m],_=Math.max(0,a-s-1),F=Math.min(c-1,a+s);for(let p=_;p<F;++p){let k=f!==e[p],S=i[g+p]+ +k,y=i[g+p+1]+1,I=i[m+p]+1,j=i[m+p+1]=Math.min(S,y,I);if(j<l)l=j}if(l>s)continue t}U(t.get(d),e,s,n,i,a,c,o+d)}};class w{constructor(t=new Map,e=""){this._size=void 0,this._tree=t,this._prefix=e}atPrefix(t){if(!t.startsWith(this._prefix))throw Error("Mismatched prefix");let[e,s]=E(this._tree,t.slice(this._prefix.length));if(e===void 0){let[n,i]=R(s);for(let r of n.keys())if(r!==""&&r.startsWith(i)){let c=new Map;return c.set(r.slice(i.length),n.get(r)),new w(c,t)}}return new w(e,t)}clear(){this._size=void 0,this._tree.clear()}delete(t){return this._size=void 0,Z(this._tree,t)}entries(){return new L(this,"ENTRIES")}forEach(t){for(let[e,s]of this)t(e,s,this)}fuzzyGet(t,e){return G(this._tree,t,e)}get(t){let e=A(this._tree,t);return e!==void 0?e.get(""):void 0}has(t){let e=A(this._tree,t);return e!==void 0&&e.has("")}keys(){return new L(this,"KEYS")}set(t,e){if(typeof t!=="string")throw Error("key must be a string");return this._size=void 0,M(this._tree,t).set("",e),this}get size(){if(this._size)return this._size;this._size=0;let t=this.entries();while(!t.next().done)this._size+=1;return this._size}update(t,e){if(typeof t!=="string")throw Error("key must be a string");this._size=void 0;let s=M(this._tree,t);return s.set("",e(s.get(""))),this}fetch(t,e){if(typeof t!=="string")throw Error("key must be a string");this._size=void 0;let s=M(this._tree,t),n=s.get("");if(n===void 0)s.set("",n=e());return n}values(){return new L(this,"VALUES")}[Symbol.iterator](){return this.entries()}static from(t){let e=new w;for(let[s,n]of t)e.set(s,n);return e}static fromObject(t){return w.from(Object.entries(t))}}var E=(t,e,s=[])=>{if(e.length===0||t==null)return[t,s];for(let n of t.keys())if(n!==""&&e.startsWith(n))return s.push([t,n]),E(t.get(n),e.slice(n.length),s);return s.push([t,e]),E(void 0,"",s)},A=(t,e)=>{if(e.length===0||t==null)return t;for(let s of t.keys())if(s!==""&&e.startsWith(s))return A(t.get(s),e.slice(s.length))},M=(t,e)=>{let s=e.length;t:for(let n=0;t&&n<s;){for(let r of t.keys())if(r!==""&&e[n]===r[0]){let c=Math.min(s-n,r.length),o=1;while(o<c&&e[n+o]===r[o])++o;let u=t.get(r);if(o===r.length)t=u;else{let d=new Map;d.set(r.slice(o),u),t.set(e.slice(n,n+o),d),t.delete(r),t=d}n+=o;continue t}let i=new Map;return t.set(e.slice(n),i),i}return t},Z=(t,e)=>{let[s,n]=E(t,e);if(s===void 0)return;if(s.delete(""),s.size===0)Q(n);else if(s.size===1){let[i,r]=s.entries().next().value;B(n,i,r)}},Q=(t)=>{if(t.length===0)return;let[e,s]=R(t);if(e.delete(s),e.size===0)Q(t.slice(0,-1));else if(e.size===1){let[n,i]=e.entries().next().value;if(n!=="")B(t.slice(0,-1),n,i)}},B=(t,e,s)=>{if(t.length===0)return;let[n,i]=R(t);n.set(i+e,s),n.delete(i)},R=(t)=>t[t.length-1],N="or",K="and",H="and_not";class x{constructor(t){if((t===null||t===void 0?void 0:t.fields)==null)throw Error('MiniSearch: option "fields" must be provided');let e=t.autoVacuum==null||t.autoVacuum===!0?C:t.autoVacuum;this._options={...V,...t,autoVacuum:e,searchOptions:{...P,...t.searchOptions||{}},autoSuggestOptions:{...nt,...t.autoSuggestOptions||{}}},this._index=new w,this._documentCount=0,this._documentIds=new Map,this._idToShortId=new Map,this._fieldIds={},this._fieldLength=new Map,this._avgFieldLength=[],this._nextId=0,this._storedFields=new Map,this._dirtCount=0,this._currentVacuum=null,this._enqueuedVacuum=null,this._enqueuedVacuumConditions=D,this.addFields(this._options.fields)}add(t){let{extractField:e,stringifyField:s,tokenize:n,processTerm:i,fields:r,idField:c}=this._options,o=e(t,c);if(o==null)throw Error(`MiniSearch: document does not have ID field "${c}"`);if(this._idToShortId.has(o))throw Error(`MiniSearch: duplicate ID ${o}`);let u=this.addDocumentId(o);this.saveStoredFields(u,t);for(let d of r){let a=e(t,d);if(a==null)continue;let h=n(s(a,d),d),f=this._fieldIds[d],m=new Set(h).size;this.addFieldLength(u,f,this._documentCount-1,m);for(let g of h){let l=i(g,d);if(Array.isArray(l))for(let _ of l)this.addTerm(f,u,_);else if(l)this.addTerm(f,u,l)}}}addAll(t){for(let e of t)this.add(e)}addAllAsync(t,e={}){let{chunkSize:s=10}=e,n={chunk:[],promise:Promise.resolve()},{chunk:i,promise:r}=t.reduce(({chunk:c,promise:o},u,d)=>{if(c.push(u),(d+1)%s===0)return{chunk:[],promise:o.then(()=>new Promise((a)=>setTimeout(a,0))).then(()=>this.addAll(c))};else return{chunk:c,promise:o}},n);return r.then(()=>this.addAll(i))}remove(t){let{tokenize:e,processTerm:s,extractField:n,stringifyField:i,fields:r,idField:c}=this._options,o=n(t,c);if(o==null)throw Error(`MiniSearch: document does not have ID field "${c}"`);let u=this._idToShortId.get(o);if(u==null)throw Error(`MiniSearch: cannot remove document with ID ${o}: it is not in the index`);for(let d of r){let a=n(t,d);if(a==null)continue;let h=e(i(a,d),d),f=this._fieldIds[d],m=new Set(h).size;this.removeFieldLength(u,f,this._documentCount,m);for(let g of h){let l=s(g,d);if(Array.isArray(l))for(let _ of l)this.removeTerm(f,u,_);else if(l)this.removeTerm(f,u,l)}}this._storedFields.delete(u),this._documentIds.delete(u),this._idToShortId.delete(o),this._fieldLength.delete(u),this._documentCount-=1}removeAll(t){if(t)for(let e of t)this.remove(e);else if(arguments.length>0)throw Error("Expected documents to be present. Omit the argument to remove all documents.");else this._index=new w,this._documentCount=0,this._documentIds=new Map,this._idToShortId=new Map,this._fieldLength=new Map,this._avgFieldLength=[],this._storedFields=new Map,this._nextId=0}discard(t){let e=this._idToShortId.get(t);if(e==null)throw Error(`MiniSearch: cannot discard document with ID ${t}: it is not in the index`);this._idToShortId.delete(t),this._documentIds.delete(e),this._storedFields.delete(e),(this._fieldLength.get(e)||[]).forEach((s,n)=>{this.removeFieldLength(e,n,this._documentCount,s)}),this._fieldLength.delete(e),this._documentCount-=1,this._dirtCount+=1,this.maybeAutoVacuum()}maybeAutoVacuum(){if(this._options.autoVacuum===!1)return;let{minDirtFactor:t,minDirtCount:e,batchSize:s,batchWait:n}=this._options.autoVacuum;this.conditionalVacuum({batchSize:s,batchWait:n},{minDirtCount:e,minDirtFactor:t})}discardAll(t){let e=this._options.autoVacuum;try{this._options.autoVacuum=!1;for(let s of t)this.discard(s)}finally{this._options.autoVacuum=e}this.maybeAutoVacuum()}replace(t){let{idField:e,extractField:s}=this._options,n=s(t,e);this.discard(n),this.add(t)}vacuum(t={}){return this.conditionalVacuum(t)}conditionalVacuum(t,e){if(this._currentVacuum){if(this._enqueuedVacuumConditions=this._enqueuedVacuumConditions&&e,this._enqueuedVacuum!=null)return this._enqueuedVacuum;return this._enqueuedVacuum=this._currentVacuum.then(()=>{let s=this._enqueuedVacuumConditions;return this._enqueuedVacuumConditions=D,this.performVacuuming(t,s)}),this._enqueuedVacuum}if(this.vacuumConditionsMet(e)===!1)return Promise.resolve();return this._currentVacuum=this.performVacuuming(t),this._currentVacuum}async performVacuuming(t,e){let s=this._dirtCount;if(this.vacuumConditionsMet(e)){let n=t.batchSize||T.batchSize,i=t.batchWait||T.batchWait,r=1;for(let[c,o]of this._index){for(let[u,d]of o)for(let[a]of d){if(this._documentIds.has(a))continue;if(d.size<=1)o.delete(u);else d.delete(a)}if(this._index.get(c).size===0)this._index.delete(c);if(r%n===0)await new Promise((u)=>setTimeout(u,i));r+=1}this._dirtCount-=s}await null,this._currentVacuum=this._enqueuedVacuum,this._enqueuedVacuum=null}vacuumConditionsMet(t){if(t==null)return!0;let{minDirtCount:e,minDirtFactor:s}=t;return e=e||C.minDirtCount,s=s||C.minDirtFactor,this.dirtCount>=e&&this.dirtFactor>=s}get isVacuuming(){return this._currentVacuum!=null}get dirtCount(){return this._dirtCount}get dirtFactor(){return this._dirtCount/(1+this._documentCount+this._dirtCount)}has(t){return this._idToShortId.has(t)}getStoredFields(t){let e=this._idToShortId.get(t);if(e==null)return;return this._storedFields.get(e)}search(t,e={}){let{searchOptions:s}=this._options,n={...s,...e},i=this.executeQuery(t,e),r=[];for(let[c,{score:o,terms:u,match:d}]of i){let a=u.length||1,h={id:this._documentIds.get(c),score:o*a,terms:Object.keys(d),queryTerms:u,match:d};if(Object.assign(h,this._storedFields.get(c)),n.filter==null||n.filter(h))r.push(h)}if(t===x.wildcard&&n.boostDocument==null)return r;return r.sort(J),r}autoSuggest(t,e={}){e={...this._options.autoSuggestOptions,...e};let s=new Map;for(let{score:i,terms:r}of this.search(t,e)){let c=r.join(" "),o=s.get(c);if(o!=null)o.score+=i,o.count+=1;else s.set(c,{score:i,terms:r,count:1})}let n=[];for(let[i,{score:r,terms:c,count:o}]of s)n.push({suggestion:i,terms:c,score:r/o});return n.sort(J),n}get documentCount(){return this._documentCount}get termCount(){return this._index.size}static loadJSON(t,e){if(e==null)throw Error("MiniSearch: loadJSON should be given the same options used when serializing the index");return this.loadJS(JSON.parse(t),e)}static async loadJSONAsync(t,e){if(e==null)throw Error("MiniSearch: loadJSON should be given the same options used when serializing the index");return this.loadJSAsync(JSON.parse(t),e)}static getDefault(t){if(V.hasOwnProperty(t))return O(V,t);else throw Error(`MiniSearch: unknown option "${t}"`)}static loadJS(t,e){let{index:s,documentIds:n,fieldLength:i,storedFields:r,serializationVersion:c}=t,o=this.instantiateMiniSearch(t,e);o._documentIds=b(n),o._fieldLength=b(i),o._storedFields=b(r);for(let[u,d]of o._documentIds)o._idToShortId.set(d,u);for(let[u,d]of s){let a=new Map;for(let h of Object.keys(d)){let f=d[h];if(c===1)f=f.ds;a.set(parseInt(h,10),b(f))}o._index.set(u,a)}return o}static async loadJSAsync(t,e){let{index:s,documentIds:n,fieldLength:i,storedFields:r,serializationVersion:c}=t,o=this.instantiateMiniSearch(t,e);o._documentIds=await v(n),o._fieldLength=await v(i),o._storedFields=await v(r);for(let[d,a]of o._documentIds)o._idToShortId.set(a,d);let u=0;for(let[d,a]of s){let h=new Map;for(let f of Object.keys(a)){let m=a[f];if(c===1)m=m.ds;h.set(parseInt(f,10),await v(m))}if(++u%1000===0)await Y(0);o._index.set(d,h)}return o}static instantiateMiniSearch(t,e){let{documentCount:s,nextId:n,fieldIds:i,averageFieldLength:r,dirtCount:c,serializationVersion:o}=t;if(o!==1&&o!==2)throw Error("MiniSearch: cannot deserialize an index created with an incompatible version");let u=new x(e);return u._documentCount=s,u._nextId=n,u._idToShortId=new Map,u._fieldIds=i,u._avgFieldLength=r,u._dirtCount=c||0,u._index=new w,u}executeQuery(t,e={}){if(t===x.wildcard)return this.executeWildcardQuery(e);if(typeof t!=="string"){let h={...e,...t,queries:void 0},f=t.queries.map((m)=>this.executeQuery(m,h));return this.combineResults(f,h.combineWith)}let{tokenize:s,processTerm:n,searchOptions:i}=this._options,r={tokenize:s,processTerm:n,...i,...e},{tokenize:c,processTerm:o}=r,a=c(t).flatMap((h)=>o(h)).filter((h)=>!!h).map(st(r)).map((h)=>this.executeQuerySpec(h,r));return this.combineResults(a,r.combineWith)}executeQuerySpec(t,e){let s={...this._options.searchOptions,...e},n=(s.fields||this._options.fields).reduce((g,l)=>({...g,[l]:O(s.boost,l)||1}),{}),{boostDocument:i,weights:r,maxFuzzy:c,bm25:o}=s,{fuzzy:u,prefix:d}={...P.weights,...r},a=this._index.get(t.term),h=this.termResults(t.term,t.term,1,t.termBoost,a,n,i,o),f,m;if(t.prefix)f=this._index.atPrefix(t.term);if(t.fuzzy){let g=t.fuzzy===!0?0.2:t.fuzzy,l=g<1?Math.min(c,Math.round(t.term.length*g)):g;if(l)m=this._index.fuzzyGet(t.term,l)}if(f)for(let[g,l]of f){let _=g.length-t.term.length;if(!_)continue;m===null||m===void 0||m.delete(g);let F=d*g.length/(g.length+0.3*_);this.termResults(t.term,g,F,t.termBoost,l,n,i,o,h)}if(m)for(let g of m.keys()){let[l,_]=m.get(g);if(!_)continue;let F=u*g.length/(g.length+_);this.termResults(t.term,g,F,t.termBoost,l,n,i,o,h)}return h}executeWildcardQuery(t){let e=new Map,s={...this._options.searchOptions,...t};for(let[n,i]of this._documentIds){let r=s.boostDocument?s.boostDocument(i,"",this._storedFields.get(n)):1;e.set(n,{score:r,terms:[],match:{}})}return e}combineResults(t,e=N){if(t.length===0)return new Map;let s=e.toLowerCase(),n=X[s];if(!n)throw Error(`Invalid combination operator: ${e}`);return t.reduce(n)||new Map}toJSON(){let t=[];for(let[e,s]of this._index){let n={};for(let[i,r]of s)n[i]=Object.fromEntries(r);t.push([e,n])}return{documentCount:this._documentCount,nextId:this._nextId,documentIds:Object.fromEntries(this._documentIds),fieldIds:this._fieldIds,fieldLength:Object.fromEntries(this._fieldLength),averageFieldLength:this._avgFieldLength,storedFields:Object.fromEntries(this._storedFields),dirtCount:this._dirtCount,index:t,serializationVersion:2}}termResults(t,e,s,n,i,r,c,o,u=new Map){if(i==null)return u;for(let d of Object.keys(r)){let a=r[d],h=this._fieldIds[d],f=i.get(h);if(f==null)continue;let m=f.size,g=this._avgFieldLength[h];for(let l of f.keys()){if(!this._documentIds.has(l)){this.removeTerm(h,l,e),m-=1;continue}let _=c?c(this._documentIds.get(l),e,this._storedFields.get(l)):1;if(!_)continue;let F=f.get(l),p=this._fieldLength.get(l)[h],k=et(F,m,this._documentCount,p,g,o),S=s*n*a*_*k,y=u.get(l);if(y){y.score+=S,it(y.terms,t);let I=O(y.match,e);if(I)I.push(d);else y.match[e]=[d]}else u.set(l,{score:S,terms:[t],match:{[e]:[d]}})}}return u}addTerm(t,e,s){let n=this._index.fetch(s,q),i=n.get(t);if(i==null)i=new Map,i.set(e,1),n.set(t,i);else{let r=i.get(e);i.set(e,(r||0)+1)}}removeTerm(t,e,s){if(!this._index.has(s)){this.warnDocumentChanged(e,t,s);return}let n=this._index.fetch(s,q),i=n.get(t);if(i==null||i.get(e)==null)this.warnDocumentChanged(e,t,s);else if(i.get(e)<=1)if(i.size<=1)n.delete(t);else i.delete(e);else i.set(e,i.get(e)-1);if(this._index.get(s).size===0)this._index.delete(s)}warnDocumentChanged(t,e,s){for(let n of Object.keys(this._fieldIds))if(this._fieldIds[n]===e){this._options.logger("warn",`MiniSearch: document with ID ${this._documentIds.get(t)} has changed before removal: term "${s}" was not present in field "${n}". Removing a document after it has changed can corrupt the index!`,"version_conflict");return}}addDocumentId(t){let e=this._nextId;return this._idToShortId.set(t,e),this._documentIds.set(e,t),this._documentCount+=1,this._nextId+=1,e}addFields(t){for(let e=0;e<t.length;e++)this._fieldIds[t[e]]=e}addFieldLength(t,e,s,n){let i=this._fieldLength.get(t);if(i==null)this._fieldLength.set(t,i=[]);i[e]=n;let c=(this._avgFieldLength[e]||0)*s+n;this._avgFieldLength[e]=c/(s+1)}removeFieldLength(t,e,s,n){if(s===1){this._avgFieldLength[e]=0;return}let i=this._avgFieldLength[e]*s-n;this._avgFieldLength[e]=i/(s-1)}saveStoredFields(t,e){let{storeFields:s,extractField:n}=this._options;if(s==null||s.length===0)return;let i=this._storedFields.get(t);if(i==null)this._storedFields.set(t,i={});for(let r of s){let c=n(e,r);if(c!==void 0)i[r]=c}}}x.wildcard=Symbol("*");var O=(t,e)=>Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0,X={[N]:(t,e)=>{for(let s of e.keys()){let n=t.get(s);if(n==null)t.set(s,e.get(s));else{let{score:i,terms:r,match:c}=e.get(s);n.score=n.score+i,n.match=Object.assign(n.match,c),W(n.terms,r)}}return t},[K]:(t,e)=>{let s=new Map;for(let n of e.keys()){let i=t.get(n);if(i==null)continue;let{score:r,terms:c,match:o}=e.get(n);W(i.terms,c),s.set(n,{score:i.score+r,terms:i.terms,match:Object.assign(i.match,o)})}return s},[H]:(t,e)=>{for(let s of e.keys())t.delete(s);return t}},tt={k:1.2,b:0.7,d:0.5},et=(t,e,s,n,i,r)=>{let{k:c,b:o,d:u}=r;return Math.log(1+(s-e+0.5)/(e+0.5))*(u+t*(c+1)/(t+c*(1-o+o*n/i)))},st=(t)=>(e,s,n)=>{let i=typeof t.fuzzy==="function"?t.fuzzy(e,s,n):t.fuzzy||!1,r=typeof t.prefix==="function"?t.prefix(e,s,n):t.prefix===!0,c=typeof t.boostTerm==="function"?t.boostTerm(e,s,n):1;return{term:e,fuzzy:i,prefix:r,termBoost:c}},V={idField:"id",extractField:(t,e)=>t[e],stringifyField:(t,e)=>t.toString(),tokenize:(t)=>t.split(ot),processTerm:(t)=>t.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(t,e)=>{if(typeof(console===null||console===void 0?void 0:console[t])==="function")console[t](e)},autoVacuum:!0},P={combineWith:N,prefix:!1,fuzzy:!1,maxFuzzy:6,boost:{},weights:{fuzzy:0.45,prefix:0.375},bm25:tt},nt={combineWith:K,prefix:(t,e,s)=>e===s.length-1},T={batchSize:1000,batchWait:10},D={minDirtFactor:0.1,minDirtCount:20},C={...T,...D},it=(t,e)=>{if(!t.includes(e))t.push(e)},W=(t,e)=>{for(let s of e)if(!t.includes(s))t.push(s)},J=({score:t},{score:e})=>e-t,q=()=>new Map,b=(t)=>{let e=new Map;for(let s of Object.keys(t))e.set(parseInt(s,10),t[s]);return e},v=async(t)=>{let e=new Map,s=0;for(let n of Object.keys(t))if(e.set(parseInt(n,10),t[n]),++s%1000===0)await Y(0);return e},Y=(t)=>new Promise((e)=>setTimeout(e,t)),ot=/[\n\r\p{Z}\p{P}]+/u;var rt=new Set(("a an and are as at be but by can do does for from how i if in is it its me my of on or so that the their them then there these this to was what when where which who why will with you your au aux avec ce ces comment dans de des du elle en est et il je la le les leur ma mais me mes "+"mon ne nous on ou où par pas pour qu que quel quelle quels qui sa se ses son sont sur ta te tu "+"un une vos votre vous y").split(" ")),ct=0.05,ut=(t)=>t.normalize("NFD").replace(/\p{M}/gu,"").toLowerCase();function dt(t){return t.chunks.map((e)=>{let s=t.docs[e.doc];return{...e,url:s?.url??"",title:s?.title??""}})}function It(t){let e=dt(t),s=new x({fields:["title","heading","text"],processTerm:(n)=>{let i=ut(n);return i.length<2||rt.has(i)?null:i},searchOptions:{prefix:(n)=>n.length>3,fuzzy:(n)=>n.length>4?0.15:0,boost:{title:2,heading:1.5}}});return s.addAll(e.map((n,i)=>({id:i,title:n.title,heading:n.heading,text:n.text}))),{async search(n,{limit:i=6,budgetTokens:r=3000}={}){let c=[],o=0,u=s.search(n,{combineWith:"OR"}),d=(u[0]?.score??0)*ct;for(let a of u){if(a.score<d)break;let h=e[Number(a.id)];if(!h)continue;let f=Ye(h.text)+24;if(o+f>r)continue;if(o+=f,c.push(h),c.length>=i)break}return c}}}
|
|
2
|
-
export{
|
|
1
|
+
import{Ye}from"./embed-n5nzhrf2.js";class L{constructor(t,e){let s=t._tree,n=Array.from(s.keys());this.set=t,this._type=e,this._path=n.length>0?[{node:s,keys:n}]:[]}next(){let t=this.dive();return this.backtrack(),t}dive(){if(this._path.length===0)return{done:!0,value:void 0};let{node:t,keys:e}=z(this._path);if(z(e)==="")return{done:!1,value:this.result()};let s=t.get(z(e));return this._path.push({node:s,keys:Array.from(s.keys())}),this.dive()}backtrack(){if(this._path.length===0)return;let t=z(this._path).keys;if(t.pop(),t.length>0)return;this._path.pop(),this.backtrack()}key(){return this.set._prefix+this._path.map(({keys:t})=>z(t)).filter((t)=>t!=="").join("")}value(){return z(this._path).node.get("")}result(){switch(this._type){case"VALUES":return this.value();case"KEYS":return this.key();default:return[this.key(),this.value()]}}[Symbol.iterator](){return this}}var z=(t)=>t[t.length-1],G=(t,e,s)=>{let n=new Map;if(e===void 0)return n;let i=e.length+1,r=i+s,c=new Uint8Array(r*i).fill(s+1);for(let o=0;o<i;++o)c[o]=o;for(let o=1;o<r;++o)c[o*i]=o;return U(t,e,s,n,c,1,i,""),n},U=(t,e,s,n,i,r,c,o)=>{let u=r*c;t:for(let d of t.keys())if(d===""){let a=i[u-1];if(a<=s)n.set(o,[t.get(d),a])}else{let a=r;for(let h=0;h<d.length;++h,++a){let f=d[h],m=c*a,g=m-c,l=i[m],_=Math.max(0,a-s-1),F=Math.min(c-1,a+s);for(let p=_;p<F;++p){let k=f!==e[p],S=i[g+p]+ +k,y=i[g+p+1]+1,I=i[m+p]+1,j=i[m+p+1]=Math.min(S,y,I);if(j<l)l=j}if(l>s)continue t}U(t.get(d),e,s,n,i,a,c,o+d)}};class w{constructor(t=new Map,e=""){this._size=void 0,this._tree=t,this._prefix=e}atPrefix(t){if(!t.startsWith(this._prefix))throw Error("Mismatched prefix");let[e,s]=E(this._tree,t.slice(this._prefix.length));if(e===void 0){let[n,i]=R(s);for(let r of n.keys())if(r!==""&&r.startsWith(i)){let c=new Map;return c.set(r.slice(i.length),n.get(r)),new w(c,t)}}return new w(e,t)}clear(){this._size=void 0,this._tree.clear()}delete(t){return this._size=void 0,Z(this._tree,t)}entries(){return new L(this,"ENTRIES")}forEach(t){for(let[e,s]of this)t(e,s,this)}fuzzyGet(t,e){return G(this._tree,t,e)}get(t){let e=A(this._tree,t);return e!==void 0?e.get(""):void 0}has(t){let e=A(this._tree,t);return e!==void 0&&e.has("")}keys(){return new L(this,"KEYS")}set(t,e){if(typeof t!=="string")throw Error("key must be a string");return this._size=void 0,M(this._tree,t).set("",e),this}get size(){if(this._size)return this._size;this._size=0;let t=this.entries();while(!t.next().done)this._size+=1;return this._size}update(t,e){if(typeof t!=="string")throw Error("key must be a string");this._size=void 0;let s=M(this._tree,t);return s.set("",e(s.get(""))),this}fetch(t,e){if(typeof t!=="string")throw Error("key must be a string");this._size=void 0;let s=M(this._tree,t),n=s.get("");if(n===void 0)s.set("",n=e());return n}values(){return new L(this,"VALUES")}[Symbol.iterator](){return this.entries()}static from(t){let e=new w;for(let[s,n]of t)e.set(s,n);return e}static fromObject(t){return w.from(Object.entries(t))}}var E=(t,e,s=[])=>{if(e.length===0||t==null)return[t,s];for(let n of t.keys())if(n!==""&&e.startsWith(n))return s.push([t,n]),E(t.get(n),e.slice(n.length),s);return s.push([t,e]),E(void 0,"",s)},A=(t,e)=>{if(e.length===0||t==null)return t;for(let s of t.keys())if(s!==""&&e.startsWith(s))return A(t.get(s),e.slice(s.length))},M=(t,e)=>{let s=e.length;t:for(let n=0;t&&n<s;){for(let r of t.keys())if(r!==""&&e[n]===r[0]){let c=Math.min(s-n,r.length),o=1;while(o<c&&e[n+o]===r[o])++o;let u=t.get(r);if(o===r.length)t=u;else{let d=new Map;d.set(r.slice(o),u),t.set(e.slice(n,n+o),d),t.delete(r),t=d}n+=o;continue t}let i=new Map;return t.set(e.slice(n),i),i}return t},Z=(t,e)=>{let[s,n]=E(t,e);if(s===void 0)return;if(s.delete(""),s.size===0)Q(n);else if(s.size===1){let[i,r]=s.entries().next().value;B(n,i,r)}},Q=(t)=>{if(t.length===0)return;let[e,s]=R(t);if(e.delete(s),e.size===0)Q(t.slice(0,-1));else if(e.size===1){let[n,i]=e.entries().next().value;if(n!=="")B(t.slice(0,-1),n,i)}},B=(t,e,s)=>{if(t.length===0)return;let[n,i]=R(t);n.set(i+e,s),n.delete(i)},R=(t)=>t[t.length-1],N="or",K="and",H="and_not";class x{constructor(t){if((t===null||t===void 0?void 0:t.fields)==null)throw Error('MiniSearch: option "fields" must be provided');let e=t.autoVacuum==null||t.autoVacuum===!0?C:t.autoVacuum;this._options={...V,...t,autoVacuum:e,searchOptions:{...P,...t.searchOptions||{}},autoSuggestOptions:{...nt,...t.autoSuggestOptions||{}}},this._index=new w,this._documentCount=0,this._documentIds=new Map,this._idToShortId=new Map,this._fieldIds={},this._fieldLength=new Map,this._avgFieldLength=[],this._nextId=0,this._storedFields=new Map,this._dirtCount=0,this._currentVacuum=null,this._enqueuedVacuum=null,this._enqueuedVacuumConditions=D,this.addFields(this._options.fields)}add(t){let{extractField:e,stringifyField:s,tokenize:n,processTerm:i,fields:r,idField:c}=this._options,o=e(t,c);if(o==null)throw Error(`MiniSearch: document does not have ID field "${c}"`);if(this._idToShortId.has(o))throw Error(`MiniSearch: duplicate ID ${o}`);let u=this.addDocumentId(o);this.saveStoredFields(u,t);for(let d of r){let a=e(t,d);if(a==null)continue;let h=n(s(a,d),d),f=this._fieldIds[d],m=new Set(h).size;this.addFieldLength(u,f,this._documentCount-1,m);for(let g of h){let l=i(g,d);if(Array.isArray(l))for(let _ of l)this.addTerm(f,u,_);else if(l)this.addTerm(f,u,l)}}}addAll(t){for(let e of t)this.add(e)}addAllAsync(t,e={}){let{chunkSize:s=10}=e,n={chunk:[],promise:Promise.resolve()},{chunk:i,promise:r}=t.reduce(({chunk:c,promise:o},u,d)=>{if(c.push(u),(d+1)%s===0)return{chunk:[],promise:o.then(()=>new Promise((a)=>setTimeout(a,0))).then(()=>this.addAll(c))};else return{chunk:c,promise:o}},n);return r.then(()=>this.addAll(i))}remove(t){let{tokenize:e,processTerm:s,extractField:n,stringifyField:i,fields:r,idField:c}=this._options,o=n(t,c);if(o==null)throw Error(`MiniSearch: document does not have ID field "${c}"`);let u=this._idToShortId.get(o);if(u==null)throw Error(`MiniSearch: cannot remove document with ID ${o}: it is not in the index`);for(let d of r){let a=n(t,d);if(a==null)continue;let h=e(i(a,d),d),f=this._fieldIds[d],m=new Set(h).size;this.removeFieldLength(u,f,this._documentCount,m);for(let g of h){let l=s(g,d);if(Array.isArray(l))for(let _ of l)this.removeTerm(f,u,_);else if(l)this.removeTerm(f,u,l)}}this._storedFields.delete(u),this._documentIds.delete(u),this._idToShortId.delete(o),this._fieldLength.delete(u),this._documentCount-=1}removeAll(t){if(t)for(let e of t)this.remove(e);else if(arguments.length>0)throw Error("Expected documents to be present. Omit the argument to remove all documents.");else this._index=new w,this._documentCount=0,this._documentIds=new Map,this._idToShortId=new Map,this._fieldLength=new Map,this._avgFieldLength=[],this._storedFields=new Map,this._nextId=0}discard(t){let e=this._idToShortId.get(t);if(e==null)throw Error(`MiniSearch: cannot discard document with ID ${t}: it is not in the index`);this._idToShortId.delete(t),this._documentIds.delete(e),this._storedFields.delete(e),(this._fieldLength.get(e)||[]).forEach((s,n)=>{this.removeFieldLength(e,n,this._documentCount,s)}),this._fieldLength.delete(e),this._documentCount-=1,this._dirtCount+=1,this.maybeAutoVacuum()}maybeAutoVacuum(){if(this._options.autoVacuum===!1)return;let{minDirtFactor:t,minDirtCount:e,batchSize:s,batchWait:n}=this._options.autoVacuum;this.conditionalVacuum({batchSize:s,batchWait:n},{minDirtCount:e,minDirtFactor:t})}discardAll(t){let e=this._options.autoVacuum;try{this._options.autoVacuum=!1;for(let s of t)this.discard(s)}finally{this._options.autoVacuum=e}this.maybeAutoVacuum()}replace(t){let{idField:e,extractField:s}=this._options,n=s(t,e);this.discard(n),this.add(t)}vacuum(t={}){return this.conditionalVacuum(t)}conditionalVacuum(t,e){if(this._currentVacuum){if(this._enqueuedVacuumConditions=this._enqueuedVacuumConditions&&e,this._enqueuedVacuum!=null)return this._enqueuedVacuum;return this._enqueuedVacuum=this._currentVacuum.then(()=>{let s=this._enqueuedVacuumConditions;return this._enqueuedVacuumConditions=D,this.performVacuuming(t,s)}),this._enqueuedVacuum}if(this.vacuumConditionsMet(e)===!1)return Promise.resolve();return this._currentVacuum=this.performVacuuming(t),this._currentVacuum}async performVacuuming(t,e){let s=this._dirtCount;if(this.vacuumConditionsMet(e)){let n=t.batchSize||T.batchSize,i=t.batchWait||T.batchWait,r=1;for(let[c,o]of this._index){for(let[u,d]of o)for(let[a]of d){if(this._documentIds.has(a))continue;if(d.size<=1)o.delete(u);else d.delete(a)}if(this._index.get(c).size===0)this._index.delete(c);if(r%n===0)await new Promise((u)=>setTimeout(u,i));r+=1}this._dirtCount-=s}await null,this._currentVacuum=this._enqueuedVacuum,this._enqueuedVacuum=null}vacuumConditionsMet(t){if(t==null)return!0;let{minDirtCount:e,minDirtFactor:s}=t;return e=e||C.minDirtCount,s=s||C.minDirtFactor,this.dirtCount>=e&&this.dirtFactor>=s}get isVacuuming(){return this._currentVacuum!=null}get dirtCount(){return this._dirtCount}get dirtFactor(){return this._dirtCount/(1+this._documentCount+this._dirtCount)}has(t){return this._idToShortId.has(t)}getStoredFields(t){let e=this._idToShortId.get(t);if(e==null)return;return this._storedFields.get(e)}search(t,e={}){let{searchOptions:s}=this._options,n={...s,...e},i=this.executeQuery(t,e),r=[];for(let[c,{score:o,terms:u,match:d}]of i){let a=u.length||1,h={id:this._documentIds.get(c),score:o*a,terms:Object.keys(d),queryTerms:u,match:d};if(Object.assign(h,this._storedFields.get(c)),n.filter==null||n.filter(h))r.push(h)}if(t===x.wildcard&&n.boostDocument==null)return r;return r.sort(J),r}autoSuggest(t,e={}){e={...this._options.autoSuggestOptions,...e};let s=new Map;for(let{score:i,terms:r}of this.search(t,e)){let c=r.join(" "),o=s.get(c);if(o!=null)o.score+=i,o.count+=1;else s.set(c,{score:i,terms:r,count:1})}let n=[];for(let[i,{score:r,terms:c,count:o}]of s)n.push({suggestion:i,terms:c,score:r/o});return n.sort(J),n}get documentCount(){return this._documentCount}get termCount(){return this._index.size}static loadJSON(t,e){if(e==null)throw Error("MiniSearch: loadJSON should be given the same options used when serializing the index");return this.loadJS(JSON.parse(t),e)}static async loadJSONAsync(t,e){if(e==null)throw Error("MiniSearch: loadJSON should be given the same options used when serializing the index");return this.loadJSAsync(JSON.parse(t),e)}static getDefault(t){if(V.hasOwnProperty(t))return O(V,t);else throw Error(`MiniSearch: unknown option "${t}"`)}static loadJS(t,e){let{index:s,documentIds:n,fieldLength:i,storedFields:r,serializationVersion:c}=t,o=this.instantiateMiniSearch(t,e);o._documentIds=b(n),o._fieldLength=b(i),o._storedFields=b(r);for(let[u,d]of o._documentIds)o._idToShortId.set(d,u);for(let[u,d]of s){let a=new Map;for(let h of Object.keys(d)){let f=d[h];if(c===1)f=f.ds;a.set(parseInt(h,10),b(f))}o._index.set(u,a)}return o}static async loadJSAsync(t,e){let{index:s,documentIds:n,fieldLength:i,storedFields:r,serializationVersion:c}=t,o=this.instantiateMiniSearch(t,e);o._documentIds=await v(n),o._fieldLength=await v(i),o._storedFields=await v(r);for(let[d,a]of o._documentIds)o._idToShortId.set(a,d);let u=0;for(let[d,a]of s){let h=new Map;for(let f of Object.keys(a)){let m=a[f];if(c===1)m=m.ds;h.set(parseInt(f,10),await v(m))}if(++u%1000===0)await Y(0);o._index.set(d,h)}return o}static instantiateMiniSearch(t,e){let{documentCount:s,nextId:n,fieldIds:i,averageFieldLength:r,dirtCount:c,serializationVersion:o}=t;if(o!==1&&o!==2)throw Error("MiniSearch: cannot deserialize an index created with an incompatible version");let u=new x(e);return u._documentCount=s,u._nextId=n,u._idToShortId=new Map,u._fieldIds=i,u._avgFieldLength=r,u._dirtCount=c||0,u._index=new w,u}executeQuery(t,e={}){if(t===x.wildcard)return this.executeWildcardQuery(e);if(typeof t!=="string"){let h={...e,...t,queries:void 0},f=t.queries.map((m)=>this.executeQuery(m,h));return this.combineResults(f,h.combineWith)}let{tokenize:s,processTerm:n,searchOptions:i}=this._options,r={tokenize:s,processTerm:n,...i,...e},{tokenize:c,processTerm:o}=r,a=c(t).flatMap((h)=>o(h)).filter((h)=>!!h).map(st(r)).map((h)=>this.executeQuerySpec(h,r));return this.combineResults(a,r.combineWith)}executeQuerySpec(t,e){let s={...this._options.searchOptions,...e},n=(s.fields||this._options.fields).reduce((g,l)=>({...g,[l]:O(s.boost,l)||1}),{}),{boostDocument:i,weights:r,maxFuzzy:c,bm25:o}=s,{fuzzy:u,prefix:d}={...P.weights,...r},a=this._index.get(t.term),h=this.termResults(t.term,t.term,1,t.termBoost,a,n,i,o),f,m;if(t.prefix)f=this._index.atPrefix(t.term);if(t.fuzzy){let g=t.fuzzy===!0?0.2:t.fuzzy,l=g<1?Math.min(c,Math.round(t.term.length*g)):g;if(l)m=this._index.fuzzyGet(t.term,l)}if(f)for(let[g,l]of f){let _=g.length-t.term.length;if(!_)continue;m===null||m===void 0||m.delete(g);let F=d*g.length/(g.length+0.3*_);this.termResults(t.term,g,F,t.termBoost,l,n,i,o,h)}if(m)for(let g of m.keys()){let[l,_]=m.get(g);if(!_)continue;let F=u*g.length/(g.length+_);this.termResults(t.term,g,F,t.termBoost,l,n,i,o,h)}return h}executeWildcardQuery(t){let e=new Map,s={...this._options.searchOptions,...t};for(let[n,i]of this._documentIds){let r=s.boostDocument?s.boostDocument(i,"",this._storedFields.get(n)):1;e.set(n,{score:r,terms:[],match:{}})}return e}combineResults(t,e=N){if(t.length===0)return new Map;let s=e.toLowerCase(),n=X[s];if(!n)throw Error(`Invalid combination operator: ${e}`);return t.reduce(n)||new Map}toJSON(){let t=[];for(let[e,s]of this._index){let n={};for(let[i,r]of s)n[i]=Object.fromEntries(r);t.push([e,n])}return{documentCount:this._documentCount,nextId:this._nextId,documentIds:Object.fromEntries(this._documentIds),fieldIds:this._fieldIds,fieldLength:Object.fromEntries(this._fieldLength),averageFieldLength:this._avgFieldLength,storedFields:Object.fromEntries(this._storedFields),dirtCount:this._dirtCount,index:t,serializationVersion:2}}termResults(t,e,s,n,i,r,c,o,u=new Map){if(i==null)return u;for(let d of Object.keys(r)){let a=r[d],h=this._fieldIds[d],f=i.get(h);if(f==null)continue;let m=f.size,g=this._avgFieldLength[h];for(let l of f.keys()){if(!this._documentIds.has(l)){this.removeTerm(h,l,e),m-=1;continue}let _=c?c(this._documentIds.get(l),e,this._storedFields.get(l)):1;if(!_)continue;let F=f.get(l),p=this._fieldLength.get(l)[h],k=et(F,m,this._documentCount,p,g,o),S=s*n*a*_*k,y=u.get(l);if(y){y.score+=S,it(y.terms,t);let I=O(y.match,e);if(I)I.push(d);else y.match[e]=[d]}else u.set(l,{score:S,terms:[t],match:{[e]:[d]}})}}return u}addTerm(t,e,s){let n=this._index.fetch(s,q),i=n.get(t);if(i==null)i=new Map,i.set(e,1),n.set(t,i);else{let r=i.get(e);i.set(e,(r||0)+1)}}removeTerm(t,e,s){if(!this._index.has(s)){this.warnDocumentChanged(e,t,s);return}let n=this._index.fetch(s,q),i=n.get(t);if(i==null||i.get(e)==null)this.warnDocumentChanged(e,t,s);else if(i.get(e)<=1)if(i.size<=1)n.delete(t);else i.delete(e);else i.set(e,i.get(e)-1);if(this._index.get(s).size===0)this._index.delete(s)}warnDocumentChanged(t,e,s){for(let n of Object.keys(this._fieldIds))if(this._fieldIds[n]===e){this._options.logger("warn",`MiniSearch: document with ID ${this._documentIds.get(t)} has changed before removal: term "${s}" was not present in field "${n}". Removing a document after it has changed can corrupt the index!`,"version_conflict");return}}addDocumentId(t){let e=this._nextId;return this._idToShortId.set(t,e),this._documentIds.set(e,t),this._documentCount+=1,this._nextId+=1,e}addFields(t){for(let e=0;e<t.length;e++)this._fieldIds[t[e]]=e}addFieldLength(t,e,s,n){let i=this._fieldLength.get(t);if(i==null)this._fieldLength.set(t,i=[]);i[e]=n;let c=(this._avgFieldLength[e]||0)*s+n;this._avgFieldLength[e]=c/(s+1)}removeFieldLength(t,e,s,n){if(s===1){this._avgFieldLength[e]=0;return}let i=this._avgFieldLength[e]*s-n;this._avgFieldLength[e]=i/(s-1)}saveStoredFields(t,e){let{storeFields:s,extractField:n}=this._options;if(s==null||s.length===0)return;let i=this._storedFields.get(t);if(i==null)this._storedFields.set(t,i={});for(let r of s){let c=n(e,r);if(c!==void 0)i[r]=c}}}x.wildcard=Symbol("*");var O=(t,e)=>Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0,X={[N]:(t,e)=>{for(let s of e.keys()){let n=t.get(s);if(n==null)t.set(s,e.get(s));else{let{score:i,terms:r,match:c}=e.get(s);n.score=n.score+i,n.match=Object.assign(n.match,c),W(n.terms,r)}}return t},[K]:(t,e)=>{let s=new Map;for(let n of e.keys()){let i=t.get(n);if(i==null)continue;let{score:r,terms:c,match:o}=e.get(n);W(i.terms,c),s.set(n,{score:i.score+r,terms:i.terms,match:Object.assign(i.match,o)})}return s},[H]:(t,e)=>{for(let s of e.keys())t.delete(s);return t}},tt={k:1.2,b:0.7,d:0.5},et=(t,e,s,n,i,r)=>{let{k:c,b:o,d:u}=r;return Math.log(1+(s-e+0.5)/(e+0.5))*(u+t*(c+1)/(t+c*(1-o+o*n/i)))},st=(t)=>(e,s,n)=>{let i=typeof t.fuzzy==="function"?t.fuzzy(e,s,n):t.fuzzy||!1,r=typeof t.prefix==="function"?t.prefix(e,s,n):t.prefix===!0,c=typeof t.boostTerm==="function"?t.boostTerm(e,s,n):1;return{term:e,fuzzy:i,prefix:r,termBoost:c}},V={idField:"id",extractField:(t,e)=>t[e],stringifyField:(t,e)=>t.toString(),tokenize:(t)=>t.split(ot),processTerm:(t)=>t.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(t,e)=>{if(typeof(console===null||console===void 0?void 0:console[t])==="function")console[t](e)},autoVacuum:!0},P={combineWith:N,prefix:!1,fuzzy:!1,maxFuzzy:6,boost:{},weights:{fuzzy:0.45,prefix:0.375},bm25:tt},nt={combineWith:K,prefix:(t,e,s)=>e===s.length-1},T={batchSize:1000,batchWait:10},D={minDirtFactor:0.1,minDirtCount:20},C={...T,...D},it=(t,e)=>{if(!t.includes(e))t.push(e)},W=(t,e)=>{for(let s of e)if(!t.includes(s))t.push(s)},J=({score:t},{score:e})=>e-t,q=()=>new Map,b=(t)=>{let e=new Map;for(let s of Object.keys(t))e.set(parseInt(s,10),t[s]);return e},v=async(t)=>{let e=new Map,s=0;for(let n of Object.keys(t))if(e.set(parseInt(n,10),t[n]),++s%1000===0)await Y(0);return e},Y=(t)=>new Promise((e)=>setTimeout(e,t)),ot=/[\n\r\p{Z}\p{P}]+/u;var rt=new Set(("a an and are as at be but by can do does for from how i if in is it its me my of on or so that the their them then there these this to was what when where which who why will with you your au aux avec ce ces comment dans de des du elle en est et il je la le les leur ma mais me mes "+"mon ne nous on ou où par pas pour qu que quel quelle quels qui sa se ses son sont sur ta te tu "+"un une vos votre vous y").split(" ")),ct=0.05,ut=(t)=>t.normalize("NFD").replace(/\p{M}/gu,"").toLowerCase();function dt(t){return t.chunks.map((e)=>{let s=t.docs[e.doc];return{...e,url:s?.url??"",title:s?.title??""}})}function Mt(t){let e=dt(t),s=new x({fields:["title","heading","text"],processTerm:(n)=>{let i=ut(n);return i.length<2||rt.has(i)?null:i},searchOptions:{prefix:(n)=>n.length>3,fuzzy:(n)=>n.length>4?0.15:0,boost:{title:2,heading:1.5}}});return s.addAll(e.map((n,i)=>({id:i,title:n.title,heading:n.heading,text:n.text}))),{async search(n,{limit:i=6,budgetTokens:r=3000}={}){let c=[],o=0,u=s.search(n,{combineWith:"OR"}),d=(u[0]?.score??0)*ct;for(let a of u){if(a.score<d)break;let h=e[Number(a.id)];if(!h)continue;let f=Ye(h.text)+24;if(o+f>r)continue;if(o+=f,c.push(h),c.length>=i)break}return c}}}
|
|
2
|
+
export{Mt};
|