mirror of
https://github.com/zadam/trilium.git
synced 2025-01-14 19:19:28 +08:00
search hit with exact note title match gets a strong score boost, closes #3470
This commit is contained in:
parent
ca4e1c19a7
commit
797ddf6205
5 changed files with 21 additions and 10 deletions
|
@ -68,8 +68,6 @@ function updateNoteAttribute(req) {
|
|||
attribute.markAsDeleted();
|
||||
}
|
||||
|
||||
console.log(attribute);
|
||||
|
||||
attribute.save();
|
||||
|
||||
return {
|
||||
|
|
|
@ -24,6 +24,7 @@ class SearchContext {
|
|||
this.fuzzyAttributeSearch = !!params.fuzzyAttributeSearch;
|
||||
this.highlightedTokens = [];
|
||||
this.originalQuery = "";
|
||||
this.fulltextQuery = ""; // complete fulltext part
|
||||
// if true, becca does not have (up-to-date) information needed to process the query
|
||||
// and some extra data needs to be loaded before executing
|
||||
this.dbLoadNeeded = false;
|
||||
|
|
|
@ -17,18 +17,22 @@ class SearchResult {
|
|||
return this.notePathArray[this.notePathArray.length - 1];
|
||||
}
|
||||
|
||||
computeScore(tokens) {
|
||||
computeScore(fulltextQuery, tokens) {
|
||||
this.score = 0;
|
||||
|
||||
const note = becca.notes[this.noteId];
|
||||
|
||||
if (note.title.toLowerCase() === fulltextQuery) {
|
||||
this.score += 100; // high reward for exact match #3470
|
||||
}
|
||||
|
||||
// notes with matches on its own note title as opposed to ancestors or descendants
|
||||
this.addScoreForStrings(tokens, note.title, 1.5);
|
||||
|
||||
// matches in attributes don't get extra points and thus are implicitly valued less than note path matches
|
||||
|
||||
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
|
||||
const note = becca.notes[this.noteId];
|
||||
this.addScoreForStrings(tokens, note.title, 1.5);
|
||||
|
||||
if (note.isInHiddenSubtree()) {
|
||||
this.score = this.score / 2;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
function lex(str) {
|
||||
str = str.toLowerCase();
|
||||
|
||||
let fulltextQuery = "";
|
||||
const fulltextTokens = [];
|
||||
const expressionTokens = [];
|
||||
|
||||
|
@ -37,6 +38,8 @@ function lex(str) {
|
|||
expressionTokens.push(rec);
|
||||
} else {
|
||||
fulltextTokens.push(rec);
|
||||
|
||||
fulltextQuery = str.substr(0, endIndex + 1);
|
||||
}
|
||||
|
||||
currentWord = '';
|
||||
|
@ -129,7 +132,10 @@ function lex(str) {
|
|||
|
||||
finishWord(str.length - 1);
|
||||
|
||||
fulltextQuery = fulltextQuery.trim();
|
||||
|
||||
return {
|
||||
fulltextQuery,
|
||||
fulltextTokens,
|
||||
expressionTokens
|
||||
}
|
||||
|
|
|
@ -170,7 +170,7 @@ function findResultsWithExpression(expression, searchContext) {
|
|||
.filter(note => !!note);
|
||||
|
||||
for (const res of searchResults) {
|
||||
res.computeScore(searchContext.highlightedTokens);
|
||||
res.computeScore(searchContext.fulltextQuery, searchContext.highlightedTokens);
|
||||
}
|
||||
|
||||
if (!noteSet.sorted) {
|
||||
|
@ -195,7 +195,9 @@ function findResultsWithExpression(expression, searchContext) {
|
|||
}
|
||||
|
||||
function parseQueryToExpression(query, searchContext) {
|
||||
const {fulltextTokens, expressionTokens} = lex(query);
|
||||
const {fulltextQuery, fulltextTokens, expressionTokens} = lex(query);
|
||||
searchContext.fulltextQuery = fulltextQuery;
|
||||
|
||||
let structuredExpressionTokens;
|
||||
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue