()
| 4155 | } |
| 4156 | |
| 4157 | async function searchWiki() { |
| 4158 | const rawQuery = $("wikiQuery").value.trim(); |
| 4159 | if (!rawQuery) { |
| 4160 | await loadWiki(); |
| 4161 | return; |
| 4162 | } |
| 4163 | const data = await api(`/api/wiki/search?user_id=${encodeURIComponent(currentUser())}&q=${encodeURIComponent(rawQuery)}&limit=20`); |
| 4164 | const nodes = data.nodes || []; |
| 4165 | state.wikiNodes = nodes; |
| 4166 | try { |
| 4167 | const graph = await api(`/api/wiki/graph?user_id=${encodeURIComponent(currentUser())}&q=${encodeURIComponent(rawQuery)}&limit=120`); |
| 4168 | if (graph.nodes?.length) state.wikiGraph = graph; |
| 4169 | } catch (error) { |
| 4170 | console.warn("Wiki search graph unavailable.", error); |
| 4171 | } |
| 4172 | renderWikiResultNodes(nodes, ui().wiki.resultsCount(nodes.length)); |
| 4173 | if (nodes[0]) setWikiEntry(rawGraphTitle(nodes[0]), rawGraphBody(nodes[0]), nodes[0].node_id || graphId(nodes[0]), { renderRelations: false }); |
| 4174 | if (state.wikiView === "graph") renderWikiGraph(); |
| 4175 | if (state.wikiView === "list") renderWikiList(); |
| 4176 | } |
| 4177 | |
| 4178 | function normalizeCitationSource(source, index = 0) { |
| 4179 | const metadata = source?.metadata || {}; |
no test coverage detected