/**
* EmbeddedSolrConnector
* Copyright 2012 by Michael Peter Christen
* First released 21.06.2012 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 .
*/
package net.yacy.search.solr;
import java.io.File;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import net.yacy.cora.services.federated.solr.AbstractSolrConnector;
import net.yacy.cora.services.federated.solr.SolrConnector;
import net.yacy.cora.services.federated.solr.SolrDoc;
import net.yacy.kelondro.logging.Log;
import net.yacy.search.index.SolrField;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrException;
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.SearchHandler;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrQueryRequestBase;
import org.apache.solr.request.SolrRequestInfo;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.servlet.SolrRequestParsers;
import org.xml.sax.SAXException;
import com.google.common.io.Files;
public class EmbeddedSolrConnector extends AbstractSolrConnector implements SolrConnector {
public static final String SELECT = "/select";
public static final String CONTEXT = "/solr";
private final static String[] confFiles = {"solrconfig.xml", "schema.xml", "stopwords.txt", "synonyms.txt", "protwords.txt", "currency.xml", "elevate.xml", "lang/"};
private final CoreContainer cores;
private final String defaultCoreName;
private final SolrCore defaultCore;
protected SolrRequestParsers adminRequestParser;
private final SearchHandler requestHandler;
public EmbeddedSolrConnector(File storagePath, File solr_config) throws IOException {
super();
// copy the solrconfig.xml to the storage path
File conf = new File(storagePath, "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()) {
Files.copy(new File(source, cfl), new File(target, cfl));
}
} else {
target = new File(conf, cf);
target.getParentFile().mkdirs();
Files.copy(source, target);
}
}
try {
this.cores = new CoreContainer(storagePath.getAbsolutePath(), new File(solr_config, "solr.xml"));
} catch (ParserConfigurationException e) {
throw new IOException(e.getMessage(), e);
} catch (SAXException e) {
throw new IOException(e.getMessage(), e);
}
this.defaultCoreName = this.cores.getDefaultCoreName();
this.defaultCore = this.cores.getCore(this.defaultCoreName); // should be "collection1"
final NamedList