There is a ‘#’ char exists in my query key like below:
17\#30\#36\#94\#35
So a query url will be generated as:http://10.251.25.12:8080/commentindex/comment/select?q=17\#30\#36\#94\#35&rows=200&wt=json. You can see, the url will be truncated before sending to server because of ‘#’ existing, and I will get error result, error rows count, error doc type(not json I set).
For the above instance, I encoded the url as http://10.251.25.12:8080/commentindex/comment/select?q=17%5c%2330%5c%2336%5c%2394%5c%2335&rows=200&wt=json. Everything goes as my expect. However, I encounter another error if query key looked like:
←\~\\(≧▽≦\)\/\~!!|
Url will be generated as:
http://10.251.25.12:8080/commentindex/comment/select?q=%e2%86%90%5c%7e%5c%5c(%e2%89%a7%e2%96%bd%e2%89%a6%5c)%5c%2f%5c%7e%ef%bc%81%ef%bc%81%7c&rows=200&wt=json
Do you find the parentheses? It’s special char in solr query! 400 bad request I will get from the url.
I noticed that all of query key has been escaped with ‘\’, so if I should not encode whole url and only encode ‘#’ char? Is there any other special char I should note?
These are the special characters in Lucene/Solr:
and of course characters like
#that have a special meaning in URLs. If you want to search for any literal character among the above you must escape it. This list is from http://lucene.apache.org/core/3_6_0/queryparsersyntax.html#Escaping%20Special%20Characters.