trilium/src/services/search/expressions/property_comparison.js

30 lines
670 B
JavaScript

"use strict";
const Expression = require('./expression');
const NoteSet = require('../note_set');
class PropertyComparisonExp extends Expression {
constructor(propertyName, comparator) {
super();
this.propertyName = propertyName;
this.comparator = comparator;
}
execute(noteSet, searchContext) {
const resNoteSet = new NoteSet();
for (const note of noteSet.notes) {
const value = note[this.propertyName].toLowerCase();
if (this.comparator(value)) {
resNoteSet.add(note);
}
}
return resNoteSet;
}
}
module.exports = PropertyComparisonExp;