refactoring of "some path" WIP

This commit is contained in:
zadam
2023-04-16 09:22:24 +02:00
parent 7aa26580ba
commit a1d4e062ed
6 changed files with 45 additions and 137 deletions

View File

@@ -24,7 +24,7 @@ class NoteFlatTextExp extends Expression {
*/
function searchDownThePath(note, tokens, path) {
if (tokens.length === 0) {
const retPath = beccaService.getSomePath(note, path);
const retPath = this.getNotePath(note, path);
if (retPath) {
const noteId = retPath[retPath.length - 1];
@@ -131,6 +131,17 @@ class NoteFlatTextExp extends Expression {
return resultNoteSet;
}
getNotePath(note, path) {
if (path.length === 0) {
return note.getBestNotePath();
} else {
const closestNoteId = path[0];
const closestNoteBestNotePath = becca.getNote(closestNoteId).getBestNotePathString();
return [...closestNoteBestNotePath, ...path.slice(1)];
}
}
/**
* Returns noteIds which have at least one matching tokens
*

View File

@@ -157,7 +157,7 @@ function findResultsWithExpression(expression, searchContext) {
const searchResults = noteSet.notes
.filter(note => !note.isDeleted)
.map(note => {
const notePathArray = executionContext.noteIdToNotePath[note.noteId] || beccaService.getSomePath(note);
const notePathArray = executionContext.noteIdToNotePath[note.noteId] || note.getBestNotePath();
if (!notePathArray) {
throw new Error(`Can't find note path for note ${JSON.stringify(note.getPojo())}`);