mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
refactored note_content_protected_fulltext.js and note_content_unprotected_fulltext.js into one class
This commit is contained in:
parent
963c18b8e4
commit
91d23c540a
122
package-lock.json
generated
122
package-lock.json
generated
@ -19,8 +19,8 @@
|
||||
"commonmark": "0.30.0",
|
||||
"cookie-parser": "1.4.6",
|
||||
"csurf": "1.11.0",
|
||||
"dayjs": "1.11.1",
|
||||
"ejs": "3.1.7",
|
||||
"dayjs": "1.11.2",
|
||||
"ejs": "3.1.8",
|
||||
"electron-debug": "3.2.0",
|
||||
"electron-dl": "3.3.1",
|
||||
"electron-find": "1.0.7",
|
||||
@ -28,7 +28,7 @@
|
||||
"express": "4.18.1",
|
||||
"express-partial-content": "1.0.2",
|
||||
"express-rate-limit": "6.4.0",
|
||||
"express-session": "1.17.2",
|
||||
"express-session": "1.17.3",
|
||||
"fs-extra": "10.1.0",
|
||||
"helmet": "5.0.2",
|
||||
"html": "1.0.0",
|
||||
@ -70,7 +70,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"cross-env": "7.0.3",
|
||||
"electron": "16.2.4",
|
||||
"electron": "16.2.6",
|
||||
"electron-builder": "23.0.3",
|
||||
"electron-packager": "15.5.1",
|
||||
"electron-rebuild": "3.2.7",
|
||||
@ -79,7 +79,7 @@
|
||||
"jsdoc": "3.6.10",
|
||||
"lorem-ipsum": "2.0.4",
|
||||
"rcedit": "3.0.1",
|
||||
"webpack": "5.72.0",
|
||||
"webpack": "5.72.1",
|
||||
"webpack-cli": "4.9.2"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
@ -3200,9 +3200,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/dayjs": {
|
||||
"version": "1.11.1",
|
||||
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.1.tgz",
|
||||
"integrity": "sha512-ER7EjqVAMkRRsxNCC5YqJ9d9VQYuWdGt7aiH2qA5R5wt8ZmWaP2dLUSIK6y/kVzLMlmh1Tvu5xUf4M/wdGJ5KA=="
|
||||
"version": "1.11.2",
|
||||
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.2.tgz",
|
||||
"integrity": "sha512-F4LXf1OeU9hrSYRPTTj/6FbO4HTjPKXvEIC1P2kcnFurViINCVk3ZV0xAS3XVx9MkMsXbbqlK6hjseaYbgKEHw=="
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "4.3.3",
|
||||
@ -3596,9 +3596,9 @@
|
||||
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
|
||||
},
|
||||
"node_modules/ejs": {
|
||||
"version": "3.1.7",
|
||||
"resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.7.tgz",
|
||||
"integrity": "sha512-BIar7R6abbUxDA3bfXrO4DSgwo8I+fB5/1zgujl3HLLjwd6+9iOnrT+t3grn2qbk9vOgBubXOFwX2m9axoFaGw==",
|
||||
"version": "3.1.8",
|
||||
"resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.8.tgz",
|
||||
"integrity": "sha512-/sXZeMlhS0ArkfX2Aw780gJzXSMPnKjtspYZv+f3NiKLlubezAHDU5+9xz6gd3/NhG3txQCo6xlglmTS+oTGEQ==",
|
||||
"dependencies": {
|
||||
"jake": "^10.8.5"
|
||||
},
|
||||
@ -3610,9 +3610,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/electron": {
|
||||
"version": "16.2.4",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-16.2.4.tgz",
|
||||
"integrity": "sha512-A40aU+gh41EtyspwEBMSuy5KBB56Z8OYSDsqZK9Y8nJdVIFKDtp824x/jnU7N6zNnzVil6oDIFBMGp/hkFu6FQ==",
|
||||
"version": "16.2.6",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-16.2.6.tgz",
|
||||
"integrity": "sha512-FJLnIu318WNh1WigMmWqSidOPwipwym2Qi3Hs/YY6znquztf6ZJuaq/TdJJyHIJHld+znG0hSmq3VbyW5KUr9A==",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"@electron/get": "^1.13.0",
|
||||
@ -4630,9 +4630,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/enhanced-resolve": {
|
||||
"version": "5.9.2",
|
||||
"resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.9.2.tgz",
|
||||
"integrity": "sha512-GIm3fQfwLJ8YZx2smuHpBKkXC1yOk+OBEmKckVyL0i/ea8mqDEykK3ld5dgH1QYPNyT/lIllxV2LULnxCHaHkA==",
|
||||
"version": "5.9.3",
|
||||
"resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.9.3.tgz",
|
||||
"integrity": "sha512-Bq9VSor+kjvW3f9/MiiR4eE3XYgOl7/rS8lnSxbRbF3kS0B2r+Y9w5krBWxZgDxASVZbdYrn5wT4j/Wb0J9qow==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"graceful-fs": "^4.2.4",
|
||||
@ -4960,11 +4960,11 @@
|
||||
}
|
||||
},
|
||||
"node_modules/express-session": {
|
||||
"version": "1.17.2",
|
||||
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.2.tgz",
|
||||
"integrity": "sha512-mPcYcLA0lvh7D4Oqr5aNJFMtBMKPLl++OKKxkHzZ0U0oDq1rpKBnkR5f5vCHR26VeArlTOEF9td4x5IjICksRQ==",
|
||||
"version": "1.17.3",
|
||||
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.3.tgz",
|
||||
"integrity": "sha512-4+otWXlShYlG1Ma+2Jnn+xgKUZTMJ5QD3YvfilX3AcocOAbIkVylSWEklzALe/+Pu4qV6TYBj5GwOBFfdKqLBw==",
|
||||
"dependencies": {
|
||||
"cookie": "0.4.1",
|
||||
"cookie": "0.4.2",
|
||||
"cookie-signature": "1.0.6",
|
||||
"debug": "2.6.9",
|
||||
"depd": "~2.0.0",
|
||||
@ -4978,9 +4978,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/express-session/node_modules/cookie": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz",
|
||||
"integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==",
|
||||
"version": "0.4.2",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz",
|
||||
"integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
@ -6745,10 +6745,10 @@
|
||||
"resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz",
|
||||
"integrity": "sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg="
|
||||
},
|
||||
"node_modules/json-parse-better-errors": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz",
|
||||
"integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==",
|
||||
"node_modules/json-parse-even-better-errors": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz",
|
||||
"integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/json-schema": {
|
||||
@ -10323,9 +10323,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/webpack": {
|
||||
"version": "5.72.0",
|
||||
"resolved": "https://registry.npmjs.org/webpack/-/webpack-5.72.0.tgz",
|
||||
"integrity": "sha512-qmSmbspI0Qo5ld49htys8GY9XhS9CGqFoHTsOVAnjBdg0Zn79y135R+k4IR4rKK6+eKaabMhJwiVB7xw0SJu5w==",
|
||||
"version": "5.72.1",
|
||||
"resolved": "https://registry.npmjs.org/webpack/-/webpack-5.72.1.tgz",
|
||||
"integrity": "sha512-dXG5zXCLspQR4krZVR6QgajnZOjW2K/djHvdcRaDQvsjV9z9vaW6+ja5dZOYbqBBjF6kGXka/2ZyxNdc+8Jung==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/eslint-scope": "^3.7.3",
|
||||
@ -10337,13 +10337,13 @@
|
||||
"acorn-import-assertions": "^1.7.6",
|
||||
"browserslist": "^4.14.5",
|
||||
"chrome-trace-event": "^1.0.2",
|
||||
"enhanced-resolve": "^5.9.2",
|
||||
"enhanced-resolve": "^5.9.3",
|
||||
"es-module-lexer": "^0.9.0",
|
||||
"eslint-scope": "5.1.1",
|
||||
"events": "^3.2.0",
|
||||
"glob-to-regexp": "^0.4.1",
|
||||
"graceful-fs": "^4.2.9",
|
||||
"json-parse-better-errors": "^1.0.2",
|
||||
"json-parse-even-better-errors": "^2.3.1",
|
||||
"loader-runner": "^4.2.0",
|
||||
"mime-types": "^2.1.27",
|
||||
"neo-async": "^2.6.2",
|
||||
@ -13413,9 +13413,9 @@
|
||||
}
|
||||
},
|
||||
"dayjs": {
|
||||
"version": "1.11.1",
|
||||
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.1.tgz",
|
||||
"integrity": "sha512-ER7EjqVAMkRRsxNCC5YqJ9d9VQYuWdGt7aiH2qA5R5wt8ZmWaP2dLUSIK6y/kVzLMlmh1Tvu5xUf4M/wdGJ5KA=="
|
||||
"version": "1.11.2",
|
||||
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.2.tgz",
|
||||
"integrity": "sha512-F4LXf1OeU9hrSYRPTTj/6FbO4HTjPKXvEIC1P2kcnFurViINCVk3ZV0xAS3XVx9MkMsXbbqlK6hjseaYbgKEHw=="
|
||||
},
|
||||
"debug": {
|
||||
"version": "4.3.3",
|
||||
@ -13721,17 +13721,17 @@
|
||||
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
|
||||
},
|
||||
"ejs": {
|
||||
"version": "3.1.7",
|
||||
"resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.7.tgz",
|
||||
"integrity": "sha512-BIar7R6abbUxDA3bfXrO4DSgwo8I+fB5/1zgujl3HLLjwd6+9iOnrT+t3grn2qbk9vOgBubXOFwX2m9axoFaGw==",
|
||||
"version": "3.1.8",
|
||||
"resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.8.tgz",
|
||||
"integrity": "sha512-/sXZeMlhS0ArkfX2Aw780gJzXSMPnKjtspYZv+f3NiKLlubezAHDU5+9xz6gd3/NhG3txQCo6xlglmTS+oTGEQ==",
|
||||
"requires": {
|
||||
"jake": "^10.8.5"
|
||||
}
|
||||
},
|
||||
"electron": {
|
||||
"version": "16.2.4",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-16.2.4.tgz",
|
||||
"integrity": "sha512-A40aU+gh41EtyspwEBMSuy5KBB56Z8OYSDsqZK9Y8nJdVIFKDtp824x/jnU7N6zNnzVil6oDIFBMGp/hkFu6FQ==",
|
||||
"version": "16.2.6",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-16.2.6.tgz",
|
||||
"integrity": "sha512-FJLnIu318WNh1WigMmWqSidOPwipwym2Qi3Hs/YY6znquztf6ZJuaq/TdJJyHIJHld+znG0hSmq3VbyW5KUr9A==",
|
||||
"requires": {
|
||||
"@electron/get": "^1.13.0",
|
||||
"@types/node": "^14.6.2",
|
||||
@ -14503,9 +14503,9 @@
|
||||
}
|
||||
},
|
||||
"enhanced-resolve": {
|
||||
"version": "5.9.2",
|
||||
"resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.9.2.tgz",
|
||||
"integrity": "sha512-GIm3fQfwLJ8YZx2smuHpBKkXC1yOk+OBEmKckVyL0i/ea8mqDEykK3ld5dgH1QYPNyT/lIllxV2LULnxCHaHkA==",
|
||||
"version": "5.9.3",
|
||||
"resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.9.3.tgz",
|
||||
"integrity": "sha512-Bq9VSor+kjvW3f9/MiiR4eE3XYgOl7/rS8lnSxbRbF3kS0B2r+Y9w5krBWxZgDxASVZbdYrn5wT4j/Wb0J9qow==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"graceful-fs": "^4.2.4",
|
||||
@ -14780,11 +14780,11 @@
|
||||
"requires": {}
|
||||
},
|
||||
"express-session": {
|
||||
"version": "1.17.2",
|
||||
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.2.tgz",
|
||||
"integrity": "sha512-mPcYcLA0lvh7D4Oqr5aNJFMtBMKPLl++OKKxkHzZ0U0oDq1rpKBnkR5f5vCHR26VeArlTOEF9td4x5IjICksRQ==",
|
||||
"version": "1.17.3",
|
||||
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.17.3.tgz",
|
||||
"integrity": "sha512-4+otWXlShYlG1Ma+2Jnn+xgKUZTMJ5QD3YvfilX3AcocOAbIkVylSWEklzALe/+Pu4qV6TYBj5GwOBFfdKqLBw==",
|
||||
"requires": {
|
||||
"cookie": "0.4.1",
|
||||
"cookie": "0.4.2",
|
||||
"cookie-signature": "1.0.6",
|
||||
"debug": "2.6.9",
|
||||
"depd": "~2.0.0",
|
||||
@ -14795,9 +14795,9 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"cookie": {
|
||||
"version": "0.4.1",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz",
|
||||
"integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA=="
|
||||
"version": "0.4.2",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz",
|
||||
"integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA=="
|
||||
},
|
||||
"debug": {
|
||||
"version": "2.6.9",
|
||||
@ -16110,10 +16110,10 @@
|
||||
"resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz",
|
||||
"integrity": "sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg="
|
||||
},
|
||||
"json-parse-better-errors": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz",
|
||||
"integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==",
|
||||
"json-parse-even-better-errors": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz",
|
||||
"integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==",
|
||||
"dev": true
|
||||
},
|
||||
"json-schema": {
|
||||
@ -18906,9 +18906,9 @@
|
||||
"integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g=="
|
||||
},
|
||||
"webpack": {
|
||||
"version": "5.72.0",
|
||||
"resolved": "https://registry.npmjs.org/webpack/-/webpack-5.72.0.tgz",
|
||||
"integrity": "sha512-qmSmbspI0Qo5ld49htys8GY9XhS9CGqFoHTsOVAnjBdg0Zn79y135R+k4IR4rKK6+eKaabMhJwiVB7xw0SJu5w==",
|
||||
"version": "5.72.1",
|
||||
"resolved": "https://registry.npmjs.org/webpack/-/webpack-5.72.1.tgz",
|
||||
"integrity": "sha512-dXG5zXCLspQR4krZVR6QgajnZOjW2K/djHvdcRaDQvsjV9z9vaW6+ja5dZOYbqBBjF6kGXka/2ZyxNdc+8Jung==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/eslint-scope": "^3.7.3",
|
||||
@ -18920,13 +18920,13 @@
|
||||
"acorn-import-assertions": "^1.7.6",
|
||||
"browserslist": "^4.14.5",
|
||||
"chrome-trace-event": "^1.0.2",
|
||||
"enhanced-resolve": "^5.9.2",
|
||||
"enhanced-resolve": "^5.9.3",
|
||||
"es-module-lexer": "^0.9.0",
|
||||
"eslint-scope": "5.1.1",
|
||||
"events": "^3.2.0",
|
||||
"glob-to-regexp": "^0.4.1",
|
||||
"graceful-fs": "^4.2.9",
|
||||
"json-parse-better-errors": "^1.0.2",
|
||||
"json-parse-even-better-errors": "^2.3.1",
|
||||
"loader-runner": "^4.2.0",
|
||||
"mime-types": "^2.1.27",
|
||||
"neo-async": "^2.6.2",
|
||||
|
10
package.json
10
package.json
@ -33,8 +33,8 @@
|
||||
"commonmark": "0.30.0",
|
||||
"cookie-parser": "1.4.6",
|
||||
"csurf": "1.11.0",
|
||||
"dayjs": "1.11.1",
|
||||
"ejs": "3.1.7",
|
||||
"dayjs": "1.11.2",
|
||||
"ejs": "3.1.8",
|
||||
"electron-debug": "3.2.0",
|
||||
"electron-dl": "3.3.1",
|
||||
"electron-find": "1.0.7",
|
||||
@ -43,7 +43,7 @@
|
||||
"express": "4.18.1",
|
||||
"express-partial-content": "1.0.2",
|
||||
"express-rate-limit": "6.4.0",
|
||||
"express-session": "1.17.2",
|
||||
"express-session": "1.17.3",
|
||||
"fs-extra": "10.1.0",
|
||||
"helmet": "5.0.2",
|
||||
"html": "1.0.0",
|
||||
@ -82,7 +82,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"cross-env": "7.0.3",
|
||||
"electron": "16.2.4",
|
||||
"electron": "16.2.6",
|
||||
"electron-builder": "23.0.3",
|
||||
"electron-packager": "15.5.1",
|
||||
"electron-rebuild": "3.2.7",
|
||||
@ -91,7 +91,7 @@
|
||||
"jsdoc": "3.6.10",
|
||||
"lorem-ipsum": "2.0.4",
|
||||
"rcedit": "3.0.1",
|
||||
"webpack": "5.72.0",
|
||||
"webpack": "5.72.1",
|
||||
"webpack-cli": "4.9.2"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
|
@ -58,11 +58,8 @@ describe("Parser", () => {
|
||||
expect(subs[0].constructor.name).toEqual("NoteFlatTextExp");
|
||||
expect(subs[0].tokens).toEqual(["hello", "hi"]);
|
||||
|
||||
expect(subs[1].constructor.name).toEqual("NoteContentProtectedFulltextExp");
|
||||
expect(subs[1].constructor.name).toEqual("NoteContentFulltextExp");
|
||||
expect(subs[1].tokens).toEqual(["hello", "hi"]);
|
||||
|
||||
expect(subs[2].constructor.name).toEqual("NoteContentUnprotectedFulltextExp");
|
||||
expect(subs[2].tokens).toEqual(["hello", "hi"]);
|
||||
});
|
||||
|
||||
it("simple label comparison", () => {
|
||||
|
@ -8,8 +8,7 @@ const protectedSessionService = require('../../protected_session');
|
||||
const striptags = require('striptags');
|
||||
const utils = require("../../utils");
|
||||
|
||||
// FIXME: create common subclass with NoteContentUnprotectedFulltextExp to avoid duplication
|
||||
class NoteContentProtectedFulltextExp extends Expression {
|
||||
class NoteContentFulltextExp extends Expression {
|
||||
constructor(operator, {tokens, raw, flatText}) {
|
||||
super();
|
||||
|
||||
@ -24,29 +23,29 @@ class NoteContentProtectedFulltextExp extends Expression {
|
||||
|
||||
execute(inputNoteSet) {
|
||||
const resultNoteSet = new NoteSet();
|
||||
|
||||
if (!protectedSessionService.isProtectedSessionAvailable()) {
|
||||
return resultNoteSet;
|
||||
}
|
||||
|
||||
const sql = require('../../sql');
|
||||
|
||||
for (let {noteId, type, mime, content} of sql.iterateRows(`
|
||||
SELECT noteId, type, mime, content
|
||||
for (let {noteId, type, mime, content, isProtected} of sql.iterateRows(`
|
||||
SELECT noteId, type, mime, content, isProtected
|
||||
FROM notes JOIN note_contents USING (noteId)
|
||||
WHERE type IN ('text', 'code', 'mermaid') AND isDeleted = 0 AND isProtected = 1`)) {
|
||||
WHERE type IN ('text', 'code', 'mermaid') AND isDeleted = 0`)) {
|
||||
|
||||
if (!inputNoteSet.hasNoteId(noteId) || !(noteId in becca.notes)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isProtected) {
|
||||
if (!protectedSessionService.isProtectedSessionAvailable()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
content = protectedSessionService.decryptString(content);
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
log.info(`Cannot decrypt content of note ${noteId}`);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
content = this.preprocessContent(content, type, mime);
|
||||
|
||||
@ -82,8 +81,9 @@ class NoteContentProtectedFulltextExp extends Expression {
|
||||
|
||||
content = content.replace(/ /g, ' ');
|
||||
}
|
||||
return content;
|
||||
|
||||
return content.trim();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NoteContentProtectedFulltextExp;
|
||||
module.exports = NoteContentFulltextExp;
|
@ -1,75 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
const Expression = require('./expression');
|
||||
const NoteSet = require('../note_set');
|
||||
const becca = require('../../../becca/becca');
|
||||
const striptags = require('striptags');
|
||||
const utils = require("../../utils");
|
||||
|
||||
// FIXME: create common subclass with NoteContentProtectedFulltextExp to avoid duplication
|
||||
class NoteContentUnprotectedFulltextExp extends Expression {
|
||||
constructor(operator, {tokens, raw, flatText}) {
|
||||
super();
|
||||
|
||||
if (operator !== '*=*') {
|
||||
throw new Error(`Note content can be searched only with *=* operator`);
|
||||
}
|
||||
|
||||
this.tokens = tokens;
|
||||
this.raw = !!raw;
|
||||
this.flatText = !!flatText;
|
||||
}
|
||||
|
||||
execute(inputNoteSet) {
|
||||
const resultNoteSet = new NoteSet();
|
||||
|
||||
const sql = require('../../sql');
|
||||
|
||||
for (let {noteId, type, mime, content} of sql.iterateRows(`
|
||||
SELECT noteId, type, mime, content
|
||||
FROM notes JOIN note_contents USING (noteId)
|
||||
WHERE type IN ('text', 'code', 'mermaid') AND isDeleted = 0 AND isProtected = 0`)) {
|
||||
|
||||
if (!inputNoteSet.hasNoteId(noteId) || !(noteId in becca.notes)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
content = this.preprocessContent(content, type, mime);
|
||||
|
||||
const nonMatchingToken = this.tokens.find(token =>
|
||||
!content.includes(token) &&
|
||||
(
|
||||
// in case of default fulltext search we should consider both title, attrs and content
|
||||
// so e.g. "hello world" should match when "hello" is in title and "world" in content
|
||||
!this.flatText
|
||||
|| !becca.notes[noteId].getFlatText().includes(token)
|
||||
)
|
||||
);
|
||||
|
||||
if (!nonMatchingToken) {
|
||||
resultNoteSet.add(becca.notes[noteId]);
|
||||
}
|
||||
}
|
||||
|
||||
return resultNoteSet;
|
||||
}
|
||||
|
||||
preprocessContent(content, type, mime) {
|
||||
content = utils.normalize(content.toString());
|
||||
|
||||
if (type === 'text' && mime === 'text/html') {
|
||||
if (!this.raw && content.length < 20000) { // striptags is slow for very large notes
|
||||
// allow link to preserve URLs: https://github.com/zadam/trilium/issues/2412
|
||||
content = striptags(content, ['a']);
|
||||
|
||||
// at least the closing tag can be easily stripped
|
||||
content = content.replace(/<\/a>/ig, "");
|
||||
}
|
||||
|
||||
content = content.replace(/ /g, ' ');
|
||||
}
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NoteContentUnprotectedFulltextExp;
|
@ -12,8 +12,7 @@ const PropertyComparisonExp = require('../expressions/property_comparison');
|
||||
const AttributeExistsExp = require('../expressions/attribute_exists');
|
||||
const LabelComparisonExp = require('../expressions/label_comparison');
|
||||
const NoteFlatTextExp = require('../expressions/note_flat_text');
|
||||
const NoteContentProtectedFulltextExp = require('../expressions/note_content_protected_fulltext');
|
||||
const NoteContentUnprotectedFulltextExp = require('../expressions/note_content_unprotected_fulltext');
|
||||
const NoteContentFulltextExp = require('../expressions/note_content_fulltext.js');
|
||||
const OrderByAndLimitExp = require('../expressions/order_by_and_limit');
|
||||
const AncestorExp = require("../expressions/ancestor");
|
||||
const buildComparator = require('./build_comparator');
|
||||
@ -32,8 +31,7 @@ function getFulltext(tokens, searchContext) {
|
||||
if (!searchContext.fastSearch) {
|
||||
return new OrExp([
|
||||
new NoteFlatTextExp(tokens),
|
||||
new NoteContentProtectedFulltextExp('*=*', {tokens, flatText: true}),
|
||||
new NoteContentUnprotectedFulltextExp('*=*', {tokens, flatText: true})
|
||||
new NoteContentFulltextExp('*=*', {tokens, flatText: true})
|
||||
]);
|
||||
}
|
||||
else {
|
||||
@ -140,10 +138,7 @@ function getExpression(tokens, searchContext, level = 0) {
|
||||
|
||||
i++;
|
||||
|
||||
return new OrExp([
|
||||
new NoteContentUnprotectedFulltextExp(operator, {tokens: [tokens[i].token], raw }),
|
||||
new NoteContentProtectedFulltextExp(operator, {tokens: [tokens[i].token], raw })
|
||||
]);
|
||||
return new NoteContentFulltextExp(operator, {tokens: [tokens[i].token], raw });
|
||||
}
|
||||
|
||||
if (tokens[i].token === 'parents') {
|
||||
@ -196,8 +191,7 @@ function getExpression(tokens, searchContext, level = 0) {
|
||||
|
||||
return new OrExp([
|
||||
new PropertyComparisonExp(searchContext, 'title', '*=*', tokens[i].token),
|
||||
new NoteContentProtectedFulltextExp('*=*', {tokens: [tokens[i].token]}),
|
||||
new NoteContentUnprotectedFulltextExp('*=*', {tokens: [tokens[i].token]})
|
||||
new NoteContentFulltextExp('*=*', {tokens: [tokens[i].token]})
|
||||
]);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user