Adjust shared notes search api

This commit is contained in:
Zack Rauen 2023-10-08 14:54:37 -04:00
parent d259931bd2
commit ec6b8476f9
3 changed files with 13 additions and 14 deletions

View File

@ -333,31 +333,31 @@ function register(router) {
});
// 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();
const ancestorNoteId = req.query.ancestorNoteId ?? "_share";
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;
}
const {query} = req.query;
const {search} = req.query;
if (!query?.trim()) {
return res.status(400).json({ message: "'query' parameter is mandatory." });
if (!search?.trim()) {
return res.status(400).json({ message: "'search' parameter is mandatory." });
}
const subRootPath = getSharedSubTreeRoot(note);
const subRoot = subRootPath.note;
const searchContext = new SearchContext({ancestorNoteId: subRoot.noteId});
const searchResults = searchService.findResultsWithQuery(query, searchContext);
const searchContext = new SearchContext({ancestorNoteId: ancestorNoteId});
const searchResults = searchService.findResultsWithQuery(search, searchContext);
const filteredResults = searchResults.map(sr => {
const fullNote = shaca.notes[sr.noteId];
const startIndex = sr.notePathArray.indexOf(subRoot.noteId);
const localPathArray = sr.notePathArray.slice(startIndex + 1);
const startIndex = sr.notePathArray.indexOf(ancestorNoteId);
const localPathArray = sr.notePathArray.slice(startIndex + 1).filter(id => shaca.notes[id]);
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 });

View File

@ -32,7 +32,7 @@
<%- header %>
<title><%= note.title %></title>
</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="main">
<% if (note.parents[0].noteId !== '_share' && note.parents.length !== 0) { %>

View File

@ -2,7 +2,6 @@
const isExternalLink = note.hasLabel('shareExternalLink');
const linkHref = isExternalLink ? note.getLabelValue('shareExternalLink') : `./${note.shareId}`;
const target = isExternalLink ? ` target="_blank" rel="noopener noreferrer"` : '';
console.log(note.shareId, note.title, isExternalLink, linkHref, target);
%>
<p>
<% const titleWithPrefix = (branch.prefix ? `${branch.prefix} - ` : '') + note.title; %>