prefuse.data.search
Class LuceneSearcher

java.lang.Object
  extended by prefuse.data.search.LuceneSearcher

public class LuceneSearcher
extends java.lang.Object

Adapter class for interfacing with the Lucene search engine. By default, instances of this class use an in-memory search index for English language text, for use within a single application session. The class can, however, be parameterized for any number of other configurations, including accessing persistent search indices.

Version:
1.0
Author:
jeffrey heer

Field Summary
static java.lang.String FIELD
          Default Document field used to index text.
static java.lang.String ID
          Document field used to store the document ID number.
 
Constructor Summary
LuceneSearcher()
          Create a new LuceneSearcher using an in-memory search index.
LuceneSearcher(org.apache.lucene.store.Directory dir)
          Create a new LuceneSearcher using the specified search index location.
LuceneSearcher(org.apache.lucene.store.Directory dir, java.lang.String[] fields, boolean readOnly)
          Create a new LuceneSearcher using a specified search index location, a particular Document fields to index, and given read/write status.
LuceneSearcher(org.apache.lucene.store.Directory dir, java.lang.String field, boolean readOnly)
          Create a new LuceneSearcher using a specified search index location, a particular Document field to index, and given read/write status.
 
Method Summary
 void addDocument(org.apache.lucene.document.Document d)
          Add a document to the Lucene search index.
 org.apache.lucene.analysis.Analyzer getAnalyzer()
          Returns the Analyzer used to process text.
 java.lang.String[] getFields()
          Returns the indexed Document fields.
 org.apache.lucene.index.IndexReader getIndexReader()
          Returns the Lucene IndexReader.
 org.apache.lucene.search.Searcher getIndexSearcher()
          Returns the Lucene IndexSearcher.
 boolean isReadOnly()
          Indicates if ths LuceneSearcher is read-only.
 int numHits(java.lang.String query)
          Return the result count for the given search query.
 org.apache.lucene.search.Hits search(java.lang.String query)
          Searches the Lucene index using the given query String, returns an object which provides access to the search results.
 void setAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
          Sets the Analyzer used to process text.
 void setFields(java.lang.String[] fields)
          Sets the indexed Document fields.
 boolean setReadMode(boolean mode)
          Sets if this LuceneSearcher is in read mode or write mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIELD

public static final java.lang.String FIELD
Default Document field used to index text.

See Also:
Constant Field Values

ID

public static final java.lang.String ID
Document field used to store the document ID number.

See Also:
Constant Field Values
Constructor Detail

LuceneSearcher

public LuceneSearcher()
Create a new LuceneSearcher using an in-memory search index.


LuceneSearcher

public LuceneSearcher(org.apache.lucene.store.Directory dir)
Create a new LuceneSearcher using the specified search index location.

Parameters:
dir - the Lucene Directory indicating the search index to use.

LuceneSearcher

public LuceneSearcher(org.apache.lucene.store.Directory dir,
                      java.lang.String field,
                      boolean readOnly)
Create a new LuceneSearcher using a specified search index location, a particular Document field to index, and given read/write status.

Parameters:
dir - the Lucene Directory indicating the search index to use.
field - the Lucene Document field that should be indexed.
readOnly - if this index is read-only or is writable.

LuceneSearcher

public LuceneSearcher(org.apache.lucene.store.Directory dir,
                      java.lang.String[] fields,
                      boolean readOnly)
Create a new LuceneSearcher using a specified search index location, a particular Document fields to index, and given read/write status.

Parameters:
dir - the Lucene Directory indicating the search index to use.
fields - the Lucene Document fields that should be indexed.
readOnly - if this index is read-only or is writable.
Method Detail

setReadMode

public boolean setReadMode(boolean mode)
Sets if this LuceneSearcher is in read mode or write mode. In read more searches can be issued, in write mode new Documents can be indexed. Read-only LuceneSearcher instances can not be put into write mode.

Parameters:
mode - true for read mode, false for write mode.
Returns:
true if the mode was successfully set, false otherwise.

search

public org.apache.lucene.search.Hits search(java.lang.String query)
                                     throws org.apache.lucene.queryParser.ParseException,
                                            java.io.IOException
Searches the Lucene index using the given query String, returns an object which provides access to the search results.

Parameters:
query - the search query
Returns:
the search Hits
Throws:
org.apache.lucene.queryParser.ParseException - if the query is not parsed successfully
java.io.IOException - if an input/ouput error occurs
java.lang.IllegalStateException - if the searcher is in write mode

numHits

public int numHits(java.lang.String query)
            throws org.apache.lucene.queryParser.ParseException,
                   java.io.IOException
Return the result count for the given search query. To allow quick repeated look ups, the hit count is cached (this cache is cleared whenever a change to the search index occurs).

Parameters:
query - the search query
Returns:
the number of matches to the query
Throws:
org.apache.lucene.queryParser.ParseException - if the query is not parsed successfully
java.io.IOException - if an input/ouput error occurs
java.lang.IllegalStateException - if the searcher is in write mode

addDocument

public void addDocument(org.apache.lucene.document.Document d)
Add a document to the Lucene search index.

Parameters:
d - the Document to add
Throws:
java.lang.IllegalStateException - if the searcher is not in write mode

getAnalyzer

public org.apache.lucene.analysis.Analyzer getAnalyzer()
Returns the Analyzer used to process text. See Lucene documentation for more details.

Returns:
returns the analyzer.

setAnalyzer

public void setAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
Sets the Analyzer used to process text. See Lucene documentation for more details.

Parameters:
analyzer - the analyzer to set

getFields

public java.lang.String[] getFields()
Returns the indexed Document fields. These fields determine which fields are indexed as Documents are added and which fields are queried over when searches are issued.

Returns:
returns the indexed Document fields

setFields

public void setFields(java.lang.String[] fields)
Sets the indexed Document fields. These fields determine which fields are indexed as Documents are added and which fields are queried over when searches are issued. param fields the indexed Document fields to use


getIndexReader

public org.apache.lucene.index.IndexReader getIndexReader()
Returns the Lucene IndexReader. See Lucene documentation for more details.

Returns:
teturns the IndexReader.

getIndexSearcher

public org.apache.lucene.search.Searcher getIndexSearcher()
Returns the Lucene IndexSearcher. See Lucene documentation for more details.

Returns:
returns the IndexSearcher.

isReadOnly

public boolean isReadOnly()
Indicates if ths LuceneSearcher is read-only.

Returns:
true if read-only, false if writes are allowed


Copyright © 2007 Regents of the University of California