mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fixed search API and its default settings to include archived notes
This commit is contained in:
parent
69e36d2677
commit
75c9db6432
16
package-lock.json
generated
16
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "trilium",
|
"name": "trilium",
|
||||||
"version": "0.43.4",
|
"version": "0.44.1-beta",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -3543,9 +3543,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"electron-rebuild": {
|
"electron-rebuild": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/electron-rebuild/-/electron-rebuild-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/electron-rebuild/-/electron-rebuild-2.0.2.tgz",
|
||||||
"integrity": "sha512-oXCnKKS+FpLxXiiSHtSCFI3zo+4H2y6zUegSQTI031RJXn2fzQV9UJMAfBrnW7Z083chIo3/L4+xFM4R8mreOQ==",
|
"integrity": "sha512-A0rQwHasP4bcHf4vOzDNlTlmTOwNVtMtn+NPOm9GvqwHMttigx43uTLHJ2FKXGaour8HgdeWtg8g70TKiGNImw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"@malept/cross-spawn-promise": "^1.1.0",
|
"@malept/cross-spawn-promise": "^1.1.0",
|
||||||
@ -3555,7 +3555,7 @@
|
|||||||
"fs-extra": "^9.0.1",
|
"fs-extra": "^9.0.1",
|
||||||
"node-abi": "^2.19.1",
|
"node-abi": "^2.19.1",
|
||||||
"node-gyp": "^7.1.0",
|
"node-gyp": "^7.1.0",
|
||||||
"ora": "^5.0.0",
|
"ora": "^5.1.0",
|
||||||
"yargs": "^15.4.1"
|
"yargs": "^15.4.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -6341,9 +6341,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ora": {
|
"ora": {
|
||||||
"version": "5.0.0",
|
"version": "5.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/ora/-/ora-5.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/ora/-/ora-5.1.0.tgz",
|
||||||
"integrity": "sha512-s26qdWqke2kjN/wC4dy+IQPBIMWBJlSU/0JZhk30ZDBLelW25rv66yutUWARMigpGPzcXHb+Nac5pNhN/WsARw==",
|
"integrity": "sha512-9tXIMPvjZ7hPTbk8DFq1f7Kow/HU/pQYB60JbNq+QnGwcyhWVZaQ4hM9zQDEsPxw/muLpgiHSaumUZxCAmod/w==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"chalk": "^4.1.0",
|
"chalk": "^4.1.0",
|
||||||
|
@ -80,7 +80,7 @@
|
|||||||
"electron": "9.3.0",
|
"electron": "9.3.0",
|
||||||
"electron-builder": "22.8.0",
|
"electron-builder": "22.8.0",
|
||||||
"electron-packager": "15.1.0",
|
"electron-packager": "15.1.0",
|
||||||
"electron-rebuild": "2.0.1",
|
"electron-rebuild": "2.0.2",
|
||||||
"esm": "3.2.25",
|
"esm": "3.2.25",
|
||||||
"jasmine": "3.6.1",
|
"jasmine": "3.6.1",
|
||||||
"jsdoc": "3.6.5",
|
"jsdoc": "3.6.5",
|
||||||
|
@ -162,7 +162,7 @@ export default class Entrypoints extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async searchForResultsCommand({searchText}) {
|
async searchForResultsCommand({searchText}) {
|
||||||
const response = await server.get('search/' + encodeURIComponent(searchText));
|
const response = await server.get('search/' + encodeURIComponent(searchText) + '?includeNoteContent=true&excludeArchived=true&fuzzyAttributeSearch=false');
|
||||||
|
|
||||||
if (!response.success) {
|
if (!response.success) {
|
||||||
toastService.showError("Search failed.", 3000);
|
toastService.showError("Search failed.", 3000);
|
||||||
|
@ -1,13 +1,19 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const repository = require('../../services/repository');
|
const repository = require('../../services/repository');
|
||||||
const noteCacheService = require('../../services/note_cache/note_cache_service');
|
const ParsingContext = require('../../services/search/parsing_context');
|
||||||
const log = require('../../services/log');
|
const log = require('../../services/log');
|
||||||
const scriptService = require('../../services/script');
|
const scriptService = require('../../services/script');
|
||||||
const searchService = require('../../services/search/services/search');
|
const searchService = require('../../services/search/services/search');
|
||||||
|
|
||||||
function searchNotes(req) {
|
function searchNotes(req) {
|
||||||
const {count, results} = searchService.searchTrimmedNotes(req.params.searchString);
|
const parsingContext = new ParsingContext({
|
||||||
|
includeNoteContent: req.query.includeNoteContent === 'true',
|
||||||
|
excludeArchived: req.query.excludeArchived === 'true',
|
||||||
|
fuzzyAttributeSearch: req.query.fuzzyAttributeSearch === 'true'
|
||||||
|
});
|
||||||
|
|
||||||
|
const {count, results} = searchService.searchTrimmedNotes(req.params.searchString, parsingContext);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return {
|
return {
|
||||||
|
@ -11,7 +11,8 @@ const axios = require('axios');
|
|||||||
const dayjs = require('dayjs');
|
const dayjs = require('dayjs');
|
||||||
const cloningService = require('./cloning');
|
const cloningService = require('./cloning');
|
||||||
const appInfo = require('./app_info');
|
const appInfo = require('./app_info');
|
||||||
const searchService = require('./search/services/search.js');
|
const searchService = require('./search/services/search');
|
||||||
|
const ParsingContext = require("./search/parsing_context");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the main backend API interface for scripts. It's published in the local "api" object.
|
* This is the main backend API interface for scripts. It's published in the local "api" object.
|
||||||
@ -90,10 +91,18 @@ function BackendScriptApi(currentNote, apiParams) {
|
|||||||
* "#dateModified =* MONTH AND #log". See full documentation for all options at: https://github.com/zadam/trilium/wiki/Search
|
* "#dateModified =* MONTH AND #log". See full documentation for all options at: https://github.com/zadam/trilium/wiki/Search
|
||||||
*
|
*
|
||||||
* @method
|
* @method
|
||||||
* @param {string} searchString
|
* @param {string} query
|
||||||
|
* @param {ParsingContext} [parsingContext]
|
||||||
* @returns {Note[]}
|
* @returns {Note[]}
|
||||||
*/
|
*/
|
||||||
this.searchForNotes = searchService.searchNoteEntities;
|
this.searchForNotes = (query, parsingContext) => {
|
||||||
|
parsingContext = parsingContext || new ParsingContext();
|
||||||
|
|
||||||
|
const noteIds = searchService.findNotesWithQuery(query, parsingContext)
|
||||||
|
.map(sr => sr.noteId);
|
||||||
|
|
||||||
|
return repository.getNotes(noteIds);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a powerful search method - you can search by attributes and their values, e.g.:
|
* This is a powerful search method - you can search by attributes and their values, e.g.:
|
||||||
|
@ -70,6 +70,10 @@ function parseQueryToExpression(query, parsingContext) {
|
|||||||
* @return {SearchResult[]}
|
* @return {SearchResult[]}
|
||||||
*/
|
*/
|
||||||
function findNotesWithQuery(query, parsingContext) {
|
function findNotesWithQuery(query, parsingContext) {
|
||||||
|
if (!query.trim().length) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
return utils.stopWatch(`Search with query "${query}"`, () => {
|
return utils.stopWatch(`Search with query "${query}"`, () => {
|
||||||
const expression = parseQueryToExpression(query, parsingContext);
|
const expression = parseQueryToExpression(query, parsingContext);
|
||||||
|
|
||||||
@ -81,25 +85,8 @@ function findNotesWithQuery(query, parsingContext) {
|
|||||||
}, 20);
|
}, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
function searchTrimmedNotes(query, parsingContext) {
|
||||||
* @return {SearchResult[]}
|
const allSearchResults = findNotesWithQuery(query, parsingContext);
|
||||||
*/
|
|
||||||
function searchNotes(query) {
|
|
||||||
if (!query.trim().length) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const parsingContext = new ParsingContext({
|
|
||||||
includeNoteContent: true,
|
|
||||||
excludeArchived: true,
|
|
||||||
fuzzyAttributeSearch: false
|
|
||||||
});
|
|
||||||
|
|
||||||
return findNotesWithQuery(query, parsingContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
function searchTrimmedNotes(query) {
|
|
||||||
const allSearchResults = searchNotes(query);
|
|
||||||
const trimmedSearchResults = allSearchResults.slice(0, 200);
|
const trimmedSearchResults = allSearchResults.slice(0, 200);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -109,23 +96,17 @@ function searchTrimmedNotes(query) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function searchNotesForAutocomplete(query) {
|
function searchNotesForAutocomplete(query) {
|
||||||
if (!query.trim().length) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const parsingContext = new ParsingContext({
|
const parsingContext = new ParsingContext({
|
||||||
includeNoteContent: false,
|
includeNoteContent: false,
|
||||||
excludeArchived: true,
|
excludeArchived: true,
|
||||||
fuzzyAttributeSearch: true
|
fuzzyAttributeSearch: true
|
||||||
});
|
});
|
||||||
|
|
||||||
let searchResults = findNotesWithQuery(query, parsingContext);
|
const results = searchTrimmedNotes(query, parsingContext);
|
||||||
|
|
||||||
searchResults = searchResults.slice(0, 200);
|
highlightSearchResults(results, parsingContext.highlightedTokens);
|
||||||
|
|
||||||
highlightSearchResults(searchResults, parsingContext.highlightedTokens);
|
return results.map(result => {
|
||||||
|
|
||||||
return searchResults.map(result => {
|
|
||||||
return {
|
return {
|
||||||
notePath: result.notePath,
|
notePath: result.notePath,
|
||||||
noteTitle: noteCacheService.getNoteTitle(result.noteId),
|
noteTitle: noteCacheService.getNoteTitle(result.noteId),
|
||||||
@ -198,15 +179,8 @@ function formatAttribute(attr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function searchNoteEntities(query) {
|
|
||||||
return searchNotes(query)
|
|
||||||
.map(res => repository.getNote(res.noteId));
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
searchNotes,
|
|
||||||
searchTrimmedNotes,
|
searchTrimmedNotes,
|
||||||
searchNotesForAutocomplete,
|
searchNotesForAutocomplete,
|
||||||
findNotesWithQuery,
|
findNotesWithQuery
|
||||||
searchNoteEntities
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user