mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
recent notes and jump to note are filtered by hoisted note
This commit is contained in:
parent
86fcbb0354
commit
6c16cdb011
@ -3,6 +3,8 @@
|
|||||||
const noteCacheService = require('../../services/note_cache');
|
const noteCacheService = require('../../services/note_cache');
|
||||||
const repository = require('../../services/repository');
|
const repository = require('../../services/repository');
|
||||||
const log = require('../../services/log');
|
const log = require('../../services/log');
|
||||||
|
const utils = require('../../services/utils');
|
||||||
|
const optionService = require('../../services/options');
|
||||||
|
|
||||||
async function getAutocomplete(req) {
|
async function getAutocomplete(req) {
|
||||||
const query = req.query.query;
|
const query = req.query.query;
|
||||||
@ -16,7 +18,7 @@ async function getAutocomplete(req) {
|
|||||||
results = await getRecentNotes(currentNoteId);
|
results = await getRecentNotes(currentNoteId);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
results = noteCacheService.findNotes(query);
|
results = await noteCacheService.findNotes(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
const msTaken = Date.now() - timestampStarted;
|
const msTaken = Date.now() - timestampStarted;
|
||||||
@ -29,6 +31,13 @@ async function getAutocomplete(req) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getRecentNotes(currentNoteId) {
|
async function getRecentNotes(currentNoteId) {
|
||||||
|
let extraCondition = '';
|
||||||
|
|
||||||
|
const hoistedNoteId = await optionService.getOption('hoistedNoteId');
|
||||||
|
if (hoistedNoteId !== 'root') {
|
||||||
|
extraCondition = `AND recent_notes.notePath LIKE '%${utils.sanitizeSql(hoistedNoteId)}%'`;
|
||||||
|
}
|
||||||
|
|
||||||
const recentNotes = await repository.getEntities(`
|
const recentNotes = await repository.getEntities(`
|
||||||
SELECT
|
SELECT
|
||||||
recent_notes.*
|
recent_notes.*
|
||||||
@ -39,6 +48,7 @@ async function getRecentNotes(currentNoteId) {
|
|||||||
recent_notes.isDeleted = 0
|
recent_notes.isDeleted = 0
|
||||||
AND branches.isDeleted = 0
|
AND branches.isDeleted = 0
|
||||||
AND branches.noteId != ?
|
AND branches.noteId != ?
|
||||||
|
${extraCondition}
|
||||||
ORDER BY
|
ORDER BY
|
||||||
dateCreated DESC
|
dateCreated DESC
|
||||||
LIMIT 200`, [currentNoteId]);
|
LIMIT 200`, [currentNoteId]);
|
||||||
|
@ -20,7 +20,7 @@ async function searchNotes(req) {
|
|||||||
let searchTextResults = null;
|
let searchTextResults = null;
|
||||||
|
|
||||||
if (searchText.trim().length > 0) {
|
if (searchText.trim().length > 0) {
|
||||||
searchTextResults = noteCacheService.findNotes(searchText);
|
searchTextResults = await noteCacheService.findNotes(searchText);
|
||||||
|
|
||||||
let fullTextNoteIds = await getFullTextResults(searchText);
|
let fullTextNoteIds = await getFullTextResults(searchText);
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ const eventService = require('./events');
|
|||||||
const repository = require('./repository');
|
const repository = require('./repository');
|
||||||
const protectedSessionService = require('./protected_session');
|
const protectedSessionService = require('./protected_session');
|
||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
|
const options = require('./options');
|
||||||
|
|
||||||
let loaded = false;
|
let loaded = false;
|
||||||
let noteTitles = {};
|
let noteTitles = {};
|
||||||
@ -63,7 +64,7 @@ function highlightResults(results, allTokens) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function findNotes(query) {
|
async function findNotes(query) {
|
||||||
if (!noteTitles || !query.length) {
|
if (!noteTitles || !query.length) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@ -72,7 +73,7 @@ function findNotes(query) {
|
|||||||
// filtering '/' because it's used as separator
|
// filtering '/' because it's used as separator
|
||||||
const allTokens = query.trim().toLowerCase().split(" ").filter(token => token !== '/');
|
const allTokens = query.trim().toLowerCase().split(" ").filter(token => token !== '/');
|
||||||
const tokens = allTokens.slice();
|
const tokens = allTokens.slice();
|
||||||
const results = [];
|
let results = [];
|
||||||
|
|
||||||
let noteIds = Object.keys(noteTitles);
|
let noteIds = Object.keys(noteTitles);
|
||||||
|
|
||||||
@ -120,6 +121,12 @@ function findNotes(query) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hoistedNoteId = await options.getOption('hoistedNoteId');
|
||||||
|
|
||||||
|
if (hoistedNoteId !== 'root') {
|
||||||
|
results = results.filter(res => res.pathArray.includes(hoistedNoteId));
|
||||||
|
}
|
||||||
|
|
||||||
// sort results by depth of the note. This is based on the assumption that more important results
|
// sort results by depth of the note. This is based on the assumption that more important results
|
||||||
// are closer to the note root.
|
// are closer to the note root.
|
||||||
results.sort((a, b) => {
|
results.sort((a, b) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user