mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
server-ts: Port services/search/search_result
This commit is contained in:
parent
fbf77f3382
commit
80e6ced5db
@ -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;
|
@ -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');
|
||||
|
Loading…
x
Reference in New Issue
Block a user