|
SPT Object Database API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sptci.prevayler.StorageSystem
com.sptci.prevayler.IndexSystem
com.sptci.prevayler.ConstraintSystem
com.sptci.prevayler.SearchSystem
abstract class SearchSystem
Abstracts all the full-text search indexing and de-indexing operations for the prevalent system. Indexing is performed using Lucene.
Note:The field values are converted to String using
the Object.toString() method to retrieve the content to index.
To ensure meaningful indices ensure that the fields annotated return
meaningful values.
© Copyright 2008 Sans Pareil Technologies, Inc.
| Nested Class Summary | |
|---|---|
private static class |
SearchSystem.Closer
A thread used as a shutdown hook to the JVM to close the writer and other lucene resources. |
| Nested classes/interfaces inherited from class com.sptci.prevayler.StorageSystem |
|---|
StorageSystem.TaskQueue |
| Field Summary | |
|---|---|
static String |
CLASS_FIELD
The name of the field in the indexed document that stores the class name. |
(package private) static String |
DOCUMENT_ID_FIELD
The name of the field in the indexed document that stores the unique document id. |
static String |
OBJECT_ID_FIELD
The name of the field in the indexed document that stores the object id. |
protected static org.apache.lucene.index.IndexReader |
reader
The index reader instance to use to read the index. |
static int |
SAVE_COUNT
The number or index updates before a IndexWriter.commit() is invoked. |
private int |
saveCount
A counter to ensure that the IndexWriter.commit()
method is called periodically. |
protected static org.apache.lucene.search.IndexSearcher |
searcher
The index searcher instance to use to search documents. |
static char |
SEPARATOR_CHAR
The separator character used to delimit composite index field names. |
private static long |
serialVersionUID
|
protected static org.apache.lucene.index.IndexWriter |
writer
The index writer instance to use to create/delete documents. |
| Fields inherited from class com.sptci.prevayler.StorageSystem |
|---|
logger |
| Constructor Summary | |
|---|---|
SearchSystem()
|
|
| Method Summary | |
|---|---|
private void |
commit()
Commit pending writes to the index and refresh the reader. |
private org.apache.lucene.document.Document |
createDocument(PrevalentObject object)
Create a document to store the full-text indices for the specified object. |
private String |
getDocumentId(PrevalentObject object)
Return the unique document id for the index document representing the specified prevalent object. |
private boolean |
hasIndices(PrevalentObject object)
Determine whether the prevalent object has any full-text search indices specified. |
protected void |
index(PrevalentObject object)
Over-ridden to process search annotations for the object. |
private void |
indexClass(PrevalentObject object,
org.apache.lucene.document.Document doc)
Add full-text search indices for composite indices defined at the class level. |
private void |
indexFields(PrevalentObject object,
org.apache.lucene.document.Document doc)
Add full=text search indices for any fields annotated as searchable in the prevalent object. |
private void |
indexSearchable(PrevalentObject object,
org.apache.lucene.document.Document doc,
Searchable index)
Process the Searchable annotation
for the specified prevalent object class. |
private void |
indexSearchables(PrevalentObject object,
org.apache.lucene.document.Document doc)
Process the Searchables annotation
for the specified prevalent object class. |
protected void |
remove(PrevalentObject object)
Over-ridden to remove the search index for the specified prevalent object. |
private void |
save(PrevalentObject object,
org.apache.lucene.document.Document document)
Save the specified document to the index writer. |
protected void |
search(org.apache.lucene.search.Query query,
org.apache.lucene.search.Filter filter,
int count,
org.apache.lucene.search.Sort sort,
Collection<PrevalentObject> collection)
Search the search indices and retrieve all the objects (regardless of type) that match the specified query and return up to the specified number of results. |
| Methods inherited from class com.sptci.prevayler.ConstraintSystem |
|---|
checkFields, checkUnique, checkUnique, indexClass, indexFields, preAdd, preDelete, preDelete |
| Methods inherited from class com.sptci.prevayler.StorageSystem |
|---|
generateOid, getIndexStorage, getIndexStorage, getPrimaryStorage, getPrimaryStorage, getReferenceStorage, getReferenceStorage, getRelationStorage, getRelationStorage, getTaskQueue |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface com.sptci.prevayler.DatabaseSystem |
|---|
delete, save |
| Methods inherited from interface com.sptci.prevayler.AbstractDatabase |
|---|
count, fetch, fetch, fetch, fetchIntersection, fetchUnion, search |
| Field Detail |
|---|
private static final long serialVersionUID
protected static final transient org.apache.lucene.index.IndexWriter writer
protected static transient org.apache.lucene.index.IndexReader reader
protected static transient org.apache.lucene.search.IndexSearcher searcher
static final String DOCUMENT_ID_FIELD
public static final String CLASS_FIELD
public static final String OBJECT_ID_FIELD
public static final char SEPARATOR_CHAR
public static final int SAVE_COUNT
IndexWriter.commit() is invoked. Invoked only
in batches to avoid expensive operation on each transaction.
private int saveCount
IndexWriter.commit()
method is called periodically.
| Constructor Detail |
|---|
SearchSystem()
| Method Detail |
|---|
protected void index(PrevalentObject object)
throws PrevalentException
Document that holds all the indexed fields
in the prevalent object.
index in class IndexSystemobject - The prevalent object to add query support for.
PrevalentException - If errors are encountered
while fetching the values of the fields in prevalent object.IndexSystem.indexFields(com.sptci.prevayler.PrevalentObject),
IndexSystem.indexClass(com.sptci.prevayler.PrevalentObject)
protected void remove(PrevalentObject object)
throws PrevalentException
remove in class ConstraintSystemobject - The prevalent object to de-index.
PrevalentException - If errors are encountered while removing the
index for the prevalent object.
private boolean hasIndices(PrevalentObject object)
throws PrevalentException
object - The prevalent object to check.
true if any search indices have been specified.
PrevalentException - If errors are encountered
while reflecting upon the annotations in the prevalent object.private org.apache.lucene.document.Document createDocument(PrevalentObject object)
object - The prevalent object to index.
getDocumentId(PrevalentObject)private String getDocumentId(PrevalentObject object)
object - The prevalent object for which the document id is to be
retrieved.
private void indexFields(PrevalentObject object,
org.apache.lucene.document.Document doc)
throws IllegalAccessException
object - The prevalent object whose fields are to be indexed.doc - The document to which indices are to be added.
IllegalAccessException - If errors are encountered
while reflecting upon the fields in the prevalent object.
private void indexClass(PrevalentObject object,
org.apache.lucene.document.Document doc)
throws IllegalAccessException
Searchable.name().
The concatenated names are delimited by the SEPARATOR_CHAR.
object - The prevalent object whose composite fields are to be indexed.doc - The document to which indices are to be added.
IllegalAccessException - If errors are encountered
while reflecting upon the fields in the prevalent object.indexSearchables(PrevalentObject, org.apache.lucene.document.Document),
indexSearchable(PrevalentObject, org.apache.lucene.document.Document,
com.sptci.prevayler.annotations.Searchable)
private void indexSearchables(PrevalentObject object,
org.apache.lucene.document.Document doc)
throws IllegalAccessException
Searchables annotation
for the specified prevalent object class. Create the composite
indices for the specified array of composite indices.
object - The prevalent object whose composite fields are to be indexed.doc - The document to which indices are to be added.
IllegalAccessException - If errors are encountered while fetching
the field values of the prevalent object.
private void indexSearchable(PrevalentObject object,
org.apache.lucene.document.Document doc,
Searchable index)
throws IllegalAccessException
Searchable annotation
for the specified prevalent object class. Create the composite index
for the array of fields.
object - The prevalent object whose composite fields are to be indexed.doc - The document to which indices are to be added.index - The searchable index annotation to process.
IllegalAccessException - If errors are encountered while fetching
the field values of the prevalent object.
private void save(PrevalentObject object,
org.apache.lucene.document.Document document)
throws IOException
object - The prevalent object that is being indexed.document - The new document to add to the index.
IOException - If errors are encountered while saving the
document.IndexWriter.updateDocument(
org.apache.lucene.index.Term, org.apache.lucene.document.Document),
commit()
private void commit()
throws IOException
IOException - If errors are encountered while saving the
document.
protected void search(org.apache.lucene.search.Query query,
org.apache.lucene.search.Filter filter,
int count,
org.apache.lucene.search.Sort sort,
Collection<PrevalentObject> collection)
throws Exception
query - The query to execute.filter - The filter to apply to the search.count - The maximum number of results to return.sort - The sort fields to apply to the results.collection - The collection to which matching objects are added.
Exception - If errors are encountered while reconstituting the
prevalent objects or executing the search.AbstractDatabase.fetch(Class, Object)
|
SPT Object Database API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||