|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.java.ao.EntityManager
net.java.ao.SearchableEntityManager
public class SearchableEntityManager
Required to manage entities with enabled full-text searching. This is where
all the "meat" of the Lucene indexing support is actually implemented. It is
required to use this EntityManager
implementation to use full-text
searching. Example:
public interface Post extends Entity { // ... @Searchable @SQLType(Types.BLOB) public String getBody(); @Searchable @SQLType(Types.BLOB) public void setBody(String body); } // ... SearchableEntityManager manager = new SearchableEntityManager( uri, username, password, FSDirectory.getDirectory("~/lucene_index")); manager.search(Post.class, "my search string"); // returns results as Post[]
This class does not support any Java full-text search libraries other than Lucene. Also, the support for Lucene itself is comparatively limited. If your requirements dictate more advanced functionality, you should consider writing a custom implementation of this class to provide the enhancements you need. More features are planned for this class in future...
Searchable
Constructor Summary | |
---|---|
SearchableEntityManager(DatabaseProvider databaseProvider,
EntityManagerConfiguration configuration,
LuceneConfiguration luceneConfiguration)
|
Method Summary | ||
---|---|---|
void |
addToIndex(RawEntity<?> entity)
Adds the entity instance to the index. |
|
void |
delete(RawEntity<?>... entities)
Deletes the specified entities from the database. |
|
org.apache.lucene.analysis.Analyzer |
getAnalyzer()
|
|
protected
|
getAndInstantiate(Class<T> type,
K key)
Creates a new instance of the entity of the specified type corresponding to the given primary key. |
|
org.apache.lucene.store.Directory |
getIndexDir()
|
|
void |
optimize()
Optimizes the Lucene index for searching. |
|
void |
removeFromIndex(RawEntity<?> entity)
Removes the specified entity from the Lucene index. |
|
|
search(Class<T> type,
String strQuery)
Runs a Lucene full-text search on the specified entity type with the given query. |
Methods inherited from class net.java.ao.EntityManager |
---|
count, count, count, create, create, find, find, find, find, findWithSQL, flush, flushAll, get, get, getCache, getFieldNameConverter, getNameConverters, getPolymorphicTypeMapper, getProvider, getTableNameConverter, migrate, peer, peer, setCache, setPolymorphicTypeMapper, stream, stream |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SearchableEntityManager(DatabaseProvider databaseProvider, EntityManagerConfiguration configuration, LuceneConfiguration luceneConfiguration) throws IOException
IOException
Method Detail |
---|
protected <T extends RawEntity<K>,K> T getAndInstantiate(Class<T> type, K key)
EntityManager
EntityManager.get(Class, Object[])
} to create the entity
if the instance is not found already in the cache. This method should not be
repurposed to perform any caching, since ActiveObjects already assumes that
the caching has been performed.
getAndInstantiate
in class EntityManager
type
- The type of the entity to create.key
- The primary key corresponding to the entity instance required.
public <T extends RawEntity<K>,K> T[] search(Class<T> type, String strQuery) throws IOException, org.apache.lucene.queryParser.ParseException, SQLException
Searchable
field within
the entity. No caching is performed in this method. Rather, AO relies
upon the underlying Lucene code to be performant.
type
- The type of the entities to search for.strQuery
- The query to pass to Lucene for the search.
IOException
- If Lucene was unable to open the index.
org.apache.lucene.queryParser.ParseException
- If Lucene was unable to parse the search string into a valid query.
SQLException
public void delete(RawEntity<?>... entities) throws SQLException
EntityManager
Deletes the specified entities from the database. DELETE statements are called on the rows in the corresponding tables and the entities are removed from the instance cache. The entity instances themselves are not invalidated, but it doesn't even make sense to continue using the instance without a row with which it is paired.
This method does attempt to group the DELETE statements on a per-type
basis. Thus, if you pass 5 instances of EntityA
and two
instances of EntityB
, the following SQL prepared statements
will be invoked:
DELETE FROM entityA WHERE id IN (?,?,?,?,?); DELETE FROM entityB WHERE id IN (?,?);
Thus, this method scales very well for large numbers of entities grouped into types. However, the execution time increases linearly for each entity of unique type.
delete
in class EntityManager
entities
- A varargs array of entities to delete. Method returns immediately
if length == 0.
SQLException
public void addToIndex(RawEntity<?> entity) throws IOException
Searchable
fields within the entity will be added to the
index as part of the document corresponding to the instance.
entity
- The entity to add to the index.
IOException
- If Lucene was unable to open the index.public void removeFromIndex(RawEntity<?> entity) throws IOException
Document
.
entity
- The entity to remove from the index.
IOException
- If Lucene was unable to open the index.public void optimize() throws IOException
Optimizes the Lucene index for searching. This call peers down to
IndexWriter#optimize()
. For sizable indexes, this
call will take some time, so it is best not to perform the operation
in scenarios where it may block interface responsiveness (such as
in the middle of a page request, or within the EDT).
This method is the only optimization call made against the Lucene
index. Meaning, SearchableEntityManager
never
optimizes the index automatically, as this could potentially cause major
performance issues. Developers should be aware of this and the
negative impact lack-of optimization can have upon search performance.
IOException
- If Lucene was unable to open the index.public org.apache.lucene.store.Directory getIndexDir()
public org.apache.lucene.analysis.Analyzer getAnalyzer()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |