Merge remote-tracking branch 'origin/stable'

# Conflicts:
#	package-lock.json
This commit is contained in:
zadam 2021-12-20 22:24:50 +01:00
commit 8b56fb10fd
7 changed files with 42 additions and 23 deletions

View File

@ -42,7 +42,7 @@ class NoteBuilder {
} }
child(childNoteBuilder, prefix = "") { child(childNoteBuilder, prefix = "") {
new Branch(becca, { new Branch({
branchId: id(), branchId: id(),
noteId: childNoteBuilder.note.noteId, noteId: childNoteBuilder.note.noteId,
parentNoteId: this.note.noteId, parentNoteId: this.note.noteId,

View File

@ -37,7 +37,7 @@ describe("Parser", () => {
expect(rootExp.constructor.name).toEqual("AndExp"); expect(rootExp.constructor.name).toEqual("AndExp");
expect(rootExp.subExpressions[0].constructor.name).toEqual("PropertyComparisonExp"); expect(rootExp.subExpressions[0].constructor.name).toEqual("PropertyComparisonExp");
expect(rootExp.subExpressions[1].constructor.name).toEqual("OrExp"); expect(rootExp.subExpressions[1].constructor.name).toEqual("OrExp");
expect(rootExp.subExpressions[1].subExpressions[0].constructor.name).toEqual("BeccaFlatTextExp"); expect(rootExp.subExpressions[1].subExpressions[0].constructor.name).toEqual("NoteFlatTextExp");
expect(rootExp.subExpressions[1].subExpressions[0].tokens).toEqual(["hello", "hi"]); expect(rootExp.subExpressions[1].subExpressions[0].tokens).toEqual(["hello", "hi"]);
}); });
@ -55,7 +55,7 @@ describe("Parser", () => {
const subs = rootExp.subExpressions[1].subExpressions; const subs = rootExp.subExpressions[1].subExpressions;
expect(subs[0].constructor.name).toEqual("BeccaFlatTextExp"); expect(subs[0].constructor.name).toEqual("NoteFlatTextExp");
expect(subs[0].tokens).toEqual(["hello", "hi"]); expect(subs[0].tokens).toEqual(["hello", "hi"]);
expect(subs[1].constructor.name).toEqual("NoteContentProtectedFulltextExp"); expect(subs[1].constructor.name).toEqual("NoteContentProtectedFulltextExp");
@ -182,7 +182,7 @@ describe("Parser", () => {
expect(firstSub.propertyName).toEqual('isArchived'); expect(firstSub.propertyName).toEqual('isArchived');
expect(secondSub.constructor.name).toEqual("OrExp"); expect(secondSub.constructor.name).toEqual("OrExp");
expect(secondSub.subExpressions[0].constructor.name).toEqual("BeccaFlatTextExp"); expect(secondSub.subExpressions[0].constructor.name).toEqual("NoteFlatTextExp");
expect(secondSub.subExpressions[0].tokens).toEqual(["hello"]); expect(secondSub.subExpressions[0].tokens).toEqual(["hello"]);
expect(thirdSub.constructor.name).toEqual("LabelComparisonExp"); expect(thirdSub.constructor.name).toEqual("LabelComparisonExp");

View File

@ -13,7 +13,7 @@ describe("Search", () => {
becca.reset(); becca.reset();
rootNote = new NoteBuilder(new Note({noteId: 'root', title: 'root', type: 'text'})); rootNote = new NoteBuilder(new Note({noteId: 'root', title: 'root', type: 'text'}));
new Branch(becca, {branchId: 'root', noteId: 'root', parentNoteId: 'none', notePosition: 10}); new Branch({branchId: 'root', noteId: 'root', parentNoteId: 'none', notePosition: 10});
}); });
it("simple path match", () => { it("simple path match", () => {
@ -157,6 +157,21 @@ describe("Search", () => {
expect(findNoteByTitle(searchResults, "Czech Republic")).toBeTruthy(); expect(findNoteByTitle(searchResults, "Czech Republic")).toBeTruthy();
}); });
it("inherited label comparison", () => {
rootNote
.child(note("Europe")
.label('country', '', true)
.child(note("Austria"))
.child(note("Czech Republic"))
);
const searchContext = new SearchContext();
const searchResults = searchService.findResultsWithQuery('austria #country', searchContext);
expect(searchResults.length).toEqual(1);
expect(findNoteByTitle(searchResults, "Austria")).toBeTruthy();
});
it("numeric label comparison fallback to string comparison", () => { it("numeric label comparison fallback to string comparison", () => {
// dates should not be coerced into numbers which would then give wrong numbers // dates should not be coerced into numbers which would then give wrong numbers
@ -169,7 +184,7 @@ describe("Search", () => {
.label('established', '1993-01-01')) .label('established', '1993-01-01'))
.child(note("Hungary") .child(note("Hungary")
.label('established', '1920-06-04')) .label('established', '1920-06-04'))
); );
const searchContext = new SearchContext(); const searchContext = new SearchContext();
@ -218,7 +233,7 @@ describe("Search", () => {
test("#month = month", 1); test("#month = month", 1);
test("#month = 'MONTH'", 0); test("#month = 'MONTH'", 0);
test("note.dateCreated =* month", 1); test("note.dateCreated =* month", 2);
test("#date = TODAY", 1); test("#date = TODAY", 1);
test("#date = today", 1); test("#date = today", 1);
@ -337,11 +352,11 @@ describe("Search", () => {
const searchContext = new SearchContext(); const searchContext = new SearchContext();
let searchResults = searchService.findResultsWithQuery('#city AND note.getAncestors().title = Europe', searchContext); let searchResults = searchService.findResultsWithQuery('#city AND note.ancestors.title = Europe', searchContext);
expect(searchResults.length).toEqual(1); expect(searchResults.length).toEqual(1);
expect(findNoteByTitle(searchResults, "Prague")).toBeTruthy(); expect(findNoteByTitle(searchResults, "Prague")).toBeTruthy();
searchResults = searchService.findResultsWithQuery('#city AND note.getAncestors().title = Asia', searchContext); searchResults = searchService.findResultsWithQuery('#city AND note.ancestors.title = Asia', searchContext);
expect(searchResults.length).toEqual(1); expect(searchResults.length).toEqual(1);
expect(findNoteByTitle(searchResults, "Taipei")).toBeTruthy(); expect(findNoteByTitle(searchResults, "Taipei")).toBeTruthy();
}); });

View File

@ -84,5 +84,11 @@ export default class EmptyTypeWidget extends TypeWidget {
.on('click', () => this.triggerCommand('hoistNote', {noteId: workspaceNote.noteId})) .on('click', () => this.triggerCommand('hoistNote', {noteId: workspaceNote.noteId}))
); );
} }
if (workspaceNotes.length === 0) {
this.$autoComplete
.trigger('focus')
.trigger('select');
}
} }
} }

View File

@ -23,20 +23,18 @@ class AttributeExistsExp extends Expression {
for (const attr of attrs) { for (const attr of attrs) {
const note = attr.note; const note = attr.note;
if (inputNoteSet.hasNoteId(note.noteId)) { if (attr.isInheritable) {
if (attr.isInheritable) { resultNoteSet.addAll(note.getSubtreeNotesIncludingTemplated());
resultNoteSet.addAll(note.getSubtreeNotesIncludingTemplated()); }
} else if (note.isTemplate()) {
else if (note.isTemplate()) { resultNoteSet.addAll(note.getTemplatedNotes());
resultNoteSet.addAll(note.getTemplatedNotes()); }
} else {
else { resultNoteSet.add(note);
resultNoteSet.add(note);
}
} }
} }
return resultNoteSet; return resultNoteSet.intersection(inputNoteSet);
} }
} }

