8 lines
4.2 KiB
JavaScript
8 lines
4.2 KiB
JavaScript
/**
|
|
* Bundled by jsDelivr using Rollup v2.79.2 and Terser v5.37.0.
|
|
* Original file: /npm/@orama/plugin-pt15@3.0.8/dist/index.js
|
|
*
|
|
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
|
|
*/
|
|
import{index as e,isVectorType as r,getVectorSize as t}from"./components.js";import{vector as n,bkd as o,flat as s,avl as i,bool as a}from"./trees.js";function l(){return Object.create(null)}function c(e,f,u){for(let[h,p]of Object.entries(f)){let f=`${u}${u?".":""}${h}`;if("object"!=typeof p||Array.isArray(p))if(r(p))e.searchableProperties.push(f),e.searchablePropertiesWithTypes[f]=p,e.vectorIndexes[f]={type:"Vector",node:new n.VectorIndex(t(p)),isArray:!1};else{let r=/\[/.test(p);switch(p){case"boolean":case"boolean[]":e.indexes[f]={type:"Bool",node:new a.BoolNode,isArray:r};break;case"number":case"number[]":e.indexes[f]={type:"AVL",node:new i.AVLTree(0,[]),isArray:r};break;case"string":case"string[]":e.indexes[f]={type:"Position",node:[l(),l(),l(),l(),l(),l(),l(),l(),l(),l(),l(),l(),l(),l(),l()],isArray:r};break;case"enum":case"enum[]":e.indexes[f]={type:"Flat",node:new s.FlatTree,isArray:r};break;case"geopoint":e.indexes[f]={type:"BKD",node:new o.BKDTree,isArray:r};break;default:throw new Error("INVALID_SCHEMA_TYPE: "+f)}e.searchableProperties.push(f),e.searchablePropertiesWithTypes[f]=p}else c(e,p,f)}}function f(e,r,t,n,o,s){let i=s.tokenize(e,o,t),a=i.length;for(let e=0;e<a;e++){let t=i[e],o=r[15-u(e,a)-1];for(let e=t.length;e>0;e--){let r=t.slice(0,e);o[r]=o[r]||[],o[r].push(n)}}}function u(e,r){return r<15?e:Math.floor(15*e/r)}function h(e,r,t,n,o){let s=e.tokenize(r),i=new Map;for(let e of s)for(let r=0;r<15;r++){let s=t[r];if(s[e]){let t=s[e],a=t.length;for(let e=0;e<a;e++){if(o&&!o.has(t[e]))continue;let s=t[e];i.has(s)?i.set(s,i.get(s)+r*n):i.set(s,r*n)}}}return i}function p(e,r,t,n,o,s){let i=o.tokenize(e,s,t),a=i.length;for(let e=0;e<a;e++){let t=i[e],o=r[15-u(e,a)-1];for(let e=t.length;e>0;e--){let r=o[t.slice(0,e)];if(r){let e=r.indexOf(n);-1!==e&&r.splice(e,1)}}}}function d(){return{name:"orama-plugin-pt15",getComponents:function(r){return t=r,{index:{create:function(){let e={indexes:{},vectorIndexes:{},searchableProperties:[],searchablePropertiesWithTypes:{}};return c(e,t,""),e},insert:function(r,t,n,o,s,i,a,l,c,u){if("string"!==a&&"string[]"!==a)return e.insert(r,t,n,o,s,i,a,l,c,u);let h=t.indexes[n].node;if(Array.isArray(i))for(let e of i)f(e,h,n,s,l,c);else f(i,h,n,s,l,c)},remove:function(r,t,n,o,s,i,a,l,c,f){if("string"!==a&&"string[]"!==a)return e.remove(r,t,n,o,s,i,a,l,c,f);let u=t.indexes[n].node;if(Array.isArray(i))for(let e of i)p(e,u,n,s,c,l);else p(i,u,n,s,c,l);return!0},insertDocumentScoreParameters:()=>{throw new Error},insertTokenScoreParameters:()=>{throw new Error},removeDocumentScoreParameters:()=>{throw new Error},removeTokenScoreParameters:()=>{throw new Error},calculateResultScores:()=>{throw new Error},search:function(e,r,t,n,o,s,i,a,l,c,f){if(0!==i)throw new Error("Tolerance not implemented yet");if(!0===s)throw new Error("Exact not implemented yet");let u=[],p=o.length,d={score:-1/0,id:-1};for(let n=0;n<p;n++){let s=o[n],i=h(t,r,e.indexes[s].node,a[s]??1,f);i.size>d.score&&(d={score:i.size,id:n}),u.push(i)}if(1===u.length)return Array.from(u[0]);let m=u[d.id];for(let e=0;e<u.length;e++){if(e===d.id)continue;let r=u[e];for(let[e,t]of r)m.has(e)?m.set(e,m.get(e)+t):m.set(e,t)}return Array.from(m)},searchByWhereClause:function(r,t,n,o){if(0!==Object.entries(n).filter((([e])=>"Position"===r.indexes[e].type)).length)throw new Error("String filters are not supported");return e.searchByWhereClause(r,t,n,o)},getSearchableProperties:function(e){return e.searchableProperties},getSearchablePropertiesWithTypes:function(e){return e.searchablePropertiesWithTypes},load:function(r,t){let n=e.load(r,t[0]),o=t[1];return{...n,indexes:{...Object.fromEntries(o),...n.indexes}}},save:function(r){let t=r,n=Object.entries(r.indexes).filter((([,{type:e}])=>"Position"!==e));return[e.save({...t,indexes:Object.fromEntries(n)}),Object.entries(r.indexes).filter((([,{type:e}])=>"Position"===e))]}}};var t}}}export{d as pluginPT15};export default null;
|
|
//# sourceMappingURL=/sm/9290bf4b5ed900820f02b4776293f727066e78a3773ccc7b60ac4bc598932c1c.map
|