com.swfit.core.search
Class BasicSearchObjectIndex

java.lang.Object
  |
  +--com.swfit.core.search.BasicSearchObjectIndex

public class BasicSearchObjectIndex
extends java.lang.Object

A BasicSearchObjectIndex is a class that instantiates the necessary resources needed to call the Lucene IndexWriter. An important point to remember, is that the Analyzer used to store the data, must be the same Analyzer used to search the data. For that reason any BasicSearchObjectIndex created will be stored in a Hashtable.

Jakarta Lucene is a high-performance, full-featured text search engine written entirely in Java. It is a technology suitable for nearly any application that requires full-text search, especially cross-platform. Jakarta Lucene is an open source project available for free download from Apache Jakarta:

     http://jakarta.apache.org/lucene/docs/index.html
 

All in all this is my effort to understand the underlying structure of Lucene. I assume that there are all sorts of smart things one can do to optimize the searching processes, but I see from the FAQs and tutorials that it is recommended to be on the safe side (better safe than clever).

Since:
SWFIT1.0
Version:
$Revision: 1.5 $ $Date: 2003/04/20 13:14:00 $
Author:
Olaf Havnes

Field Summary
static java.lang.String ANALYZER_STRING
           
static java.lang.String[] ANALYZER_STRINGS
           
static org.apache.lucene.analysis.Analyzer[] ANALYZERS
          Tools for setting an Analyzer from a parameter.
static java.lang.String BSO_CODE
          Fields for sorting BasicSearchObjects in lists.
static java.lang.String BSO_NAME
          Fields for sorting BasicSearchObjects in lists.
static java.lang.String BSO_TYPE
          Fields for sorting BasicSearchObjects in lists.
static int DEFAULT_ANALYZER
           
static int SCANDINAVIAN_ANALYZER
           
static int STANDARD_ANALYZER
           
 
Method Summary
 void allBSOtoIndex(BasicSearchObject handle)
          Store a set of BasicSearchObjects in this index.
 org.apache.lucene.document.Document[] allDocumentsOfType(BasicSearchObject bso)
          Get all the Documents needed to rebuild a list of BasicSearchObjects.
 org.apache.lucene.analysis.Analyzer analyzer()
           
static org.apache.lucene.analysis.Analyzer analyzer(int analyzer)
           
static int analyzer(java.lang.String analyzer)
           
 void closeReader()
          Close a reader to free resources and enable a writer to write new segments.
 void closeWriter()
          If the writer has the index locked for write, we need to close it to enable the reader to delete docs.
 void freeSearcher()
          Tells this BasicSearchObjectIndex that it is OK to hand out the searcher again.
static BasicSearchObjectIndex getIndexer(java.io.File index_directory, org.apache.lucene.analysis.Analyzer analyzer)
          Build a BasicSearchObjectIndex with the directory to store the Lucene index in, a parameter code for the Analyzer to use and a set of standard file types.
static BasicSearchObjectIndex getIndexer(java.lang.String index_directory)
          Build a BasicSearchObjectIndex with the directory to store the Lucene index in.
static BasicSearchObjectIndex getIndexer(java.lang.String index_directory, int analyzer)
          Build a BasicSearchObjectIndex with the directory to store the Lucene index in and a parameter code for the Analyzer to use.
 org.apache.lucene.search.Searcher getSearcher()
          Check if the resources are unused, create a searcher if necessary, and hand it out.
 org.apache.lucene.document.Document singleDocumentByCode(int code)
          Get all the Documents needed to rebuild a list of BasicSearchObjects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ANALYZERS

public static final org.apache.lucene.analysis.Analyzer[] ANALYZERS
Tools for setting an Analyzer from a parameter.

An Analyzer should have no state. From the Official Lucene FAQ:

"An Analyzer object is merely a factory for TokenStream objects and in typical implementations it does not have any state so you can create one during program initialization and keep it in a static variable."

The following are tools for configuring the analyzer though the web.xml file.


STANDARD_ANALYZER

public static final int STANDARD_ANALYZER

SCANDINAVIAN_ANALYZER

public static final int SCANDINAVIAN_ANALYZER

DEFAULT_ANALYZER

public static final int DEFAULT_ANALYZER

ANALYZER_STRING