View File

@ -11,7 +11,7 @@ const RelationWhereExp = require('../expressions/relation_where');
const PropertyComparisonExp = require('../expressions/property_comparison'); const PropertyComparisonExp = require('../expressions/property_comparison');
const AttributeExistsExp = require('../expressions/attribute_exists'); const AttributeExistsExp = require('../expressions/attribute_exists');
const LabelComparisonExp = require('../expressions/label_comparison'); const LabelComparisonExp = require('../expressions/label_comparison');
const BeccaFlatTextExp = require('../expressions/note_cache_flat_text'); const NoteFlatTextExp = require('../expressions/note_flat_text.js');
const NoteContentProtectedFulltextExp = require('../expressions/note_content_protected_fulltext'); const NoteContentProtectedFulltextExp = require('../expressions/note_content_protected_fulltext');
const NoteContentUnprotectedFulltextExp = require('../expressions/note_content_unprotected_fulltext'); const NoteContentUnprotectedFulltextExp = require('../expressions/note_content_unprotected_fulltext');
const OrderByAndLimitExp = require('../expressions/order_by_and_limit'); const OrderByAndLimitExp = require('../expressions/order_by_and_limit');
@ -31,13 +31,13 @@ function getFulltext(tokens, searchContext) {
if (!searchContext.fastSearch) { if (!searchContext.fastSearch) {
return new OrExp([ return new OrExp([
new BeccaFlatTextExp(tokens), new NoteFlatTextExp(tokens),
new NoteContentProtectedFulltextExp('*=*', tokens), new NoteContentProtectedFulltextExp('*=*', tokens),
new NoteContentUnprotectedFulltextExp('*=*', tokens) new NoteContentUnprotectedFulltextExp('*=*', tokens)
]); ]);
} }
else { else {
return new BeccaFlatTextExp(tokens); return new NoteFlatTextExp(tokens);
} }
} }