Hi Upayavira,

You were rigtht. I had to only replace the Content-type to appliacation/xml
and it worked correctly.

Roland

2015-08-30 11:22 GMT+02:00 Upayavira <u...@odoko.co.uk>:

>
>
> On Sat, Aug 29, 2015, at 05:30 PM, Szűcs Roland wrote:
> > Hello SOLR experts,
> >
> > I am new to solr as you will see from my problem. I just try to
> > understand
> > how solr works. I use one core (BandW) on my locla machine and I use
> > javascript for my learning purpose.
> >
> > I have a test schema.xml: with two fileds: id, title. I managed to run
> > queries with faceting, autocomplete, etc. In all cases I used Ajax post
> > method. For example my search was (searchWithSuggest.searchAjaxRequest is
> > an XMLHttpRequest object):
> > var s=document.getElementById(searchWithSuggest.inputBoxId).value;
> > var params='q='+s+'&start=0&rows=10';
> > a=searchWithSuggest.solrServer+'/query';
> > searchWithSuggest.searchAjaxRequest.open("POST",a, true);
> > searchWithSuggest.searchAjaxRequest.setRequestHeader("Content-type",
> > "application/x-www-form-urlencoded");
> > searchWithSuggest.searchAjaxRequest.send(encodeURIComponent(params));
> >
> > It worked fine. I thought that an xml update can work the same way so I
> > tried to add and index one new document by xml(a is an XMLHttpRequest
> > object):
> > a.open("POST","http://localhost:8983/solr/bandw/update",true);
> > a.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
> > a.send(encodeURIComponent("stream.body=<add commitWithin=5000><doc><field
> > name='id'>3222</field><field name='title'>Blade</field></doc></add>"));
> >
> > I got a response with error: missing content stream.
> >
> > I have changed only the a.open function call to this one:
> > a.open("POST","http://localhost:8983/solr/bandw/update?commit=true
> ",true);
> > the rest of the did not change.
> > Finally, I got response with no error from SOLR. Later it turned out that
> > the new doc was not indexed at all.
> >
> > My questions:
> > 1. If I get no error from solr what is wrong with the second solution and
> > how can I fix it?
> > 2. Is there any solution to put all the parameters to the a.send call as
> > in
> > case of queries. I tried
> > a.send(encodeURIComponent("commit=true&stream.body=<add
> > commitWithin=5000><doc><field name='id'>3222</field><field
> > name='title'>Blade</field></doc></add>")); but it was not working.
> > 3. Why 95% of the examples in SOLR wiki pages relates to curl. Is this
> > the
> > most efficient alternative? Is there a "mapping" between a curl syntax
> > and
> > the post request?
> >
> > Best Regards,
> > Roland
>
> You're using a POST to fake a GET - just make the Content-type text/xml
> (or application/xml, I forget) and call a.send("<add>....</add>");
>
> You may need the encodeURIComponent, not sure.
>
> The stream.body feature allows you to do an HTTP GET that has a stream
> within it, but you are already doing a POST so it isn't needed.
>
> Upayavira
>



-- 
<https://www.linkedin.com/pub/roland-sz%C5%B1cs/28/226/24/hu>Szűcs Roland
<https://www.linkedin.com/pub/roland-sz%C5%B1cs/28/226/24/hu>Ismerkedjünk
meg a Linkedin <https://www.linkedin.com/pub/roland-sz%C5%B1cs/28/226/24/hu>
-en <https://bookandwalk.hu/>ÜgyvezetőTelefon: +36 1 210 81 13Bookandwalk.hu
<https://bokandwalk.hu/>

Reply via email to