org.apache.solr.core
Class SolrCore

java.lang.Object
  extended by org.apache.solr.core.SolrCore
All Implemented Interfaces:
SolrInfoMBean

public final class SolrCore
extends Object
implements SolrInfoMBean


Nested Class Summary
 class SolrCore.LazyQueryResponseWriterWrapper
           
 
Nested classes/interfaces inherited from interface org.apache.solr.core.SolrInfoMBean
SolrInfoMBean.Category
 
Field Summary
static Map<String,QueryResponseWriter> DEFAULT_RESPONSE_WRITERS
           
static org.slf4j.Logger log
           
static AtomicLong numCloses
           
static AtomicLong numOpens
           
static Map<SolrCore,Exception> openHandles
           
static boolean VERBOSE
           
static String version
           
 
Constructor Summary
SolrCore(String name, CoreDescriptor cd)
          Creates a new core that is to be loaded lazily.
SolrCore(String name, String dataDir, SolrConfig config, IndexSchema schema, CoreDescriptor cd)
          Creates a new core and register it in the list of cores.
SolrCore(String name, String dataDir, SolrConfig config, IndexSchema schema, CoreDescriptor cd, UpdateHandler updateHandler, IndexDeletionPolicyWrapper delPolicy, SolrCore prev)
          Creates a new core and register it in the list of cores.
 
Method Summary
 void addCloseHook(CloseHook hook)
          Add a close callback hook
 void addTransformerFactory(String name, TransformerFactory factory)
           
 void close()
          Close all resources allocated by the core if it is no longer in use...
 void closeSearcher()
           
 SolrEventListener createEventListener(String className)
           
<T> T
createInitInstance(PluginInfo info, Class<T> cast, String msg, String defClassName)
           
 SolrRequestHandler createRequestHandler(String className)
           
 void execute(SolrRequestHandler handler, SolrQueryRequest req, SolrQueryResponse rsp)
           
protected  void finalize()
           
 SolrInfoMBean.Category getCategory()
          Purpose of this Class
 Codec getCodec()
           
 String getConfigResource()
          Gets the configuration resource name used by this core instance.
 CoreDescriptor getCoreDescriptor()
           
 String getDataDir()
           
 IndexDeletionPolicyWrapper getDeletionPolicy()
           
 String getDescription()
          Simple one or two line description
 DirectoryFactory getDirectoryFactory()
           
 URL[] getDocs()
          Documentation URL list.
 String getIndexDir()
           
 IndexReaderFactory getIndexReaderFactory()
           
 Map<String,SolrInfoMBean> getInfoRegistry()
          Returns a Map of name vs SolrInfoMBean objects.
 IndexSchema getLatestSchema()
           
 String getLogId()
           
 String getName()
          Simple common usage name, e.g.
 RefCounted<SolrIndexSearcher> getNewestSearcher(boolean openNew)
          Return the newest normal RefCounted<SolrIndexSearcher> with the reference count incremented.
 String getNewIndexDir()
          Returns the indexdir as given in index.properties.
 int getOpenCount()
          Current core usage count.
 QParserPlugin getQueryPlugin(String parserName)
           
 QueryResponseWriter getQueryResponseWriter(SolrQueryRequest request)
          Returns the appropriate writer for a request.
 QueryResponseWriter getQueryResponseWriter(String writerName)
          Finds a writer by name, or returns the default writer if not found.
 RefCounted<SolrIndexSearcher> getRealtimeSearcher()
          Gets the latest real-time searcher w/o forcing open a new searcher if one already exists.
 RefCounted<SolrIndexSearcher> getRegisteredSearcher()
          Returns the current registered searcher with its reference count incremented, or null if none are registered.
 SolrRequestHandler getRequestHandler(String handlerName)
          Get the request handler registered to a given name.
 Map<String,SolrRequestHandler> getRequestHandlers()
          Returns an unmodifiable Map containing the registered handlers
