fulltext now ignores archived notes like it used to in the old implementation

This commit is contained in:
zadam 2020-08-20 00:15:08 +02:00
parent d1f70efdb4
commit 52e0f838a9
7 changed files with 42 additions and 17 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
PKG_DIR=dist/trilium-linux-x64-server
NODE_VERSION=12.16.3
NODE_VERSION=12.18.3
if [ "$1" != "DONTCOPY" ]
then

View File

@ -27,8 +27,9 @@ describe("Parser", () => {
parsingContext: new ParsingContext({includeNoteContent: false})
});
expect(rootExp.constructor.name).toEqual("NoteCacheFlatTextExp");
expect(rootExp.tokens).toEqual(["hello", "hi"]);
expect(rootExp.constructor.name).toEqual("AndExp");
expect(rootExp.subExpressions[0].constructor.name).toEqual("NoteCacheFlatTextExp");
expect(rootExp.subExpressions[0].tokens).toEqual(["hello", "hi"]);
});
it("fulltext parser with content", () => {
@ -38,8 +39,11 @@ describe("Parser", () => {
parsingContext: new ParsingContext({includeNoteContent: true})
});
expect(rootExp.constructor.name).toEqual("OrExp");
const subs = rootExp.subExpressions;
expect(rootExp.constructor.name).toEqual("AndExp");
expect(rootExp.subExpressions[0].constructor.name).toEqual("OrExp");
expect(rootExp.subExpressions[1].constructor.name).toEqual("PropertyComparisonExp");
const subs = rootExp.subExpressions[0].subExpressions;
expect(subs[0].constructor.name).toEqual("NoteCacheFlatTextExp");
expect(subs[0].tokens).toEqual(["hello", "hi"]);
@ -149,8 +153,9 @@ describe("Parser", () => {
expect(rootExp.constructor.name).toEqual("AndExp");
const [firstSub, secondSub] = rootExp.subExpressions;
expect(firstSub.constructor.name).toEqual("NoteCacheFlatTextExp");
expect(firstSub.tokens).toEqual(["hello"]);
expect(firstSub.constructor.name).toEqual("AndExp");
expect(firstSub.subExpressions[0].constructor.name).toEqual("NoteCacheFlatTextExp");
expect(firstSub.subExpressions[0].tokens).toEqual(["hello"]);
expect(secondSub.constructor.name).toEqual("LabelComparisonExp");
expect(secondSub.attributeName).toEqual("mylabel");

View File

@ -544,6 +544,23 @@ describe("Search", () => {
expect(noteCache.notes[searchResults[0].noteId].title).toEqual("Slovakia");
});
it("test that fulltext does not match archived notes", () => {
const italy = note("Italy").label("capital", "Rome");
const slovakia = note("Slovakia").label("capital", "Bratislava");
rootNote
.child(note("Reddit").label('archived', '', true)
.child(note('Post X'))
.child(note('Post Y')))
.child(note ('Reddit is bad'));
const parsingContext = new ParsingContext();
let searchResults = searchService.findNotesWithQuery('reddit', parsingContext);
expect(searchResults.length).toEqual(1);
expect(noteCache.notes[searchResults[0].noteId].title).toEqual("Reddit is bad");
});
// FIXME: test what happens when we order without any filter criteria
// it("comparison between labels", () => {

View File

@ -115,7 +115,7 @@ class Note {
}
hasAttribute(type, name) {
return this.attributes.find(attr => attr.type === type && attr.name === name);
return !!this.attributes.find(attr => attr.type === type && attr.name === name);
}
getLabelValue(name) {

View File

@ -75,11 +75,6 @@ class NoteCacheFlatTextExp extends Expression {
continue;
}
// for leaf note it doesn't matter if "archived" label is inheritable or not
if (note.isArchived) {
continue;
}
const foundAttrTokens = [];
for (const attribute of note.ownedAttributes) {

View File

@ -13,7 +13,7 @@ const PROP_MAPPING = {
"type": "type",
"mime": "mime",
"isprotected": "isProtected",
"isarhived": "isArchived",
"isarchived": "isArchived",
"datecreated": "dateCreated",
"datemodified": "dateModified",
"utcdatecreated": "utcDateCreated",

View File

@ -25,16 +25,24 @@ function getFulltext(tokens, parsingContext) {
if (tokens.length === 0) {
return null;
}
else if (parsingContext.includeNoteContent) {
return new OrExp([
let textSearchExpression;
if (parsingContext.includeNoteContent) {
textSearchExpression = new OrExp([
new NoteCacheFulltextExp(tokens),
new NoteContentProtectedFulltextExp('*=*', tokens),
new NoteContentUnprotectedFulltextExp('*=*', tokens)
]);
}
else {
return new NoteCacheFulltextExp(tokens);
textSearchExpression = new NoteCacheFulltextExp(tokens);
}
return new AndExp([
textSearchExpression,
new PropertyComparisonExp("isarchived", comparatorBuilder("=", "false"))
]);
}
function isOperator(str) {