Hi Chris,

thanks for the fast response. I'll try to be more specific about the
problem I am having.

# cat tmp.xml
<add>
        <doc>
                <field name="id">9553522</field>
                <field name="comments">quote: (") backslash: (\)
backslash-quote: (\")
newline: (
) backslash-n: (\n)</field>
        </doc>
</add>



# curl 'http://localhost:8983/solr/collection1/update?commit=true'
--data-binary @tmp.xml -H 'Content-Type: application/xml'
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">0</int><int
name="QTime">134</int></lst>
</response>



# curl '
http://localhost:8983/solr/collection1/select?q=id:9553522&indent=true&omitHeader=true&wt=xml
'
<?xml version="1.0" encoding="UTF-8"?>
<response>

<result name="response" numFound="1" start="0">
  <doc>
    <str name="id">9553522</str>
    <str name="comments">quote: (") backslash: (\)
backslash-quote: (\")
newline: (
) backslash-n: (\n)</str>
    <arr name="text_en">
      <str>quote: (") backslash: (\)
backslash-quote: (\")
newline: (
) backslash-n: (\n)</str>
    </arr>
    <arr name="text_es">
      <str>quote: (") backslash: (\)
backslash-quote: (\")
newline: (
) backslash-n: (\n)</str>
    </arr>
    <arr name="text_nl">
      <str>quote: (") backslash: (\)
backslash-quote: (\")
newline: (
) backslash-n: (\n)</str>
    </arr>
    <long name="_version_">1458042122530717696</long></doc>
</result>
</response>



# curl '
http://localhost:8983/solr/collection1/select?q=id:9553522&indent=true&omitHeader=true&wt=json&fl=id,comments,_version_
'
{
  "response":{"numFound":1,"start":0,"docs":[
      {
        "id":"9553522",
        "comments":"quote: (\") backslash: (\\) \nbackslash-quote: (\\\")
\nnewline: ( \n) backslash-n: (\\n)",
        "_version_":1458042122530717696}]
  }}



So my setup gives the same responses as yours.

The problem I have is if I try to parse this response in *php *using
*json_decode()* I get a syntax error because of the '*\n*' s that are in
the response. I could escape the before doing the *json_decode() *or at the
point of submitting to the index but this seems wrong...

I am probably doing something silly and a good nights sleep will reveal
what I am doing wrong ;-)

Thanks
Steven



On 23 January 2014 16:15, Chris Hostetter-3 [via Lucene] <
ml-node+s472066n4113017...@n3.nabble.com> wrote:

>
> : I am finding that if any fields in a document returned by a Solr query
> : (*wt=json* to get a JSON response) contain backslash *'\'* characters,
> they
> : are not being escaped (to make then valid JSON).
>
> you're going to have to give us more concrete specifics on how you are
> indexing your data, and how you are looking at the response, because i
> can't reproduce anything close to what you are describing (see below)
>
> https://wiki.apache.org/solr/UsingMailingLists
>
>
>
>
> hossman@frisbee:~$ cat tmp/tmp.xml
> <add>
>   <doc>
>     <field name="id">HOSS</field>
>     <field name="name">quote: (") backslash: (\) backslash-quote: (\")
> newline: (
> ) backslash-n: (\n)</field>
>   </doc>
> </add>
>
>
> hossman@frisbee:~$ curl '
> http://localhost:8983/solr/collection1/update?commit=true' --data-binary
> @tmp/tmp.xml -H 'Content-Type: application/xml'
> <?xml version="1.0" encoding="UTF-8"?>
> <response>
> <lst name="responseHeader"><int name="status">0</int><int
> name="QTime">678</int></lst>
> </response>
>
>
>
> hossman@frisbee:~$ curl '
> http://localhost:8983/solr/collection1/select?q=id:HOSS&indent=true&omitHeader=true&wt=xml'
> <?xml version="1.0" encoding="UTF-8"?>
> <response>
>
> <result name="response" numFound="1" start="0">
>   <doc>
>     <str name="id">HOSS</str>
>     <str name="name">quote: (") backslash: (\) backslash-quote: (\")
> newline: (
> ) backslash-n: (\n)</str>
>     <long name="_version_">1458038035233898496</long></doc>
> </result>
> </response>
>
>
> hossman@frisbee:~$ curl '
> http://localhost:8983/solr/collection1/select?q=id:HOSS&indent=true&omitHeader=true&wt=json'
> {
>   "response":{"numFound":1,"start":0,"docs":[
>       {
>         "id":"HOSS",
>         "name":"quote: (\") backslash: (\\) backslash-quote: (\\\")
> newline: (\n) backslash-n: (\\n)",
>         "_version_":1458038035233898496}]
>   }}
>
>
> hossman@frisbee:~$ cat tmp/tmp.json
> [
>  {"id" : "HOSS",
>   "name" : "quote: (\") backslash: (\\) backslash-quote: (\\\") newline:
> (\n) backslash-n: (\\n)"}
> ]
>
>
> hossman@frisbee:~$ curl '
> http://localhost:8983/solr/collection1/update?commit=true' --data-binary
> @tmp/tmp.json -H 'Content-Type: application/json'
> {"responseHeader":{"status":0,"QTime":605}}
>
>
> hossman@frisbee:~$ curl '
> http://localhost:8983/solr/collection1/select?q=id:HOSS&indent=true&omitHeader=true&wt=xml'
> <?xml version="1.0" encoding="UTF-8"?>
> <response>
>
> <result name="response" numFound="1" start="0">
>   <doc>
>     <str name="id">HOSS</str>
>     <str name="name">quote: (") backslash: (\) backslash-quote: (\")
> newline: (
> ) backslash-n: (\n)</str>
>     <long name="_version_">1458038130437259264</long></doc>
> </result>
> </response>
>
>
> hossman@frisbee:~$ curl '
> http://localhost:8983/solr/collection1/select?q=id:HOSS&indent=true&omitHeader=true&wt=json'
> {
>   "response":{"numFound":1,"start":0,"docs":[
>       {
>         "id":"HOSS",
>         "name":"quote: (\") backslash: (\\) backslash-quote: (\\\")
> newline: (\n) backslash-n: (\\n)",
>         "_version_":1458038130437259264}]
>   }}
>
>
>
>
> -Hoss
> http://www.lucidworks.com/
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://lucene.472066.n3.nabble.com/Solr-solr-JSONResponseWriter-not-escaping-backslash-characters-tp4112990p4113017.html
>  To unsubscribe from Solr solr.JSONResponseWriter not escaping backslash
> '\' characters, click 
> here<http://lucene.472066.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4112990&code=c3RldmVuQGFjdHVhbC1zeXN0ZW1zLmNvbXw0MTEyOTkwfC0xMTI0NTgzNDI1>
> .
> NAML<http://lucene.472066.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>



-- 

Kind regards

Steven McGovern

Hollander International Systems Ltd

t: +44 (0)131 538 8538

f: +44 (0)131 538 8539

e: ste...@actual-systems.com

w: http://www.actual-systems.com



[image: Hollander International RGB (2)]



Search the UK's largest online used part database:
http://www.autopartstrader.co.uk

Vat Registration No. 429422452
Registered in Scotland No. SC211063
Registered Office: Birch House, 10 Bankhead Crossway South, Edinburgh, EH11
4EP


image003.png (23K) 
<http://lucene.472066.n3.nabble.com/attachment/4113029/0/image003.png>




--
View this message in context: 
http://lucene.472066.n3.nabble.com/Solr-solr-JSONResponseWriter-not-escaping-backslash-characters-tp4112990p4113029.html
Sent from the Solr - User mailing list archive at Nabble.com.

Reply via email to