mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
server-ts: Port services/search/expressions/note_flat_text
This commit is contained in:
parent
414964e791
commit
460982d290
@ -1,29 +1,34 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const Expression = require('./expression');
|
import BNote = require("../../../becca/entities/bnote");
|
||||||
const NoteSet = require('../note_set');
|
import SearchContext = require("../search_context");
|
||||||
const becca = require('../../../becca/becca');
|
|
||||||
const utils = require('../../utils');
|
import Expression = require('./expression');
|
||||||
|
import NoteSet = require('../note_set');
|
||||||
|
import becca = require('../../../becca/becca');
|
||||||
|
import utils = require('../../utils');
|
||||||
|
|
||||||
class NoteFlatTextExp extends Expression {
|
class NoteFlatTextExp extends Expression {
|
||||||
constructor(tokens) {
|
private tokens: string[];
|
||||||
|
|
||||||
|
constructor(tokens: string[]) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.tokens = tokens;
|
this.tokens = tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
execute(inputNoteSet, executionContext, searchContext) {
|
execute(inputNoteSet: NoteSet, executionContext: any, searchContext: SearchContext) {
|
||||||
// has deps on SQL which breaks unit test so needs to be dynamically required
|
// has deps on SQL which breaks unit test so needs to be dynamically required
|
||||||
const beccaService = require('../../../becca/becca_service');
|
const beccaService = require('../../../becca/becca_service');
|
||||||
const resultNoteSet = new NoteSet();
|
const resultNoteSet = new NoteSet();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {BNote} note
|
* @param note
|
||||||
* @param {string[]} remainingTokens - tokens still needed to be found in the path towards root
|
* @param remainingTokens - tokens still needed to be found in the path towards root
|
||||||
* @param {string[]} takenPath - path so far taken towards from candidate note towards the root.
|
* @param takenPath - path so far taken towards from candidate note towards the root.
|
||||||
* It contains the suffix fragment of the full note path.
|
* It contains the suffix fragment of the full note path.
|
||||||
*/
|
*/
|
||||||
const searchPathTowardsRoot = (note, remainingTokens, takenPath) => {
|
const searchPathTowardsRoot = (note: BNote, remainingTokens: string[], takenPath: string[]) => {
|
||||||
if (remainingTokens.length === 0) {
|
if (remainingTokens.length === 0) {
|
||||||
// we're done, just build the result
|
// we're done, just build the result
|
||||||
const resultPath = this.getNotePath(note, takenPath);
|
const resultPath = this.getNotePath(note, takenPath);
|
||||||
@ -134,12 +139,7 @@ class NoteFlatTextExp extends Expression {
|
|||||||
return resultNoteSet;
|
return resultNoteSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
getNotePath(note: BNote, takenPath: string[]): string[] {
|
||||||
* @param {BNote} note
|
|
||||||
* @param {string[]} takenPath
|
|
||||||
* @returns {string[]}
|
|
||||||
*/
|
|
||||||
getNotePath(note, takenPath) {
|
|
||||||
if (takenPath.length === 0) {
|
if (takenPath.length === 0) {
|
||||||
throw new Error("Path is not expected to be empty.");
|
throw new Error("Path is not expected to be empty.");
|
||||||
} else if (takenPath.length === 1 && takenPath[0] === note.noteId) {
|
} else if (takenPath.length === 1 && takenPath[0] === note.noteId) {
|
||||||
@ -147,7 +147,7 @@ class NoteFlatTextExp extends Expression {
|
|||||||
} else {
|
} else {
|
||||||
// this note is the closest to root containing the last matching token(s), thus completing the requirements
|
// this note is the closest to root containing the last matching token(s), thus completing the requirements
|
||||||
// what's in this note's predecessors does not matter, thus we'll choose the best note path
|
// what's in this note's predecessors does not matter, thus we'll choose the best note path
|
||||||
const topMostMatchingTokenNotePath = becca.getNote(takenPath[0]).getBestNotePath();
|
const topMostMatchingTokenNotePath = becca.getNote(takenPath[0])?.getBestNotePath() || [];
|
||||||
|
|
||||||
return [...topMostMatchingTokenNotePath, ...takenPath.slice(1)];
|
return [...topMostMatchingTokenNotePath, ...takenPath.slice(1)];
|
||||||
}
|
}
|
||||||
@ -155,11 +155,8 @@ class NoteFlatTextExp extends Expression {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns noteIds which have at least one matching tokens
|
* Returns noteIds which have at least one matching tokens
|
||||||
*
|
|
||||||
* @param {NoteSet} noteSet
|
|
||||||
* @returns {BNote[]}
|
|
||||||
*/
|
*/
|
||||||
getCandidateNotes(noteSet) {
|
getCandidateNotes(noteSet: NoteSet): BNote[] {
|
||||||
const candidateNotes = [];
|
const candidateNotes = [];
|
||||||
|
|
||||||
for (const note of noteSet.notes) {
|
for (const note of noteSet.notes) {
|
||||||
@ -175,4 +172,4 @@ class NoteFlatTextExp extends Expression {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = NoteFlatTextExp;
|
export = NoteFlatTextExp;
|
@ -11,7 +11,7 @@ const RelationWhereExp = require('../expressions/relation_where.js');
|
|||||||
const PropertyComparisonExp = require('../expressions/property_comparison.js');
|
const PropertyComparisonExp = require('../expressions/property_comparison.js');
|
||||||
const AttributeExistsExp = require('../expressions/attribute_exists');
|
const AttributeExistsExp = require('../expressions/attribute_exists');
|
||||||
const LabelComparisonExp = require('../expressions/label_comparison');
|
const LabelComparisonExp = require('../expressions/label_comparison');
|
||||||
const NoteFlatTextExp = require('../expressions/note_flat_text.js');
|
const NoteFlatTextExp = require('../expressions/note_flat_text');
|
||||||
const NoteContentFulltextExp = require('../expressions/note_content_fulltext');
|
const NoteContentFulltextExp = require('../expressions/note_content_fulltext');
|
||||||
const OrderByAndLimitExp = require('../expressions/order_by_and_limit.js');
|
const OrderByAndLimitExp = require('../expressions/order_by_and_limit.js');
|
||||||
const AncestorExp = require('../expressions/ancestor');
|
const AncestorExp = require('../expressions/ancestor');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user