mirror of https://github.com/apache/lucene.git
SOLR-536 - adding the binder to SolrServer.
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@666684 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2ce5049e36
commit
a00f94c4a9
|
@ -20,6 +20,7 @@ package org.apache.solr.client.solrj;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.apache.solr.client.solrj.request.QueryRequest;
|
import org.apache.solr.client.solrj.request.QueryRequest;
|
||||||
import org.apache.solr.client.solrj.request.SolrPing;
|
import org.apache.solr.client.solrj.request.SolrPing;
|
||||||
|
@ -27,6 +28,7 @@ import org.apache.solr.client.solrj.request.UpdateRequest;
|
||||||
import org.apache.solr.client.solrj.response.QueryResponse;
|
import org.apache.solr.client.solrj.response.QueryResponse;
|
||||||
import org.apache.solr.client.solrj.response.SolrPingResponse;
|
import org.apache.solr.client.solrj.response.SolrPingResponse;
|
||||||
import org.apache.solr.client.solrj.response.UpdateResponse;
|
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.SolrInputDocument;
|
||||||
import org.apache.solr.common.params.SolrParams;
|
import org.apache.solr.common.params.SolrParams;
|
||||||
import org.apache.solr.common.util.NamedList;
|
import org.apache.solr.common.util.NamedList;
|
||||||
|
@ -37,6 +39,8 @@ import org.apache.solr.common.util.NamedList;
|
||||||
*/
|
*/
|
||||||
public abstract class SolrServer implements Serializable
|
public abstract class SolrServer implements Serializable
|
||||||
{
|
{
|
||||||
|
private DocumentObjectBinder binder;
|
||||||
|
|
||||||
public UpdateResponse add(Collection<SolrInputDocument> docs, boolean overwrite ) throws SolrServerException, IOException {
|
public UpdateResponse add(Collection<SolrInputDocument> docs, boolean overwrite ) throws SolrServerException, IOException {
|
||||||
UpdateRequest req = new UpdateRequest();
|
UpdateRequest req = new UpdateRequest();
|
||||||
req.add(docs);
|
req.add(docs);
|
||||||
|
@ -44,6 +48,15 @@ public abstract class SolrServer implements Serializable
|
||||||
return req.process(this);
|
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 {
|
public UpdateResponse add(SolrInputDocument doc, boolean overwrite ) throws SolrServerException, IOException {
|
||||||
UpdateRequest req = new UpdateRequest();
|
UpdateRequest req = new UpdateRequest();
|
||||||
req.add(doc);
|
req.add(doc);
|
||||||
|
@ -51,14 +64,26 @@ public abstract class SolrServer implements Serializable
|
||||||
return req.process(this);
|
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 {
|
public UpdateResponse add(SolrInputDocument doc) throws SolrServerException, IOException {
|
||||||
return add(doc, true);
|
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 {
|
public UpdateResponse add(Collection<SolrInputDocument> docs) throws SolrServerException, IOException {
|
||||||
return add(docs, true);
|
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
|
/** waitFlush=true and waitSearcher=true to be inline with the defaults for plain HTTP access
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
|
@ -100,5 +125,12 @@ public abstract class SolrServer implements Serializable
|
||||||
/**
|
/**
|
||||||
* SolrServer implementations need to implement a how a request is actually processed
|
* 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;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -81,7 +81,7 @@ public class QueryRequest extends SolrRequest
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
QueryResponse res = new QueryResponse( server.request( this ) );
|
QueryResponse res = new QueryResponse( server.request( this ), server);
|
||||||
res.setElapsedTime( System.currentTimeMillis()-startTime );
|
res.setElapsedTime( System.currentTimeMillis()-startTime );
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.apache.solr.common.SolrDocumentList;
|
import org.apache.solr.common.SolrDocumentList;
|
||||||
import org.apache.solr.common.util.NamedList;
|
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 @@ public class QueryResponse extends SolrResponseBase
|
||||||
private List<FacetField> _facetFields = null;
|
private List<FacetField> _facetFields = null;
|
||||||
private List<FacetField> _limitingFacets = null;
|
private List<FacetField> _limitingFacets = null;
|
||||||
private List<FacetField> _facetDates = null;
|
private List<FacetField> _facetDates = null;
|
||||||
|
|
||||||
// Highlight Info
|
// Highlight Info
|
||||||
private Map<String,Map<String,List<String>>> _highlighting = null;
|
private Map<String,Map<String,List<String>>> _highlighting = null;
|
||||||
|
|
||||||
// Debug Info
|
// Debug Info
|
||||||
private Map<String,Object> _debugMap = null;
|
private Map<String,Object> _debugMap = null;
|
||||||
private Map<String,String> _explainMap = 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 );
|
super( res );
|
||||||
|
|
||||||
|
@ -241,6 +249,12 @@ public class QueryResponse extends SolrResponseBase
|
||||||
public List<FacetField> getLimitingFacets() {
|
public List<FacetField> getLimitingFacets() {
|
||||||
return _limitingFacets;
|
return _limitingFacets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> List<T> getBeans(Class<T> type){
|
||||||
|
return solrServer == null ?
|
||||||
|
new DocumentObjectBinder().getBeans(type,_results):
|
||||||
|
solrServer.getBinder().getBeans(type, _results);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue