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/search_result
Elian Doran80e6ced5db91
diff --git a/src/services/search/search_result.js b/src/services/search/search_result.tssimilarity index 77%rename from src/services/search/search_result.jsrename to src/services/search/search_result.tsindex ca3811f8ec..61075910fe 100644--- a/src/services/search/search_result.js+++ b/src/services/search/search_result.ts@@ -1,10 +1,14 @@"use strict";-const beccaService = require('../../becca/becca_service');-const becca = require('../../becca/becca');+import beccaService = require('../../becca/becca_service');+import becca = require('../../becca/becca');class SearchResult {- constructor(notePathArray) {+ private notePathArray: string[];+ private notePathTitle: string;+ private score?: number;++ constructor(notePathArray: string[]) {this.notePathArray = notePathArray;this.notePathTitle = beccaService.getNoteTitleForPath(notePathArray);}@@ -17,7 +21,7 @@ class SearchResult {return this.notePathArray[this.notePathArray.length - 1];}- computeScore(fulltextQuery, tokens) {+ computeScore(fulltextQuery: string, tokens: string[]) {this.score = 0;const note = becca.notes[this.noteId];@@ -42,9 +46,13 @@ class SearchResult {}}- addScoreForStrings(tokens, str, factor) {+ addScoreForStrings(tokens: string[], str: string, factor: number) {const chunks = str.toLowerCase().split(" ");+ if (!this.score) {+ this.score = 0;+ }+for (const chunk of chunks) {for (const token of tokens) {if (chunk === token) {@@ -59,4 +67,4 @@ class SearchResult {}}-module.exports = SearchResult;+export = SearchResult;diff --git a/src/services/search/services/search.js b/src/services/search/services/search.jsindex 36a6540996..4c2291a339 100644--- a/src/services/search/services/search.js+++ b/src/services/search/services/search.js@@ -4,7 +4,7 @@ const normalizeString = require("normalize-strings");const lex = require('./lex.js');const handleParens = require('./handle_parens.js');const parse = require('./parse.js');-const SearchResult = require('../search_result.js');+const SearchResult = require('../search_result');const SearchContext = require('../search_context');const becca = require('../../../becca/becca');const beccaService = require('../../../becca/becca_service');