Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
server-ts: Port services/search/expressions/property_comparison
Elian Doran29b3fb364617
diff --git a/src/services/search/expressions/property_comparison.js b/src/services/search/expressions/property_comparison.tssimilarity index 74%rename from src/services/search/expressions/property_comparison.jsrename to src/services/search/expressions/property_comparison.tsindex 8ab21f448d..843b5a862e 100644--- a/src/services/search/expressions/property_comparison.js+++ b/src/services/search/expressions/property_comparison.ts@@ -1,14 +1,14 @@"use strict";-const Expression = require('./expression');-const NoteSet = require('../note_set');-const buildComparator = require('../services/build_comparator');+import Expression = require('./expression');+import NoteSet = require('../note_set');+import buildComparator = require('../services/build_comparator');/*** Search string is lower cased for case-insensitive comparison. But when retrieving properties,* we need the case-sensitive form, so we have this translation object.*/-const PROP_MAPPING = {+const PROP_MAPPING: Record<string, string> = {"noteid": "noteId","title": "title","type": "type",@@ -36,12 +36,22 @@ const PROP_MAPPING = {"revisioncount": "revisionCount"};+interface SearchContext {+ dbLoadNeeded?: boolean;+}+class PropertyComparisonExp extends Expression {- static isProperty(name) {++ private propertyName: string;+ private operator: string;+ private comparedValue: string;+ private comparator;++ static isProperty(name: string) {return name in PROP_MAPPING;}- constructor(searchContext, propertyName, operator, comparedValue) {+ constructor(searchContext: SearchContext, propertyName: string, operator: string, comparedValue: string) {super();this.propertyName = PROP_MAPPING[propertyName];@@ -54,11 +64,11 @@ class PropertyComparisonExp extends Expression {}}- execute(inputNoteSet, executionContext, searchContext) {+ execute(inputNoteSet: NoteSet, executionContext: {}, searchContext: SearchContext) {const resNoteSet = new NoteSet();for (const note of inputNoteSet.notes) {- let value = note[this.propertyName];+ let value = (note as any)[this.propertyName];if (value !== undefined && value !== null && typeof value !== 'string') {value = value.toString();@@ -68,7 +78,7 @@ class PropertyComparisonExp extends Expression {value = value.toLowerCase();}- if (this.comparator(value)) {+ if (this.comparator && this.comparator(value)) {resNoteSet.add(note);}}@@ -77,4 +87,4 @@ class PropertyComparisonExp extends Expression {}}-module.exports = PropertyComparisonExp;+export = PropertyComparisonExp;diff --git a/src/services/search/services/parse.js b/src/services/search/services/parse.jsindex 330f139c08..568a002279 100644--- a/src/services/search/services/parse.js+++ b/src/services/search/services/parse.js@@ -8,7 +8,7 @@ const ChildOfExp = require('../expressions/child_of');const DescendantOfExp = require('../expressions/descendant_of');const ParentOfExp = require('../expressions/parent_of');const RelationWhereExp = require('../expressions/relation_where');-const PropertyComparisonExp = require('../expressions/property_comparison.js');+const PropertyComparisonExp = require('../expressions/property_comparison');const AttributeExistsExp = require('../expressions/attribute_exists');const LabelComparisonExp = require('../expressions/label_comparison');const NoteFlatTextExp = require('../expressions/note_flat_text');