Many programming environments are able to send HTTP requests and retrieve responses. Parsing the responses is a slightly more thorny problem. Fortunately, Solr makes it easy to choose an output format that will be easy to handle on the client side.

Specify a response format using the wt parameter in a query.

Most client APIs hide this detail for you, so for many types of client applications, you won’t ever have to specify a wt parameter. In JavaScript, however, the interface to Solr is a little closer to the metal, so you will need to add this parameter yourself.

Client API Lineup

As of now, solr has follwoing client API’s in provision:

Name Environment URL

SolRuby

Ruby

https://github.com/rsolr/rsolr

DelSolr

Ruby

https://github.com/avvo/delsolr

acts_as_solr

Rails

http://acts-as-solr.rubyforge.org/http://rubyforge.org/projects/background-solr/

Flare

Rails

http://wiki.apache.org/solr/Flare

SolPHP

PHP

http://wiki.apache.org/solr/SolPHP

SolrJ

Java

http://wiki.apache.org/solr/SolJava

Python API

Python

http://wiki.apache.org/solr/SolPython

PySolr

Python

http://code.google.com/p/pysolr/

SolPerl

Perl

http://wiki.apache.org/solr/SolPerl

Solr.pm

Perl

http://search.cpan.org/~garafola/Solr-0.03/lib/Solr.pm

SolrForrest

Forrest/Cocoon

http://wiki.apache.org/solr/SolrForrest

SolrSharp

C#

http://www.codeplex.com/solrsharp

SolColdfusion

ColdFusion

http://solcoldfusion.riaforge.org/

SolrNet

.NET

https://github.com/mausch/SolrNet

AJAX Solr

AJAX

http://github.com/evolvingweb/ajax-solr/wiki

Using JavaScript

Using Solr from JavaScript clients is so straightforward that it deserves a special mention. In fact, it is so straightforward that there is no client API. You don’t need to install any packages or configure anything.

HTTP requests can be sent to Solr using the standard XMLHttpRequest mechanism.

By default, Solr sends Javascript Object Notation(JSON) responses, which are easily interpreted in JavaScript. You don’t need to add anything to the request URL to have responses sent as JSON.

Using SolrJ

Building and Running SolrJ Applications

The SolrJ API ships with Solr, so you do not have to download or install anything else. But you will need to configure your build to include SolrJ and its dependencies.

Common Build Systems

Most mainstream build systems greatly simplify dependency management, making it easy to add SolrJ to your project.

For projects built with Ant (using Ivy), place the following in your ivy.xml:

For projects built with Maven, place the following in your pom.xml

For projects built with Gradle, place the following in your build.gradle:

Adding SolrJ to the Classpath Manually

If you are not using one of the above build system, it’s still easy to add SolrJ to your build.

At build time, all that is required is the SolrJ jar itself: solr-solrj-7.4.0.jar. To compile code manually that uses SolrJ, use a javac command similar to:

At runtime, you need a few of SolrJ’s dependencies, in addition to SolrJ itself. For convenience, these dependencies are made available in the dist/solrj-lib directory. Run your project with a classpath like:

Querying in SolrJ

SolrClient has a number of query() methods for fetching results from Solr. Each of these methods takes in a SolrParams,an object encapsulating arbitrary query-parameters. And each method outputs a QueryResponse, a wrapper which can be used to access the result documents and other related metadata.

The following snippet uses a SolrClient to query Solr’s “techproducts” example collection, and iterate over the results.

SolrParams has a SolrQuery subclass, which provides some convenience methods that greatly simplifies query creation. The following snippet shows how the query from the previous example can be built using some of the convenience methods in SolrQuery:

Indexing in SolrJ

Indexing is also simple using SolrJ. Users build the documents they want to index as instances of SolrInputDocument, and provide them as arguments to one of the add() methods on SolrClient.

The following example shows how to use SolrJ to add a document to Solr’s “techproducts” example collection:

So , this is it about solr client API’s. We will be back with another post very soon.10 Solr Client API’s