diff --git a/spec/search/note_cache_mocking.js b/spec/search/note_cache_mocking.js index 2e5eeab49..7d7ccb683 100644 --- a/spec/search/note_cache_mocking.js +++ b/spec/search/note_cache_mocking.js @@ -42,7 +42,7 @@ class NoteBuilder { } child(childNoteBuilder, prefix = "") { - new Branch(becca, { + new Branch({ branchId: id(), noteId: childNoteBuilder.note.noteId, parentNoteId: this.note.noteId, diff --git a/spec/search/parser.spec.js b/spec/search/parser.spec.js index 71325709e..ff5b5caf5 100644 --- a/spec/search/parser.spec.js +++ b/spec/search/parser.spec.js @@ -37,7 +37,7 @@ describe("Parser", () => { expect(rootExp.constructor.name).toEqual("AndExp"); expect(rootExp.subExpressions[0].constructor.name).toEqual("PropertyComparisonExp"); 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"]); }); @@ -55,7 +55,7 @@ describe("Parser", () => { 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[1].constructor.name).toEqual("NoteContentProtectedFulltextExp"); @@ -182,7 +182,7 @@ describe("Parser", () => { expect(firstSub.propertyName).toEqual('isArchived'); 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(thirdSub.constructor.name).toEqual("LabelComparisonExp"); diff --git a/spec/search/search.spec.js b/spec/search/search.spec.js index 9c4ec61b9..35da25150 100644 --- a/spec/search/search.spec.js +++ b/spec/search/search.spec.js @@ -13,7 +13,7 @@ describe("Search", () => { becca.reset(); 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", () => { @@ -157,6 +157,21 @@ describe("Search", () => { 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", () => { // dates should not be coerced into numbers which would then give wrong numbers @@ -169,7 +184,7 @@ describe("Search", () => { .label('established', '1993-01-01')) .child(note("Hungary") .label('established', '1920-06-04')) - ); + ); const searchContext = new SearchContext(); @@ -218,7 +233,7 @@ describe("Search", () => { test("#month = month", 1); test("#month = 'MONTH'", 0); - test("note.dateCreated =* month", 1); + test("note.dateCreated =* month", 2); test("#date = TODAY", 1); test("#date = today", 1); @@ -337,11 +352,11 @@ describe("Search", () => { 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(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(findNoteByTitle(searchResults, "Taipei")).toBeTruthy(); }); diff --git a/src/public/app/widgets/type_widgets/empty.js b/src/public/app/widgets/type_widgets/empty.js index 2f35d8c3a..6a718084e 100644 --- a/src/public/app/widgets/type_widgets/empty.js +++ b/src/public/app/widgets/type_widgets/empty.js @@ -84,5 +84,11 @@ export default class EmptyTypeWidget extends TypeWidget { .on('click', () => this.triggerCommand('hoistNote', {noteId: workspaceNote.noteId})) ); } + + if (workspaceNotes.length === 0) { + this.$autoComplete + .trigger('focus') + .trigger('select'); + } } } diff --git a/src/services/search/expressions/attribute_exists.js b/src/services/search/expressions/attribute_exists.js index b72c2d69b..f28185ebc 100644 --- a/src/services/search/expressions/attribute_exists.js +++ b/src/services/search/expressions/attribute_exists.js @@ -23,20 +23,18 @@ class AttributeExistsExp extends Expression { for (const attr of attrs) { const note = attr.note; - if (inputNoteSet.hasNoteId(note.noteId)) { - if (attr.isInheritable) { - resultNoteSet.addAll(note.getSubtreeNotesIncludingTemplated()); - } - else if (note.isTemplate()) { - resultNoteSet.addAll(note.getTemplatedNotes()); - } - else { - resultNoteSet.add(note); - } + if (attr.isInheritable) { + resultNoteSet.addAll(note.getSubtreeNotesIncludingTemplated()); + } + else if (note.isTemplate()) { + resultNoteSet.addAll(note.getTemplatedNotes()); + } + else { + resultNoteSet.add(note); } } - return resultNoteSet; + return resultNoteSet.intersection(inputNoteSet); } } diff --git a/src/services/search/expressions/note_cache_flat_text.js b/src/services/search/expressions/note_flat_text.js similarity index 100% rename from src/services/search/expressions/note_cache_flat_text.js rename to src/services/search/expressions/note_flat_text.js diff --git a/src/services/search/services/parse.js b/src/services/search/services/parse.js index a635c7fcb..ac92a2c02 100644 --- a/src/services/search/services/parse.js +++ b/src/services/search/services/parse.js @@ -11,7 +11,7 @@ const RelationWhereExp = require('../expressions/relation_where'); const PropertyComparisonExp = require('../expressions/property_comparison'); const AttributeExistsExp = require('../expressions/attribute_exists'); 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 NoteContentUnprotectedFulltextExp = require('../expressions/note_content_unprotected_fulltext'); const OrderByAndLimitExp = require('../expressions/order_by_and_limit'); @@ -31,13 +31,13 @@ function getFulltext(tokens, searchContext) { if (!searchContext.fastSearch) { return new OrExp([ - new BeccaFlatTextExp(tokens), + new NoteFlatTextExp(tokens), new NoteContentProtectedFulltextExp('*=*', tokens), new NoteContentUnprotectedFulltextExp('*=*', tokens) ]); } else { - return new BeccaFlatTextExp(tokens); + return new NoteFlatTextExp(tokens); } }