org.apache.solr.client.solrj.embedded.EmbeddedSolrServer Maven / Gradle / Ivy
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.client.solrj.embedded;
import java.io.IOException;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
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.core.CoreContainer;
import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.core.SolrCore;
import org.apache.solr.request.BinaryResponseWriter;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrQueryResponse;
import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.servlet.SolrRequestParsers;
/**
* SolrServer that connects directly to SolrCore
*
* TODO -- this implementation sends the response to XML and then parses it.
* It *should* be able to convert the response directly into a named list.
*
* @version $Id: EmbeddedSolrServer.java 718395 2008-11-17 21:44:01Z ryan $
* @since solr 1.3
*/
public class EmbeddedSolrServer extends SolrServer
{
protected final CoreContainer coreContainer;
protected final String coreName;
private final SolrRequestParsers _parser;
/**
* Use the other constructor using a CoreContainer and a name.
* @param core
* @deprecated
*/
@Deprecated
public EmbeddedSolrServer( SolrCore core )
{
if ( core == null ) {
throw new NullPointerException("SolrCore instance required");
}
CoreDescriptor dcore = core.getCoreDescriptor();
if (dcore == null)
throw new NullPointerException("CoreDescriptor required");
CoreContainer cores = dcore.getCoreContainer();
if (cores == null)
throw new NullPointerException("CoreContainer required");
coreName = dcore.getName();
coreContainer = cores;
_parser = new SolrRequestParsers( null );
}
/**
* Creates a SolrServer.
* @param coreContainer the core container
* @param coreName the core name
*/
public EmbeddedSolrServer( CoreContainer coreContainer, String coreName )
{
if ( coreContainer == null ) {
throw new NullPointerException("CoreContainer instance required");
}
this.coreContainer = coreContainer;
this.coreName = coreName == null? "" : coreName;
_parser = new SolrRequestParsers( null );
}
@Override
public NamedList