org.crosswire.jsword.book.search.lucene
Class LuceneIndex

java.lang.Object
  extended by org.crosswire.jsword.book.search.lucene.LuceneIndex
All Implemented Interfaces:
Activatable, Index

public class LuceneIndex
extends Object
implements Index, Activatable

Implement the SearchEngine using Lucene as the search engine.

Distribution Licence:
JSword is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
The License is available on the internet here, or by writing to: Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
The copyright to this program is held by it's authors.

Version:
$Id: LuceneIndex.java,v 1.13 2005/03/25 04:02:52 dmsmith Exp $
Author:
Joe Walker [joe at eireneh dot com]
See Also:
Licence

Field Summary
private  boolean active
          Are we active
protected  Book book
          The Book that we are indexing
private static Object CREATING
          A synchronization lock point to prevent us from doing 2 index runs at a time.
protected static String FIELD_BODY
          The Lucene field for the verse contents
protected static String FIELD_NAME
          The Lucene field for the verse name
protected static String FIELD_STRONG
          The Lucene field for the strong numbers
private static Logger log
          The log stream
private  String path
          The location of this index
protected  org.apache.lucene.search.Searcher searcher
          The Lucene search engine
 
Constructor Summary
LuceneIndex(Book book, URL storage)
          Read an existing index and use it.
LuceneIndex(Book book, URL storage, boolean create)
          Generate an index to use, telling the job about progress as you go.
 
Method Summary
 void activate(Lock lock)
          Called to indicate that the Book should initialize itself, and consume whatever system resources it needs to be able to respond to other queries.
protected  void checkActive()
          Helper method so we can quickly activate ourselves on access
 void deactivate(Lock lock)
          Called to indicate that the Book should release whatever system resources it can to make way for other uses.
 Key findWord(String search)
          For a given word find a list of references to it.
private  void generateSearchIndexImpl(Job job, List errors, org.apache.lucene.index.IndexWriter writer, Key key)
          Dig down into a Key indexing as we go.
 Key getKey(String name)
          An index must be able to create KeyLists for users in a similar way to the Book that it is indexing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CREATING

private static final Object CREATING
A synchronization lock point to prevent us from doing 2 index runs at a time.


active

private boolean active
Are we active


log

private static final Logger log
The log stream


FIELD_NAME

protected static final String FIELD_NAME
The Lucene field for the verse name

See Also:
Constant Field Values

FIELD_BODY

protected static final String FIELD_BODY
The Lucene field for the verse contents

See Also:
Constant Field Values

FIELD_STRONG

protected static final String FIELD_STRONG
The Lucene field for the strong numbers

See Also:
Constant Field Values

book

protected Book book
The Book that we are indexing


path

private String path
The location of this index


searcher

protected org.apache.lucene.search.Searcher searcher
The Lucene search engine

Constructor Detail

LuceneIndex

public LuceneIndex(Book book,
                   URL storage)
            throws BookException
Read an existing index and use it.

Throws:
BookException - If we fail to read the index files

LuceneIndex

public LuceneIndex(Book book,
                   URL storage,
                   boolean create)
            throws BookException
Generate an index to use, telling the job about progress as you go.

Throws:
BookException - If we fail to read the index files
Method Detail

findWord

public Key findWord(String search)
             throws BookException
Description copied from interface: Index
For a given word find a list of references to it. If the word being searched for is null then an empty Key MUST be returned. Users of this index may use this functionality to get empty KeyLists which they then use to aggregate other searches done on this index.

Specified by:
findWord in interface Index
Parameters:
search - The text to search for
Returns:
The references to the word
Throws:
BookException

getKey

public Key getKey(String name)
           throws NoSuchKeyException
Description copied from interface: Index
An index must be able to create KeyLists for users in a similar way to the Book that it is indexing.

Specified by:
getKey in interface Index
Parameters:
name - The string to convert to a Key
Returns:
A new Key representing the given string, if possible
Throws:
NoSuchKeyException - If the string can not be turned into a Key
See Also:
KeyFactory.getKey(String)

activate

public final void activate(Lock lock)
Description copied from interface: Activatable
Called to indicate that the Book should initialize itself, and consume whatever system resources it needs to be able to respond to other queries.

Specified by:
activate in interface Activatable
Parameters:
lock - An attempt to ensure that only the Activator calls this method

deactivate

public final void deactivate(Lock lock)
Description copied from interface: Activatable
Called to indicate that the Book should release whatever system resources it can to make way for other uses.

Specified by:
deactivate in interface Activatable
Parameters:
lock - An attempt to ensure that only the Activator calls this method

checkActive

protected final void checkActive()
Helper method so we can quickly activate ourselves on access


generateSearchIndexImpl

private void generateSearchIndexImpl(Job job,
                                     List errors,
                                     org.apache.lucene.index.IndexWriter writer,
                                     Key key)
                              throws BookException,
                                     IOException
Dig down into a Key indexing as we go.

Throws:
BookException
IOException

Copyright ? 2003-2004