improvements to saved search

This commit is contained in:
zadam 2020-11-30 23:20:12 +01:00
parent 2a6978c349
commit a68c61b2f0
7 changed files with 37 additions and 21 deletions

View 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}`);
}
}
};

View File

@ -152,7 +152,8 @@ class NoteListRenderer {
this.viewType = parentNote.getLabelValue('viewType'); this.viewType = parentNote.getLabelValue('viewType');
if (!['list', 'grid'].includes(this.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'); this.$noteList.addClass(this.viewType + '-view');

View File

@ -32,15 +32,6 @@ export default class NoteListWidget extends TabAwareWidget {
} }
async refreshWithNote(note) { async refreshWithNote(note) {
// this.tabContext.autoBookDisabled;
//
// const noteComplement = await this.tabContext.getNoteComplement();
//
// if (utils.isHtmlEmpty(noteComplement.content)) {
//
// }
//
const noteListRenderer = new NoteListRenderer(note, note.getChildNoteIds()); const noteListRenderer = new NoteListRenderer(note, note.getChildNoteIds());
this.$content.empty().append(await noteListRenderer.renderList()); this.$content.empty().append(await noteListRenderer.renderList());

View File

@ -131,8 +131,7 @@ const TPL = `
} }
.tree-item-button { .tree-item-button {
font-size: 120%; font-size: 130%;
padding: 2px;
cursor: pointer; cursor: pointer;
border-radius: 3px; border-radius: 3px;
border: 1px solid var(--main-background-color); border: 1px solid var(--main-background-color);

View File

@ -110,9 +110,8 @@ export default class SearchDefinitionWidget extends TabAwareWidget {
await treeCache.reloadNotes([this.noteId]); await treeCache.reloadNotes([this.noteId]);
} }
async doRefresh(note) { async refreshWithNote(note) {
this.$component.show(); this.$component.show();
this.$searchString.val(this.note.getLabelValue('searchString')); this.$searchString.val(this.note.getLabelValue('searchString'));
this.$searchWithinNoteContent.prop('checked', this.note.getLabelValue('includeNoteContent') === 'true'); this.$searchWithinNoteContent.prop('checked', this.note.getLabelValue('includeNoteContent') === 'true');
this.$limitSearchToSubtree.val(this.note.getLabelValue('subTreeNoteId')); this.$limitSearchToSubtree.val(this.note.getLabelValue('subTreeNoteId'));

View File

@ -46,16 +46,16 @@ async function searchFromNote(req) {
return [400, `Note ${req.params.noteId} is not search note.`] return [400, `Note ${req.params.noteId} is not search note.`]
} }
const searchString = note.getLabelValue('searchString');
let searchResultNoteIds; let searchResultNoteIds;
try { try {
if (searchString.startsWith('=')) { const searchScript = note.getRelationValue('searchScript');
const relationName = searchString.substr(1).trim(); const searchString = note.getLabelValue('searchString');
searchResultNoteIds = await searchFromRelation(note, relationName); if (searchScript) {
} else { searchResultNoteIds = await searchFromRelation(note, 'searchScript');
}
else if (searchString) {
const searchContext = new SearchContext({ const searchContext = new SearchContext({
includeNoteContent: note.getLabelValue('includeNoteContent') === 'true', includeNoteContent: note.getLabelValue('includeNoteContent') === 'true',
excludeArchived: true, excludeArchived: true,
@ -65,6 +65,9 @@ async function searchFromNote(req) {
searchResultNoteIds = searchService.findNotesWithQuery(searchString, searchContext) searchResultNoteIds = searchService.findNotesWithQuery(searchString, searchContext)
.map(sr => sr.noteId); .map(sr => sr.noteId);
} }
else {
searchResultNoteIds = [];
}
} }
catch (e) { catch (e) {
log.error(`Search failed for note ${note.noteId}: ` + e.message + ": " + e.stack); log.error(`Search failed for note ${note.noteId}: ` + e.message + ": " + e.stack);

View File

@ -4,7 +4,7 @@ const build = require('./build');
const packageJson = require('../../package'); const packageJson = require('../../package');
const {TRILIUM_DATA_DIR} = require('./data_dir'); const {TRILIUM_DATA_DIR} = require('./data_dir');
const APP_DB_VERSION = 171; const APP_DB_VERSION = 172;
const SYNC_VERSION = 16; const SYNC_VERSION = 16;
const CLIPPER_PROTOCOL_VERSION = "1.0"; const CLIPPER_PROTOCOL_VERSION = "1.0";