Sending file to Solr via HTTP POST

View: New views
2 Messages — Rating Filter:   Alert me  

Sending file to Solr via HTTP POST

by Caroline Tan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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=@...

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

by Jay Hill :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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 <caroline.tcf@...>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=@...
>
> 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
>