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 Caroline Tan <ca...@gmail.com> on 2009/11/04 07:38:18 UTC

Sending file to Solr via HTTP POST

Hi,
>From the Solr wiki on ExtractingRequestHandler tutorial, when it comes to
the part to post file to Solr, it always uses the curl command, e.g.
curl 'http://localhost:8983/*solr*/update/extract?literal.id=doc1&commit=true'
-F myfile=@tutorial.html

I have never used curl and i was thinking is  there any replacement to such
method?

Is there any API that i can use to achieve the same thing in a java
project without relying on CURL? Does SolrJ have such method? Thanks

~caroLine

Re: Sending file to Solr via HTTP POST

Posted by Jay Hill <ja...@gmail.com>.
Here is a brief example of how to use SolrJ with the
ExtractingRequestHandler:

          ContentStreamUpdateRequest req = new
ContentStreamUpdateRequest("/update/extract");
          req.addFile(fileToIndex);
          req.setParam("literal.id", getId(fileToIndex));
          req.setParam("literal.hostname", getHostname());
          req.setParam("literal.filename", fileToIndex.getName());

          try {
            getSolrServer().request(req);
          } catch (SolrServerException e) {
            e.printStackTrace();
          }

You'll need a request handler configured in solrconfig.xml:

  <!-- Solr Cell Wiki: http://wiki.apache.org/solr/ExtractingRequestHandler-->
  <requestHandler name="/update/extract"
class="org.apache.solr.handler.extraction.ExtractingRequestHandler"
startup="lazy">
    <lst name="defaults">
      <!-- All the main content goes into this field... if you need to
return
           the extracted text or do highlighting, use a stored field. -->
      <str name="map.content">text</str>
      <str name="lowernames">true</str>
      <str name="uprefix">ignored_</str>
    </lst>
  </requestHandler>

Note that the example also shows how to use the "literal.*" parameter to add
metadata fields of your choice to the document.

Hope that helps get you started.

-Jay
http://www.lucidimagination.com


On Tue, Nov 3, 2009 at 10:38 PM, Caroline Tan <ca...@gmail.com>wrote:

> Hi,
> From the Solr wiki on ExtractingRequestHandler tutorial, when it comes to
> the part to post file to Solr, it always uses the curl command, e.g.
> curl '
> http://localhost:8983/*solr*/update/extract?literal.id=doc1&commit=true'
> -F myfile=@tutorial.html
>
> I have never used curl and i was thinking is  there any replacement to such
> method?
>
> Is there any API that i can use to achieve the same thing in a java
> project without relying on CURL? Does SolrJ have such method? Thanks
>
> ~caroLine
>