mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-02 19:36:12 +01:00 
			
		
		
		
	becca conversion WIP
This commit is contained in:
		@@ -6,6 +6,7 @@ const log = require('../../services/log');
 | 
			
		||||
const scriptService = require('../../services/script');
 | 
			
		||||
const searchService = require('../../services/search/services/search');
 | 
			
		||||
const noteRevisionService = require("../../services/note_revisions.js");
 | 
			
		||||
const {formatAttrForSearch} = require("../../services/attribute_formatter.js");
 | 
			
		||||
 | 
			
		||||
async function searchFromNoteInt(note) {
 | 
			
		||||
    let searchResultNoteIds;
 | 
			
		||||
@@ -267,51 +268,6 @@ function getRelatedNotes(req) {
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function formatAttrForSearch(attr, searchWithValue) {
 | 
			
		||||
    let searchStr = '';
 | 
			
		||||
 | 
			
		||||
    if (attr.type === 'label') {
 | 
			
		||||
        searchStr += '#';
 | 
			
		||||
    }
 | 
			
		||||
    else if (attr.type === 'relation') {
 | 
			
		||||
        searchStr += '~';
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        throw new Error(`Unrecognized attribute type ${JSON.stringify(attr)}`);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    searchStr += attr.name;
 | 
			
		||||
 | 
			
		||||
    if (searchWithValue && attr.value) {
 | 
			
		||||
        if (attr.type === 'relation') {
 | 
			
		||||
            searchStr += ".noteId";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        searchStr += '=';
 | 
			
		||||
        searchStr += formatValue(attr.value);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return searchStr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function formatValue(val) {
 | 
			
		||||
    if (!/[^\w_-]/.test(val)) {
 | 
			
		||||
        return val;
 | 
			
		||||
    }
 | 
			
		||||
    else if (!val.includes('"')) {
 | 
			
		||||
        return '"' + val + '"';
 | 
			
		||||
    }
 | 
			
		||||
    else if (!val.includes("'")) {
 | 
			
		||||
        return "'" + val + "'";
 | 
			
		||||
    }
 | 
			
		||||
    else if (!val.includes("`")) {
 | 
			
		||||
        return "`" + val + "`";
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        return '"' + val.replace(/"/g, '\\"') + '"';
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports = {
 | 
			
		||||
    searchFromNote,
 | 
			
		||||
    searchAndExecute,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user