dweb-search-frontend
dweb-search-frontend copied to clipboard
reserved characters in the search query cause error
In elastic search, there are reserved characters, that can not be used for queries: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_reserved_characters
If we type one of these into the search field, we get an error back from the API. Check for example: https://ipfs-search.com/#/search?q=who+is+the+king+of+Spain?&page=1
There are 2 potential ways to fix this:
- Infix the query into (double) quotes before sending it into the API formatter; this is the easiest, if it works. Of course it needs to be tested properly, also when searching for something with quotes.
- or escape the reserved characters
The latter can be done just like the function elasticSearchEscape
does in the file apiHelper.js
, with the special notion, that this function currently omits wildcard characters (*
and ?
), to allow wildcard searching on metadata; it only escapes /
and :
, as these are so far the only ones found in metadata fields or names. This means that to use this mechanism, either a second function needs to be made that does the same but then for all reserved characters, or the function needs to be expanded to have options for different use cases.