11.05.2016 Views

Apache Solr Reference Guide Covering Apache Solr 6.0

21SiXmO

21SiXmO

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

curl "http://localhost:8983/solr/techproducts/update/extract?&extractOnly=true"<br />

--data-binary @example/exampledocs/sample.html -H 'Content-type:text/html'<br />

The output includes XML generated by Tika (and further escaped by <strong>Solr</strong>'s XML) using a different output format<br />

to make it more readable (`-out yes` instructs the tool to echo <strong>Solr</strong>'s output to the console):<br />

bin/post -c techproducts -params "extractOnly=true&wt=ruby&indent=true" -out yes<br />

example/exampledocs/sample.html<br />

Sending Documents to <strong>Solr</strong> with a POST<br />

The example below streams the file as the body of the POST, which does not, then, provide information to <strong>Solr</strong><br />

about the name of the file.<br />

curl<br />

"http://localhost:8983/solr/techproducts/update/extract?literal.id=doc6&defaultField<br />

=text&commit=true" --data-binary @example/exampledocs/sample.html -H<br />

'Content-type:text/html'<br />

Sending Documents to <strong>Solr</strong> with <strong>Solr</strong> Cell and <strong>Solr</strong>J<br />

<strong>Solr</strong>J is a Java client that you can use to add documents to the index, update the index, or query the index. You'll<br />

find more information on <strong>Solr</strong>J in Client APIs.<br />

Here's an example of using <strong>Solr</strong> Cell and <strong>Solr</strong>J to add documents to a <strong>Solr</strong> index.<br />

First, let's use <strong>Solr</strong>J to create a new <strong>Solr</strong>Client, then we'll construct a request containing a ContentStream<br />

(essentially a wrapper around a file) and sent it to <strong>Solr</strong>:<br />

public class <strong>Solr</strong>CellRequestDemo {<br />

public static void main (String[] args) throws IOException, <strong>Solr</strong>ServerException {<br />

<strong>Solr</strong>Client server = new<br />

Http<strong>Solr</strong>Client("http://localhost:8983/solr/my_collection");<br />

ContentStreamUpdateRequest req = new<br />

ContentStreamUpdateRequest("/update/extract");<br />

req.addFile(new File("my-file.pdf"));<br />

req.setParam(ExtractingParams.EXTRACT_ONLY, "true");<br />

NamedList result = server.request(req);<br />

System.out.println("Result: " + result);<br />

}<br />

This operation streams the file my-file.pdf into the <strong>Solr</strong> index for my_collection.<br />

The sample code above calls the extract command, but you can easily substitute other commands that are<br />

supported by <strong>Solr</strong> Cell. The key class to use is the ContentStreamUpdateRequest, which makes sure the<br />

ContentStreams are set properly. <strong>Solr</strong>J takes care of the rest.<br />

Note that the ContentStreamUpdateRequest is not just specific to <strong>Solr</strong> Cell. You can send CSV to the CSV<br />

Update handler and to any other Request Handler that works with Content Streams for updates.<br />

Related Topics<br />

<strong>Apache</strong> <strong>Solr</strong> <strong>Reference</strong> <strong>Guide</strong> <strong>6.0</strong><br />

205

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!