<T extends SolrRequestHandler>
Map<String,T>
getRequestHandlers(Class<T> clazz)
          Returns an unmodifiable Map containing the registered handlers of the specified type.
 SolrResourceLoader getResourceLoader()
          The SolrResourceLoader used to load all resources for this core.
 String getSchemaResource()
          Gets the schema resource name used by this core instance.
 SearchComponent getSearchComponent(String name)
           
 Map<String,SearchComponent> getSearchComponents()
          Accessor for all the Search Components
 RefCounted<SolrIndexSearcher> getSearcher()
          Return a registered RefCounted<SolrIndexSearcher> with the reference count incremented.
 RefCounted<SolrIndexSearcher> getSearcher(boolean forceNew, boolean returnSearcher, Future[] waitSearcher)
           
 RefCounted<SolrIndexSearcher> getSearcher(boolean forceNew, boolean returnSearcher, Future[] waitSearcher, boolean updateHandlerReopens)
          Get a SolrIndexSearcher or start the process of creating a new one.
 SolrConfig getSolrConfig()
          Gets the configuration object used by this core instance.
 SolrCoreState getSolrCoreState()
           
 String getSource()
          CVS Source, SVN Source, etc
 long getStartTime()
           
 NamedList getStatistics()
          Any statistics this instance would like to be publicly available via the Solr Administration interface.
 TransformerFactory getTransformerFactory(String name)
           
 UpdateHandler getUpdateHandler()
          RequestHandlers need access to the updateHandler so they can all talk to the same RAM indexer.
 UpdateRequestProcessorChain getUpdateProcessingChain(String name)
           
 ValueSourceParser getValueSourceParser(String parserName)
           
 String getVersion()
          Simple common usage version, e.g.
<T> List<T>
initPlugins(List<PluginInfo> pluginInfos, Class<T> type, String defClassName)
          For a given List of PluginInfo return the instances as a List
<T> T
initPlugins(List<PluginInfo> pluginInfos, Map<String,T> registry, Class<T> type, String defClassName)
           
<T> T
initPlugins(Map<String,T> registry, Class<T> type)
           
<T> T
initPlugins(Map<String,T> registry, Class<T> type, String defClassName)
           
 boolean isClosed()
          Whether this core is closed.
 boolean isReloaded()
           
static void log(Throwable e)
           
 SolrIndexSearcher newSearcher(String name)
           
 void open()
          expert: increments the core reference count
 RefCounted<SolrIndexSearcher> openNewSearcher(boolean updateHandlerReopens, boolean realtime)
          Opens a new searcher and returns a RefCounted<SolrIndexSearcher> with it's reference incremented.
static void postDecorateResponse(SolrRequestHandler handler, SolrQueryRequest req, SolrQueryResponse rsp)
          Put status, QTime, and possibly request handler and params, in the response header
static void preDecorateResponse(SolrQueryRequest req, SolrQueryResponse rsp)
           
 void registerFirstSearcherListener(SolrEventListener listener)
          NOTE: this function is not thread safe.
 void registerNewSearcherListener(SolrEventListener listener)
          NOTE: this function is not thread safe.
 SolrRequestHandler registerRequestHandler(String handlerName, SolrRequestHandler handler)
          Registers a handler at the specified location.
 QueryResponseWriter registerResponseWriter(String name, QueryResponseWriter responseWriter)
          NOTE: this function is not thread safe.
 SolrCore reload(SolrCore prev)
           
 SolrCore reload(SolrResourceLoader resourceLoader, SolrCore prev)
           
 void setLatestSchema(IndexSchema replacementSchema)
          Sets the latest schema snapshot to be used by this core instance.
 void setName(String v)
           
static void verbose(Object... args)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

version

public static final String version
See Also:
Constant Field Values

numOpens

public static final AtomicLong numOpens

numCloses

public static final AtomicLong numCloses

openHandles

public static Map<SolrCore,Exception> openHandles

log

public static org.slf4j.Logger log

VERBOSE

public static boolean VERBOSE
NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
Debugging aid only. No non-test code should be released with uncommented verbose() calls.

DEFAULT_RESPONSE_WRITERS

public static final Map<String,QueryResponseWriter> DEFAULT_RESPONSE_WRITERS
Constructor Detail

SolrCore

public SolrCore(String name,
                String dataDir,
                SolrConfig config,
                IndexSchema schema,
                CoreDescriptor cd)
Creates a new core and register it in the list of cores. If a core with the same name already exists, it will be stopped and replaced by this one.

Parameters:
dataDir - the index directory
config - a solr config instance
schema - a solr schema instance
Since:
solr 1.3

SolrCore

public SolrCore(String name,
                CoreDescriptor cd)
Creates a new core that is to be loaded lazily. i.e. lazyLoad="true" in solr.xml

Since:
solr 4.1

SolrCore

public SolrCore(String name,
                String dataDir,
                SolrConfig config,
                IndexSchema schema,
                CoreDescriptor cd,
                UpdateHandler updateHandler,
                IndexDeletionPolicyWrapper delPolicy,
                SolrCore prev)
Creates a new core and register it in the list of cores. If a core with the same name already exists, it will be stopped and replaced by this one.

