lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Solr Wiki] Update of "SolJava" by ErikHatcher
Date Thu, 13 Nov 2008 11:51:22 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Solr Wiki" for change notification.

The following page has been changed by ErikHatcher:
http://wiki.apache.org/solr/SolJava

The comment on the change is:
Added example to call arbitrary request handler

------------------------------------------------------------------------------
  
  ["Solrj"] is a robust Java client for adding, deleting and updating documents with Solr.
 ["Solrj"] includes an option to access an embedded solr instance without the need to run
an HTTP server.
  
+ == Translating requests to SolrJ ==
+ 
+ SolrJ can call to any solrconfig.xml registered request handler.  Given a request handler
like this:
+ 
+ {{{
+   <requestHandler name="/spellCheckCompRH" class="solr.SearchHandler">
+     <lst name="defaults">
+       <!-- omp = Only More Popular -->
+       <str name="spellcheck.onlyMorePopular">false</str>
+       <!-- exr = Extended Results -->
+       <str name="spellcheck.extendedResults">false</str>
+       <!--  The number of suggestions to return -->
+       <str name="spellcheck.count">1</str>
+     </lst>
+     <arr name="last-components">
+       <str>spellcheck</str>
+     </arr>
+   </requestHandler>
+ }}}
+ 
+ This SolrJ code will call the handler:
+ 
+ {{{
+ import org.apache.solr.client.solrj.SolrServer;
+ import org.apache.solr.client.solrj.SolrServerException;
+ import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
+ import org.apache.solr.client.solrj.response.QueryResponse;
+ import org.apache.solr.common.params.ModifiableSolrParams;
+ 
+ import java.net.MalformedURLException;
+ 
+ public class SolrJExample {
+   public static void main(String[] args) throws MalformedURLException, SolrServerException
{
+     SolrServer solr = new CommonsHttpSolrServer("http://localhost:8983/solr");
+ 
+     // http://localhost:8983/solr/spellCheckCompRH?q=epod&spellcheck=on&spellcheck.build=true
+     ModifiableSolrParams params = new ModifiableSolrParams();
+     params.set("qt", "/spellCheckCompRH");
+     params.set("q", "epod");
+     params.set("spellcheck", "on");
+     params.set("spellcheck.build", "true");
+ 
+     QueryResponse response = solr.query(params);
+     System.out.println("response = " + response);
+   }
+ }
+ }}}
+ 
  
  = SimplePostTool =
  

Mime
View raw message