SOLR-1930: remove SolrCore deprecations

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1054149 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2010-12-31 17:50:45 +00:00
parent deb1e81db0
commit 9f72957010
9 changed files with 46 additions and 107 deletions

View File

@ -38,6 +38,7 @@ import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.core.SolrCore;
import org.apache.solr.handler.clustering.SearchClusteringEngine;
import org.apache.solr.handler.component.HighlightComponent;
import org.apache.solr.highlight.SolrHighlighter;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
@ -175,7 +176,7 @@ public class CarrotClusteringEngine extends SearchClusteringEngine {
SolrQueryRequest req = null;
String[] snippetFieldAry = null;
if (produceSummary == true) {
highlighter = core.getHighlighter();
highlighter = HighlightComponent.getHighlighter(core);
if (highlighter != null){
Map args = new HashMap();
snippetFieldAry = new String[]{snippetField};

View File

@ -105,12 +105,6 @@ public final class SolrCore implements SolrInfoMBean {
public long getStartTime() { return startTime; }
/**
* @deprecated Use {@link CoreContainer#getCore(String)} instead.
*/
@Deprecated
private static SolrCore instance;
static int boolean_query_max_clause_count = Integer.MIN_VALUE;
// only change the BooleanQuery maxClauseCount once for ALL cores...
void booleanQueryMaxClauseCount() {
@ -140,15 +134,7 @@ public final class SolrCore implements SolrInfoMBean {
public String getConfigResource() {
return solrConfig.getResourceName();
}
/**
* Gets the configuration resource name used by this core instance.
* @deprecated Use {@link #getConfigResource()} instead.
*/
@Deprecated
public String getConfigFile() {
return solrConfig.getResourceName();
}
/**
* Gets the configuration object used by this core instance.
*/
@ -164,15 +150,6 @@ public final class SolrCore implements SolrInfoMBean {
return schema.getResourceName();
}
/**
* Gets the schema resource name used by this core instance.
* @deprecated Use {@link #getSchemaResource()} instead.
*/
@Deprecated
public String getSchemaFile() {
return schema.getResourceName();
}
/**
* Gets the schema object used by this core instance.
*/
@ -463,30 +440,6 @@ public final class SolrCore implements SolrInfoMBean {
return createInstance(className, UpdateHandler.class, "Update Handler");
}
/**
* @return the last core initialized. If you are using multiple cores,
* this is not a function to use.
*
* @deprecated Use {@link CoreContainer#getCore(String)} instead.
*/
@Deprecated
public static SolrCore getSolrCore() {
synchronized( SolrCore.class ) {
if( instance == null ) {
try {
// sets 'instance' to the latest solr core
CoreContainer.Initializer init = new CoreContainer.Initializer();
instance = init.initialize().getCore("");
} catch(Exception xany) {
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,
"error creating core", xany );
}
}
}
return instance;
}
/**
*
* @param dataDir
@ -555,7 +508,7 @@ public final class SolrCore implements SolrInfoMBean {
initQParsers();
initValueSourceParsers();
this.searchComponents = loadSearchComponents();
this.searchComponents = Collections.unmodifiableMap(loadSearchComponents());
// Processors initialized before the handlers
updateProcessorChains = loadUpdateProcessorChains();
@ -592,7 +545,6 @@ public final class SolrCore implements SolrInfoMBean {
// Finally tell anyone who wants to know
resourceLoader.inform( resourceLoader );
resourceLoader.inform( this ); // last call before the latch is released.
instance = this; // set singleton for backwards compatibility
} catch (IOException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, null, e, false);
} finally {
@ -768,16 +720,7 @@ public final class SolrCore implements SolrInfoMBean {
closeHooks.add( hook );
}
/**
* Returns a Request object based on the admin/pingQuery section
* of the Solr config file.
*
* @deprecated use {@link org.apache.solr.handler.PingRequestHandler} instead
*/
@Deprecated
public SolrQueryRequest getPingQueryRequest() {
return solrConfig.getPingQueryRequest(this);
}
////////////////////////////////////////////////////////////////////////////////
// Request Handler
////////////////////////////////////////////////////////////////////////////////
@ -805,14 +748,6 @@ public final class SolrCore implements SolrInfoMBean {
return reqHandlers.getRequestHandlers();
}
/**
* Get the SolrHighlighter
*/
@Deprecated
public SolrHighlighter getHighlighter() {
HighlightComponent hl = (HighlightComponent) searchComponents.get(HighlightComponent.COMPONENT_NAME);
return hl==null? null: hl.getHighlighter();
}
/**
* Registers a handler at the specified location. If one exists there, it will be replaced.
@ -892,7 +827,7 @@ public final class SolrCore implements SolrInfoMBean {
* @return An unmodifiable Map of Search Components
*/
public Map<String, SearchComponent> getSearchComponents() {
return Collections.unmodifiableMap(searchComponents);
return searchComponents;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -50,6 +50,10 @@ public class HighlightComponent extends SearchComponent implements PluginInfoIni
private PluginInfo info = PluginInfo.EMPTY_INFO;
private SolrHighlighter highlighter;
public static SolrHighlighter getHighlighter(SolrCore core) {
HighlightComponent hl = (HighlightComponent) core.getSearchComponents().get(HighlightComponent.COMPONENT_NAME);
return hl==null ? null: hl.getHighlighter();
}
public void init(PluginInfo info) {
this.info = info;

View File

@ -527,8 +527,7 @@ public class QueryComponent extends SearchComponent
SolrQueryResponse rsp = rb.rsp;
//pre-fetch returned documents
if (!req.getParams().getBool(ShardParams.IS_SHARD,false) && rb.getResults().docList != null && rb.getResults().docList.size()<=50) {
// TODO: this may depend on the highlighter component (or other components?)
SolrPluginUtils.optimizePreFetchDocs(rb.getResults().docList, rb.getQuery(), req, rsp);
SolrPluginUtils.optimizePreFetchDocs(rb, rb.getResults().docList, rb.getQuery(), req, rsp);
}
}

View File

@ -33,6 +33,7 @@ import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.common.util.StrUtils;
import org.apache.solr.core.SolrCore;
import org.apache.solr.handler.component.HighlightComponent;
import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.highlight.SolrHighlighter;
import org.apache.solr.request.SolrQueryRequest;
@ -168,7 +169,8 @@ public class SolrPluginUtils {
*
* If lazy field loading is disabled, this method does nothing.
*/
public static void optimizePreFetchDocs(DocList docs,
public static void optimizePreFetchDocs(ResponseBuilder rb,
DocList docs,
Query query,
SolrQueryRequest req,
SolrQueryResponse res) throws IOException {
@ -178,28 +180,34 @@ public class SolrPluginUtils {
return;
}
Set<String> fieldFilter = null;
Set<String> returnFields = res.getReturnFields();
Set<String> fieldFilter = returnFields;
if(returnFields != null) {
// copy return fields list
fieldFilter = new HashSet<String>(returnFields);
// add highlight fields
SolrHighlighter highligher = req.getCore().getHighlighter();
if(highligher.isHighlightingEnabled(req.getParams())) {
for(String field: highligher.getHighlightFields(query, req, null))
if (rb.doHighlights) {
// copy return fields list
fieldFilter = new HashSet<String>(returnFields);
// add highlight fields
SolrHighlighter highlighter = HighlightComponent.getHighlighter(req.getCore());
for (String field: highlighter.getHighlightFields(query, req, null))
fieldFilter.add(field);
}
// fetch unique key if one exists.
SchemaField keyField = req.getSearcher().getSchema().getUniqueKeyField();
if(null != keyField)
// fetch unique key if one exists.
SchemaField keyField = req.getSearcher().getSchema().getUniqueKeyField();
if(null != keyField)
fieldFilter.add(keyField.getName());
}
// get documents
DocIterator iter = docs.iterator();
for (int i=0; i<docs.size(); i++) {
searcher.doc(iter.nextDoc(), fieldFilter);
}
}
// get documents
DocIterator iter = docs.iterator();
for (int i=0; i<docs.size(); i++) {
searcher.doc(iter.nextDoc(), fieldFilter);
}
}

View File

@ -20,6 +20,7 @@ package org.apache.solr.highlight;
import java.util.HashMap;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.handler.component.HighlightComponent;
import org.apache.solr.util.TestHarness;
import org.junit.BeforeClass;
import org.junit.Test;
@ -33,7 +34,7 @@ public class FastVectorHighlighterTest extends SolrTestCaseJ4 {
@Test
public void testConfig(){
SolrHighlighter highlighter = h.getCore().getHighlighter();
SolrHighlighter highlighter = HighlightComponent.getHighlighter(h.getCore());
// Make sure we loaded the one fragListBuilder
SolrFragListBuilder solrFlbNull = highlighter.fragListBuilders.get( null );

View File

@ -16,6 +16,7 @@
*/
package org.apache.solr.highlight;
import org.apache.solr.handler.component.HighlightComponent;
import org.apache.solr.util.AbstractSolrTestCase;
import org.apache.solr.util.TestHarness;
@ -42,7 +43,7 @@ public class HighlighterConfigTest extends AbstractSolrTestCase {
public void testConfig()
{
SolrHighlighter highlighter = h.getCore().getHighlighter();
SolrHighlighter highlighter = HighlightComponent.getHighlighter(h.getCore());
log.info( "highlighter" );
assertTrue( highlighter instanceof DummyHighlighter );

View File

@ -21,6 +21,7 @@ import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.core.WhitespaceAnalyzer;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.handler.component.HighlightComponent;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.util.*;
import org.apache.solr.common.params.HighlightParams;
@ -62,7 +63,7 @@ public class HighlighterTest extends SolrTestCaseJ4 {
@Test
public void testConfig()
{
SolrHighlighter highlighter = h.getCore().getHighlighter();
SolrHighlighter highlighter = HighlightComponent.getHighlighter(h.getCore());
// Make sure we loaded the one formatter
SolrFormatter fmt1 = highlighter.formatters.get( null );
@ -697,7 +698,7 @@ public class HighlighterTest extends SolrTestCaseJ4 {
10, args);
SolrQueryRequest request = lrf.makeRequest("test");
SolrHighlighter highlighter = request.getCore().getHighlighter();
SolrHighlighter highlighter = HighlightComponent.getHighlighter(h.getCore());
List<String> highlightFieldNames = Arrays.asList(highlighter
.getHighlightFields(null, request, new String[] {}));
assertTrue("Expected to highlight on field \"title\"", highlightFieldNames
@ -711,7 +712,7 @@ public class HighlighterTest extends SolrTestCaseJ4 {
args.put("hl.fl", "foo_*");
lrf = h.getRequestFactory("standard", 0, 10, args);
request = lrf.makeRequest("test");
highlighter = request.getCore().getHighlighter();
highlighter = HighlightComponent.getHighlighter(h.getCore());
highlightFieldNames = Arrays.asList(highlighter.getHighlightFields(null,
request, new String[] {}));
assertEquals("Expected one field to highlight on", 1, highlightFieldNames

View File

@ -53,19 +53,8 @@ import org.apache.solr.schema.IndexSchema;
*/
public class DirectSolrConnection
{
final SolrCore core;
final SolrRequestParsers parser;
/**
* Initialize using the static singleton SolrCore.getSolrCore().
*
* @deprecated use {@link #DirectSolrConnection(SolrCore)}
*/
@Deprecated
public DirectSolrConnection()
{
this( SolrCore.getSolrCore() );
}
protected final SolrCore core;
protected final SolrRequestParsers parser;
/**
* Initialize using an explicit SolrCore