Parameters:
dataDir - the index directory
config - a solr config instance
schema - a solr schema instance
Since:
solr 1.3
Method Detail

getStartTime

public long getStartTime()

getResourceLoader

public SolrResourceLoader getResourceLoader()
The SolrResourceLoader used to load all resources for this core.

Since:
solr 1.3

getConfigResource

public String getConfigResource()
Gets the configuration resource name used by this core instance.

Since:
solr 1.3

getSolrConfig

public SolrConfig getSolrConfig()
Gets the configuration object used by this core instance.


getSchemaResource

public String getSchemaResource()
Gets the schema resource name used by this core instance.

Since:
solr 1.3

getLatestSchema

public IndexSchema getLatestSchema()
Returns:
the latest snapshot of the schema used by this core instance.

setLatestSchema

public void setLatestSchema(IndexSchema replacementSchema)
Sets the latest schema snapshot to be used by this core instance.


getDataDir

public String getDataDir()

getIndexDir

public String getIndexDir()

getNewIndexDir

public String getNewIndexDir()
Returns the indexdir as given in index.properties. If index.properties exists in dataDir and there is a property index available and it points to a valid directory in dataDir that is returned Else dataDir/index is returned. Only called for creating new indexSearchers and indexwriters. Use the getIndexDir() method to know the active index directory

Returns:
the indexdir as given in index.properties

getDirectoryFactory

public DirectoryFactory getDirectoryFactory()

getIndexReaderFactory

public IndexReaderFactory getIndexReaderFactory()

getName

public String getName()
Description copied from interface: SolrInfoMBean
Simple common usage name, e.g. BasicQueryHandler, or fully qualified clas name.

Specified by:
getName in interface SolrInfoMBean

setName

public void setName(String v)

getLogId

public String getLogId()

getInfoRegistry

public Map<String,SolrInfoMBean> getInfoRegistry()
Returns a Map of name vs SolrInfoMBean objects. The returned map is an instance of a ConcurrentHashMap and therefore no synchronization is needed for putting, removing or iterating over it.

Returns:
the Info Registry map which contains SolrInfoMBean objects keyed by name
Since:
solr 1.3

registerFirstSearcherListener

public void registerFirstSearcherListener(SolrEventListener listener)
NOTE: this function is not thread safe. However, it is safe to call within the inform( SolrCore core ) function for SolrCoreAware classes. Outside inform, this could potentially throw a ConcurrentModificationException

See Also:
SolrCoreAware

registerNewSearcherListener

public void registerNewSearcherListener(SolrEventListener listener)
NOTE: this function is not thread safe. However, it is safe to call within the inform( SolrCore core ) function for SolrCoreAware classes. Outside inform, this could potentially throw a ConcurrentModificationException

See Also:
SolrCoreAware

registerResponseWriter

public QueryResponseWriter registerResponseWriter(String name,
                                                  QueryResponseWriter responseWriter)
NOTE: this function is not thread safe. However, it is safe to call within the inform( SolrCore core ) function for SolrCoreAware classes. Outside inform, this could potentially throw a ConcurrentModificationException

See Also:
SolrCoreAware

reload

public SolrCore reload(SolrCore prev)
                throws IOException,
                       ParserConfigurationException,
                       SAXException
Throws:
IOException
ParserConfigurationException
SAXException

reload

public SolrCore reload(SolrResourceLoader resourceLoader,
                       SolrCore prev)
                throws IOException,
                       ParserConfigurationException,
                       SAXException
Throws:
IOException
ParserConfigurationException
SAXException

newSearcher

public SolrIndexSearcher newSearcher(String name)
                              throws IOException
Throws:
IOException

createInitInstance

public <T> T createInitInstance(PluginInfo info,
                                Class<T> cast,
                                String msg,
                                String defClassName)

createEventListener

public SolrEventListener createEventListener(String className)

createRequestHandler

public SolrRequestHandler createRequestHandler(String className)

getSolrCoreState

public SolrCoreState getSolrCoreState()

getUpdateProcessingChain

public UpdateRequestProcessorChain getUpdateProcessingChain(String name)
Returns:
an update processor registered to the given name. Throw an exception if this chain is undefined

open

public void open()
expert: increments the core reference count


close

public void close()
Close all resources allocated by the core if it is no longer in use...

The behavior of this method is determined by the result of decrementing the core's reference count (A core is created with a reference count of 1)...

See Also:
isClosed()

getOpenCount

public int getOpenCount()
Current core usage count.


isClosed

