You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by John Randall <jm...@yahoo.com> on 2013/08/12 20:49:12 UTC

Problem escaping ampersands in HTTP GET

I am using an HTTP GET to add docs to Solr. All the docs load fine as long as none contain an ampersand. I get a syntax error when a doc contains a field, for example, with the phrase "Jack & Jill". 
 
How can I escape the ampersand so that the doc loads normally?
 
Thanks in advance.

Re: Problem escaping ampersands in HTTP GET

Posted by John Randall <jm...@yahoo.com>.
Already fixed thanks to Shawn Heisey. Had to URL encode the ampersand and semicolon in &amp;



________________________________
From: Erik Hatcher <er...@gmail.com>
To: "solr-user@lucene.apache.org" <so...@lucene.apache.org> 
Sent: Monday, August 12, 2013 9:06 PM
Subject: Re: Problem escaping ampersands in HTTP GET


How are you indexing documents?

You need to either URL encode things or XML encode, sounds like. 

  Erik

On Aug 12, 2013, at 14:49, John Randall <jm...@yahoo.com> wrote:

> I am using an HTTP GET to add docs to Solr. All the docs load fine as long as none contain an ampersand. I get a syntax error when a doc contains a field, for example, with the phrase "Jack & Jill". 
>  
> How can I escape the ampersand so that the doc loads normally?
>  
> Thanks in advance.

Re: Problem escaping ampersands in HTTP GET

Posted by Erik Hatcher <er...@gmail.com>.
How are you indexing documents?

You need to either URL encode things or XML encode, sounds like. 

   Erik

On Aug 12, 2013, at 14:49, John Randall <jm...@yahoo.com> wrote:

> I am using an HTTP GET to add docs to Solr. All the docs load fine as long as none contain an ampersand. I get a syntax error when a doc contains a field, for example, with the phrase "Jack & Jill". 
>  
> How can I escape the ampersand so that the doc loads normally?
>  
> Thanks in advance.

Re: Problem escaping ampersands in HTTP GET

Posted by John Randall <jm...@yahoo.com>.
Beautiful! It worked. Thanks so much.



________________________________
From: Shawn Heisey <so...@elyograg.org>
To: solr-user@lucene.apache.org 
Sent: Monday, August 12, 2013 3:12 PM
Subject: Re: Problem escaping ampersands in HTTP GET


On 8/12/2013 12:49 PM, John Randall wrote:
> I am using an HTTP GET to add docs to Solr. All the docs load fine as long as none contain an ampersand. I get a syntax error when a doc contains a field, for example, with the phrase "Jack & Jill".
>
> How can I escape the ampersand so that the doc loads normally?

If the input format of your document is XML and it's in the URL on a 
GET, then you'll need to do two kinds of encoding - first to XML (&amp;) 
and then URL.  The final string for a single ampersand after both kinds 
of encoding is:  %26amp%3B

If you are using JSON format, then I think you could just use %26 for an 
ampersand.

This is one reason that POST is preferred to GET.

Thanks,
Shawn

Re: Problem escaping ampersands in HTTP GET

Posted by Shawn Heisey <so...@elyograg.org>.
On 8/12/2013 12:49 PM, John Randall wrote:
> I am using an HTTP GET to add docs to Solr. All the docs load fine as long as none contain an ampersand. I get a syntax error when a doc contains a field, for example, with the phrase "Jack & Jill".
>
> How can I escape the ampersand so that the doc loads normally?

If the input format of your document is XML and it's in the URL on a 
GET, then you'll need to do two kinds of encoding - first to XML (&amp;) 
and then URL.  The final string for a single ampersand after both kinds 
of encoding is:  %26amp%3B

If you are using JSON format, then I think you could just use %26 for an 
ampersand.

This is one reason that POST is preferred to GET.

Thanks,
Shawn