mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
Adjust shared notes search api
This commit is contained in:
parent
d259931bd2
commit
ec6b8476f9
@ -333,31 +333,31 @@ function register(router) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Used for searching, require noteId so we know the subTreeRoot
|
// Used for searching, require noteId so we know the subTreeRoot
|
||||||
router.get('/share/api/search/:noteId', (req, res, next) => {
|
router.get('/share/api/notes', (req, res, next) => {
|
||||||
shacaLoader.ensureLoad();
|
shacaLoader.ensureLoad();
|
||||||
|
|
||||||
|
const ancestorNoteId = req.query.ancestorNoteId ?? "_share";
|
||||||
let note;
|
let note;
|
||||||
|
|
||||||
if (!(note = checkNoteAccess(req.params.noteId, req, res))) {
|
// This will automatically return if no ancestorNoteId is provided and there is no shareIndex
|
||||||
|
if (!(note = checkNoteAccess(ancestorNoteId, req, res))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const {query} = req.query;
|
const {search} = req.query;
|
||||||
|
|
||||||
if (!query?.trim()) {
|
if (!search?.trim()) {
|
||||||
return res.status(400).json({ message: "'query' parameter is mandatory." });
|
return res.status(400).json({ message: "'search' parameter is mandatory." });
|
||||||
}
|
}
|
||||||
|
|
||||||
const subRootPath = getSharedSubTreeRoot(note);
|
const searchContext = new SearchContext({ancestorNoteId: ancestorNoteId});
|
||||||
const subRoot = subRootPath.note;
|
const searchResults = searchService.findResultsWithQuery(search, searchContext);
|
||||||
const searchContext = new SearchContext({ancestorNoteId: subRoot.noteId});
|
|
||||||
const searchResults = searchService.findResultsWithQuery(query, searchContext);
|
|
||||||
const filteredResults = searchResults.map(sr => {
|
const filteredResults = searchResults.map(sr => {
|
||||||
const fullNote = shaca.notes[sr.noteId];
|
const fullNote = shaca.notes[sr.noteId];
|
||||||
const startIndex = sr.notePathArray.indexOf(subRoot.noteId);
|
const startIndex = sr.notePathArray.indexOf(ancestorNoteId);
|
||||||
const localPathArray = sr.notePathArray.slice(startIndex + 1);
|
const localPathArray = sr.notePathArray.slice(startIndex + 1).filter(id => shaca.notes[id]);
|
||||||
const pathTitle = localPathArray.map(id => shaca.notes[id].title).join(" / ");
|
const pathTitle = localPathArray.map(id => shaca.notes[id].title).join(" / ");
|
||||||
return { id: fullNote.noteId, title: fullNote.title, score: sr.score, path: pathTitle };
|
return { id: fullNote.shareId, title: fullNote.title, score: sr.score, path: pathTitle };
|
||||||
});
|
});
|
||||||
|
|
||||||
res.json({ results: filteredResults });
|
res.json({ results: filteredResults });
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
<%- header %>
|
<%- header %>
|
||||||
<title><%= note.title %></title>
|
<title><%= note.title %></title>
|
||||||
</head>
|
</head>
|
||||||
<body data-note-id="<%= note.noteId %>" data-wtf="true">
|
<body data-note-id="<%= note.noteId %>" data-ancestor-note-id="<%= subRoot.note.noteId %>">
|
||||||
<div id="layout">
|
<div id="layout">
|
||||||
<div id="main">
|
<div id="main">
|
||||||
<% if (note.parents[0].noteId !== '_share' && note.parents.length !== 0) { %>
|
<% if (note.parents[0].noteId !== '_share' && note.parents.length !== 0) { %>
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
const isExternalLink = note.hasLabel('shareExternalLink');
|
const isExternalLink = note.hasLabel('shareExternalLink');
|
||||||
const linkHref = isExternalLink ? note.getLabelValue('shareExternalLink') : `./${note.shareId}`;
|
const linkHref = isExternalLink ? note.getLabelValue('shareExternalLink') : `./${note.shareId}`;
|
||||||
const target = isExternalLink ? ` target="_blank" rel="noopener noreferrer"` : '';
|
const target = isExternalLink ? ` target="_blank" rel="noopener noreferrer"` : '';
|
||||||
console.log(note.shareId, note.title, isExternalLink, linkHref, target);
|
|
||||||
%>
|
%>
|
||||||
<p>
|
<p>
|
||||||
<% const titleWithPrefix = (branch.prefix ? `${branch.prefix} - ` : '') + note.title; %>
|
<% const titleWithPrefix = (branch.prefix ? `${branch.prefix} - ` : '') + note.title; %>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user