From 29b3fb3646178f2dd579e5032d85caf80ea0755c Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 18 Feb 2024 01:50:16 +0200 Subject: [PATCH] server-ts: Port services/search/expressions/property_comparison --- ...y_comparison.js => property_comparison.ts} | 30 ++++++++++++------- src/services/search/services/parse.js | 2 +- 2 files changed, 21 insertions(+), 11 deletions(-) rename src/services/search/expressions/{property_comparison.js => property_comparison.ts} (74%) diff --git a/src/services/search/expressions/property_comparison.js b/src/services/search/expressions/property_comparison.ts similarity index 74% rename from src/services/search/expressions/property_comparison.js rename to src/services/search/expressions/property_comparison.ts index 8ab21f448..843b5a862 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 = { "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.js index 330f139c0..568a00227 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');