diff --git a/package-lock.json b/package-lock.json index 272f64cbe..c5624b0f7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "trilium", - "version": "0.45.0-beta", + "version": "0.45.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2658,9 +2658,9 @@ } }, "electron": { - "version": "9.3.2", - "resolved": "https://registry.npmjs.org/electron/-/electron-9.3.2.tgz", - "integrity": "sha512-0lleEf9msAXGDi2GukAuiGdw3VDgSTlONOnJgqDEz1fuSEVsXz5RX+hNPKDsVDerLTFg/C34RuJf4LwHvkKcBA==", + "version": "9.3.3", + "resolved": "https://registry.npmjs.org/electron/-/electron-9.3.3.tgz", + "integrity": "sha512-xghKeUY1qgnEcJ5w2rXo/toH+8NT2Dktx2aAxBNPV7CIJr3mejJJAPwLbycwtddzr37tgKxHeHlc8ivfKtMkJQ==", "dev": true, "requires": { "@electron/get": "^1.0.1", diff --git a/package.json b/package.json index dada5857c..10549929d 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,7 @@ }, "devDependencies": { "cross-env": "7.0.2", - "electron": "9.3.2", + "electron": "9.3.3", "electron-builder": "22.9.1", "electron-packager": "15.1.0", "electron-rebuild": "2.3.2", diff --git a/spec/search/note_cache_mocking.js b/spec/search/note_cache_mocking.js index 992d2369e..0554093a9 100644 --- a/spec/search/note_cache_mocking.js +++ b/spec/search/note_cache_mocking.js @@ -57,8 +57,15 @@ function id() { return randtoken.generate(10); } -function note(title, type = 'text', mime = 'text/html') { - const note = new Note(noteCache, {noteId: id(), title, type, mime}); +function note(title, extraParams = {}) { + const row = Object.assign({ + noteId: id(), + title: title, + type: 'text', + mime: 'text/html' + }, extraParams); + + const note = new Note(noteCache, row); return new NoteBuilder(note); } diff --git a/spec/search/parser.spec.js b/spec/search/parser.spec.js index 5814fbae3..556986446 100644 --- a/spec/search/parser.spec.js +++ b/spec/search/parser.spec.js @@ -247,6 +247,6 @@ describe("Invalid expressions", () => { searchContext }); - expect(searchContext.error).toEqual('Misplaced or incomplete expression "="') + expect(searchContext.error).toEqual('Relation can be compared only with property, e.g. ~relation.title=hello in ""') }); }); diff --git a/spec/search/search.spec.js b/spec/search/search.spec.js index 30d78bb3d..861b902d8 100644 --- a/spec/search/search.spec.js +++ b/spec/search/search.spec.js @@ -53,8 +53,8 @@ describe("Search", () => { it("normal search looks also at type and mime", () => { rootNote - .child(note("Effective Java", 'book', '')) - .child(note("Hello World.java", 'code', 'text/x-java')); + .child(note("Effective Java", {type: 'book', mime:''})) + .child(note("Hello World.java", {type: 'code', mime: 'text/x-java'})); const searchContext = new SearchContext(); let searchResults = searchService.findNotesWithQuery('book', searchContext); @@ -178,7 +178,7 @@ describe("Search", () => { // dates should not be coerced into numbers which would then give wrong numbers rootNote - .child(note("My note") + .child(note("My note", {dateCreated: dateUtils.localNowDateTime()}) .label('year', new Date().getFullYear().toString()) .label('month', dateUtils.localNowDate().substr(0, 7)) .label('date', dateUtils.localNowDate()) @@ -209,6 +209,8 @@ describe("Search", () => { test("#month = month", 1); test("#month = 'MONTH'", 0); + test("note.dateCreated =* month", 1); + test("#date = TODAY", 1); test("#date = today", 1); test("#date = 'today'", 0); @@ -586,7 +588,7 @@ describe("Search", () => { const searchContext = new SearchContext(); - let searchResults = searchService.findNotesWithQuery('# note.text *=* rati and note.noteId != root', searchContext); + let searchResults = searchService.findNotesWithQuery('# note.text *=* vaki and note.noteId != root', searchContext); expect(searchResults.length).toEqual(1); expect(noteCache.notes[searchResults[0].noteId].title).toEqual("Slovakia"); }); diff --git a/src/services/search/services/build_comparator.js b/src/services/search/services/build_comparator.js index 9f6e602f7..561f3df66 100644 --- a/src/services/search/services/build_comparator.js +++ b/src/services/search/services/build_comparator.js @@ -5,9 +5,9 @@ const stringComparators = { ">=": comparedValue => (val => val >= comparedValue), "<": comparedValue => (val => val < comparedValue), "<=": comparedValue => (val => val <= comparedValue), - "*=": comparedValue => (val => val.endsWith(comparedValue)), - "=*": comparedValue => (val => val.startsWith(comparedValue)), - "*=*": comparedValue => (val => val.includes(comparedValue)), + "*=": comparedValue => (val => val && val.endsWith(comparedValue)), + "=*": comparedValue => (val => val && val.startsWith(comparedValue)), + "*=*": comparedValue => (val => val && val.includes(comparedValue)), }; const numericComparators = { diff --git a/src/services/search/services/parse.js b/src/services/search/services/parse.js index 44084ff0c..fefbb72ad 100644 --- a/src/services/search/services/parse.js +++ b/src/services/search/services/parse.js @@ -80,10 +80,14 @@ function getExpression(tokens, searchContext, level = 0) { if (i + 2 < tokens.length) { if (tokens[i + 1].token === '+') { - delta += parseInt(tokens[i + 2].token); + i += 2; + + delta += parseInt(tokens[i].token); } else if (tokens[i + 1].token === '-') { - delta -= parseInt(tokens[i + 2].token); + i += 2; + + delta -= parseInt(tokens[i].token); } } @@ -196,16 +200,18 @@ function getExpression(tokens, searchContext, level = 0) { if (PropertyComparisonExp.isProperty(tokens[i].token)) { const propertyName = tokens[i].token; const operator = tokens[i + 1].token; - const comparedValue = tokens[i + 2].token; + + i += 2; + + const comparedValue = resolveConstantOperand(); + const comparator = buildComparator(operator, comparedValue); if (!comparator) { - searchContext.addError(`Can't find operator '${operator}' in ${context(i)}`); + searchContext.addError(`Can't find operator '${operator}' in ${context(i - 2)}`); return; } - i += 2; - return new PropertyComparisonExp(propertyName, comparator); }