Class LuceneKdStorage

  • All Implemented Interfaces:
    IKdStorage, java.io.Closeable, java.lang.AutoCloseable

    public class LuceneKdStorage
    extends BaseLuceneStorage
    implements IKdStorage
    Lucene implementation of {key:document} NoSQL storage.

    Design:

    • "document" is serialized to byte[] and stored in a field FIELD_DATA.
    • "document"'s scalar fields (string, number, boolean) are indexed in corresponding Lucene fields.

    Since:
    0.10.0
    Author:
    Thanh Nguyen
    • Constructor Detail

      • LuceneKdStorage

        public LuceneKdStorage()
    • Method Detail

      • delete

        public void delete​(java.lang.String spaceId,
                           java.lang.String key,
                           IDeleteCallback callback)
        Delete an existing entry from storage.
        Specified by:
        delete in interface IKdStorage
      • keyExists

        public boolean keyExists​(java.lang.String spaceId,
                                 java.lang.String key)
                          throws java.io.IOException
        Check if a key exists.
        Specified by:
        keyExists in interface IKdStorage
        Returns:
        Throws:
        java.io.IOException
      • get

        public java.util.Map<java.lang.String,​java.lang.Object> get​(java.lang.String spaceId,
                                                                          java.lang.String key)
                                                                   throws java.io.IOException
        Get/Load an entry by key.
        Specified by:
        get in interface IKdStorage
        Returns:
        Throws:
        java.io.IOException
      • get

        public <T> T get​(IKdEntryMapper<T> mapper,
                         java.lang.String spaceId,
                         java.lang.String key)
                  throws java.io.IOException
        Get/Load an entry by key.
        Specified by:
        get in interface IKdStorage
        Returns:
        Throws:
        java.io.IOException
      • put

        public void put​(java.lang.String spaceId,
                        java.lang.String key,
                        java.util.Map<java.lang.String,​java.lang.Object> doc,
                        IPutCallback<java.util.Map<java.lang.String,​java.lang.Object>> callback)
        Put/Store an entry.
        Specified by:
        put in interface IKdStorage
      • size

        public long size​(java.lang.String spaceId)
                  throws java.io.IOException
        Return number of entries.
        Specified by:
        size in interface IKdStorage
        Returns:
        number of entries currently in the storage, -1 if counting number entries is not supported
        Throws:
        java.io.IOException
      • bytesToDocument

        protected java.util.Map<java.lang.String,​java.lang.Object> bytesToDocument​(byte[] data)
        De-serialize byte array to "document".
        Parameters:
        data -
        Returns:
      • documentToBytes

        protected byte[] documentToBytes​(java.util.Map<java.lang.String,​java.lang.Object> doc)
        Serialize "document" to byte array.
        Parameters:
        doc -
        Returns:
      • createIndexField

        protected org.apache.lucene.document.Field createIndexField​(java.lang.String key,
                                                                    java.lang.Object value)
        Create index field for a document's field value.
        • Boolean: indexed as a IntPoint with value 1=true/0=false
        • Character: indexed as a StringField
        • Byte, Short, Integer, Long: indexed as a LongPoint
        • Float, Double: indexed as a DoublePoint
        • String: indexed as a StringField if value contains no space, TextField otherwise
        • Date: indexed as a StringField, Date is converted to String with format DATETIME_FORMAT.
        Parameters:
        key -
        value -
        Returns: