multiple solr cores instead of just one. Therefore it is now necessary to distuingish between solr server connections (called an 'Instance') and a connection to a single solr core. One Instance may now have multiple connector classes assigned to it, each connecting to a single core. To support multiple cores it is also necessary to distinguish between the connection configuration and the configuration of the index schema. We will have multiple schema configurations in the future, each for every solr core. This caused that the IndexFederated servlet had to be split into two parts, the new Servlet for the Schema editor is now in the IndexSchema Servlet.pull/1/head
parent
4111606654
commit
b6de1f42dc
@ -0,0 +1,48 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>YaCy '#[clientname]#': Solr Schema Editor</title>
|
||||
#%env/templates/metas.template%#
|
||||
</head>
|
||||
<body id="IndexSchema_p">
|
||||
<div id="api">
|
||||
<a href="/api/schema.xml">
|
||||
<img src="env/grafics/api.png" width="60" height="40" alt="API" /></a>
|
||||
<span>The solr schema can also be retrieved as xml here. Click the API icon to see the xml. Just copy this xml to solr/conf/schema.xml to configure solr.</span>
|
||||
</div>
|
||||
#%env/templates/header.template%#
|
||||
#%env/templates/submenuIndexControl.template%#
|
||||
<h2>Solr Schema Editor</h2>
|
||||
<p>If you use a custom Solr schema you may enter a different field name in the column 'Custom Solr Field Name' of the YaCy default attribute name</p>
|
||||
|
||||
<form action="IndexSchema_p.html" method="post" enctype="multipart/form-data" accept-charset="UTF-8">
|
||||
<fieldset>
|
||||
<div>
|
||||
<table class="sortable" border="0" cellpadding="2" cellspacing="1">
|
||||
<tr class="TableHeader" valign="bottom">
|
||||
<td>Active</td>
|
||||
<td>Attribute</td>
|
||||
<td>Custom Solr Field Name</td>
|
||||
<td>Comment</td>
|
||||
</tr>
|
||||
#{schema}#
|
||||
<tr class="TableCell#(dark)#Light::Dark::Summary#(/dark)#">
|
||||
<td align="center"><input type="checkbox" name="schema_#[key]#" value="checked" #(checked)#::checked="checked"#(/checked)#/></td>
|
||||
<td align="left">#[key]#</td>
|
||||
<td align="left"><input type="text" name="schema_solrfieldname_#[key]#" value="#[solrfieldname]#"/></td>
|
||||
<td align="left">#[comment]#</td>
|
||||
</tr>
|
||||
#{/schema}#
|
||||
</table>
|
||||
<dl>
|
||||
<dt class="TableCellDark">Lazy Value Initialization</dt>
|
||||
<dd><input type="checkbox" name="lazy" id="lazy" #(lazy.checked)#:: checked="checked"#(/lazy.checked)# /> (if checked, only non-zero values and non-empty strings are written)</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</fieldset>
|
||||
<input type="submit" name="set" value="Set" />
|
||||
</form>
|
||||
|
||||
#%env/templates/footer.template%#
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,92 @@
|
||||
/**
|
||||
* IndexSchemaFulltext_p
|
||||
* Copyright 2011 by Michael Peter Christen, mc@yacy.net, Frankfurt am Main, Germany
|
||||
* First released 13.02.2013 at http://yacy.net
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program in the file lgpl21.txt
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.yacy.cora.federate.solr.YaCySchema;
|
||||
import net.yacy.cora.federate.yacy.ConfigurationSet;
|
||||
import net.yacy.cora.protocol.RequestHeader;
|
||||
import net.yacy.search.Switchboard;
|
||||
import net.yacy.search.SwitchboardConstants;
|
||||
import net.yacy.server.serverObjects;
|
||||
import net.yacy.server.serverSwitch;
|
||||
|
||||
public class IndexSchema_p {
|
||||
|
||||
public static serverObjects respond(@SuppressWarnings("unused") final RequestHeader header, final serverObjects post, final serverSwitch env) {
|
||||
// return variable that accumulates replacements
|
||||
final serverObjects prop = new serverObjects();
|
||||
final Switchboard sb = (Switchboard) env;
|
||||
|
||||
if (post != null && post.containsKey("set")) {
|
||||
// read index schema table flags
|
||||
final Iterator<ConfigurationSet.Entry> i = sb.index.fulltext().getSolrSchema().entryIterator();
|
||||
ConfigurationSet.Entry entry;
|
||||
boolean modified = false; // flag to remember changes
|
||||
while (i.hasNext()) {
|
||||
entry = i.next();
|
||||
final String v = post.get("schema_" + entry.key());
|
||||
final String sfn = post.get("schema_solrfieldname_" + entry.key());
|
||||
if (sfn != null ) {
|
||||
// set custom solr field name
|
||||
if (!sfn.equals(entry.getValue())) {
|
||||
entry.setValue(sfn);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
// set enable flag
|
||||
final boolean c = v != null && v.equals("checked");
|
||||
if (entry.enabled() != c) {
|
||||
entry.setEnable(c);
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
if (modified) { // save settings to config file if modified
|
||||
try {
|
||||
sb.index.fulltext().getSolrSchema().commit();
|
||||
modified = false;
|
||||
} catch (IOException ex) {}
|
||||
}
|
||||
|
||||
boolean lazy = post.getBoolean("lazy");
|
||||
env.setConfig(SwitchboardConstants.FEDERATED_SERVICE_SOLR_INDEXING_LAZY, lazy);
|
||||
|
||||
}
|
||||
|
||||
int c = 0;
|
||||
boolean dark = false;
|
||||
// use enum SolrField to keep defined order
|
||||
for(YaCySchema field : YaCySchema.values()) {
|
||||
prop.put("schema_" + c + "_dark", dark ? 1 : 0); dark = !dark;
|
||||
prop.put("schema_" + c + "_checked", sb.index.fulltext().getSolrSchema().contains(field.name()) ? 1 : 0);
|
||||
prop.putHTML("schema_" + c + "_key", field.name());
|
||||
prop.putHTML("schema_" + c + "_solrfieldname",field.name().equalsIgnoreCase(field.getSolrFieldName()) ? "" : field.getSolrFieldName());
|
||||
if (field.getComment() != null) prop.putHTML("schema_" + c + "_comment",field.getComment());
|
||||
c++;
|
||||
}
|
||||
prop.put("schema", c);
|
||||
|
||||
prop.put("lazy.checked", env.getConfigBool(SwitchboardConstants.FEDERATED_SERVICE_SOLR_INDEXING_LAZY, true) ? 1 : 0);
|
||||
|
||||
// return rewrite properties
|
||||
return prop;
|
||||
}
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
/**
|
||||
* SolrEmbeddedInstance
|
||||
* Copyright 2013 by Michael Peter Christen
|
||||
* First released 13.02.2013 at http://yacy.net
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program in the file lgpl21.txt
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.yacy.cora.federate.solr.instance;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.yacy.kelondro.logging.Log;
|
||||
import net.yacy.kelondro.util.MemoryControl;
|
||||
|
||||
import org.apache.solr.client.solrj.SolrServer;
|
||||
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
|
||||
import org.apache.solr.core.CoreContainer;
|
||||
import org.apache.solr.core.SolrCore;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
|
||||
public class SolrEmbeddedInstance implements SolrInstance {
|
||||
|
||||
private final static String[] confFiles = {"solrconfig.xml", "schema.xml", "stopwords.txt", "synonyms.txt", "protwords.txt", "currency.xml", "elevate.xml", "xslt/example.xsl", "xslt/json.xsl", "lang/"};
|
||||
|
||||
private CoreContainer cores;
|
||||
private String defaultCoreName;
|
||||
private SolrCore defaultCore;
|
||||
private SolrServer defaultServer;
|
||||
private File storagePath;
|
||||
|
||||
public SolrEmbeddedInstance(final File corePath, final File solr_config) throws IOException {
|
||||
super();
|
||||
// copy the solrconfig.xml to the storage path
|
||||
this.storagePath = corePath;
|
||||
File conf = new File(corePath, "conf");
|
||||
conf.mkdirs();
|
||||
File source, target;
|
||||
for (String cf: confFiles) {
|
||||
source = new File(solr_config, cf);
|
||||
if (source.isDirectory()) {
|
||||
target = new File(conf, cf);
|
||||
target.mkdirs();
|
||||
for (String cfl: source.list()) {
|
||||
try {
|
||||
Files.copy(new File(source, cfl), new File(target, cfl));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
target = new File(conf, cf);
|
||||
target.getParentFile().mkdirs();
|
||||
try {
|
||||
Files.copy(source, target);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
String dir = corePath.getAbsolutePath();
|
||||
File configFile = new File(solr_config, "solr.xml");
|
||||
this.cores = new CoreContainer(dir, configFile); // this may take indefinitely long if solr files are broken
|
||||
if (this.cores == null) throw new IOException("cannot create core container dir = " + dir + ", configFile = " + configFile);
|
||||
this.defaultCoreName = this.cores.getDefaultCoreName();
|
||||
Log.logInfo("SolrEmbeddedInstance", "detected default solr core: " + this.defaultCoreName);
|
||||
this.defaultCore = this.cores.getCore(this.defaultCoreName); // should be "collection1"
|
||||
if (this.defaultCore == null) {
|
||||
// try again
|
||||
Collection<SolrCore> cores = this.cores.getCores();
|
||||
if (cores.size() > 0) {
|
||||
this.defaultCore = cores.iterator().next();
|
||||
this.defaultCoreName = this.defaultCore.getName();
|
||||
}
|
||||
}
|
||||
if (this.defaultCore == null) {
|
||||
throw new IOException("cannot get the default core; available = " + MemoryControl.available() + ", free = " + MemoryControl.free());
|
||||
}
|
||||
this.defaultServer = new EmbeddedSolrServer(this.cores, this.defaultCoreName);
|
||||
}
|
||||
|
||||
|
||||
public File getStoragePath() {
|
||||
return this.storagePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultCoreName() {
|
||||
return this.defaultCoreName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getCoreNames() {
|
||||
return this.cores.getCoreNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SolrServer getDefaultServer() {
|
||||
return this.defaultServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SolrServer getServer(String name) {
|
||||
return new EmbeddedSolrServer(this.cores, name);
|
||||
}
|
||||
|
||||
public SolrCore getDefaultCore() {
|
||||
return this.defaultCore;
|
||||
}
|
||||
|
||||
public SolrCore getCore(String name) {
|
||||
return this.cores.getCore(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void close() {
|
||||
try {this.cores.shutdown();} catch (Throwable e) {Log.logException(e);}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* SolrInstance
|
||||
* Copyright 2013 by Michael Peter Christen
|
||||
* First released 13.02.2013 at http://yacy.net
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program in the file lgpl21.txt
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.yacy.cora.federate.solr.instance;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.solr.client.solrj.SolrServer;
|
||||
|
||||
public interface SolrInstance {
|
||||
|
||||
public String getDefaultCoreName();
|
||||
|
||||
public Collection<String> getCoreNames();
|
||||
|
||||
public SolrServer getDefaultServer();
|
||||
|
||||
public SolrServer getServer(String name);
|
||||
|
||||
public void close();
|
||||
}
|
@ -0,0 +1,226 @@
|
||||
/**
|
||||
* SolrRemoteInstance
|
||||
* Copyright 2013 by Michael Peter Christen
|
||||
* First released 13.02.2013 at http://yacy.net
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program in the file lgpl21.txt
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.yacy.cora.federate.solr.instance;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.yacy.cora.document.MultiProtocolURI;
|
||||
import net.yacy.cora.protocol.Domains;
|
||||
import net.yacy.kelondro.logging.Log;
|
||||
|
||||
import org.apache.commons.httpclient.HttpException;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HeaderElement;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpRequestInterceptor;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpResponseInterceptor;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.http.client.AuthCache;
|
||||
import org.apache.http.client.entity.GzipDecompressingEntity;
|
||||
import org.apache.http.client.protocol.ClientContext;
|
||||
import org.apache.http.impl.auth.BasicScheme;
|
||||
import org.apache.http.impl.client.BasicAuthCache;
|
||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
||||
import org.apache.http.protocol.HttpContext;
|
||||
import org.apache.solr.client.solrj.SolrServer;
|
||||
import org.apache.solr.client.solrj.impl.HttpSolrServer;
|
||||
|
||||
public class SolrRemoteInstance implements SolrInstance {
|
||||
|
||||
private String solrurl;
|
||||
private DefaultHttpClient client;
|
||||
|
||||
private String defaultCoreName;
|
||||
private HttpSolrServer defaultServer;
|
||||
private Collection<String> coreNames;
|
||||
|
||||
public SolrRemoteInstance(final String url) throws IOException {
|
||||
this(url, null, url.endsWith("solr/") || url.endsWith("solr") ? "solr" : "shard0");
|
||||
}
|
||||
|
||||
public SolrRemoteInstance(final String url, final Collection<String> coreNames, final String defaultCoreName) throws IOException {
|
||||
this.solrurl = url;
|
||||
if (this.solrurl == null) this.solrurl = "http://127.0.0.1:8983/solr/"; // that should work for the example configuration of solr 4.x.x
|
||||
this.coreNames = coreNames == null ? new ArrayList<String>() : coreNames;
|
||||
this.defaultCoreName = defaultCoreName;
|
||||
if (this.defaultCoreName == null) this.defaultCoreName = "shard0";
|
||||
if (!this.coreNames.contains(this.defaultCoreName)) this.coreNames.add(this.defaultCoreName);
|
||||
|
||||
// check the url
|
||||
if (this.solrurl.endsWith("/")) {
|
||||
// this could mean that we have a path without a core name (correct)
|
||||
// or that the core name is appended and contains a badly '/' at the end (must be corrected)
|
||||
if (this.solrurl.endsWith(this.defaultCoreName + "/")) {
|
||||
this.solrurl = this.solrurl.substring(0, this.solrurl.length() - this.defaultCoreName.length() - 1);
|
||||
}
|
||||
} else {
|
||||
// this could mean that we have an url which ends with the core name (must be corrected)
|
||||
// or that the url has a mising '/' (must be corrected)
|
||||
if (this.solrurl.endsWith(this.defaultCoreName)) {
|
||||
this.solrurl = this.solrurl.substring(0, this.solrurl.length() - this.defaultCoreName.length());
|
||||
} else {
|
||||
this.solrurl = this.solrurl + "/";
|
||||
}
|
||||
}
|
||||
|
||||
// Make a http client, connect using authentication. An url like
|
||||
// http://127.0.0.1:8983/solr/shard0
|
||||
// is proper, and contains the core name as last element in the path
|
||||
final MultiProtocolURI u;
|
||||
try {
|
||||
u = new MultiProtocolURI(this.solrurl + this.defaultCoreName);
|
||||
} catch (MalformedURLException e) {
|
||||
throw new IOException(e.getMessage());
|
||||
}
|
||||
String solraccount, solrpw;
|
||||
String host = u.getHost();
|
||||
final String userinfo = u.getUserInfo();
|
||||
if (userinfo == null || userinfo.isEmpty()) {
|
||||
solraccount = ""; solrpw = "";
|
||||
} else {
|
||||
final int p = userinfo.indexOf(':');
|
||||
if (p < 0) {
|
||||
solraccount = userinfo; solrpw = "";
|
||||
} else {
|
||||
solraccount = userinfo.substring(0, p); solrpw = userinfo.substring(p + 1);
|
||||
}
|
||||
}
|
||||
if (solraccount.length() > 0) {
|
||||
PoolingClientConnectionManager cm = new PoolingClientConnectionManager(); // try also: ThreadSafeClientConnManager
|
||||
cm.setMaxTotal(100);
|
||||
|
||||
this.client = new DefaultHttpClient(cm) {
|
||||
@Override
|
||||
protected HttpContext createHttpContext() {
|
||||
HttpContext context = super.createHttpContext();
|
||||
AuthCache authCache = new BasicAuthCache();
|
||||
BasicScheme basicAuth = new BasicScheme();
|
||||
HttpHost targetHost = new HttpHost(u.getHost(), u.getPort(), u.getProtocol());
|
||||
authCache.put(targetHost, basicAuth);
|
||||
context.setAttribute(ClientContext.AUTH_CACHE, authCache);
|
||||
return context;
|
||||
}
|
||||
};
|
||||
this.client.addRequestInterceptor(new HttpRequestInterceptor() {
|
||||
@Override
|
||||
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
|
||||
if (!request.containsHeader("Accept-Encoding")) request.addHeader("Accept-Encoding", "gzip");
|
||||
}
|
||||
|
||||
});
|
||||
this.client.addResponseInterceptor(new HttpResponseInterceptor() {
|
||||
@Override
|
||||
public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException {
|
||||
HttpEntity entity = response.getEntity();
|
||||
if (entity != null) {
|
||||
Header ceheader = entity.getContentEncoding();
|
||||
if (ceheader != null) {
|
||||
HeaderElement[] codecs = ceheader.getElements();
|
||||
for (HeaderElement codec : codecs) {
|
||||
if (codec.getName().equalsIgnoreCase("gzip")) {
|
||||
response.setEntity(new GzipDecompressingEntity(response.getEntity()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
|
||||
credsProvider.setCredentials(new AuthScope(host, AuthScope.ANY_PORT), new UsernamePasswordCredentials(solraccount, solrpw));
|
||||
this.client.setCredentialsProvider(credsProvider);
|
||||
} else {
|
||||
this.client = null;
|
||||
}
|
||||
|
||||
this.defaultServer = (HttpSolrServer) getServer(this.defaultCoreName);
|
||||
if (this.defaultServer == null) throw new IOException("cannot connect to url " + url + " and connect core " + defaultCoreName);
|
||||
}
|
||||
|
||||
public String getAdminInterface() {
|
||||
final InetAddress localhostExternAddress = Domains.myPublicLocalIP();
|
||||
final String localhostExtern = localhostExternAddress == null ? "127.0.0.1" : localhostExternAddress.getHostAddress();
|
||||
String u = this.solrurl;
|
||||
int p = u.indexOf("localhost",0);
|
||||
if (p < 0) p = u.indexOf("127.0.0.1",0);
|
||||
if (p < 0) p = u.indexOf("0:0:0:0:0:0:0:1",0);
|
||||
if (p >= 0) u = u.substring(0, p) + localhostExtern + u.substring(p + 9);
|
||||
return u + (u.endsWith("/") ? "admin/" : "/admin/");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultCoreName() {
|
||||
return this.defaultCoreName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getCoreNames() {
|
||||
return this.coreNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SolrServer getDefaultServer() {
|
||||
return this.defaultServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SolrServer getServer(String name) {
|
||||
HttpSolrServer server;
|
||||
if (this.client != null) {
|
||||
final MultiProtocolURI u;
|
||||
try {
|
||||
u = new MultiProtocolURI(this.solrurl + name);
|
||||
} catch (MalformedURLException e) {
|
||||
return null;
|
||||
}
|
||||
String host = u.getHost();
|
||||
int port = u.getPort();
|
||||
String solrpath = u.getPath();
|
||||
String p = "http://" + host + ":" + port + solrpath;
|
||||
Log.logInfo("RemoteSolrConnector", "connecting Solr authenticated with url:" + p);
|
||||
server = new HttpSolrServer(p, client);
|
||||
} else {
|
||||
Log.logInfo("RemoteSolrConnector", "connecting Solr with url:" + this.solrurl + name);
|
||||
server = new HttpSolrServer(this.solrurl + name);
|
||||
}
|
||||
server.setAllowCompression(true);
|
||||
server.setConnectionTimeout(60000);
|
||||
server.setMaxRetries(1); // Solr-Doc: No more than 1 recommended (depreciated)
|
||||
server.setSoTimeout(60000);
|
||||
return server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (this.client != null) this.client.getConnectionManager().shutdown();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue