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 NoblePaul:
http://wiki.apache.org/solr/Solrj

------------------------------------------------------------------------------
  [[TableOfContents]]
  
  Solrj is a java client to access solr. It offers a java interface to add, 
update, and query the solr index.
- 
- /!\ NOTE -- the default solrj update command expects to use a standard 
!RequestHandler, '''not''' the deprecated !SolrUpdateServlet.  Make sure your 
solrconfig.xml includes:
- {{{
-   <requestHandler name="/update" class="solr.XmlUpdateRequestHandler" />
- }}}
- If your are calling the server.commit() and the documents are not getting 
commited, this is most likely your problem.
  
  
  = CommonsHttpSolrServer =
@@ -19, +13 @@

  
  {{{
    String url = "http://localhost:8983/solr";;
-   CommonsHttpSolrServer server = new CommonsHttpSolrServer( url );
+   SolrServer server = new CommonsHttpSolrServer( url );
-   ...
+   
  }}} 
  == Setting XMLResponseParser ==
  SolrJ has uses a binary format as the default format now. For users with Solr 
1.2 or older versions of Solr 1.3 must explicitly ask SolrJ to use XML format.
@@ -110, +104 @@

    UpdateResponse rsp = req.process( server );  
  }}}
  
+ === Directly adding POJOs to Solr ===
+ * Create a Java bean with annotations. The [EMAIL PROTECTED] annotation can 
be applied to a field or a setter method. If the field name is different from 
the bean field name give the aliased name in the annotation itself as shown in 
the categories field.
+ {{{
+  public static class Item {
+     @Field
+     String id;
+ 
+     @Field("cat")
+     String[] categories;
+ 
+     @Field
+     List<String> features;
+ 
+   }
+ }}}
+ * Get an instance of server
+ {{{
+     SolrServer server = getSolrServer();
+ }}}
+ * Create the bean instances 
+ {{{
+     Item item = new Item();
+     item.id = "one";
+     item.categories =  new String[] { "aaa", "bbb", "ccc" };
+     
+ }}}
+ * Add to Solr
+ {{{
+    server.addBean(item);
+ }}}
+ 
+ 
+ 
  == Reading Data from Solr ==
   * Get an instance of server first
  {{{

Reply via email to