wiki-plugin-similarity 0.1.7 → 0.1.8
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/client/similarity.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* wiki-plugin-similarity - 0.1.
|
|
1
|
+
/* wiki-plugin-similarity - 0.1.8 - Tue, 09 Jun 2026 20:28:12 GMT */
|
|
2
2
|
(()=>{var R={high:.78,medium:.68,low:.58},v=R.medium,I=10,z=t=>{let e=[],n=null,s=null,i="search",d=(o,a)=>o===a||o.startsWith(a)&&/^[\s:]/.test(o.slice(a.length)),r=(o,a)=>o.slice(a.length).replace(/^\s*:?\s*/,"").trim();for(let o of t.split(`
|
|
3
3
|
`)){let a=o.trim();if(!a||a.startsWith("#"))continue;let l=a.toUpperCase();if(d(l,"LIST")){!e.length&&i==="search"&&(i="list");continue}if(d(l,"SIMILAR")){let h=r(l,"SIMILAR").toLowerCase();n=R[h]||v,!e.length&&i==="search"&&(i="similar");continue}if(d(l,"THRESHOLD")){n=parseFloat(r(a,"THRESHOLD"))||v;continue}if(d(l,"LIMIT")){s=parseInt(r(a,"LIMIT"))||I;continue}e.push(a)}return{mode:i,specs:e,threshold:n??v,limit:s??I}},F=t=>t.includes("*")||t.includes("?"),U=t=>t.toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,""),S=new Map,A=async(t,e)=>{if(S.has(t))return S.get(t);let n=`${e}/system/indexed-domains.json?pattern=${encodeURIComponent(t)}`,s=await fetch(n);if(!s.ok)throw new Error(`indexed-domains failed: ${s.status}`);let i=await s.json();return S.set(t,i),i},P=async(t,e)=>{t.length||(t=[window.location.hostname]);let n=new Set,s=[];for(let i of t)if(i==="*"||F(i))for(let d of await A(i,e))n.has(d.domain)||(n.add(d.domain),s.push(d));else n.has(i)||(n.add(i),s.push({domain:i,page_count:null}));return s},E=new Map,_=()=>{let t=window.location.hostname;return t==="localhost"||t.endsWith(".localhost")||t==="127.0.0.1"},O=t=>_()?`${window.location.origin}/system/semantic-vectors.json?domain=${encodeURIComponent(t)}`:`http://${t}/system/semantic-vectors.json`,H=async t=>{if(E.has(t))return E.get(t);let e=await fetch(O(t));if(!e.ok)return[];let n=await e.json();return E.set(t,n),n},k=async(t,e)=>{let n=await fetch(`${e}/system/embed.json?text=${encodeURIComponent(t)}`);if(!n.ok)throw new Error(`embed failed: ${n.status}`);return(await n.json()).vector},q=async(t,e)=>{let s=(await H(e)).find(i=>i.slug===t);return s?s.vector:null},D=(t,e,{threshold:n,limit:s,excludeSlug:i,excludeDomain:d})=>{let r=[];for(let{domain:o,pages:a}of e)for(let{slug:l,title:h,vector:p}of a){if(l===i&&o===d)continue;let g=0;for(let c=0;c<t.length;c++)g+=t[c]*p[c];g>=n&&r.push({domain:o,slug:l,title:h,score:g})}return r.sort((o,a)=>a.score-o.score),r.slice(0,s)},T=async(t,e)=>{let n=await P(t,e);return(await Promise.all(n.map(async({domain:i})=>({domain:i,pages:await H(i)})))).filter(i=>i.pages.length>0)},C=`
|
|
4
4
|
.sim-form { display:flex; gap:6px; margin-bottom:8px; }
|
package/package.json
CHANGED
|
@@ -4,7 +4,12 @@
|
|
|
4
4
|
{
|
|
5
5
|
"type": "markdown",
|
|
6
6
|
"id": "61ccb2d2cdb60c71",
|
|
7
|
-
"text": "The Similarity plugin adds semantic similarity search to a Federated Wiki farm.
|
|
7
|
+
"text": "The Similarity plugin adds semantic similarity search to a Federated Wiki farm. One item type — **similarity** — with behaviour controlled by a DSL: interactive search form by default, ambient similar-pages panel when `SIMILAR` is the first line."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"type": "markdown",
|
|
11
|
+
"id": "a3f7c8d2e1b94056",
|
|
12
|
+
"text": "**Version:** 0.1.7 — [GitHub](https://github.com/Hitchhikers-Guide-to-the-Galaxy/wiki-plugin-similarity) · [npm](https://www.npmjs.com/package/wiki-plugin-similarity)"
|
|
8
13
|
},
|
|
9
14
|
{
|
|
10
15
|
"type": "similarity",
|
|
@@ -19,7 +24,7 @@
|
|
|
19
24
|
{
|
|
20
25
|
"type": "markdown",
|
|
21
26
|
"id": "0d628d43edf9f8e8",
|
|
22
|
-
"text": "The item's `text` field configures which domains to search and how
|
|
27
|
+
"text": "The item's `text` field configures which domains to search and how:\n\n```\n* all indexed domains on this server\ndavid.* glob pattern\ndavid.hitchhikers.earth explicit domain\n# comment ignored\nLIST show a table of indexed domains\nSIMILAR ambient mode (default: medium threshold)\nSIMILAR high threshold preset (high=0.78 / medium=0.68 / low=0.58)\nTHRESHOLD 0.72 exact cosine threshold\nLIMIT 8 max results (default 10)\n```\n\nColons and extra whitespace are optional — `LIMIT: 8`, `LIMIT 8`, and `LIMIT:8` all work. Leave `text` empty for an interactive search form on the current domain."
|
|
23
28
|
},
|
|
24
29
|
{
|
|
25
30
|
"type": "markdown",
|