|
|
|
@ -22,34 +22,25 @@
|
|
|
|
|
package net.yacy.cora.federate.solr.connector;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import net.yacy.cora.federate.solr.instance.EmbeddedInstance;
|
|
|
|
|
import net.yacy.cora.federate.solr.instance.SolrInstance;
|
|
|
|
|
import net.yacy.cora.util.ConcurrentLog;
|
|
|
|
|
|
|
|
|
|
import org.apache.solr.client.solrj.SolrServerException;
|
|
|
|
|
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
|
|
|
|
|
import org.apache.solr.client.solrj.request.QueryRequest;
|
|
|
|
|
import org.apache.solr.client.solrj.response.QueryResponse;
|
|
|
|
|
import org.apache.solr.common.SolrException;
|
|
|
|
|
import org.apache.solr.common.params.ModifiableSolrParams;
|
|
|
|
|
import org.apache.solr.common.params.SolrParams;
|
|
|
|
|
import org.apache.solr.common.util.NamedList;
|
|
|
|
|
import org.apache.solr.common.util.SimpleOrderedMap;
|
|
|
|
|
import org.apache.solr.core.CoreContainer;
|
|
|
|
|
import org.apache.solr.core.SolrConfig;
|
|
|
|
|
import org.apache.solr.core.SolrCore;
|
|
|
|
|
import org.apache.solr.handler.component.QueryComponent;
|
|
|
|
|
import org.apache.solr.handler.component.ResponseBuilder;
|
|
|
|
|
import org.apache.solr.handler.component.SearchComponent;
|
|
|
|
|
import org.apache.solr.handler.component.SearchHandler;
|
|
|
|
|
import org.apache.solr.request.SolrQueryRequest;
|
|
|
|
|
import org.apache.solr.request.SolrQueryRequestBase;
|
|
|
|
|
import org.apache.solr.request.SolrRequestHandler;
|
|
|
|
|
import org.apache.solr.request.SolrRequestInfo;
|
|
|
|
|
import org.apache.solr.response.SolrQueryResponse;
|
|
|
|
|
import org.apache.solr.servlet.SolrRequestParsers;
|
|
|
|
|
|
|
|
|
|
public class EmbeddedSolrConnector extends SolrServerConnector implements SolrConnector {
|
|
|
|
|
|
|
|
|
@ -58,7 +49,6 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo
|
|
|
|
|
|
|
|
|
|
private final SearchHandler requestHandler;
|
|
|
|
|
private final EmbeddedInstance instance;
|
|
|
|
|
private final String coreName;
|
|
|
|
|
private SolrCore core;
|
|
|
|
|
|
|
|
|
|
public EmbeddedSolrConnector(EmbeddedInstance instance) {
|
|
|
|
@ -69,7 +59,6 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo
|
|
|
|
|
this.requestHandler.init(new NamedList<Object>());
|
|
|
|
|
this.requestHandler.inform(this.core);
|
|
|
|
|
super.init(this.instance.getDefaultServer());
|
|
|
|
|
this.coreName = ((EmbeddedSolrServer) this.server).getCoreContainer().getDefaultCoreName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public EmbeddedSolrConnector(EmbeddedInstance instance, String coreName) {
|
|
|
|
@ -80,7 +69,6 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo
|
|
|
|
|
this.requestHandler.init(new NamedList<Object>());
|
|
|
|
|
this.requestHandler.inform(this.core);
|
|
|
|
|
super.init(this.instance.getServer(coreName));
|
|
|
|
|
this.coreName = coreName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SolrInstance getInstance() {
|
|
|
|
@ -95,51 +83,6 @@ public class EmbeddedSolrConnector extends SolrServerConnector implements SolrCo
|
|
|
|
|
return this.core.getSolrConfig();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static final SolrRequestParsers _parser = new SolrRequestParsers(null);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* get the size of the index. We override the implementation in SolrServerConnector
|
|
|
|
|
* because we can do this with more efficiently in a different way for embedded indexes.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public long getSize() {
|
|
|
|
|
if (this.server == null) return 0;
|
|
|
|
|
String threadname = Thread.currentThread().getName();
|
|
|
|
|
Thread.currentThread().setName("solr query: size");
|
|
|
|
|
EmbeddedSolrServer ess = (EmbeddedSolrServer) this.server;
|
|
|
|
|
CoreContainer coreContainer = ess.getCoreContainer();
|
|
|
|
|
SolrCore core = coreContainer.getCore(this.coreName);
|
|
|
|
|
if (core == null) throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "No such core: " + this.coreName);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
SolrParams params = AbstractSolrConnector.catchSuccessQuery;
|
|
|
|
|
QueryRequest request = new QueryRequest(AbstractSolrConnector.catchSuccessQuery);
|
|
|
|
|
SolrQueryRequest req = _parser.buildRequestFrom(core, params, request.getContentStreams());
|
|
|
|
|
String path = "/select";
|
|
|
|
|
req.getContext().put("path", path);
|
|
|
|
|
SolrQueryResponse rsp = new SolrQueryResponse();
|
|
|
|
|
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
|
|
|
|
|
SolrRequestHandler handler = core.getRequestHandler(path);
|
|
|
|
|
SearchHandler sh = (SearchHandler) handler;
|
|
|
|
|
List<SearchComponent> components = sh.getComponents();
|
|
|
|
|
ResponseBuilder rb = new ResponseBuilder(req, rsp, components);
|
|
|
|
|
QueryComponent qc = (QueryComponent) components.get(0);
|
|
|
|
|
qc.prepare(rb);
|
|
|
|
|
qc.process(rb);
|
|
|
|
|
qc.finishStage(rb);
|
|
|
|
|
int hits = rb.getResults().docList.matches();
|
|
|
|
|
if (req != null) req.close();
|
|
|
|
|
core.close();
|
|
|
|
|
SolrRequestInfo.clearRequestInfo();
|
|
|
|
|
Thread.currentThread().setName(threadname);
|
|
|
|
|
return hits;
|
|
|
|
|
} catch (final Throwable e) {
|
|
|
|
|
log.warn(e);
|
|
|
|
|
Thread.currentThread().setName(threadname);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public synchronized void close() {
|
|
|
|
|
try {this.commit(false);} catch (final Throwable e) {ConcurrentLog.logException(e);}
|
|
|
|
|