## org.h2.fulltext
Class FullTextLucene

    java.lang.Object
      org.h2.fulltext.FullText
          org.h2.fulltext.FullTextLucene

    public class FullTextLucene

extends FullText

This class implements the full text search based on Apache Lucene. Most methods can be called using SQL statements as well.

Nested Class Summary
`static class` `FullTextLucene.FullTextTrigger` Trigger updates the index when a inserting, updating, or deleting a row.

Field Summary
`protected static boolean` `STORE_DOCUMENT_TEXT_IN_INDEX` Whether the text content should be stored in the Lucene index.

Fields inherited from class org.h2.fulltext.FullText
`FIELD_COLUMNS, FIELD_KEYS, FIELD_QUERY, FIELD_SCHEMA, FIELD_SCORE, FIELD_TABLE`

Constructor Summary
`FullTextLucene()`

Method Summary
`protected static java.sql.SQLException` `convertException(java.lang.Exception e)` Convert an exception to a fulltext exception.
`static void` `createIndex(java.sql.Connection conn, java.lang.String schema, java.lang.String table, java.lang.String columnList)` Create a new full text index for a table and column list.
`protected static void` `createTrigger(java.sql.Connection conn, java.lang.String schema, java.lang.String table)` Create the trigger.
`static void` `dropAll(java.sql.Connection conn)` Drops all full text indexes from the database.
`protected static org.apache.lucene.index.IndexModifier` `getIndexModifier(java.sql.Connection conn)` Get the index modifier for the given connection.
`protected static java.lang.String` `getIndexPath(java.sql.Connection conn)` Get the path of the Lucene index for this database.
`protected static void` `indexExistingRows(java.sql.Connection conn, java.lang.String schema, java.lang.String table)` Add the existing data to the index.
`static void` `init(java.sql.Connection conn)` Initializes full text search functionality for this database.
`static void` `reindex(java.sql.Connection conn)` Re-creates the full text index for this database.
`protected static void` `removeIndexModifier(org.apache.lucene.index.IndexModifier indexModifier, java.lang.String indexPath)` Close the index modifier and remove it from the index modifier set.
`static java.sql.ResultSet` `search(java.sql.Connection conn, java.lang.String text, int limit, int offset)` Searches from the full text index for this database.
`protected static java.sql.ResultSet` `search(java.sql.Connection conn, java.lang.String text, int limit, int offset, boolean data)` Do the search.
`static java.sql.ResultSet` `searchData(java.sql.Connection conn, java.lang.String text, int limit, int offset)` Searches from the full text index for this database.

Methods inherited from class org.h2.fulltext.FullText
`addWords, addWords, asString, createResultSet, dropIndex, hasChanged, parseKey, quoteSQL, removeAllTriggers, setColumns, setIgnoreList`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### STORE_DOCUMENT_TEXT_IN_INDEX

    protected static final boolean STORE_DOCUMENT_TEXT_IN_INDEX

  Whether the text content should be stored in the Lucene index.

Constructor Detail

### FullTextLucene

    public FullTextLucene()

Method Detail

### init

    public static void init(java.sql.Connection conn)
                     throws java.sql.SQLException

  Initializes full text search functionality for this database. This adds the following Java functions to the database:
  - FTL_CREATE_INDEX(schemaNameString, tableNameString, columnListString)
  - FTL_SEARCH(queryString, limitInt, offsetInt): result set
  - FTL_REINDEX()
  - FTL_DROP_ALL()
  It also adds a schema FTL to the database where bookkeeping information is stored. This function may be called from a Java application, or by using the SQL statements:

       CREATE ALIAS IF NOT EXISTS FTL_INIT FOR
            "org.h2.fulltext.FullTextLucene.init";
       CALL FTL_INIT();

  Parameters:
    `conn` - the connection
  Throws:
    `java.sql.SQLException`

### createIndex

    public static void createIndex(java.sql.Connection conn,
                                   java.lang.String schema,
                                   java.lang.String table,
                                   java.lang.String columnList)
                            throws java.sql.SQLException

  Create a new full text index for a table and column list. Each table may only have one index at any time.

  Parameters:
    `conn` - the connection
    `schema` - the schema name of the table (case sensitive)
    `table` - the table name (case sensitive)
    `columnList` - the column list (null for all columns)
  Throws:
    `java.sql.SQLException`

