{"version":"1.0","provider_name":"Aeologic Blog","provider_url":"https:\/\/www.aeologic.com\/blog","title":"Solr Client API's - Ultimate Solr Guide - Aeologic Blog","type":"rich","width":600,"height":338,"html":"<blockquote class=\"wp-embedded-content\" data-secret=\"ir0tT20q45\"><a href=\"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-10-solr-client-apis\/\">Solr Client API&#8217;s &#8211; Ultimate Solr Guide<\/a><\/blockquote><iframe sandbox=\"allow-scripts\" security=\"restricted\" src=\"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-10-solr-client-apis\/embed\/#?secret=ir0tT20q45\" width=\"600\" height=\"338\" title=\"&#8220;Solr Client API&#8217;s &#8211; Ultimate Solr Guide&#8221; &#8212; Aeologic Blog\" data-secret=\"ir0tT20q45\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" class=\"wp-embedded-content\"><\/iframe><script>\n\/*! This file is auto-generated *\/\n!function(d,l){\"use strict\";l.querySelector&&d.addEventListener&&\"undefined\"!=typeof URL&&(d.wp=d.wp||{},d.wp.receiveEmbedMessage||(d.wp.receiveEmbedMessage=function(e){var t=e.data;if((t||t.secret||t.message||t.value)&&!\/[^a-zA-Z0-9]\/.test(t.secret)){for(var s,r,n,a=l.querySelectorAll('iframe[data-secret=\"'+t.secret+'\"]'),o=l.querySelectorAll('blockquote[data-secret=\"'+t.secret+'\"]'),c=new RegExp(\"^https?:$\",\"i\"),i=0;i<o.length;i++)o[i].style.display=\"none\";for(i=0;i<a.length;i++)s=a[i],e.source===s.contentWindow&&(s.removeAttribute(\"style\"),\"height\"===t.message?(1e3<(r=parseInt(t.value,10))?r=1e3:~~r<200&&(r=200),s.height=r):\"link\"===t.message&&(r=new URL(s.getAttribute(\"src\")),n=new URL(t.value),c.test(n.protocol))&&n.host===r.host&&l.activeElement===s&&(d.top.location.href=t.value))}},d.addEventListener(\"message\",d.wp.receiveEmbedMessage,!1),l.addEventListener(\"DOMContentLoaded\",function(){for(var e,t,s=l.querySelectorAll(\"iframe.wp-embedded-content\"),r=0;r<s.length;r++)(t=(e=s[r]).getAttribute(\"data-secret\"))||(t=Math.random().toString(36).substring(2,12),e.src+=\"#?secret=\"+t,e.setAttribute(\"data-secret\",t)),e.contentWindow.postMessage({message:\"ready\",secret:t},\"*\")},!1)))}(window,document);\n\/\/# sourceURL=https:\/\/www.aeologic.com\/blog\/wp-includes\/js\/wp-embed.min.js\n<\/script>\n","thumbnail_url":"https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2020\/02\/Solr-Client-APIs.png","thumbnail_width":1080,"thumbnail_height":622,"description":"Hello Everyone! Today we will discuss another important aspect in solr which is widely used in enterprise-grade applications harnessing the power of solr. In most scenarios, we need to interact with data types of different types and from different sources. Solr provides with multiple client Api&#8217;s to deal with this type of scenario and do much more. Introduction to Client APIs At its heart, Solr is a Web application, but because it is built on open protocols, any type of client application can use Solr. HTTP is the fundamental protocol used between client applications and Solr. The client makes a request and Solr does some work and provides a response. Clients use requests to ask Solr to do things like performing queries or index documents. Client applications can reach Solr by creating HTTP requests and parsing the HTTP responses. Client APIs encapsulate much of the work of sending requests and parsing responses, which makes it much easier to write client applications. Clients use Solr\u2019s five fundamental operations to work with Solr. The operations are query, index, delete, commit, and optimize. Queries are executed by creating a URL that contains all the query parameters. Solr examines the request URL, performs the query, and returns the results. The other operations are similar, although in certain cases the HTTP request is a POST operation and contains information beyond whatever is included in the request URL. An index operation, for example, may contain a document in the body of the request. Choosing an Output Format 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\u00a0wt parameter in a query. Most client APIs hide this detail for you, so for many types of client applications, you won\u2019t ever have to specify a\u00a0wt\u00a0parameter. 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&#8217;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\/,\u00a0http:\/\/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\u2019t need to install any packages or configure anything. HTTP requests can be sent to Solr using the standard\u00a0XMLHttpRequest\u00a0mechanism. By default, Solr sends Javascript Object Notation(JSON) responses, which are easily interpreted in JavaScript. You don\u2019t 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\u00a0Ivy), place the following in your\u00a0ivy.xml: For projects built with Maven, place the following in your\u00a0pom.xml For projects built with Gradle, place the following in your\u00a0build.gradle: Adding SolrJ to the Classpath Manually If you are not using one of the above build system, it\u2019s still easy to add SolrJ to your build. At build time, all that is required is the SolrJ jar itself:\u00a0solr-solrj-7.4.0.jar. To compile code manually that uses SolrJ, use a\u00a0javac\u00a0command similar to: At runtime, you need a few of SolrJ\u2019s dependencies, in addition to SolrJ itself. For convenience, these dependencies are made available in the\u00a0dist\/solrj-lib\u00a0directory. Run your project with a classpath like: Querying in SolrJ SolrClient\u00a0has a number of\u00a0query()\u00a0methods for fetching results from Solr. Each of these methods takes in a\u00a0SolrParams,an object encapsulating arbitrary query-parameters. And each method outputs a\u00a0QueryResponse, a wrapper which can be used to access the result documents and other related metadata. The following snippet uses a SolrClient to query Solr\u2019s &#8220;techproducts&#8221; example collection, and iterate over the results. SolrParams\u00a0has a\u00a0SolrQuery\u00a0subclass, 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\u00a0SolrQuery: Indexing in SolrJ Indexing is also simple using SolrJ. Users build the documents they want to index as instances of\u00a0SolrInputDocument, and provide them as arguments to one of the\u00a0add()\u00a0methods on\u00a0SolrClient. The following example shows how to use SolrJ to add a document to Solr\u2019s &#8220;techproducts&#8221; example collection: So , this is it about solr client API&#8217;s. We will be back with another post very soon.10 Solr Client API&#8217;s"}