better error reporting on failed search

This commit is contained in:
zadam 2020-09-23 22:18:26 +02:00
parent 2b1383205b
commit bdebb35f62
5 changed files with 20 additions and 3 deletions

View File

@ -165,7 +165,7 @@ export default class Entrypoints extends Component {
const response = await server.get('search/' + encodeURIComponent(searchText) + '?includeNoteContent=true&excludeArchived=true&fuzzyAttributeSearch=false'); const response = await server.get('search/' + encodeURIComponent(searchText) + '?includeNoteContent=true&excludeArchived=true&fuzzyAttributeSearch=false');
if (!response.success) { if (!response.success) {
toastService.showError("Search failed.", 3000); toastService.showError("Search failed: " + response.message, 10000);
return; return;
} }

View File

@ -17,7 +17,8 @@ function searchNotes(req) {
try { try {
return { return {
success: true, success: !searchContext.hasError(),
message: searchContext.getError(),
count, count,
results results
} }

View File

@ -16,6 +16,14 @@ class SearchContext {
this.error = error; this.error = error;
} }
} }
hasError() {
return !!this.error;
}
getError() {
return this.error;
}
} }
module.exports = SearchContext; module.exports = SearchContext;

View File

@ -263,7 +263,13 @@ function getExpression(tokens, searchContext, level = 0) {
i += 1; i += 1;
return new RelationWhereExp(relationName, parseNoteProperty()); return new RelationWhereExp(relationName, parseNoteProperty());
} else { }
else if (i < tokens.length - 2 && isOperator(tokens[i + 1].token)) {
searchContext.addError(`Relation can be compared only with property, e.g. ~relation.title=hello in ${context(i)}`);
return null;
}
else {
return new AttributeExistsExp('relation', relationName, searchContext.fuzzyAttributeSearch); return new AttributeExistsExp('relation', relationName, searchContext.fuzzyAttributeSearch);
} }
} }

View File

@ -73,6 +73,8 @@ function findNotesWithQuery(query, searchContext) {
return []; return [];
} }
searchContext.originalQuery = query;
return utils.stopWatch(`Search with query "${query}"`, () => { return utils.stopWatch(`Search with query "${query}"`, () => {
const expression = parseQueryToExpression(query, searchContext); const expression = parseQueryToExpression(query, searchContext);