Re: Does SOLR provide a java class to perform url-encoding

2010-05-25 Thread Ryan McKinley
You may also want to look at:
ClientUtils.escapeQueryChars( String s )

http://lucene.apache.org/solr/api/org/apache/solr/client/solrj/util/ClientUtils.html#escapeQueryChars%28java.lang.String%29

this will escape any lucene query chars, then pass it to URLEncoder
and you should be good to go.


On Tue, May 25, 2010 at 1:58 PM, JohnRodey  wrote:
>
> Thanks Sean, that was exactly what I need.  One question though...
>
> How to correctly retain the Solr specific characters.
> I tried adding escape chars but URLEncoder doesn't seem to care about that:
> Example:
> String s1 = "\"mr. bill\" oh n?";
> String s2 = "\\\"mr. bill\\\" oh n\\?";
> String encoded1 = URLEncoder.encode(s1, "UTF-8");
> String encoded2 = URLEncoder.encode(s2, "UTF-8");
> System.out.println(encoded1);
> System.out.println(encoded2);
> Output:
> %22mr.+bill%22+oh+n%3F
> %5C%22mr.+bill%5C%22+oh+n%5C%3F
>
> Should I allow the URLEncoder to translate s1, then replace %22 with ", %3F
> with ?, and so on?
> Or is there a better way?
> --
> View this message in context: 
> http://lucene.472066.n3.nabble.com/Does-SOLR-provide-a-java-class-to-perform-url-encoding-tp842660p842744.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>


Re: Does SOLR provide a java class to perform url-encoding

2010-05-25 Thread JohnRodey

I was assuming that I needed to leave the special characters in the http get,
but running the solr admin it looks like it converts them the same way that
URLEncoder.encode does.  What is the need to preserve special characters?

http://localhost:8983/solr/select?indent=on&version=2.2&q=%22mr.+bill%22+oh+n%3F&fq=&start=0&rows=50&fl=*%2Cscore&qt=standard&wt=standard&explainOther=&hl.fl=
-- 
View this message in context: 
http://lucene.472066.n3.nabble.com/Does-SOLR-provide-a-java-class-to-perform-url-encoding-tp842660p843177.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Does SOLR provide a java class to perform url-encoding

2010-05-25 Thread JohnRodey

Thanks Sean, that was exactly what I need.  One question though...

How to correctly retain the Solr specific characters.
I tried adding escape chars but URLEncoder doesn't seem to care about that:
Example: 
String s1 = "\"mr. bill\" oh n?";
String s2 = "\\\"mr. bill\\\" oh n\\?";
String encoded1 = URLEncoder.encode(s1, "UTF-8");
String encoded2 = URLEncoder.encode(s2, "UTF-8");
System.out.println(encoded1);
System.out.println(encoded2);
Output:
%22mr.+bill%22+oh+n%3F
%5C%22mr.+bill%5C%22+oh+n%5C%3F

Should I allow the URLEncoder to translate s1, then replace %22 with ", %3F
with ?, and so on?
Or is there a better way?
-- 
View this message in context: 
http://lucene.472066.n3.nabble.com/Does-SOLR-provide-a-java-class-to-perform-url-encoding-tp842660p842744.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Does SOLR provide a java class to perform url-encoding

2010-05-25 Thread Sean Timm

Java provides one.  You probably want to use utf-8 as the encoding scheme.

http://java.sun.com/javase/6/docs/api/java/net/URLEncoder.html

Note you also will want to strip or escape character that are meaningful 
in the Solr/Lucene query syntax.

http://lucene.apache.org/java/2_4_0/queryparsersyntax.html#Escaping%20Special%20Characters

-Sean

On 5/25/2010 1:20 PM, JohnRodey wrote:

I would like to leverage on whatever SOLR provides to properly url-encode a
search string.

For example a user enters:
"mr. bill" oh no

The URL submitted by the admin page is:
http://localhost:8983/solr/select?indent=on&version=2.2&q=%22mr.+bill%22+oh+no&fq=&start=0&rows=10&fl=*%2Cscore&qt=standard&wt=standard&explainOther=&hl.fl=

Since the admin page uses it I would image that this functionality is there,
but having some trouble finding it.