mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 09:58:32 +02:00
add score to note title matches as opposed to note path, #2927
This commit is contained in:
parent
aee350b07b
commit
6cb5144c09
@ -1,6 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const beccaService = require('../../becca/becca_service');
|
const beccaService = require('../../becca/becca_service');
|
||||||
|
const becca = require('../../becca/becca');
|
||||||
|
|
||||||
class SearchResult {
|
class SearchResult {
|
||||||
constructor(notePathArray) {
|
constructor(notePathArray) {
|
||||||
@ -21,18 +22,24 @@ class SearchResult {
|
|||||||
|
|
||||||
// matches in attributes don't get extra points and thus are implicitly valued less than note path matches
|
// matches in attributes don't get extra points and thus are implicitly valued less than note path matches
|
||||||
|
|
||||||
const chunks = this.notePathTitle.toLowerCase().split(" ");
|
this.addScoreForStrings(tokens, this.notePathTitle, 1);
|
||||||
|
|
||||||
|
// add one more time for note title alone (already contained in the notePathTitle),
|
||||||
|
// thus preferring notes with matches on its own note title as opposed to ancestors or descendants
|
||||||
|
this.addScoreForStrings(tokens, becca.notes[this.noteId].title, 1.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
addScoreForStrings(tokens, str, factor) {
|
||||||
|
const chunks = str.toLowerCase().split(" ");
|
||||||
|
|
||||||
for (const chunk of chunks) {
|
for (const chunk of chunks) {
|
||||||
for (const token of tokens) {
|
for (const token of tokens) {
|
||||||
if (chunk === token) {
|
if (chunk === token) {
|
||||||
this.score += 4 * token.length;
|
this.score += 4 * token.length * factor;
|
||||||
}
|
} else if (chunk.startsWith(token)) {
|
||||||
else if (chunk.startsWith(token)) {
|
this.score += 2 * token.length * factor;
|
||||||
this.score += 2 * token.length;
|
} else if (chunk.includes(token)) {
|
||||||
}
|
this.score += token.length * factor;
|
||||||
else if (chunk.includes(token)) {
|
|
||||||
this.score += token.length;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user