org.crosswire.jsword.index.lucene
Class LuceneIndex

java.lang.Object
  extended by org.crosswire.jsword.index.AbstractIndex
      extended by org.crosswire.jsword.index.lucene.LuceneIndex
All Implemented Interfaces:
Closeable, Index

public class LuceneIndex
extends AbstractIndex
implements Closeable

Implement the SearchEngine using Lucene as the search engine.

Author:
Joe Walker
See Also:
The GNU Lesser General Public License for details.

Field Summary
private  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.
private  org.apache.lucene.store.Directory directory
          The Lucene directory for the path.
static String FIELD_BODY
          The Lucene field for the text contents
static String FIELD_HEADING
          The Lucene field for headings
static String FIELD_INTRO
          Combines the strong numbers with the morphology field
static String FIELD_KEY
          The Lucene field for the osisID
static String FIELD_MORPHOLOGY
          Combines the strong numbers with the morphology field
static String FIELD_NOTE
          The Lucene field for the notes
static String FIELD_STRONG
          The Lucene field for the strong numbers
static String FIELD_XREF
          The Lucene field for cross references
private static org.slf4j.Logger log
          The log stream
private  String path
          The location of this index
private  org.apache.lucene.search.Searcher searcher
          The Lucene search engine
private static int WORK_ESTIMATE
          An estimate of the percent of time spent indexing.
 
Constructor Summary
LuceneIndex(Book book, URI storage)
          Read an existing index and use it.
LuceneIndex(Book book, URI storage, IndexPolicy policy)
          Generate an index to use, telling the job about progress as you go.
 
Method Summary
private  void addField(org.apache.lucene.document.Document doc, org.apache.lucene.document.Field field, String text)
          Add the text to the Field and put the Field in the document, ignoring null and empty text.
 void close()
          Closes resources related to the index
 Key find(String search)
          Find the set of references that satisfy the query.
private  void generateSearchIndexImpl(Progress job, List<Key> errors, org.apache.lucene.index.IndexWriter writer, Key key, int count, IndexPolicy policy)
          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.
 org.apache.lucene.search.Searcher getSearcher()
          Could be null if the index has been closed down.
private  void initDirectoryAndSearcher()
          Initializes the directory and searcher.
 
Methods inherited from class org.crosswire.jsword.index.AbstractIndex
getSearchModifier, setSearchModifier
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIELD_KEY

public static final String FIELD_KEY
The Lucene field for the osisID

See Also:
Constant Field Values

FIELD_BODY

public static final String FIELD_BODY
The Lucene field for the text contents

See Also:
Constant Field Values

FIELD_STRONG

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

See Also:
Constant Field Values

FIELD_HEADING

public static final String FIELD_HEADING
The Lucene field for headings

See Also:
Constant Field Values

FIELD_XREF

public static final String FIELD_XREF
The Lucene field for cross references

See Also:
Constant Field Values

FIELD_NOTE

public static final String FIELD_NOTE
The Lucene field for the notes

See Also:
Constant Field Values

FIELD_MORPHOLOGY

public static final String FIELD_MORPHOLOGY
Combines the strong numbers with the morphology field

See Also:
Constant Field Values

FIELD_INTRO

public static final String FIELD_INTRO
Combines the strong numbers with the morphology field

See Also:
Constant Field Values

WORK_ESTIMATE

private static final int WORK_ESTIMATE
An estimate of the percent of time spent indexing. The remaining time, if any, is spent doing cleanup.

See Also:
Constant Field Values

book

private Book book
The Book that we are indexing


path

private String path
The location of this index


directory

private org.apache.lucene.store.Directory directory
The Lucene directory for the path.


searcher

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


CREATING

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


log

private static final org.slf4j.Logger log
The log stream

Constructor Detail

LuceneIndex

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

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

LuceneIndex

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

Parameters:
book - the book
storage -
policy -
Throws:
BookException - If we fail to read the index files
Method Detail

initDirectoryAndSearcher

private void initDirectoryAndSearcher()
Initializes the directory and searcher.


find

public Key find(String search)
         throws BookException
Description copied from interface: Index
Find the set of references that satisfy the query. Query is anything that the underlying index can handle. If the query 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:
find 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)

close

public final void close()
Description copied from interface: Index
Closes resources related to the index

Specified by:
close in interface Closeable
Specified by:
close in interface Index

generateSearchIndexImpl

private void generateSearchIndexImpl(Progress job,
                                     List<Key> errors,
                                     org.apache.lucene.index.IndexWriter writer,
                                     Key key,
                                     int count,
                                     IndexPolicy policy)
                              throws BookException,
                                     IOException
Dig down into a Key indexing as we go.

Parameters:
policy -
Throws:
BookException
IOException

addField

private void addField(org.apache.lucene.document.Document doc,
                      org.apache.lucene.document.Field field,
                      String text)
Add the text to the Field and put the Field in the document, ignoring null and empty text.

Parameters:
doc - The Document to which the Field should be added
field - The Field to add
text - The text for the field

getSearcher

public org.apache.lucene.search.Searcher getSearcher()
Could be null if the index has been closed down. This is helpful to third party applications which wish to have greater control over the underlying Lucene functionality. Note: by using this method, you need to ensure you don't close the searcher while it is being used. See IndexManager.closeAllIndexes() for more information

Returns:
the searcher

Copyright ยจ 2003-2015