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/value_extractor
Elian Doran216f3f2c0761
diff --git a/spec/search/value_extractor.spec.js b/spec/search/value_extractor.spec.jsindex 0e44faf4a5..08508a4bf8 100644--- a/spec/search/value_extractor.spec.js+++ b/spec/search/value_extractor.spec.js@@ -1,5 +1,5 @@const {note} = require('./becca_mocking.js');-const ValueExtractor = require('../../src/services/search/value_extractor.js');+const ValueExtractor = require('../../src/services/search/value_extractor');const becca = require('../../src/becca/becca.js');const SearchContext = require('../../src/services/search/search_context');diff --git a/src/becca/entities/bnote.ts b/src/becca/entities/bnote.tsindex a39d627064..9886e7ae63 100644--- a/src/becca/entities/bnote.ts+++ b/src/becca/entities/bnote.ts@@ -450,7 +450,7 @@ class BNote extends AbstractBeccaEntity<BNote> {);}- getAttributeCaseInsensitive(type: string, name: string, value: string | null) {+ getAttributeCaseInsensitive(type: string, name: string, value?: string | null) {name = name.toLowerCase();value = value ? value.toLowerCase() : null;diff --git a/src/services/search/services/parse.js b/src/services/search/services/parse.jsindex 84c717f6ee..6b2e8fa84f 100644--- a/src/services/search/services/parse.js+++ b/src/services/search/services/parse.js@@ -16,7 +16,7 @@ const NoteContentFulltextExp = require('../expressions/note_content_fulltext.js'const OrderByAndLimitExp = require('../expressions/order_by_and_limit.js');const AncestorExp = require('../expressions/ancestor.js');const buildComparator = require('./build_comparator.js');-const ValueExtractor = require('../value_extractor.js');+const ValueExtractor = require('../value_extractor');const utils = require('../../utils');const TrueExp = require('../expressions/true.js');const IsHiddenExp = require('../expressions/is_hidden.js');diff --git a/src/services/search/value_extractor.js b/src/services/search/value_extractor.tssimilarity index 89%rename from src/services/search/value_extractor.jsrename to src/services/search/value_extractor.tsindex 27aff0e6c4..c602e5f498 100644--- a/src/services/search/value_extractor.js+++ b/src/services/search/value_extractor.ts@@ -1,10 +1,12 @@"use strict";+import BNote = require("../../becca/entities/bnote");+/*** Search string is lower cased for case-insensitive comparison. But when retrieving properties,* we need a case-sensitive form, so we have this translation object.*/-const PROP_MAPPING = {+const PROP_MAPPING: Record<string, string> = {"noteid": "noteId","title": "title","type": "type",@@ -32,8 +34,14 @@ const PROP_MAPPING = {"revisioncount": "revisionCount"};+interface SearchContext {+ dbLoadNeeded: boolean;+}+class ValueExtractor {- constructor(searchContext, propertyPath) {+ private propertyPath: string[];++ constructor(searchContext: SearchContext, propertyPath: string[]) {this.propertyPath = propertyPath.map(pathEl => pathEl.toLowerCase());if (this.propertyPath[0].startsWith('#')) {@@ -81,10 +89,10 @@ class ValueExtractor {}}- extract(note) {- let cursor = note;+ extract(note: BNote) {+ let cursor: BNote | null = note;- let i;+ let i: number = 0;const cur = () => this.propertyPath[i];@@ -105,8 +113,7 @@ class ValueExtractor {i++;const attr = cursor.getAttributeCaseInsensitive('relation', cur());-- cursor = attr ? attr.targetNote : null;+ cursor = (attr ? attr.targetNote || null : null);}else if (cur() === 'parents') {cursor = cursor.parents[0];@@ -118,7 +125,7 @@ class ValueExtractor {return Math.random().toString(); // string is expected for comparison}else if (cur() in PROP_MAPPING) {- return cursor[PROP_MAPPING[cur()]];+ return (cursor as any)[PROP_MAPPING[cur()]];}else {// FIXME