public boolean isClosed()
Whether this core is closed.


finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

addCloseHook

public void addCloseHook(CloseHook hook)
Add a close callback hook


verbose

public static void verbose(Object... args)

getRequestHandler

public SolrRequestHandler getRequestHandler(String handlerName)
Get the request handler registered to a given name. This function is thread safe.


getRequestHandlers

public <T extends SolrRequestHandler> Map<String,T> getRequestHandlers(Class<T> clazz)
Returns an unmodifiable Map containing the registered handlers of the specified type.


getRequestHandlers

public Map<String,SolrRequestHandler> getRequestHandlers()
Returns an unmodifiable Map containing the registered handlers


registerRequestHandler

public SolrRequestHandler registerRequestHandler(String handlerName,
                                                 SolrRequestHandler handler)
Registers a handler at the specified location. If one exists there, it will be replaced. To remove a handler, register null at its path Once registered the handler can be accessed through:
   http://${host}:${port}/${context}/${handlerName}
 or:  
   http://${host}:${port}/${context}/select?qt=${handlerName}
 
Handlers must be initialized before getting registered. Registered handlers can immediately accept requests. This call is thread safe.

Returns:
the previous SolrRequestHandler registered to this name null if none.

getSearchComponent

public SearchComponent getSearchComponent(String name)
Returns:
a Search Component registered to a given name. Throw an exception if the component is undefined

getSearchComponents

public Map<String,SearchComponent> getSearchComponents()
Accessor for all the Search Components

Returns:
An unmodifiable Map of Search Components

getUpdateHandler

public UpdateHandler getUpdateHandler()
RequestHandlers need access to the updateHandler so they can all talk to the same RAM indexer.


getSearcher

public RefCounted<SolrIndexSearcher> getSearcher()
Return a registered RefCounted<SolrIndexSearcher> with the reference count incremented. It must be decremented when no longer needed. This method should not be called from SolrCoreAware.inform() since it can result in a deadlock if useColdSearcher==false. If handling a normal request, the searcher should be obtained from SolrQueryRequest.getSearcher() instead.


getRegisteredSearcher

public RefCounted<SolrIndexSearcher> getRegisteredSearcher()
Returns the current registered searcher with its reference count incremented, or null if none are registered.


getNewestSearcher

public RefCounted<SolrIndexSearcher> getNewestSearcher(boolean openNew)
Return the newest normal RefCounted<SolrIndexSearcher> with the reference count incremented. It must be decremented when no longer needed. If no searcher is currently open, then if openNew==true a new searcher will be opened, or null is returned if openNew==false.


getRealtimeSearcher

public RefCounted<SolrIndexSearcher> getRealtimeSearcher()
Gets the latest real-time searcher w/o forcing open a new searcher if one already exists. The reference count will be incremented.


getSearcher

public RefCounted<SolrIndexSearcher> getSearcher(boolean forceNew,
                                                 boolean returnSearcher,
                                                 Future[] waitSearcher)

openNewSearcher

public RefCounted<SolrIndexSearcher> openNewSearcher(boolean updateHandlerReopens,
                                                     boolean realtime)