public static final java.lang.String ANALYZER_STRING

ANALYZER_STRINGS

public static final java.lang.String[] ANALYZER_STRINGS

BSO_CODE

public static final java.lang.String BSO_CODE
Fields for sorting BasicSearchObjects in lists.

BSO_NAME

public static final java.lang.String BSO_NAME
Fields for sorting BasicSearchObjects in lists.

BSO_TYPE

public static final java.lang.String BSO_TYPE
Fields for sorting BasicSearchObjects in lists.
Method Detail

analyzer

public final org.apache.lucene.analysis.Analyzer analyzer()

getIndexer

public static BasicSearchObjectIndex getIndexer(java.lang.String index_directory)
                                         throws java.io.IOException
Build a BasicSearchObjectIndex with the directory to store the Lucene index in. Indexes the default set of file types, and uses the StandardAnalyzer. The method is static, so that all requests for a BasicSearchObjectIndex first checks if one exist for that directory, before a new instance is created.

Parameters:
index_directory - the File to store the index in.
Returns:
the BasicSearchObjectIndex corresponding to the given directory.

getIndexer

public static BasicSearchObjectIndex getIndexer(java.lang.String index_directory,
                                                int analyzer)
                                         throws java.io.IOException
Build a BasicSearchObjectIndex with the directory to store the Lucene index in and a parameter code for the Analyzer to use. Will index the standard file types. The method is static, so that all requests for a BasicSearchObjectIndex first checks if one exist for that directory.

Parameters:
index_directory - the File to store the index in.
analyzer_type - the Analyzer type as a String.
Returns:
the BasicSearchObjectIndex corresponding to the given directory.

getIndexer

public static final BasicSearchObjectIndex getIndexer(java.io.File index_directory,
                                                      org.apache.lucene.analysis.Analyzer analyzer)
                                               throws java.io.IOException
Build a BasicSearchObjectIndex with the directory to store the Lucene index in, a parameter code for the Analyzer to use and a set of standard file types. The method is static, so that all requests for a BasicSearchObjectIndex first checks if one exist for that directory.

Parameters:
index_directory - the File to store the index in.
analyzer - the Analyzer to use while indexing.
file_types - the array of Strings denoting the file types to index.
Returns:
the BasicSearchObjectIndex corresponding to the given directory.

analyzer

public static final org.apache.lucene.analysis.Analyzer analyzer(int analyzer)

analyzer

public static final int analyzer(java.lang.String analyzer)

getSearcher

public final org.apache.lucene.search.Searcher getSearcher()
                                                    throws java.io.IOException,
                                                           java.lang.InterruptedException
Check if the resources are unused, create a searcher if necessary, and hand it out.

Returns:
the Searcher corresponding to this index.

freeSearcher

public final void freeSearcher()
Tells this BasicSearchObjectIndex that it is OK to hand out the searcher again.

closeReader

public final void closeReader()
                       throws java.io.IOException
Close a reader to free resources and enable a writer to write new segments. At the same time we delete any searcher (s) built on this reader. Maybe there could be more than one searchers?

closeWriter

public final void closeWriter()
                       throws java.io.IOException
If the writer has the index locked for write, we need to close it to enable the reader to delete docs.

allBSOtoIndex

public final void allBSOtoIndex(BasicSearchObject handle)
                         throws java.lang.InterruptedException,
                                java.io.IOException
Store a set of BasicSearchObjects in this index. This method changes the content of the index, so both the reader and the writer are closed afterwards.

allDocumentsOfType

public final org.apache.lucene.document.Document[] allDocumentsOfType(BasicSearchObject bso)
                                                               throws java.lang.InterruptedException,
                                                                      java.io.IOException
Get all the Documents needed to rebuild a list of BasicSearchObjects. This method does not change the content of the index, so the reader is left open, and the writer is unsed. Set num = -1 for all documents.

singleDocumentByCode

public final org.apache.lucene.document.Document singleDocumentByCode(int code)
                                                               throws java.lang.InterruptedException,
                                                                      java.io.IOException
Get all the Documents needed to rebuild a list of BasicSearchObjects. This method does not change the content of the index, so the reader is left open, and the writer is unsed.


Swfit developer homepage
Copyright © 2003 Orgdot AS. All Rights Reserved.