Class FullTextSettings


  • final class FullTextSettings
    extends java.lang.Object
    The global settings of a full text search.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.WeakHashMap<java.sql.Connection,​SoftValuesHashMap<java.lang.String,​java.sql.PreparedStatement>> cache
      The prepared statement cache.
      private java.util.HashSet<java.lang.String> ignoreList
      The set of words not to index (stop words).
      private java.util.concurrent.ConcurrentHashMap<java.lang.Integer,​IndexInfo> indexes
      The set of indexes in this database.
      private boolean initialized
      Whether this instance has been initialized.
      private static java.util.HashMap<java.lang.String,​FullTextSettings> SETTINGS
      The settings of open indexes.
      private java.lang.String whitespaceChars
      The whitespace characters.
      private java.util.HashMap<java.lang.String,​java.lang.Integer> words
      The set of words / terms.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private FullTextSettings()
      Create a new instance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addIgnored​(java.lang.Iterable<java.lang.String> words)
      Amend set of ignored words
      (package private) void addIndexInfo​(IndexInfo index)
      Add an index.
      void addWord​(java.lang.String word, java.lang.Integer id)
      Register searchable word
      void clearIgnored()
      Clear set of ignored words
      void clearWordList()
      Clear set of searchable words
      protected static void closeAll()
      Close all fulltext settings, freeing up memory.
      (package private) java.lang.String convertWord​(java.lang.String word)
      Convert a word to uppercase.
      (package private) IndexInfo getIndexInfo​(int indexId)
      Get the index information for the given index id.
      private static java.lang.String getIndexPath​(java.sql.Connection conn)
      Get the file system path.
      (package private) static FullTextSettings getInstance​(java.sql.Connection conn)
      Get or create the fulltext settings for this database.
      protected java.lang.String getWhitespaceChars()  
      java.lang.Integer getWordId​(java.lang.String word)
      Get id for a searchable word
      protected boolean isInitialized()
      Get the initialized flag.
      private static java.lang.String normalizeWord​(java.lang.String word)  
      (package private) java.sql.PreparedStatement prepare​(java.sql.Connection conn, java.lang.String sql)
      Prepare a statement.
      protected void removeAllIndexes()
      Remove all indexes from the settings.
      protected void removeIndexInfo​(IndexInfo index)
      Remove an index from the settings.
      protected void setInitialized​(boolean b)
      Set the initialized flag.
      protected void setWhitespaceChars​(java.lang.String whitespaceChars)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • SETTINGS

        private static final java.util.HashMap<java.lang.String,​FullTextSettings> SETTINGS
        The settings of open indexes.
      • initialized

        private boolean initialized
        Whether this instance has been initialized.
      • ignoreList

        private final java.util.HashSet<java.lang.String> ignoreList
        The set of words not to index (stop words).
      • words

        private final java.util.HashMap<java.lang.String,​java.lang.Integer> words
        The set of words / terms.
      • indexes

        private final java.util.concurrent.ConcurrentHashMap<java.lang.Integer,​IndexInfo> indexes
        The set of indexes in this database.
      • cache

        private final java.util.WeakHashMap<java.sql.Connection,​SoftValuesHashMap<java.lang.String,​java.sql.PreparedStatement>> cache
        The prepared statement cache.
      • whitespaceChars

        private java.lang.String whitespaceChars
        The whitespace characters.
    • Constructor Detail

      • FullTextSettings

        private FullTextSettings()
        Create a new instance.
    • Method Detail

      • clearIgnored

        public void clearIgnored()
        Clear set of ignored words
      • addIgnored

        public void addIgnored​(java.lang.Iterable<java.lang.String> words)
        Amend set of ignored words
        Parameters:
        words - to add
      • clearWordList

        public void clearWordList()
        Clear set of searchable words
      • getWordId

        public java.lang.Integer getWordId​(java.lang.String word)
        Get id for a searchable word
        Parameters:
        word - to find id for
        Returns:
        Integer id or null if word is not found
      • addWord

        public void addWord​(java.lang.String word,
                            java.lang.Integer id)
        Register searchable word
        Parameters:
        word - to register
        id - to register with
      • getIndexInfo

        IndexInfo getIndexInfo​(int indexId)
        Get the index information for the given index id.
        Parameters:
        indexId - the index id
        Returns:
        the index info
      • addIndexInfo

        void addIndexInfo​(IndexInfo index)
        Add an index.
        Parameters:
        index - the index
      • convertWord

        java.lang.String convertWord​(java.lang.String word)
        Convert a word to uppercase. This method returns null if the word is in the ignore list.
        Parameters:
        word - the word to convert and check
        Returns:
        the uppercase version of the word or null
      • getInstance

        static FullTextSettings getInstance​(java.sql.Connection conn)
                                     throws java.sql.SQLException
        Get or create the fulltext settings for this database.
        Parameters:
        conn - the connection
        Returns:
        the settings
        Throws:
        java.sql.SQLException - on failure
      • getIndexPath

        private static java.lang.String getIndexPath​(java.sql.Connection conn)
                                              throws java.sql.SQLException
        Get the file system path.
        Parameters:
        conn - the connection
        Returns:
        the file system path
        Throws:
        java.sql.SQLException
      • prepare

        java.sql.PreparedStatement prepare​(java.sql.Connection conn,
                                           java.lang.String sql)
                                    throws java.sql.SQLException
        Prepare a statement. The statement is cached in a soft reference cache.
        Parameters:
        conn - the connection
        sql - the statement
        Returns:
        the prepared statement
        Throws:
        java.sql.SQLException - on failure
      • removeAllIndexes

        protected void removeAllIndexes()
        Remove all indexes from the settings.
      • removeIndexInfo

        protected void removeIndexInfo​(IndexInfo index)
        Remove an index from the settings.
        Parameters:
        index - the index to remove
      • setInitialized

        protected void setInitialized​(boolean b)
        Set the initialized flag.
        Parameters:
        b - the new value
      • isInitialized

        protected boolean isInitialized()
        Get the initialized flag.
        Returns:
        whether this instance is initialized
      • closeAll

        protected static void closeAll()
        Close all fulltext settings, freeing up memory.
      • setWhitespaceChars

        protected void setWhitespaceChars​(java.lang.String whitespaceChars)
      • getWhitespaceChars

        protected java.lang.String getWhitespaceChars()
      • normalizeWord

        private static java.lang.String normalizeWord​(java.lang.String word)