Re: commit of xml update by AJAX
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=0rows=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=5000docfield name='id'3222/fieldfield 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=truestream.body=add commitWithin=5000docfield name='id'3222/fieldfield 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
Re: commit of xml update by AJAX
Thanks Erick, Your blog post made it clear. It was looong, but not too long. Roland 2015-08-29 19:00 GMT+02:00 Erick Erickson erickerick...@gmail.com: 1 My first guess is that your autocommit section in solrconfig.xml has openSearcherfalse/openSearcher So the commitWithin happened but a new searcher was not opened thus the document is invisible. Try issuing a separate commit or change that value in solrconfig.xml and try again. Here's a lng post on all this: https://lucidworks.com/blog/understanding-transaction-logs-softcommit-and-commit-in-sorlcloud/ 2 No clue since I'm pretty ajax-ignorant. 3 because curl easily downloadable at worst and most often already on someone's machine and let people at least get started. Pretty soon, though, for production situations people will use SolrJ or the like or use one of the off-the-shelf tools packaged around Solr. Best Erick On Sat, Aug 29, 2015 at 9:30 AM, Szűcs Roland szucs.rol...@bookandwalk.hu 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=0rows=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=5000docfield name='id'3222/fieldfield 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=truestream.body=add commitWithin=5000docfield name='id'3222/fieldfield 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 -- https://www.linkedin.com/pub/roland-sz%C5%B1cs/28/226/24/huSzű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/ -- https://www.linkedin.com/pub/roland-sz%C5%B1cs/28/226/24/huSzűcs Roland https://www.linkedin.com/pub/roland-sz%C5%B1cs/28/226/24/huIsmerkedjü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/
Re: commit of xml update by AJAX
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=0rows=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=5000docfield name='id'3222/fieldfield 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=truestream.body=add commitWithin=5000docfield name='id'3222/fieldfield 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/huSzűcs Roland https://www.linkedin.com/pub/roland-sz%C5%B1cs/28/226/24/huIsmerkedjü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/
commit of xml update by AJAX
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=0rows=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=5000docfield name='id'3222/fieldfield 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=truestream.body=add commitWithin=5000docfield name='id'3222/fieldfield 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 -- https://www.linkedin.com/pub/roland-sz%C5%B1cs/28/226/24/huSzűcs Roland https://www.linkedin.com/pub/roland-sz%C5%B1cs/28/226/24/huIsmerkedjü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/