Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion rest/src/main/groovy/whelk/rest/api/SiteSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,17 @@ Map findData(Map<String, String[]> queryParameters, String baseUri, String path)
Map findDesc = getAndIndexDescription(appId + "find");
queryParameters.put("_appConfig", new String[]{mapper.writeValueAsString(search2.buildAppConfig(findDesc))});
}
return search2.doSearch(queryParameters);
try {
return search2.doSearch(queryParameters);
} catch (InvalidQueryException re) {
// The query is broken. Often this means a bit of text (like a title) was copy-pasted as a query
// without regard for query language syntax. Let's just run the whole thing as a string search.
String[] qArr = queryParameters.get("_q");
// Escape any un-escaped quotes. Totally intuitive, right? And yet not watertight, will actually fail on escaped backslash before quote in query.
qArr[0] = qArr[0].replaceAll("[^\\\\]\"", "\\\\\"");
qArr[0] = "\"" + qArr[0] + "\""; // quote as a whole
return search2.doSearch(queryParameters); // It throws again? So be it - let the crud code return an error.
}
} else {
if (queryParameters.get("_statsrepr") == null && searchSettings.get("statsfind") != null) {
queryParameters.put("_statsrepr", new String[]{mapper.writeValueAsString(searchSettings.get("statsfind"))});
Expand Down
Loading