[ https://issues.apache.org/jira/browse/SOLR-20?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12466970 ]
Ryan McKinley commented on SOLR-20: ----------------------------------- I have dramatically reworked the client code to fit with the pluggable ContentStream model in SOLR-104. This version makes it easy to customize/extend the request/response behavior. Once it stabilizes and is better tested, I'll upload a zip, but for now, you can preview it: http://svn.lapnap.net/solr/solrj/ Major changes: * it is based on commons-httpclient-3.0.1.jar * I'm using wt=JSON rather then XML. (It maps to a hash easier) * I moved some of the common classes to o.a.s.util. Hopefully the core classes will be refactored to make it easier to share some classes * handles multiple ContentStreams using multi-part form upload * Got rid of the SolrDocumentable/SolrDocumented distinction. -- now there is only SolrDocument() * You can define and automatically build a solr document with annotations * Includes a first draft for a HibernateEventListener. When stuff is added/updated/deleted, it gets sent to solr. (Note, this class should probable not be in the main client as the hibernate prerequisite libraries are substantial - I've included them because its what i need to have working soon) When this is more stable, it will be something similar to a Compass Hibernate3GpsDevice (http://www.opensymphony.com/compass/versions/1.1RC1/html/gps-hibernate.html) The key interfaces are: public interface SolrClient { public abstract SolrResponse process( final SolrRequest req ); } public interface SolrRequest { public String getMethod(); public String getHandlerPath(); public RequestParams getParams(); public Collection<ContentStream> getContentStreams(); public SolrResponse parseResponseBody(InputStream in); public SolrResponse execute(SolrClient solr); } - - - - - - - Here is some sample usage: SolrClient client = new CommonsHttpSolrClient( new URL("http://localhost:8983/solr/") ); // Set up a simple query SolrQuery query = new SolrQuery(); query.setQuery( "solr" ); query.addFacetField( "cat" ); query.setFacetLimit( 15 ); query.setQuery( "video" ); query.setShowDebugInfo( true ); QueryResponse rsp = query.execute( client ); for( ResultDoc doc : rsp.getDocs() ) { System.out.println( doc.get( "name" ) ); System.out.println( doc.getScore() ); System.out.println( doc.getExplain() ); } SimpleSolrDoc doc = new SimpleSolrDoc(); doc.setField( "id", "xxx" ); doc.setField( "price", 12.34f ); doc.setField( "cat", new String[] { "aaa", "bbb", "ccc" } ); new AddDocuments( doc ).execute( client ); new CommitIndex().execute( client ); - - - - - - - - - - - This also includes a utility to make solr documents from annotations. Given the class: @SolrSearchable( boost=2.0 ) public class Example { @SolrSearchable public String getName() { return "hello" } @SolrSearchable( name="cat", boost=3 ) public String getSomeOtherName() { return "there" } } The DocumentBuilder can automatically make: <doc boost="2.0"> <field name="name">hello</field> <field name="cat" boost="3">there</field> </doc> - - - - - - - - - - - There are a few parts of the API i think are awkward, I'd love any feedback / review you may have. thanks ryan > A simple Java client for updating and searching > ----------------------------------------------- > > Key: SOLR-20 > URL: https://issues.apache.org/jira/browse/SOLR-20 > Project: Solr > Issue Type: New Feature > Components: clients - java > Environment: all > Reporter: Darren Erik Vengroff > Priority: Minor > Attachments: DocumentManagerClient.java, DocumentManagerClient.java, > solr-client-java-2.zip.zip, solr-client-java.zip, solr-client-sources.jar, > solr-client.zip, solr-client.zip, solr-client.zip, SolrClientException.java, > SolrServerException.java > > > I wrote a simple little client class that can connect to a Solr server and > issue add, delete, commit and optimize commands using Java methods. I'm > posting here for review and comments as suggested by Yonik. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.