import Resolver from"../resolver.js";import{create_object}from"../common.js";import{SearchResults,EnrichedSearchResults,IntermediateSearchResults,HighlightOptions}from"../type.js";Resolver.prototype.xor=function(){return this.handler("xor",return_result,arguments)};function return_result(a,b,c,d,e,f,g){let h;return a.length?(this.result.length&&a.unshift(this.result),2>a.length?this.result=a[0]:(this.result=exclusive.call(this,a,b,c,e,this.boostval),h=!0)):!f&&(this.result=a),e&&(this.await=null),e?this.resolve(b,c,d,g,h):this}function exclusive(a,b,c,d,e){const f=[],g=create_object();let h=0;for(let f,j=0;j<a.length;j++)if(f=a[j],f){h<f.length&&(h=f.length);for(let a,b=0;b<f.length;b++)if(a=f[b],a)for(let b,c=0;c<a.length;c++)b=a[c],g[b]=g[b]?2:1}for(let l,m=0,j=0;m<h;m++)for(let h,k=0;k<a.length;k++)if(h=a[k],h&&(l=h[m],l))for(let a,h=0;h<l.length;h++)if(a=l[h],1===g[a]){if(c){c--;continue}if(!d){const c=m+(k?e:0);if(f[c]||(f[c]=[]),f[c].push(a),++j===b)return f}else if(f.push(a),f.length===b)return f}return f}