mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
search error handling & sanitize input for default fulltext
This commit is contained in:
parent
fe3a0bc756
commit
ef1b32d586
@ -80,12 +80,17 @@ async function doSearch(searchText) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const results = await server.get('search/' + encodeURIComponent(searchText));
|
const response = await server.get('search/' + encodeURIComponent(searchText));
|
||||||
|
|
||||||
|
if (!response.success) {
|
||||||
|
infoService.showError("Search failed.", 3000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$searchResultsInner.empty();
|
$searchResultsInner.empty();
|
||||||
$searchResults.show();
|
$searchResults.show();
|
||||||
|
|
||||||
for (const result of results) {
|
for (const result of response.results) {
|
||||||
const link = $('<a>', {
|
const link = $('<a>', {
|
||||||
href: 'javascript:',
|
href: 'javascript:',
|
||||||
text: result.title
|
text: result.title
|
||||||
|
@ -9,7 +9,17 @@ const searchService = require('../../services/search');
|
|||||||
async function searchNotes(req) {
|
async function searchNotes(req) {
|
||||||
const noteIds = await searchService.searchForNoteIds(req.params.searchString);
|
const noteIds = await searchService.searchForNoteIds(req.params.searchString);
|
||||||
|
|
||||||
return noteIds.map(noteCacheService.getNotePath).filter(res => !!res);
|
try {
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
results: noteIds.map(noteCacheService.getNotePath).filter(res => !!res)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
return {
|
||||||
|
success: false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function searchFromNote(req) {
|
async function searchFromNote(req) {
|
||||||
|
@ -45,18 +45,20 @@ function calculateSmartValue(v) {
|
|||||||
module.exports = function (searchText) {
|
module.exports = function (searchText) {
|
||||||
// if the string doesn't start with attribute then we consider it as just standard full text search
|
// if the string doesn't start with attribute then we consider it as just standard full text search
|
||||||
if (!searchText.trim().startsWith("@")) {
|
if (!searchText.trim().startsWith("@")) {
|
||||||
|
const sanitizedSearchText = searchText.replace(/[^\w ]+/g, "");
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
relation: 'and',
|
relation: 'and',
|
||||||
name: 'text',
|
name: 'text',
|
||||||
operator: '=',
|
operator: '=',
|
||||||
value: searchText
|
value: sanitizedSearchText
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
relation: 'or',
|
relation: 'or',
|
||||||
name: 'noteId',
|
name: 'noteId',
|
||||||
operator: '=',
|
operator: '=',
|
||||||
value: searchText
|
value: sanitizedSearchText
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user