site/node_modules/flexsearch/dist/module-min/serialize.js
2024-10-14 08:09:33 +02:00

1 line
1.7 KiB
JavaScript

import{IndexInterface,DocumentInterface}from"./type.js";import{create_object,is_string}from"./common.js";function async(a,b,c,d,e,f,g,h){setTimeout(function(){const i=a(c?c+"."+d:d,JSON.stringify(g));i&&i.then?i.then(function(){b.export(a,b,c,e,f+1,h)}):b.export(a,b,c,e,f+1,h)})}export function exportIndex(a,b,c,d,e,f){let g=!0;"undefined"==typeof f&&(g=new Promise(a=>{f=a}));let h,i;switch(e||(e=0)){case 0:if(h="reg",this.fastupdate)for(let a in i=create_object(),this.register)i[a]=1;else i=this.register;break;case 1:h="cfg",i={doc:0,opt:this.optimize?1:0};break;case 2:h="map",i=this.map;break;case 3:h="ctx",i=this.ctx;break;default:return void("undefined"==typeof c&&f&&f());}return async(a,b||this,c,h,d,e,i,f),g}export function importIndex(a,b){b&&(is_string(b)&&(b=JSON.parse(b)),"cfg"===a?this.optimize=!!b.opt:"reg"===a?(this.fastupdate=!1,this.register=b):"map"===a?this.map=b:"ctx"===a?this.ctx=b:void 0)}export function exportDocument(a,b,c,d,e,f){let g;if("undefined"==typeof f&&(g=new Promise(a=>{f=a})),e||(e=0),d||(d=0),d<this.field.length){const c=this.field[d],g=this.index[c];b=this,setTimeout(function(){g.export(a,b,e?c:"",d,e++,f)||(d++,e=1,b.export(a,b,c,d,e,f))})}else{let b,g;switch(e){case 1:b="tag",g=this.tagindex,c=null;break;case 2:b="store",g=this.store,c=null;break;default:return void f();}async(a,this,c,b,d,e,g,f)}return g}export function importDocument(a,b){if(b)switch(is_string(b)&&(b=JSON.parse(b)),a){case"tag":this.tagindex=b;break;case"reg":this.fastupdate=!1,this.register=b;for(let a,c=0;c<this.field.length;c++)a=this.index[this.field[c]],a.register=b,a.fastupdate=!1;break;case"store":this.store=b;break;default:a=a.split(".");const c=a[0];a=a[1],c&&a&&this.index[c].import(a,b);}}