public class LuceneSearcher
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
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 and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
public static final java.lang.String FIELD
public static final java.lang.String ID
public LuceneSearcher()
public LuceneSearcher(org.apache.lucene.store.Directory dir)
dir - the Lucene Directory indicating the search index to use.public LuceneSearcher(org.apache.lucene.store.Directory dir,
java.lang.String field,
boolean readOnly)
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.public LuceneSearcher(org.apache.lucene.store.Directory dir,
java.lang.String[] fields,
boolean readOnly)
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.public boolean setReadMode(boolean mode)
mode - true for read mode, false for write mode.public org.apache.lucene.search.Hits search(java.lang.String query)
throws org.apache.lucene.queryParser.ParseException,
java.io.IOException
query - the search queryorg.apache.lucene.queryParser.ParseException - if the query is not parsed successfullyjava.io.IOException - if an input/output error occursjava.lang.IllegalStateException - if the searcher is in write modepublic int numHits(java.lang.String query)
throws org.apache.lucene.queryParser.ParseException,
java.io.IOException
query - the search queryorg.apache.lucene.queryParser.ParseException - if the query is not parsed successfullyjava.io.IOException - if an input/output error occursjava.lang.IllegalStateException - if the searcher is in write modepublic void addDocument(org.apache.lucene.document.Document d)
d - the Document to addjava.lang.IllegalStateException - if the searcher is not in write modepublic org.apache.lucene.analysis.Analyzer getAnalyzer()
public void setAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
analyzer - the analyzer to setpublic java.lang.String[] getFields()
public void setFields(java.lang.String[] fields)
public org.apache.lucene.index.IndexReader getIndexReader()
public org.apache.lucene.search.Searcher getIndexSearcher()
public boolean isReadOnly()