Opens a new searcher and returns a RefCounted<SolrIndexSearcher> with it's reference incremented. "realtime" means that we need to open quickly for a realtime view of the index, hence don't do any autowarming and add to the _realtimeSearchers queue rather than the _searchers queue (so it won't be used for autowarming by a future normal searcher). A "realtime" searcher will currently never become "registered" (since it currently lacks caching). realtimeSearcher is updated to the latest opened searcher, regardless of the value of "realtime". This method acquires openSearcherLock - do not call with searckLock held!


getSearcher

public RefCounted<SolrIndexSearcher> getSearcher(boolean forceNew,
                                                 boolean returnSearcher,
                                                 Future[] waitSearcher,
                                                 boolean updateHandlerReopens)
Get a SolrIndexSearcher or start the process of creating a new one.

The registered searcher is the default searcher used to service queries. A searcher will normally be registered after all of the warming and event handlers (newSearcher or firstSearcher events) have run. In the case where there is no registered searcher, the newly created searcher will be registered before running the event handlers (a slow searcher is better than no searcher).

These searchers contain read-only IndexReaders. To access a non read-only IndexReader, see newSearcher(String name, boolean readOnly).

If forceNew==true then A new searcher will be opened and registered regardless of whether there is already a registered searcher or other searchers in the process of being created.

If forceNew==false then:

If returnSearcher==true then a RefCounted<SolrIndexSearcher> will be returned with the reference count incremented. It must be decremented when no longer needed.

If waitSearcher!=null and a new SolrIndexSearcher was created, then it is filled in with a Future that will return after the searcher is registered. The Future may be set to null in which case the SolrIndexSearcher created has already been registered at the time this method returned.

Parameters:
forceNew - if true, force the open of a new index searcher regardless if there is already one open.
returnSearcher - if true, returns a SolrIndexSearcher holder with the refcount already incremented.
waitSearcher - if non-null, will be filled in with a Future that will return after the new searcher is registered.
updateHandlerReopens - if true, the UpdateHandler will be used when reopening a SolrIndexSearcher.

isReloaded

public boolean isReloaded()

closeSearcher

public void closeSearcher()

execute

public void execute(SolrRequestHandler handler,
                    SolrQueryRequest req,
                    SolrQueryResponse rsp)

preDecorateResponse

public static void preDecorateResponse(SolrQueryRequest req,
                                       SolrQueryResponse rsp)

postDecorateResponse

public static void postDecorateResponse(SolrRequestHandler handler,
                                        SolrQueryRequest req,
                                        SolrQueryResponse rsp)
Put status, QTime, and possibly request handler and params, in the response header


log

public static final void log(Throwable e)

getQueryResponseWriter

public final QueryResponseWriter getQueryResponseWriter(String writerName)
Finds a writer by name, or returns the default writer if not found.


getQueryResponseWriter

public final QueryResponseWriter getQueryResponseWriter(SolrQueryRequest request)
Returns the appropriate writer for a request. If the request specifies a writer via the 'wt' parameter, attempts to find that one; otherwise return the default writer.


getQueryPlugin

public QParserPlugin getQueryPlugin(String parserName)

getTransformerFactory

public TransformerFactory getTransformerFactory(String name)

addTransformerFactory

public void addTransformerFactory(String name,
                                  TransformerFactory factory)

initPlugins

public <T> T initPlugins(Map<String,T> registry,
                         Class<T> type,
                         String defClassName)
Parameters:
registry - The map to which the instance should be added to. The key is the name attribute
type - the class or interface that the instance should extend or implement.
defClassName - If PluginInfo does not have a classname, use this as the classname
Returns:
The default instance . The one with (default=true)

initPlugins

public <T> T initPlugins(List<PluginInfo> pluginInfos,
                         Map<String,T> registry,
                         Class<T> type,
                         String defClassName)

initPlugins

public <T> List<T> initPlugins(List<PluginInfo> pluginInfos,
                               Class<T> type,
                               String defClassName)
For a given List of PluginInfo return the instances as a List

Parameters:
defClassName - The default classname if PluginInfo#className == null
Returns:
The instances initialized

initPlugins

public <T> T initPlugins(Map<String,T> registry,
                         Class<T> type)
Parameters:
registry - The map to which the instance should be added to. The key is the name attribute
type - The type of the Plugin. These should be standard ones registered by type.getName() in SolrConfig
Returns:
The default if any

getValueSourceParser

public ValueSourceParser getValueSourceParser(String parserName)

getCoreDescriptor

public CoreDescriptor getCoreDescriptor()

getDeletionPolicy

public IndexDeletionPolicyWrapper getDeletionPolicy()

getVersion

public String getVersion()
Description copied from interface: SolrInfoMBean
Simple common usage version, e.g. 2.0

Specified by:
getVersion in interface SolrInfoMBean

getDescription

public String getDescription()
Description copied from interface: SolrInfoMBean
Simple one or two line description

Specified by:
getDescription in interface SolrInfoMBean

getCategory

public SolrInfoMBean.Category getCategory()
Description copied from interface: SolrInfoMBean
Purpose of this Class

Specified by:
getCategory in interface SolrInfoMBean

getSource

public String getSource()
Description copied from interface: SolrInfoMBean
CVS Source, SVN Source, etc

Specified by:
getSource in interface SolrInfoMBean

getDocs

public URL[] getDocs()
Description copied from interface: SolrInfoMBean
Documentation URL list.

Suggested documentation URLs: Homepage for sponsoring project, FAQ on class usage, Design doc for class, Wiki, bug reporting URL, etc...

Specified by:
getDocs in interface SolrInfoMBean

getStatistics

public NamedList getStatistics()
Description copied from interface: SolrInfoMBean
Any statistics this instance would like to be publicly available via the Solr Administration interface.

Any Object type may be stored in the list, but only the toString() representation will be used.

Specified by:
getStatistics in interface SolrInfoMBean

getCodec

public Codec getCodec()


Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.