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",
|
||||
"version": "0.43.4",
|
||||
"version": "0.44.1-beta",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -3543,9 +3543,9 @@
|
||||
}
|
||||
},
|
||||
"electron-rebuild": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/electron-rebuild/-/electron-rebuild-2.0.1.tgz",
|
||||
"integrity": "sha512-oXCnKKS+FpLxXiiSHtSCFI3zo+4H2y6zUegSQTI031RJXn2fzQV9UJMAfBrnW7Z083chIo3/L4+xFM4R8mreOQ==",
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/electron-rebuild/-/electron-rebuild-2.0.2.tgz",
|
||||
"integrity": "sha512-A0rQwHasP4bcHf4vOzDNlTlmTOwNVtMtn+NPOm9GvqwHMttigx43uTLHJ2FKXGaour8HgdeWtg8g70TKiGNImw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@malept/cross-spawn-promise": "^1.1.0",
|
||||
@ -3555,7 +3555,7 @@
|
||||
"fs-extra": "^9.0.1",
|
||||
"node-abi": "^2.19.1",
|
||||
"node-gyp": "^7.1.0",
|
||||
"ora": "^5.0.0",
|
||||
"ora": "^5.1.0",
|
||||
"yargs": "^15.4.1"
|
||||
}
|
||||
},
|
||||
@ -6341,9 +6341,9 @@
|
||||
}
|
||||
},
|
||||
"ora": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ora/-/ora-5.0.0.tgz",
|
||||
"integrity": "sha512-s26qdWqke2kjN/wC4dy+IQPBIMWBJlSU/0JZhk30ZDBLelW25rv66yutUWARMigpGPzcXHb+Nac5pNhN/WsARw==",
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/ora/-/ora-5.1.0.tgz",
|
||||
"integrity": "sha512-9tXIMPvjZ7hPTbk8DFq1f7Kow/HU/pQYB60JbNq+QnGwcyhWVZaQ4hM9zQDEsPxw/muLpgiHSaumUZxCAmod/w==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"chalk": "^4.1.0",
|
||||
|
@ -80,7 +80,7 @@
|
||||
"electron": "9.3.0",
|
||||
"electron-builder": "22.8.0",
|
||||
"electron-packager": "15.1.0",
|
||||
"electron-rebuild": "2.0.1",
|
||||
"electron-rebuild": "2.0.2",
|
||||
"esm": "3.2.25",
|
||||
"jasmine": "3.6.1",
|
||||
"jsdoc": "3.6.5",
|
||||
|
@ -162,7 +162,7 @@ export default class Entrypoints extends Component {
|
||||
}
|
||||
|
||||
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) {
|
||||
toastService.showError("Search failed.", 3000);
|
||||
|
@ -1,13 +1,19 @@
|
||||
"use strict";
|
||||
|
||||
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 scriptService = require('../../services/script');
|
||||
const searchService = require('../../services/search/services/search');
|
||||
|
||||
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 {
|
||||
return {
|
||||
|
@ -11,7 +11,8 @@ const axios = require('axios');
|
||||
const dayjs = require('dayjs');
|
||||
const cloningService = require('./cloning');
|
||||
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.
|
||||
@ -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
|
||||
*
|
||||
* @method
|
||||
* @param {string} searchString
|
||||
* @param {string} query
|
||||
* @param {ParsingContext} [parsingContext]
|
||||
* @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.:
|
||||
|
@ -70,6 +70,10 @@ function parseQueryToExpression(query, parsingContext) {
|
||||
* @return {SearchResult[]}
|
||||
*/
|
||||
function findNotesWithQuery(query, parsingContext) {
|
||||
if (!query.trim().length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return utils.stopWatch(`Search with query "${query}"`, () => {
|
||||
const expression = parseQueryToExpression(query, parsingContext);
|
||||
|
||||
@ -81,25 +85,8 @@ function findNotesWithQuery(query, parsingContext) {
|
||||
}, 20);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {SearchResult[]}
|
||||
*/
|
||||
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);
|
||||
function searchTrimmedNotes(query, parsingContext) {
|
||||
const allSearchResults = findNotesWithQuery(query, parsingContext);
|
||||
const trimmedSearchResults = allSearchResults.slice(0, 200);
|
||||
|
||||
return {
|
||||
@ -109,23 +96,17 @@ function searchTrimmedNotes(query) {
|
||||
}
|
||||
|
||||
function searchNotesForAutocomplete(query) {
|
||||
if (!query.trim().length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const parsingContext = new ParsingContext({
|
||||
includeNoteContent: false,
|
||||
excludeArchived: 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 searchResults.map(result => {
|
||||
return results.map(result => {
|
||||
return {
|
||||
notePath: result.notePath,
|
||||
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 = {
|
||||
searchNotes,
|
||||
searchTrimmedNotes,
|
||||
searchNotesForAutocomplete,
|
||||
findNotesWithQuery,
|
||||
searchNoteEntities
|
||||
findNotesWithQuery
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user