diff --git a/LICENSE-3RD-PARTY b/LICENSE-3RD-PARTY index 6399295993..44610573f8 100644 --- a/LICENSE-3RD-PARTY +++ b/LICENSE-3RD-PARTY @@ -112,6 +112,14 @@ URL: https://swiperjs.com/ License: MIT License Copyright: Copyright 2014-2021 Vladimir Kharlampidi +asset/vendors/minisearch.min.js: + +Name: Minisearch +Version: 6.0.1 +URL: https://github.com/lucaong/minisearch +License: MIT License +Copyright: Copyright 2022 Luca Ongaro + -------------------------------------------------------------------------- Licenses -------------------------------------------------------------------------- diff --git a/asset/vendors/minisearch.min.js b/asset/vendors/minisearch.min.js new file mode 100644 index 0000000000..44fabc133e --- /dev/null +++ b/asset/vendors/minisearch.min.js @@ -0,0 +1,6 @@ +/** + * MiniSearch 6.0.1 + * MIT License + * Copyright 2022 Luca Ongaro + */ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).MiniSearch=e()}(this,(function(){"use strict";var t=function(){return t=Object.assign||function(t){for(var e,r=1,n=arguments.length;r0&&i[i.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function i(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,i,o=r.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(n=o.next()).done;)u.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return u}var o,u="KEYS",a="VALUES",s="",l=function(){function t(t,e){var r=t._tree,n=Array.from(r.keys());this.set=t,this._type=e,this._path=n.length>0?[{node:r,keys:n}]:[]}return t.prototype.next=function(){var t=this.dive();return this.backtrack(),t},t.prototype.dive=function(){if(0===this._path.length)return{done:!0,value:void 0};var t=c(this._path),e=t.node,r=t.keys;if(c(r)===s)return{done:!1,value:this.result()};var n=e.get(c(r));return this._path.push({node:n,keys:Array.from(n.keys())}),this.dive()},t.prototype.backtrack=function(){if(0!==this._path.length){var t=c(this._path).keys;t.pop(),t.length>0||(this._path.pop(),this.backtrack())}},t.prototype.key=function(){return this.set._prefix+this._path.map((function(t){var e=t.keys;return c(e)})).filter((function(t){return t!==s})).join("")},t.prototype.value=function(){return c(this._path).node.get(s)},t.prototype.result=function(){switch(this._type){case a:return this.value();case u:return this.key();default:return[this.key(),this.value()]}},t.prototype[Symbol.iterator]=function(){return this},t}(),c=function(t){return t[t.length-1]},h=function(t,e,r,i,o,u,a,l){var c,d,f=u*a;try{t:for(var v=n(t.keys()),y=v.next();!y.done;y=v.next()){var p=y.value;if(p===s){var m=o[f-1];m<=r&&i.set(l,[t.get(p),m])}else{for(var _=u,g=0;gr)continue t}h(t.get(p),e,r,i,o,_,a,l+p)}}}catch(t){c={error:t}}finally{try{y&&!y.done&&(d=v.return)&&d.call(v)}finally{if(c)throw c.error}}},d=function(){function t(t,e){void 0===t&&(t=new Map),void 0===e&&(e=""),this._size=void 0,this._tree=t,this._prefix=e}return t.prototype.atPrefix=function(e){var r,o;if(!e.startsWith(this._prefix))throw new Error("Mismatched prefix");var u=i(f(this._tree,e.slice(this._prefix.length)),2),a=u[0],l=u[1];if(void 0===a){var c=i(g(l),2),h=c[0],d=c[1];try{for(var v=n(h.keys()),y=v.next();!y.done;y=v.next()){var p=y.value;if(p!==s&&p.startsWith(d)){var m=new Map;return m.set(p.slice(d.length),h.get(p)),new t(m,e)}}}catch(t){r={error:t}}finally{try{y&&!y.done&&(o=v.return)&&o.call(v)}finally{if(r)throw r.error}}}return new t(a,e)},t.prototype.clear=function(){this._size=void 0,this._tree.clear()},t.prototype.delete=function(t){return this._size=void 0,p(this._tree,t)},t.prototype.entries=function(){return new l(this,"ENTRIES")},t.prototype.forEach=function(t){var e,r;try{for(var o=n(this),u=o.next();!u.done;u=o.next()){var a=i(u.value,2);t(a[0],a[1],this)}}catch(t){e={error:t}}finally{try{u&&!u.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}},t.prototype.fuzzyGet=function(t,e){return function(t,e,r){var n=new Map;if(void 0===e)return n;for(var i=e.length+1,o=i+r,u=new Uint8Array(o*i).fill(r+1),a=0;a0)throw new Error("Expected documents to be present. Omit the argument to remove all documents.");this._index=new d,this._documentCount=0,this._documentIds=new Map,this._idToShortId=new Map,this._fieldLength=new Map,this._avgFieldLength=[],this._storedFields=new Map,this._nextId=0}},o.prototype.discard=function(t){var e=this,r=this._idToShortId.get(t);if(null==r)throw new Error("MiniSearch: cannot discard document with ID ".concat(t,": it is not in the index"));this._idToShortId.delete(t),this._documentIds.delete(r),this._storedFields.delete(r),(this._fieldLength.get(r)||[]).forEach((function(t,n){e.removeFieldLength(r,n,e._documentCount,t)})),this._fieldLength.delete(r),this._documentCount-=1,this._dirtCount+=1,this.maybeAutoVacuum()},o.prototype.maybeAutoVacuum=function(){if(!1!==this._options.autoVacuum){var t=this._options.autoVacuum,e=t.minDirtFactor,r=t.minDirtCount,n=t.batchSize,i=t.batchWait;this.conditionalVacuum({batchSize:n,batchWait:i},{minDirtCount:r,minDirtFactor:e})}},o.prototype.discardAll=function(t){var e,r,i=this._options.autoVacuum;try{this._options.autoVacuum=!1;try{for(var o=n(t),u=o.next();!u.done;u=o.next()){var a=u.value;this.discard(a)}}catch(t){e={error:t}}finally{try{u&&!u.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}}finally{this._options.autoVacuum=i}this.maybeAutoVacuum()},o.prototype.replace=function(t){var e=this._options,r=e.idField,n=(0,e.extractField)(t,r);this.discard(n),this.add(t)},o.prototype.vacuum=function(t){return void 0===t&&(t={}),this.conditionalVacuum(t)},o.prototype.conditionalVacuum=function(t,e){var r=this;return this._currentVacuum?(this._enqueuedVacuumConditions=this._enqueuedVacuumConditions&&e,null!=this._enqueuedVacuum||(this._enqueuedVacuum=this._currentVacuum.then((function(){var e=r._enqueuedVacuumConditions;return r._enqueuedVacuumConditions=I,r.performVacuuming(t,e)}))),this._enqueuedVacuum):!1===this.vacuumConditionsMet(e)?Promise.resolve():(this._currentVacuum=this.performVacuuming(t),this._currentVacuum)},o.prototype.performVacuuming=function(t,o){return e(this,void 0,void 0,(function(){var e,u,a,s,l,c,h,d,f,v,y,p,m,_,g,F,x,w,b,A,C,z,E,D,I;return r(this,(function(r){switch(r.label){case 0:if(e=this._dirtCount,!this.vacuumConditionsMet(o))return[3,10];u=t.batchSize||S.batchSize,a=t.batchWait||S.batchWait,s=1,r.label=1;case 1:r.trys.push([1,7,8,9]),l=n(this._index),c=l.next(),r.label=2;case 2:if(c.done)return[3,6];h=i(c.value,2),d=h[0],f=h[1];try{for(z=void 0,v=n(f),y=v.next();!y.done;y=v.next()){p=i(y.value,2),m=p[0],_=p[1];try{for(D=void 0,g=n(_),F=g.next();!F.done;F=g.next())x=i(F.value,1),w=x[0],this._documentIds.has(w)||(_.size<=1?f.delete(m):_.delete(w))}catch(t){D={error:t}}finally{try{F&&!F.done&&(I=g.return)&&I.call(g)}finally{if(D)throw D.error}}}}catch(t){z={error:t}}finally{try{y&&!y.done&&(E=v.return)&&E.call(v)}finally{if(z)throw z.error}}return 0===this._index.get(d).size&&this._index.delete(d),s%u!=0?[3,4]:[4,new Promise((function(t){return setTimeout(t,a)}))];case 3:r.sent(),r.label=4;case 4:s+=1,r.label=5;case 5:return c=l.next(),[3,2];case 6:return[3,9];case 7:return b=r.sent(),A={error:b},[3,9];case 8:try{c&&!c.done&&(C=l.return)&&C.call(l)}finally{if(A)throw A.error}return[7];case 9:this._dirtCount-=e,r.label=10;case 10:return[4,null];case 11:return r.sent(),this._currentVacuum=this._enqueuedVacuum,this._enqueuedVacuum=null,[2]}}))}))},o.prototype.vacuumConditionsMet=function(t){if(null==t)return!0;var e=t.minDirtCount,r=t.minDirtFactor;return e=e||k.minDirtCount,r=r||k.minDirtFactor,this.dirtCount>=e&&this.dirtFactor>=r},Object.defineProperty(o.prototype,"isVacuuming",{get:function(){return null!=this._currentVacuum},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"dirtCount",{get:function(){return this._dirtCount},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"dirtFactor",{get:function(){return this._dirtCount/(1+this._documentCount+this._dirtCount)},enumerable:!1,configurable:!0}),o.prototype.has=function(t){return this._idToShortId.has(t)},o.prototype.search=function(t,e){var r,o;void 0===e&&(e={});var u=this.executeQuery(t,e),a=[];try{for(var s=n(u),l=s.next();!l.done;l=s.next()){var c=i(l.value,2),h=c[0],d=c[1],f=d.score,v=d.terms,y=d.match,p=v.length,m={id:this._documentIds.get(h),score:f*p,terms:Object.keys(y),match:y};Object.assign(m,this._storedFields.get(h)),(null==e.filter||e.filter(m))&&a.push(m)}}catch(t){r={error:t}}finally{try{l&&!l.done&&(o=s.return)&&o.call(s)}finally{if(r)throw r.error}}return a.sort(O),a},o.prototype.autoSuggest=function(e,r){var o,u,a,s;void 0===r&&(r={}),r=t(t({},this._options.autoSuggestOptions),r);var l=new Map;try{for(var c=n(this.search(e,r)),h=c.next();!h.done;h=c.next()){var d=h.value,f=d.score,v=(x=d.terms).join(" ");null!=(g=l.get(v))?(g.score+=f,g.count+=1):l.set(v,{score:f,terms:x,count:1})}}catch(t){o={error:t}}finally{try{h&&!h.done&&(u=c.return)&&u.call(c)}finally{if(o)throw o.error}}var y=[];try{for(var p=n(l),m=p.next();!m.done;m=p.next()){var _=i(m.value,2),g=_[0],F=_[1],x=(f=F.score,F.terms),w=F.count;y.push({suggestion:g,terms:x,score:f/w})}}catch(t){a={error:t}}finally{try{m&&!m.done&&(s=p.return)&&s.call(p)}finally{if(a)throw a.error}}return y.sort(O),y},Object.defineProperty(o.prototype,"documentCount",{get:function(){return this._documentCount},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"termCount",{get:function(){return this._index.size},enumerable:!1,configurable:!0}),o.loadJSON=function(t,e){if(null==e)throw new Error("MiniSearch: loadJSON should be given the same options used when serializing the index");return this.loadJS(JSON.parse(t),e)},o.getDefault=function(t){if(z.hasOwnProperty(t))return w(z,t);throw new Error('MiniSearch: unknown option "'.concat(t,'"'))},o.loadJS=function(t,e){var r,u,a,s,l,c,h=t.index,f=t.documentCount,v=t.nextId,y=t.documentIds,p=t.fieldIds,m=t.fieldLength,_=t.averageFieldLength,g=t.storedFields,F=t.dirtCount,x=t.serializationVersion;if(1!==x&&2!==x)throw new Error("MiniSearch: cannot deserialize an index created with an incompatible version");var w=new o(e);w._documentCount=f,w._nextId=v,w._documentIds=T(y),w._idToShortId=new Map,w._fieldIds=p,w._fieldLength=T(m),w._avgFieldLength=_,w._storedFields=T(g),w._dirtCount=F||0,w._index=new d;try{for(var b=n(w._documentIds),A=b.next();!A.done;A=b.next()){var C=i(A.value,2),z=C[0],E=C[1];w._idToShortId.set(E,z)}}catch(t){r={error:t}}finally{try{A&&!A.done&&(u=b.return)&&u.call(b)}finally{if(r)throw r.error}}try{for(var D=n(h),S=D.next();!S.done;S=D.next()){var I=i(S.value,2),k=I[0],M=I[1],V=new Map;try{for(var O=(l=void 0,n(Object.keys(M))),L=O.next();!L.done;L=O.next()){var j=L.value,B=M[j];1===x&&(B=B.ds),V.set(parseInt(j,10),T(B))}}catch(t){l={error:t}}finally{try{L&&!L.done&&(c=O.return)&&c.call(O)}finally{if(l)throw l.error}}w._index.set(k,V)}}catch(t){a={error:t}}finally{try{S&&!S.done&&(s=D.return)&&s.call(D)}finally{if(a)throw a.error}}return w},o.prototype.executeQuery=function(e,r){var n=this;if(void 0===r&&(r={}),"string"!=typeof e){var i=t(t(t({},r),e),{queries:void 0}),o=e.queries.map((function(t){return n.executeQuery(t,i)}));return this.combineResults(o,i.combineWith)}var u=this._options,a=u.tokenize,s=u.processTerm,l=u.searchOptions,c=t(t({tokenize:a,processTerm:s},l),r),h=c.tokenize,d=c.processTerm,f=h(e).flatMap((function(t){return d(t)})).filter((function(t){return!!t})).map(C(c)).map((function(t){return n.executeQuerySpec(t,c)}));return this.combineResults(f,c.combineWith)},o.prototype.executeQuerySpec=function(e,r){var o,u,a,s,l,c,h=t(t({},this._options.searchOptions),r),d=(h.fields||this._options.fields).reduce((function(e,r){var n;return t(t({},e),((n={})[r]=w(h.boost,r)||1,n))}),{}),f=h.boostDocument,v=h.weights,y=h.maxFuzzy,p=h.bm25,m=t(t({},E.weights),v),_=m.fuzzy,g=m.prefix,F=this._index.get(e.term),x=this.termResults(e.term,e.term,1,F,d,f,p);if(e.prefix&&(l=this._index.atPrefix(e.term)),e.fuzzy){var b=!0===e.fuzzy?.2:e.fuzzy,A=b<1?Math.min(y,Math.round(e.term.length*b)):b;A&&(c=this._index.fuzzyGet(e.term,A))}if(l)try{for(var C=n(l),z=C.next();!z.done;z=C.next()){var D=i(z.value,2),S=D[0],I=D[1];if(O=S.length-e.term.length){null==c||c.delete(S);var k=g*S.length/(S.length+.3*O);this.termResults(e.term,S,k,I,d,f,p,x)}}}catch(t){o={error:t}}finally{try{z&&!z.done&&(u=C.return)&&u.call(C)}finally{if(o)throw o.error}}if(c)try{for(var M=n(c.keys()),V=M.next();!V.done;V=M.next()){S=V.value;var O,L=i(c.get(S),2),T=L[0];if(O=L[1]){k=_*S.length/(S.length+O);this.termResults(e.term,S,k,T,d,f,p,x)}}}catch(t){a={error:t}}finally{try{V&&!V.done&&(s=M.return)&&s.call(M)}finally{if(a)throw a.error}}return x},o.prototype.combineResults=function(t,e){if(void 0===e&&(e=F),0===t.length)return new Map;var r=e.toLowerCase();return t.reduce(b[r])||new Map},o.prototype.toJSON=function(){var t,e,r,o,u=[];try{for(var a=n(this._index),s=a.next();!s.done;s=a.next()){var l=i(s.value,2),c=l[0],h=l[1],d={};try{for(var f=(r=void 0,n(h)),v=f.next();!v.done;v=f.next()){var y=i(v.value,2),p=y[0],m=y[1];d[p]=Object.fromEntries(m)}}catch(t){r={error:t}}finally{try{v&&!v.done&&(o=f.return)&&o.call(f)}finally{if(r)throw r.error}}u.push([c,d])}}catch(e){t={error:e}}finally{try{s&&!s.done&&(e=a.return)&&e.call(a)}finally{if(t)throw t.error}}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:u,serializationVersion:2}},o.prototype.termResults=function(t,e,r,i,o,u,a,s){var l,c,h,d,f;if(void 0===s&&(s=new Map),null==i)return s;try{for(var v=n(Object.keys(o)),y=v.next();!y.done;y=v.next()){var p=y.value,m=o[p],_=this._fieldIds[p],g=i.get(_);if(null!=g){var F=g.size,x=this._avgFieldLength[_];try{for(var b=(h=void 0,n(g.keys())),C=b.next();!C.done;C=b.next()){var z=C.value;if(this._documentIds.has(z)){var E=u?u(this._documentIds.get(z),e):1;if(E){var D=g.get(z),S=this._fieldLength.get(z)[_],I=r*m*E*A(D,F,this._documentCount,S,x,a),k=s.get(z);if(k){k.score+=I,M(k.terms,t);var V=w(k.match,e);V?V.push(p):k.match[e]=[p]}else s.set(z,{score:I,terms:[t],match:(f={},f[e]=[p],f)})}}else this.removeTerm(_,z,e),F-=1}}catch(t){h={error:t}}finally{try{C&&!C.done&&(d=b.return)&&d.call(b)}finally{if(h)throw h.error}}}}}catch(t){l={error:t}}finally{try{y&&!y.done&&(c=v.return)&&c.call(v)}finally{if(l)throw l.error}}return s},o.prototype.addTerm=function(t,e,r){var n=this._index.fetch(r,L),i=n.get(t);if(null==i)(i=new Map).set(e,1),n.set(t,i);else{var o=i.get(e);i.set(e,(o||0)+1)}},o.prototype.removeTerm=function(t,e,r){if(this._index.has(r)){var n=this._index.fetch(r,L),i=n.get(t);null==i||null==i.get(e)?this.warnDocumentChanged(e,t,r):i.get(e)<=1?i.size<=1?n.delete(t):i.delete(e):i.set(e,i.get(e)-1),0===this._index.get(r).size&&this._index.delete(r)}else this.warnDocumentChanged(e,t,r)},o.prototype.warnDocumentChanged=function(t,e,r){var i,o;try{for(var u=n(Object.keys(this._fieldIds)),a=u.next();!a.done;a=u.next()){var s=a.value;if(this._fieldIds[s]===e)return void this._options.logger("warn","MiniSearch: document with ID ".concat(this._documentIds.get(t),' has changed before removal: term "').concat(r,'" was not present in field "').concat(s,'". Removing a document after it has changed can corrupt the index!'),"version_conflict")}}catch(t){i={error:t}}finally{try{a&&!a.done&&(o=u.return)&&o.call(u)}finally{if(i)throw i.error}}},o.prototype.addDocumentId=function(t){var e=this._nextId;return this._idToShortId.set(t,e),this._documentIds.set(e,t),this._documentCount+=1,this._nextId+=1,e},o.prototype.addFields=function(t){for(var e=0;e ?version:string -> filepath:string -> string -> string + + val search_index : ?version:string -> digest:string -> string -> string end = struct let with_hash = Option.fold ~none:"/p" ~some:(( ^ ) "/u/") let with_version = Option.fold ~none:"/latest" ~some:(( ^ ) "/") @@ -25,6 +27,7 @@ end = struct base ?hash ?version ("/doc/" ^ page) let file ?hash ?version ~filepath = base ?hash ?version ("/" ^ filepath) + let search_index ?version ~digest = base ?version ("/search-index/" ^ digest) end let sitemap = "/sitemap.xml" diff --git a/src/ocamlorg_frontend/components/header.eml b/src/ocamlorg_frontend/components/header.eml index b6923b7f7f..68fa108eda 100644 --- a/src/ocamlorg_frontend/components/header.eml +++ b/src/ocamlorg_frontend/components/header.eml @@ -45,7 +45,7 @@ let render <%s! Packages_autocomplete_fragment.form_attributes %> action="/packages/search" method="GET">