### reindex

    public static void reindex(java.sql.Connection conn)
                        throws java.sql.SQLException

  Re-creates the full text index for this database.

  Parameters:
    `conn` - the connection
  Throws:
    `java.sql.SQLException`

### dropAll

    public static void dropAll(java.sql.Connection conn)
                        throws java.sql.SQLException

  Drops all full text indexes from the database.

  Parameters:
    `conn` - the connection
  Throws:
    `java.sql.SQLException`

### search

    public static java.sql.ResultSet search(java.sql.Connection conn,
                                            java.lang.String text,
                                            int limit,
                                            int offset)
                                     throws java.sql.SQLException

  Searches from the full text index for this database. The returned result set has the following column:
  - QUERY (varchar): the query to use to get the data. The query does not include 'SELECT * FROM '. Example: PUBLIC.TEST WHERE ID = 1
  - SCORE (float) the relevance score as returned by Lucene.

  Parameters:
    `conn` - the connection
    `text` - the search query
    `limit` - the maximum number of rows or 0 for no limit
    `offset` - the offset or 0 for no offset
  Returns:
    the result set
  Throws:
    `java.sql.SQLException`

### searchData

    public static java.sql.ResultSet searchData(java.sql.Connection conn,
                                                java.lang.String text,
                                                int limit,
                                                int offset)
                                         throws java.sql.SQLException

  Searches from the full text index for this database. The result contains the primary key data as an array. The returned result set has the following columns:
  - SCHEMA (varchar): the schema name. Example: PUBLIC
  - TABLE (varchar): the table name. Example: TEST
  - COLUMNS (array of varchar): comma separated list of quoted column names. The column names are quoted if necessary. Example: (ID)
  - KEYS (array of values): comma separated list of values. Example: (1)
  - SCORE (float) the relevance score as returned by Lucene.

  Parameters:
    `conn` - the connection
    `text` - the search query
    `limit` - the maximum number of rows or 0 for no limit
    `offset` - the offset or 0 for no offset
  Returns:
    the result set
  Throws:
    `java.sql.SQLException`

### convertException

    protected static java.sql.SQLException convertException(java.lang.Exception e)

  Convert an exception to a fulltext exception.

  Parameters:
    `e` - the original exception
  Returns:
    the converted SQL exception

### createTrigger

    protected static void createTrigger(java.sql.Connection conn,
                                        java.lang.String schema,
                                        java.lang.String table)
                                 throws java.sql.SQLException

  Create the trigger.

  Parameters:
    `conn` - the database connection
    `schema` - the schema name
    `table` - the table name
  Throws:
    `java.sql.SQLException`

### getIndexModifier

    protected static org.apache.lucene.index.IndexModifier getIndexModifier(java.sql.Connection conn)
                                                                     throws java.sql.SQLException

  Get the index modifier for the given connection.

  Parameters:
    `conn` - the connection
  Returns:
    the index modifier
  Throws:
    `java.sql.SQLException`

### getIndexPath

    protected static java.lang.String getIndexPath(java.sql.Connection conn)
                                            throws java.sql.SQLException

  Get the path of the Lucene index for this database.

  Parameters:
    `conn` - the database connection
  Returns:
    the path
  Throws:
    `java.sql.SQLException`

### indexExistingRows

    protected static void indexExistingRows(java.sql.Connection conn,
                                            java.lang.String schema,
                                            java.lang.String table)
                                     throws java.sql.SQLException

  Add the existing data to the index.

  Parameters:
    `conn` - the database connection
    `schema` - the schema name
    `table` - the table name
  Throws:
    `java.sql.SQLException`

### removeIndexModifier

    protected static void removeIndexModifier(org.apache.lucene.index.IndexModifier indexModifier,
                                              java.lang.String indexPath)
                                       throws java.sql.SQLException

  Close the index modifier and remove it from the index modifier set.

  Parameters:
    `indexModifier` - the index modifier
    `indexPath` - the index path
  Throws:
    `java.sql.SQLException`

### search

    protected static java.sql.ResultSet search(java.sql.Connection conn,
                                               java.lang.String text,
                                               int limit,
                                               int offset,
                                               boolean data)
                                        throws java.sql.SQLException

  Do the search.

  Parameters:
    `conn` - the database connection
    `text` - the query
    `limit` - the limit
    `offset` - the offset
    `data` - whether the raw data should be returned
  Returns:
    the result set
  Throws:
    `java.sql.SQLException`