Package com.github.ddth.dao.nosql.lucene
Class BaseLuceneStorage
- java.lang.Object
-
- com.github.ddth.dao.nosql.lucene.BaseLuceneStorage
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
LuceneKdStorage
,LuceneKvStorage
public class BaseLuceneStorage extends java.lang.Object implements java.io.Closeable
Abstract Lucene implementation of NoSQL storage.Design: 3 special fields
FIELD_KEY
to store entry's id/key.FIELD_SPACE_ID
to store entry's space-id.FIELD_ID
to index termspace-id:key
- Since:
- 0.10.0
- Author:
- Thanh Nguyen
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String
FIELD_ID
protected static java.lang.String
FIELD_KEY
protected static java.lang.String
FIELD_SPACE_ID
-
Constructor Summary
Constructors Constructor Description BaseLuceneStorage()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.apache.lucene.index.Term
buildIdTerm(java.lang.String spaceId, java.lang.String key)
Build the "id" term (id="spaceId:key"
protected org.apache.lucene.search.Query
buildQuery(java.lang.String spaceId, java.lang.String key)
Build query to match entry's space-id and key.void
close()
protected org.apache.lucene.document.Document
createDocument(java.lang.String spaceId, java.lang.String key)
Create aDocument
, pre-filled with space-id and key fields.void
destroy()
protected long
doCount(java.lang.String spaceId)
Count number of documents within a space.protected void
doDelete(java.lang.String spaceId, java.lang.String key, IDeleteCallback callback)
Delete a document, identified byspaceId:key
, from index.protected org.apache.lucene.document.Document
doGet(java.lang.String spaceId, java.lang.String key)
Fetch a document, identified byspaceId:key
, from index.long
getAutoCommitPeriodMs()
When set to a positive value, data is automatically committed periodically in a background thread.protected org.apache.lucene.store.Directory
getDirectory()
Getter fordirectory
.protected com.github.ddth.lucext.directory.IndexManager
getIndexManager()
Getter forindexManager
.protected org.apache.lucene.search.IndexSearcher
getIndexSearcher()
protected org.apache.lucene.index.IndexWriter
getIndexWriter()
protected org.apache.lucene.index.IndexWriterConfig
getIndexWriterConfig()
Getter forindexWriterConfig
.BaseLuceneStorage
init()
boolean
isAsyncWrite()
In async-write mode, update operations (delete/put) are performed but not committed, which yields higher update performance but data may be lost in case of JVM crash (default valuefalse
)?BaseLuceneStorage
setAsyncWrite(boolean asyncWrite)
In async-write mode, update operations (delete/put) are performed but not committed, which yields higher update performance but data may be lost in case of JVM crash (default valuefalse
)?BaseLuceneStorage
setAutoCommitPeriodMs(long autoCommitPeriodMs)
When set to a positive value, data is automatically committed periodically in a background thread.BaseLuceneStorage
setDirectory(org.apache.lucene.store.Directory directory)
Setter fordirectory
.BaseLuceneStorage
setIndexManager(com.github.ddth.lucext.directory.IndexManager indexManager)
Setter forindexManager
.BaseLuceneStorage
setIndexWriterConfig(org.apache.lucene.index.IndexWriterConfig indexWriterConfig)
Setter forindexWriterConfig
.
-
-
-
Field Detail
-
FIELD_KEY
protected static final java.lang.String FIELD_KEY
- See Also:
- Constant Field Values
-
FIELD_SPACE_ID
protected static final java.lang.String FIELD_SPACE_ID
- See Also:
- Constant Field Values
-
FIELD_ID
protected static final java.lang.String FIELD_ID
- See Also:
- Constant Field Values
-
-
Method Detail
-
getDirectory
protected org.apache.lucene.store.Directory getDirectory()
Getter fordirectory
.- Returns:
-
setDirectory
public BaseLuceneStorage setDirectory(org.apache.lucene.store.Directory directory)
Setter fordirectory
.- Parameters:
directory
-- Returns:
-
getIndexWriterConfig
protected org.apache.lucene.index.IndexWriterConfig getIndexWriterConfig()
Getter forindexWriterConfig
.- Returns:
-
setIndexWriterConfig
public BaseLuceneStorage setIndexWriterConfig(org.apache.lucene.index.IndexWriterConfig indexWriterConfig)
Setter forindexWriterConfig
.- Parameters:
indexWriterConfig
-- Returns:
-
getIndexManager
protected com.github.ddth.lucext.directory.IndexManager getIndexManager()
Getter forindexManager
.- Returns:
-
setIndexManager
public BaseLuceneStorage setIndexManager(com.github.ddth.lucext.directory.IndexManager indexManager)
Setter forindexManager
.- Parameters:
indexManager
-- Returns:
-
isAsyncWrite
public boolean isAsyncWrite()
In async-write mode, update operations (delete/put) are performed but not committed, which yields higher update performance but data may be lost in case of JVM crash (default valuefalse
)?Note:
autoCommitPeriodMs
must be set to a positive value to enable async-write.- Returns:
- See Also:
getAutoCommitPeriodMs()
-
setAsyncWrite
public BaseLuceneStorage setAsyncWrite(boolean asyncWrite)
In async-write mode, update operations (delete/put) are performed but not committed, which yields higher update performance but data may be lost in case of JVM crash (default valuefalse
)?Note:
autoCommitPeriodMs
must be set to a positive value to enable async-write.- Parameters:
asyncWrite
-- Returns:
- See Also:
getAutoCommitPeriodMs()
-
getAutoCommitPeriodMs
public long getAutoCommitPeriodMs()
When set to a positive value, data is automatically committed periodically in a background thread.- Returns:
-
setAutoCommitPeriodMs
public BaseLuceneStorage setAutoCommitPeriodMs(long autoCommitPeriodMs)
When set to a positive value, data is automatically committed periodically in a background thread.- Parameters:
autoCommitPeriodMs
-- Returns:
-
init
public BaseLuceneStorage init() throws java.io.IOException
- Throws:
java.io.IOException
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
destroy
public void destroy()
-
getIndexWriter
protected org.apache.lucene.index.IndexWriter getIndexWriter()
-
getIndexSearcher
protected org.apache.lucene.search.IndexSearcher getIndexSearcher() throws java.io.IOException
- Throws:
java.io.IOException
-
buildQuery
protected org.apache.lucene.search.Query buildQuery(java.lang.String spaceId, java.lang.String key)
Build query to match entry's space-id and key.- Parameters:
spaceId
-key
-- Returns:
-
buildIdTerm
protected org.apache.lucene.index.Term buildIdTerm(java.lang.String spaceId, java.lang.String key)
Build the "id" term (id="spaceId:key"
- Parameters:
spaceId
-key
-- Returns:
-
createDocument
protected org.apache.lucene.document.Document createDocument(java.lang.String spaceId, java.lang.String key)
Create aDocument
, pre-filled with space-id and key fields.- Parameters:
spaceId
-key
-- Returns:
-
doDelete
protected void doDelete(java.lang.String spaceId, java.lang.String key, IDeleteCallback callback)
Delete a document, identified byspaceId:key
, from index.- Parameters:
spaceId
-key
-callback
-- Since:
- 1.0.0
-
doGet
protected org.apache.lucene.document.Document doGet(java.lang.String spaceId, java.lang.String key) throws java.io.IOException
Fetch a document, identified byspaceId:key
, from index.- Parameters:
spaceId
-key
-- Returns:
- Throws:
java.io.IOException
-
doCount
protected long doCount(java.lang.String spaceId) throws java.io.IOException
Count number of documents within a space.- Parameters:
spaceId
-- Returns:
- Throws:
java.io.IOException
-
-