refactoring for archived notes handling in note cache

This commit is contained in:
zadam 2020-09-07 00:05:01 +02:00
parent eb4d86f41d
commit 69e36d2677
8 changed files with 22 additions and 29 deletions

View file

@ -0,0 +1 @@
UPDATE attributes SET name = 'archived' WHERE name = 'hideInAutocomplete';

View file

@ -113,8 +113,8 @@ function addImagesToNote(images, note, content) {
new Attribute({
noteId: imageNote.noteId,
type: 'label',
name: 'hideInAutocomplete'
}).save();
name: 'archived'
}).save(); // so that these image notes don't show up in search / autocomplete
new Attribute({
noteId: note.noteId,

View file

@ -4,7 +4,7 @@ const build = require('./build');
const packageJson = require('../../package');
const {TRILIUM_DATA_DIR} = require('./data_dir');
const APP_DB_VERSION = 167;
const APP_DB_VERSION = 168;
const SYNC_VERSION = 16;
const CLIPPER_PROTOCOL_VERSION = "1.0";

View file

@ -138,12 +138,6 @@ class Note {
return this.hasAttribute('label', 'archived');
}
get isHideInAutocompleteOrArchived() {
return this.attributes.find(attr =>
attr.type === 'label'
&& ["archived", "hideInAutocomplete"].includes(attr.name));
}
get hasInheritableOwnedArchivedLabel() {
return !!this.ownedAttributes.find(attr => attr.type === 'label' && attr.name === 'archived' && attr.isInheritable);
}
@ -155,20 +149,19 @@ class Note {
}
/**
* @return {string} - returns flattened textual representation of note, prefixes and attributes usable for searching
* This is used for:
* - fast searching
* - note similarity evaluation
*
* @return {string} - returns flattened textual representation of note, prefixes and attributes
*/
get flatText() {
if (!this.flatTextCache) {
if (this.isHideInAutocompleteOrArchived) {
this.flatTextCache = " "; // can't be empty
return this.flatTextCache;
}
this.flatTextCache = this.noteId + ' ' + this.type + ' ' + this.mime;
this.flatTextCache = this.noteId + ' ' + this.type + ' ' + this.mime + ' ';
for (const branch of this.parentBranches) {
if (branch.prefix) {
this.flatTextCache += branch.prefix + ' - ';
this.flatTextCache += branch.prefix + ' ';
}
}
@ -176,11 +169,13 @@ class Note {
for (const attr of this.attributes) {
// it's best to use space as separator since spaces are filtered from the search string by the tokenization into words
this.flatTextCache += ' ' + (attr.type === 'label' ? '#' : '@') + attr.name;
this.flatTextCache += (attr.type === 'label' ? '#' : '~') + attr.name;
if (attr.value) {
this.flatTextCache += '=' + attr.value;
}
this.flatTextCache += ' ';
}
this.flatTextCache = this.flatTextCache.toLowerCase();

View file

@ -177,7 +177,7 @@ function getNotePath(noteId) {
function evaluateSimilarity(sourceNote, candidateNote, results) {
let coeff = stringSimilarity.compareTwoStrings(sourceNote.flatText, candidateNote.flatText);
if (coeff > 0.4) {
if (coeff > 0.5) {
const notePath = getSomePath(candidateNote);
// this takes care of note hoisting
@ -214,7 +214,7 @@ function findSimilarNotes(noteId) {
}
for (const note of Object.values(noteCache.notes)) {
if (note.isProtected && !note.isDecrypted) {
if (note.noteId === origNote.noteId) {
continue;
}

View file

@ -3,6 +3,7 @@
class ParsingContext {
constructor(params = {}) {
this.includeNoteContent = !!params.includeNoteContent;
this.excludeArchived = !!params.excludeArchived;
this.fuzzyAttributeSearch = !!params.fuzzyAttributeSearch;
this.highlightedTokens = [];
this.originalQuery = "";

View file

@ -27,23 +27,16 @@ function getFulltext(tokens, parsingContext) {
return null;
}
let textSearchExpression;
if (parsingContext.includeNoteContent) {
textSearchExpression = new OrExp([
return new OrExp([
new NoteCacheFulltextExp(tokens),
new NoteContentProtectedFulltextExp('*=*', tokens),
new NoteContentUnprotectedFulltextExp('*=*', tokens)
]);
}
else {
textSearchExpression = new NoteCacheFulltextExp(tokens);
return new NoteCacheFulltextExp(tokens);
}
return new AndExp([
textSearchExpression,
new PropertyComparisonExp("isarchived", buildComparator("=", "false"))
]);
}
function isOperator(str) {
@ -399,6 +392,7 @@ function getExpression(tokens, parsingContext, level = 0) {
function parse({fulltextTokens, expressionTokens, parsingContext}) {
return AndExp.of([
parsingContext.excludeArchived ? new PropertyComparisonExp("isarchived", buildComparator("=", "false")) : null,
getFulltext(fulltextTokens, parsingContext),
getExpression(expressionTokens, parsingContext)
]);

View file

@ -91,6 +91,7 @@ function searchNotes(query) {
const parsingContext = new ParsingContext({
includeNoteContent: true,
excludeArchived: true,
fuzzyAttributeSearch: false
});
@ -114,6 +115,7 @@ function searchNotesForAutocomplete(query) {
const parsingContext = new ParsingContext({
includeNoteContent: false,
excludeArchived: true,
fuzzyAttributeSearch: true
});