Re: Query parameter encode issue
: Date: Tue, 16 Jun 2009 20:38:24 +0530 : From: Avlesh Singh : Subject: Re: Query parameter encode issue : qryString = +text:test +site_id:(4 ) +publishDate:[2008-05-01T00\:00\:00Z : TO 2009-06-30T00\:00\:00Z]; : URLEncoder.encode(qryString, UTF-8); : : : You don't have to encode the complete query string parameter. You just need : encode the values for individual query paramters. : So it should be more like qryString = +text: + URLEncoder.encode(test, : UTF-8) ... and so on. FWIW: I consider this to be *VERY* bad advice ... in may work in some cases, but not in all cases -- in this particular case for example, the + sign that is part of the query string (and intended to mean mandatory will be left unescaped and will be treated by the webserver as an escaped (space) character. : I am having the following query, : q=+text:test +site_id:(4 ) +publishDate:[2008-05-01T00\:00\:00Z TO : 2009-06-30T00\:00\:00Z] ... : In my developed solr client, I am using the following code to encode, : : qryString = +text:test +site_id:(4 ) +publishDate:[2008-05-01T00\:00\:00Z : TO 2009-06-30T00\:00\:00Z]; : URLEncoder.encode(qryString, UTF-8); First off: just because the URL you get in your browser looks different then the one produced by URLEncoder doesn't mean you actual have a problem ... URL encoding is not a 1-to-1 mapping, there are multiple ways things can be encoded (because there are multiple ways to encode certain characters *and* there are some characters that can be encoded but don't have to be). the question is: do you have a problem? does your search work? do you get an error message of some kind? what made you send this email in which the only question is what mistake I have done here? but where you have given no example of why you think you made a mistake. Second: what are you doing with the encoded qryString in your code? if you are using a really low level HTTP api to embed it directly in a URL, then it's probably fine ... but if you are using a higher level HTTP Client library, you probably don't need to encode it yourself -- most client APIs have methods thta take in the *literal* param name and value, and the library takes care of encoding for you --- so it's possible your qryString is getting double encoded if you are using an API like that. Third: even if you should be using URLEncoder directly with your HTTP Client library, using the UTF-8 option on URLEncoder may not be correct .. it depends on how you have your serlvet container configured. My suggestion: use SolrJ and make your life a lot easier. -Hoss
RE: Query parameter encode issue
What happens when u don't use encoding? -Original Message- From: Radha C. [mailto:cra...@ceiindia.com] Sent: Tuesday, June 16, 2009 8:20 PM To: solr-user@lucene.apache.org Subject: Query parameter encode issue Hello list, I am having the following query, q=+text:test +site_id:(4 ) +publishDate:[2008-05-01T00\:00\:00Z TO 2009-06-30T00\:00\:00Z] If I try this query in the browser directly , it is working fine and the url is encoded automatically in the browser when I enter as follows http://localhost:8983/solr/TeamSite/select?q=+text:test%20+site_id:(4%20)%20 +publishDate:[2008-05-01T00\:00\:00Z%20TO%202009-06-30T00\:00\:00Z] In my developed solr client, I am using the following code to encode, qryString = +text:test +site_id:(4 ) +publishDate:[2008-05-01T00\:00\:00Z TO 2009-06-30T00\:00\:00Z]; URLEncoder.encode(qryString, UTF-8); and the encoded url is like this, http://localhost:8983/solr/TeamSite/select?q=%2Btext%3Atest+%2Bsite_id%3A%28 4+%29+%2BpublishDate%3A%5B2008-05-01T00%5C%3A00%5C%3A00Z+TO+2009-06-30T00%5C %3A00%5C%3A00Z%5D I am just encoding the parameter value ( +text:test +site_id:(4 ) +publishDate:[2008-05-01T00\:00\:00Z TO 2009-06-30T00\:00\:00Z] ) and not parameter name ( q=). Can anyone please tell me what mistake I have done here?
Re: Query parameter encode issue
qryString = +text:test +site_id:(4 ) +publishDate:[2008-05-01T00\:00\:00Z TO 2009-06-30T00\:00\:00Z]; URLEncoder.encode(qryString, UTF-8); You don't have to encode the complete query string parameter. You just need encode the values for individual query paramters. So it should be more like qryString = +text: + URLEncoder.encode(test, UTF-8) ... and so on. Cheers Avlesh On Tue, Jun 16, 2009 at 8:20 PM, Radha C. cra...@ceiindia.com wrote: Hello list, I am having the following query, q=+text:test +site_id:(4 ) +publishDate:[2008-05-01T00\:00\:00Z TO 2009-06-30T00\:00\:00Z] If I try this query in the browser directly , it is working fine and the url is encoded automatically in the browser when I enter as follows http://localhost:8983/solr/TeamSite/select?q=+text:test%20+site_id:(4%20)%20 +publishDate:[2008-05-01T00http://localhost:8983/solr/TeamSite/select?q=+text:test%20+site_id:%284%20%29%20%0A+publishDate:%5B2008-05-01T00 \:00\:00Z%20TO%202009-06-30T00\:00\:00Z] In my developed solr client, I am using the following code to encode, qryString = +text:test +site_id:(4 ) +publishDate:[2008-05-01T00\:00\:00Z TO 2009-06-30T00\:00\:00Z]; URLEncoder.encode(qryString, UTF-8); and the encoded url is like this, http://localhost:8983/solr/TeamSite/select?q=%2Btext%3Atest+%2Bsite_id%3A%28 4+%29+%2BpublishDate%3A%5B2008-05-01T00%5C%3A00%5C%3A00Z+TO+2009-06-30T00%5C %3A00%5C%3A00Z%5Dhttp://localhost:8983/solr/TeamSite/select?q=%2Btext%3Atest+%2Bsite_id%3A%28%0A4+%29+%2BpublishDate%3A%5B2008-05-01T00%5C%3A00%5C%3A00Z+TO+2009-06-30T00%5C%0A%3A00%5C%3A00Z%5D I am just encoding the parameter value ( +text:test +site_id:(4 ) +publishDate:[2008-05-01T00\:00\:00Z TO 2009-06-30T00\:00\:00Z] ) and not parameter name ( q=). Can anyone please tell me what mistake I have done here?
RE: Query parameter encode issue
Thanks for your reply.. If that is the case, I need to do as follows, +text: + URLEncoder.encode(test, UTF-8) +URLEncoder.encode( , UTF-8)++site_id+URLEncoder.encode(xx, UTF-8) Do I need to encode the space between two search field also? It is difficult for me to do like this because I am having many search fields and forming the query string dynamically. Is there any other way I can do this? or else I will follow this then. _ From: Avlesh Singh [mailto:avl...@gmail.com] Sent: Tuesday, June 16, 2009 8:38 PM To: solr-user@lucene.apache.org; cra...@ceiindia.com Subject: Re: Query parameter encode issue qryString = +text:test +site_id:(4 ) +publishDate:[2008-05-01T00\:00\:00Z TO 2009-06-30T00\:00\:00Z]; URLEncoder.encode(qryString, UTF-8); You don't have to encode the complete query string parameter. You just need encode the values for individual query paramters. So it should be more like qryString = +text: + URLEncoder.encode(test, UTF-8) ... and so on. Cheers Avlesh On Tue, Jun 16, 2009 at 8:20 PM, Radha C. cra...@ceiindia.com wrote: Hello list, I am having the following query, q=+text:test +site_id:(4 ) +publishDate:[2008-05-01T00\:00\:00Z TO 2009-06-30T00\:00\:00Z] If I try this query in the browser directly , it is working fine and the url is encoded automatically in the browser when I enter as follows http://localhost:8983/solr/TeamSite/select?q=+text:test%20+site_id:(4%20)%20 http://localhost:8983/solr/TeamSite/select?q=+text:test%20+site_id:%284%20% 29%20%0A+publishDate:%5B2008-05-01T00 +publishDate:[2008-05-01T00\:00\:00Z%20TO%202009-06-30T00\:00\:00Z] In my developed solr client, I am using the following code to encode, qryString = +text:test +site_id:(4 ) +publishDate:[2008-05-01T00\:00\:00Z TO 2009-06-30T00\:00\:00Z]; URLEncoder.encode(qryString, UTF-8); and the encoded url is like this, http://localhost:8983/solr/TeamSite/select?q=%2Btext%3Atest+%2Bsite_id%3A%28 http://localhost:8983/solr/TeamSite/select?q=%2Btext%3Atest+%2Bsite_id%3A%2 8%0A4+%29+%2BpublishDate%3A%5B2008-05-01T00%5C%3A00%5C%3A00Z+TO+2009-06-30T0 0%5C%0A%3A00%5C%3A00Z%5D 4+%29+%2BpublishDate%3A%5B2008-05-01T00%5C%3A00%5C%3A00Z+TO+2009-06-30T00%5C %3A00%5C%3A00Z%5D I am just encoding the parameter value ( +text:test +site_id:(4 ) +publishDate:[2008-05-01T00\:00\:00Z TO 2009-06-30T00\:00\:00Z] ) and not parameter name ( q=). Can anyone please tell me what mistake I have done here?