Skip to content

Build your personal knowledge base with Trilium Notes

fix using smart values with .dateCreated, closes #1338

zadam8c4ff7ed2a41
diff --git a/package-lock.json b/package-lock.json
index 272f64cbeb..c5624b0f72 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 dada5857cc..10549929d9 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 992d2369ec..0554093a9c 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 5814fbae39..5569864464 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 30d78bb3db..861b902d80 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 9f6e602f76..561f3df66b 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 44084ff0cf..fefbb72ad8 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);
}