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

Version:
$Id: SolrCore.java 691704 2008-09-03 18:09:56Z gsingers $

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.solr.core.SolrInfoMBean
SolrInfoMBean.Category
 
Field Summary
static Logger log
           
static String version
           
 
Constructor Summary
SolrCore(String dataDir, IndexSchema schema)
           
SolrCore(String name, String dataDir, SolrConfig config, IndexSchema schema, CoreDescriptor cd)
          Creates a new core and register it in the list of cores.
 
Method Summary
 void addCloseHook(CloseHook hook)
          Add a close callback hook
 void close()
          Close all resources allocated by the core...
 void closeSearcher()
           
 SolrEventListener createEventListener(String className)
           
 SolrRequestHandler createRequestHandler(String className)
           
 void execute(SolrQueryRequest req, SolrQueryResponse rsp)
          Deprecated. Use execute(SolrRequestHandler, SolrQueryRequest, SolrQueryResponse) instead.
 void execute(SolrRequestHandler handler, SolrQueryRequest req, SolrQueryResponse rsp)
           
protected  void finalize()
           
 SolrInfoMBean.Category getCategory()
          Purpose of this Class
 String getConfigFile()
          Deprecated. Use getConfigResource() instead.
 String getConfigResource()
          Gets the configuration resource name used by this core instance.
 CoreDescriptor getCoreDescriptor()
           
 String getDataDir()
           
 String getDescription()
          Simple one or two line description
 URL[] getDocs()
          Documentation URL list.
 SolrHighlighter getHighlighter()
          Get the SolrHighlighter
 String getIndexDir()
           
 Map<String,SolrInfoMBean> getInfoRegistry()
           
 String getLogId()
           
 String getName()
          Simple common usage name, e.g.
 RefCounted<SolrIndexSearcher> getNewestSearcher(boolean openNew)
          Return the newest RefCounted<SolrIndexSearcher> with the reference count incremented.
 int getOpenCount()
          Current core usage count.
 SolrQueryRequest getPingQueryRequest()
          Deprecated. use PingRequestHandler instead
 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.
 SolrRequestHandler getRequestHandler(String handlerName)
          Get the request handler registered to a given name.
 Map<String,SolrRequestHandler> getRequestHandlers()
          Returns an unmodifieable Map containing the registered handlers
 SolrResourceLoader getResourceLoader()
          The SolrResourceLoader used to load all resources for this core.
 IndexSchema getSchema()
          Gets the schema object used by this core instance.
 String getSchemaFile()
          Deprecated. Use getSchemaResource() instead.
 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)
          Get a SolrIndexSearcher or start the process of creating a new one.
 SolrConfig getSolrConfig()
          Gets the configuration object used by this core instance.
static SolrCore getSolrCore()
          Deprecated. Use CoreContainer.getCore(String) instead.
 String getSource()
          CVS Source, SVN Source, etc
 String getSourceId()
          CVS Id, SVN Id, etc
 long getStartTime()
           
 org.apache.solr.common.util.NamedList getStatistics()
          Any statistics this instance would like to be publicly available via the Solr Administration interface.
 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.
 boolean isClosed()
          Whether this core is closed.
static void log(Throwable e)
           
 SolrIndexSearcher newSearcher(String name)
           
 SolrIndexSearcher newSearcher(String name, boolean readOnly)
           
 List<SolrEventListener> parseListener(String path)
           
 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.
 void registerResponseWriter(String name, QueryResponseWriter responseWriter)
          NOTE: this function is not thread safe.
 void setName(String v)
           
protected  void setResponseHeaderValues(SolrRequestHandler handler, SolrQueryRequest req, SolrQueryResponse rsp)
           
 
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

log

public static Logger log
Constructor Detail

SolrCore

public SolrCore(String dataDir,
                IndexSchema schema)
         throws ParserConfigurationException,
                IOException,
                SAXException
Parameters:
dataDir -
schema -
Throws:
SAXException
IOException
ParserConfigurationException
Since:
solr 1.0

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
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

getConfigFile

@Deprecated
public String getConfigFile()
Deprecated. Use getConfigResource() instead.

Gets the configuration resource name used by this core instance.


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

getSchemaFile

@Deprecated
public String getSchemaFile()
Deprecated. Use getSchemaResource() instead.

Gets the schema resource name used by this core instance.


getSchema

public IndexSchema getSchema()
Gets the schema object used by this core instance.


getDataDir

public String getDataDir()

getIndexDir

public String getIndexDir()

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:
the Info Registry map which contains SolrInfoMBean objects keyed by name
Since:
solr 1.3

parseListener

public List<SolrEventListener> parseListener(String path)

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 void 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

newSearcher

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

newSearcher

public SolrIndexSearcher newSearcher(String name,
                                     boolean readOnly)
                              throws IOException
Throws:
IOException

createEventListener

public SolrEventListener createEventListener(String className)

createRequestHandler

public SolrRequestHandler createRequestHandler(String className)

getSolrCore

@Deprecated
public static SolrCore getSolrCore()
Deprecated. Use CoreContainer.getCore(String) instead.

Returns:
the last core initialized. If you are using multiple cores, this is not a function to use.

getUpdateProcessingChain

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

close

public void close()
Close all resources allocated by the core...

This should always be called when the core is obtained through CoreContainer.getCore(java.lang.String) or CoreContainer.getAdminCore()

The actual close is performed if the core usage count is 1. (A core is created with a usage count of 1). If usage count is > 1, the usage count is decreased by 1. If usage count is < 0, this is an error and a runtime exception is thrown.


getOpenCount

public int getOpenCount()
Current core usage count.


isClosed

public boolean isClosed()
Whether this core is closed.


finalize

protected void finalize()
Overrides:
finalize in class Object

addCloseHook

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


getPingQueryRequest

@Deprecated
public SolrQueryRequest getPingQueryRequest()
Deprecated. use PingRequestHandler instead

Returns a Request object based on the admin/pingQuery section of the Solr config file.


getRequestHandler

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


getRequestHandlers

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


getHighlighter

public SolrHighlighter getHighlighter()
Get the SolrHighlighter


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 initalized before getting registered. Registered handlers can immediatly 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.


getNewestSearcher

public RefCounted<SolrIndexSearcher> getNewestSearcher(boolean openNew)
Return the newest 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.


getSearcher

public RefCounted<SolrIndexSearcher> getSearcher(boolean forceNew,
                                                 boolean returnSearcher,
                                                 Future[] waitSearcher)
                                          throws IOException
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.
Throws:
IOException

closeSearcher

public void closeSearcher()

execute

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

execute

@Deprecated
public void execute(SolrQueryRequest req,
                               SolrQueryResponse rsp)
Deprecated. Use execute(SolrRequestHandler, SolrQueryRequest, SolrQueryResponse) instead.


setResponseHeaderValues

protected void setResponseHeaderValues(SolrRequestHandler handler,
                                       SolrQueryRequest req,
                                       SolrQueryResponse rsp)

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)

getValueSourceParser

public ValueSourceParser getValueSourceParser(String parserName)

getCoreDescriptor

public CoreDescriptor getCoreDescriptor()

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

getSourceId

public String getSourceId()
Description copied from interface: SolrInfoMBean
CVS Id, SVN Id, etc

Specified by:
getSourceId 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 org.apache.solr.common.util.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


Copyright © 2008 Apache Software Foundation. All Rights Reserved.