Author: ryan
Date: Wed Jun 11 07:38:49 2008
New Revision: 666684
URL: http://svn.apache.org/viewvc?rev=666684&view=rev
Log:
SOLR-536 - adding the binder to SolrServer.
Modified:
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/SolrServer.java
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/QueryRequest.java
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/response/QueryResponse.java
Modified:
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/SolrServer.java
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/SolrServer.java?rev=666684&r1=666683&r2=666684&view=diff
==============================================================================
---
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/SolrServer.java
(original)
+++
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/SolrServer.java
Wed Jun 11 07:38:49 2008
@@ -20,6 +20,7 @@
import java.io.IOException;
import java.io.Serializable;
import java.util.Collection;
+import java.util.ArrayList;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.request.SolrPing;
@@ -27,6 +28,7 @@
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.SolrPingResponse;
import org.apache.solr.client.solrj.response.UpdateResponse;
+import org.apache.solr.client.solrj.beans.DocumentObjectBinder;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
@@ -37,6 +39,8 @@
*/
public abstract class SolrServer implements Serializable
{
+ private DocumentObjectBinder binder;
+
public UpdateResponse add(Collection<SolrInputDocument> docs, boolean
overwrite ) throws SolrServerException, IOException {
UpdateRequest req = new UpdateRequest();
req.add(docs);
@@ -44,6 +48,15 @@
return req.process(this);
}
+ public UpdateResponse addBeans(Collection<Object> beans, boolean overwrite )
throws SolrServerException, IOException {
+ DocumentObjectBinder binder = this.getBinder();
+ ArrayList<SolrInputDocument> docs = new
ArrayList<SolrInputDocument>(beans.size());
+ for (Object bean : beans) {
+ docs.add(binder.toSolrInputDocument(bean));
+ }
+ return add(docs,overwrite);
+ }
+
public UpdateResponse add(SolrInputDocument doc, boolean overwrite ) throws
SolrServerException, IOException {
UpdateRequest req = new UpdateRequest();
req.add(doc);
@@ -51,14 +64,26 @@
return req.process(this);
}
+ public UpdateResponse addBean(Object obj, boolean overwrite) throws
IOException, SolrServerException {
+ return add(getBinder().toSolrInputDocument(obj), overwrite);
+ }
+
public UpdateResponse add(SolrInputDocument doc) throws SolrServerException,
IOException {
return add(doc, true);
}
+ public UpdateResponse addBean(Object obj) throws IOException,
SolrServerException {
+ return add(getBinder().toSolrInputDocument(obj), true);
+ }
+
public UpdateResponse add(Collection<SolrInputDocument> docs) throws
SolrServerException, IOException {
return add(docs, true);
}
+ public UpdateResponse addBeans(Collection<Object> beans ) throws
SolrServerException, IOException {
+ return addBeans(beans,true);
+ }
+
/** waitFlush=true and waitSearcher=true to be inline with the defaults for
plain HTTP access
* @throws IOException
*/
@@ -100,5 +125,12 @@
/**
* SolrServer implementations need to implement a how a request is actually
processed
*/
- public abstract NamedList<Object> request( final SolrRequest request )
throws SolrServerException, IOException;
+ public abstract NamedList<Object> request( final SolrRequest request )
throws SolrServerException, IOException;
+
+ public DocumentObjectBinder getBinder() {
+ if(binder == null){
+ binder = new DocumentObjectBinder();
+ }
+ return binder;
+ }
}
\ No newline at end of file
Modified:
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/QueryRequest.java
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/QueryRequest.java?rev=666684&r1=666683&r2=666684&view=diff
==============================================================================
---
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/QueryRequest.java
(original)
+++
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/request/QueryRequest.java
Wed Jun 11 07:38:49 2008
@@ -81,7 +81,7 @@
try
{
long startTime = System.currentTimeMillis();
- QueryResponse res = new QueryResponse( server.request( this ) );
+ QueryResponse res = new QueryResponse( server.request( this ), server);
res.setElapsedTime( System.currentTimeMillis()-startTime );
return res;
}
Modified:
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/response/QueryResponse.java
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/response/QueryResponse.java?rev=666684&r1=666683&r2=666684&view=diff
==============================================================================
---
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/response/QueryResponse.java
(original)
+++
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/response/QueryResponse.java
Wed Jun 11 07:38:49 2008
@@ -26,6 +26,8 @@
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.util.NamedList;
+import org.apache.solr.client.solrj.SolrServer;
+import org.apache.solr.client.solrj.beans.DocumentObjectBinder;
/**
*
@@ -47,15 +49,21 @@
private List<FacetField> _facetFields = null;
private List<FacetField> _limitingFacets = null;
private List<FacetField> _facetDates = null;
-
+
// Highlight Info
private Map<String,Map<String,List<String>>> _highlighting = null;
// Debug Info
private Map<String,Object> _debugMap = null;
private Map<String,String> _explainMap = null;
+ private SolrServer solrServer;
+ public QueryResponse( NamedList<Object> res , SolrServer solrServer){
+ this(res);
+ this.solrServer = solrServer;
+ }
- public QueryResponse( NamedList<Object> res )
+
+ public QueryResponse( NamedList<Object> res )
{
super( res );
@@ -241,6 +249,12 @@
public List<FacetField> getLimitingFacets() {
return _limitingFacets;
}
+
+ public <T> List<T> getBeans(Class<T> type){
+ return solrServer == null ?
+ new DocumentObjectBinder().getBeans(type,_results):
+ solrServer.getBinder().getBeans(type, _results);
+ }
}