net.grcomputing.opencms.search.lucene
Class IndexManager

java.lang.Object
  |
  +--net.grcomputing.opencms.search.lucene.IndexManager

public class IndexManager
extends java.lang.Object

This class builds and maintains the Lucene index.

Author:
Matt Butcher mbutcher@grcomputing.net
See Also:
http://grcomputing.net

Field Summary
static java.lang.String INDEX_TYPE_JSP
          Defines the name of what it considers to be a jsp.
static java.lang.String INDEX_TYPE_PAGE
          Defines the name of what it considers to be a page.
static java.lang.String INDEX_TYPE_PLAIN
          Defines the name of what it considers to be a plain resource.
static java.lang.String INDEX_TYPE_XML_TEMPLATE
          Defines the name of what it considers to be an XML template.
 
Constructor Summary
IndexManager(CmsObject cmso)
          Constructs an IndexManager from a CmsObject.
IndexManager(CmsObject cmso, org.w3c.dom.Element registryEle)
          Creates an index manager with a specific registry.
IndexManager(CmsObject cmso, java.lang.String registryPath)
          Creates an index manager with a specific registry.
 
Method Summary
 void doIndex(boolean create)
          Runs an IndexWriter over the appropriate files.
protected  void processDir(java.lang.String dir, boolean traverseDir, IndexWriter writer)
          Do all the hard stuff.
protected  void processFile(java.lang.String file, IndexWriter writer)
          Convenience method for processFile(CmsFile, IndexWriter).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INDEX_TYPE_PAGE

public static java.lang.String INDEX_TYPE_PAGE
Defines the name of what it considers to be a page. The way OpenCMS was constructed, there are not constants defined for each type (since new types can be added). Search, however, needs to know a lot about every type that it is supposed to index. In the long run, I will probably make this more configurable in the future, but for now, I need something quick-n-dirty.


INDEX_TYPE_PLAIN

public static java.lang.String INDEX_TYPE_PLAIN
Defines the name of what it considers to be a plain resource.


INDEX_TYPE_JSP

public static java.lang.String INDEX_TYPE_JSP
Defines the name of what it considers to be a jsp.


INDEX_TYPE_XML_TEMPLATE

public static java.lang.String INDEX_TYPE_XML_TEMPLATE
Defines the name of what it considers to be an XML template.

Constructor Detail

IndexManager

public IndexManager(CmsObject cmso)
             throws CmsException
Constructs an IndexManager from a CmsObject. This constructor will use the default registry (usually $TOMCAT/webapps/opencms/WEB_INF/config/registry.xml). This is preferred.

Throws:
CmsException - if it can't get the registry.

IndexManager

public IndexManager(CmsObject cmso,
                    java.lang.String registryPath)
             throws CmsException
Creates an index manager with a specific registry. This constuctor will use the specified registry file instead of the default one. Registry must exist in the system's filesystem (e.g. not in VFS).

Throws:
CmsException - if it can't get the registry.

IndexManager

public IndexManager(CmsObject cmso,
                    org.w3c.dom.Element registryEle)
             throws CmsException
Creates an index manager with a specific registry. This constuctor will use DOM element instead of the default one. The DOM element is equivalent to the luceneSearch element in the registry file.

Throws:
CmsException - if it can't get the registry.
Method Detail

doIndex

public void doIndex(boolean create)
             throws CmsException,
                    java.io.IOException
Runs an IndexWriter over the appropriate files. If 'create' is true, then it will try and create the index from scratch. Otherwise it will use the existing indices.

Throws:
CmsException - if files can't be generated from CMS.
IOException - if the Lucene engine has problems.

processDir

protected void processDir(java.lang.String dir,
                          boolean traverseDir,
                          IndexWriter writer)
                   throws CmsException
Do all the hard stuff. Essentially, this is a depth-first traversal of the directories passed in from the search config. Because the tree can't be very deep, a depth-first traversal should be fairly fast. Ideally, there should be a way to specify depth on directory scanning. Maybe I'll add that later.

CmsException

processFile

protected void processFile(java.lang.String file,
                           IndexWriter writer)
                    throws CmsException,
                           java.io.IOException
Convenience method for processFile(CmsFile, IndexWriter).

CmsException
java.io.IOException


Copyright © 2003 Matt Butcher of Global Resources for Computing. Reporoduction and modification of this documents are allowed as in accordance with the GPL v2. Refer to COPYING.txt for information on acceptible use