mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	improvements to saved search
This commit is contained in:
		
							
								
								
									
										23
									
								
								db/migrations/0172__migrate_saved_notes.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								db/migrations/0172__migrate_saved_notes.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,23 @@ | ||||
| const repository = require('../../src/services/repository'); | ||||
|  | ||||
| module.exports = () => { | ||||
|     for (const note of repository.getEntities("SELECT * FROM notes WHERE type = 'search' AND isProtected = 0 AND isDeleted = 0")) { | ||||
|         try { | ||||
|             let origContent = note.getJsonContent(); | ||||
|  | ||||
|             if (!origContent) { | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
|             note.addLabel('searchString', origContent.searchString); | ||||
|  | ||||
|             note.setContent(''); | ||||
|  | ||||
|             note.mime = 'text/plain'; | ||||
|             note.save(); | ||||
|         } | ||||
|         catch (e) { | ||||
|             console.log(`Changing note content for note ${note.noteId} failed with: ${e.message} ${e.stack}`); | ||||
|         } | ||||
|     } | ||||
| }; | ||||
| @@ -152,7 +152,8 @@ class NoteListRenderer { | ||||
|         this.viewType = parentNote.getLabelValue('viewType'); | ||||
|  | ||||
|         if (!['list', 'grid'].includes(this.viewType)) { | ||||
|             this.viewType = 'list'; // default | ||||
|             // when not explicitly set decide based on note type | ||||
|             this.viewType = parentNote.type === 'search' ? 'list' : 'grid'; | ||||
|         } | ||||
|  | ||||
|         this.$noteList.addClass(this.viewType + '-view'); | ||||
|   | ||||
| @@ -32,15 +32,6 @@ export default class NoteListWidget extends TabAwareWidget { | ||||
|     } | ||||
|  | ||||
|     async refreshWithNote(note) { | ||||
|         // this.tabContext.autoBookDisabled; | ||||
|         // | ||||
|         // const noteComplement = await this.tabContext.getNoteComplement(); | ||||
|         // | ||||
|         // if (utils.isHtmlEmpty(noteComplement.content)) { | ||||
|         // | ||||
|         // } | ||||
|         // | ||||
|  | ||||
|         const noteListRenderer = new NoteListRenderer(note, note.getChildNoteIds()); | ||||
|  | ||||
|         this.$content.empty().append(await noteListRenderer.renderList()); | ||||
|   | ||||
| @@ -131,8 +131,7 @@ const TPL = ` | ||||
|     } | ||||
|  | ||||
|     .tree-item-button { | ||||
|         font-size: 120%; | ||||
|         padding: 2px; | ||||
|         font-size: 130%; | ||||
|         cursor: pointer; | ||||
|         border-radius: 3px; | ||||
|         border: 1px solid var(--main-background-color); | ||||
|   | ||||
| @@ -110,9 +110,8 @@ export default class SearchDefinitionWidget extends TabAwareWidget { | ||||
|         await treeCache.reloadNotes([this.noteId]); | ||||
|     } | ||||
|  | ||||
|     async doRefresh(note) { | ||||
|     async refreshWithNote(note) { | ||||
|         this.$component.show(); | ||||
|  | ||||
|         this.$searchString.val(this.note.getLabelValue('searchString')); | ||||
|         this.$searchWithinNoteContent.prop('checked', this.note.getLabelValue('includeNoteContent') === 'true'); | ||||
|         this.$limitSearchToSubtree.val(this.note.getLabelValue('subTreeNoteId')); | ||||
|   | ||||
| @@ -46,16 +46,16 @@ async function searchFromNote(req) { | ||||
|         return [400, `Note ${req.params.noteId} is not search note.`] | ||||
|     } | ||||
|  | ||||
|     const searchString = note.getLabelValue('searchString'); | ||||
|  | ||||
|     let searchResultNoteIds; | ||||
|  | ||||
|     try { | ||||
|         if (searchString.startsWith('=')) { | ||||
|             const relationName = searchString.substr(1).trim(); | ||||
|         const searchScript = note.getRelationValue('searchScript'); | ||||
|         const searchString = note.getLabelValue('searchString'); | ||||
|  | ||||
|             searchResultNoteIds = await searchFromRelation(note, relationName); | ||||
|         } else { | ||||
|         if (searchScript) { | ||||
|             searchResultNoteIds = await searchFromRelation(note, 'searchScript'); | ||||
|         } | ||||
|         else if (searchString) { | ||||
|             const searchContext = new SearchContext({ | ||||
|                 includeNoteContent: note.getLabelValue('includeNoteContent') === 'true', | ||||
|                 excludeArchived: true, | ||||
| @@ -65,6 +65,9 @@ async function searchFromNote(req) { | ||||
|             searchResultNoteIds = searchService.findNotesWithQuery(searchString, searchContext) | ||||
|                 .map(sr => sr.noteId); | ||||
|         } | ||||
|         else { | ||||
|             searchResultNoteIds = []; | ||||
|         } | ||||
|     } | ||||
|     catch (e) { | ||||
|         log.error(`Search failed for note ${note.noteId}: ` + e.message + ": " + e.stack); | ||||
|   | ||||
| @@ -4,7 +4,7 @@ const build = require('./build'); | ||||
| const packageJson = require('../../package'); | ||||
| const {TRILIUM_DATA_DIR} = require('./data_dir'); | ||||
|  | ||||
| const APP_DB_VERSION = 171; | ||||
| const APP_DB_VERSION = 172; | ||||
| const SYNC_VERSION = 16; | ||||
| const CLIPPER_PROTOCOL_VERSION = "1.0"; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user