mirror of
https://github.com/zadam/trilium.git
synced 2025-11-05 04:45:47 +01:00
added querying by relation's properties
This commit is contained in:
41
src/services/search/expressions/relation_where.js
Normal file
41
src/services/search/expressions/relation_where.js
Normal file
@@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
|
||||
const Expression = require('./expression');
|
||||
const NoteSet = require('../note_set');
|
||||
const noteCache = require('../../note_cache/note_cache');
|
||||
|
||||
class RelationWhereExp extends Expression {
|
||||
constructor(relationName, subExpression) {
|
||||
super();
|
||||
|
||||
this.relationName = relationName;
|
||||
this.subExpression = subExpression;
|
||||
}
|
||||
|
||||
execute(inputNoteSet, searchContext) {
|
||||
const candidateNoteSet = new NoteSet();
|
||||
|
||||
for (const attr of noteCache.findAttributes('relation', this.relationName)) {
|
||||
const note = attr.note;
|
||||
|
||||
if (inputNoteSet.hasNoteId(note.noteId)) {
|
||||
const subInputNoteSet = new NoteSet([attr.targetNote]);
|
||||
const subResNoteSet = this.subExpression.execute(subInputNoteSet, searchContext);
|
||||
|
||||
if (subResNoteSet.hasNote(attr.targetNote)) {
|
||||
if (attr.isInheritable) {
|
||||
candidateNoteSet.addAll(note.subtreeNotesIncludingTemplated);
|
||||
} else if (note.isTemplate) {
|
||||
candidateNoteSet.addAll(note.templatedNotes);
|
||||
} else {
|
||||
candidateNoteSet.add(note);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return candidateNoteSet.intersection(inputNoteSet);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RelationWhereExp;
|
||||
Reference in New Issue
Block a user