org.h2.fulltext
Class FullText

java.lang.Object
  extended by org.h2.fulltext.FullText
Direct Known Subclasses:
FullTextLucene

public class FullText
extends java.lang.Object

This class implements the native full text search. Most methods can be called using SQL statements as well.


Nested Class Summary
static class FullText.FullTextTrigger
          Trigger updates the index when a inserting, updating, or deleting a row.
 
Constructor Summary
FullText()
           
 
Method Summary
protected static java.lang.String asString(java.lang.Object data, int type)
          INTERNAL.
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 SimpleResultSet createResultSet(boolean data)
          Create an empty search result and initialize the columns.
static void dropAll(java.sql.Connection conn)
          Drops all full text indexes from the database.
static void dropIndex(java.sql.Connection conn, java.lang.String schema, java.lang.String table)
          Drop an existing full text index for a table.
static void init(java.sql.Connection conn)
          Initializes full text search functionality for this database.
protected static java.lang.Object[][] parseKey(java.sql.Connection conn, java.lang.String key)
          Parse a primary key condition into the primary key columns.
protected static java.lang.String quoteSQL(java.lang.Object data, int type)
          INTERNAL.
static void reindex(java.sql.Connection conn)
          Re-creates the full text index for this database
protected static void removeAllTriggers(java.sql.Connection conn, java.lang.String prefix)
          Remove all triggers that start with the given prefix.
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.
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.
protected static void setColumns(int[] index, java.util.ArrayList<java.lang.String> keys, java.util.ArrayList<java.lang.String> columns)
          Set the column indices of a set of keys.
static void setIgnoreList(java.sql.Connection conn, java.lang.String commaSeparatedList)
          Change the ignore list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FullText

public FullText()
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: It also adds a schema FT 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 FT_INIT FOR
      "org.h2.fulltext.FullText.init";
 CALL FT_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

dropIndex

public static void dropIndex(java.sql.Connection conn,
                             java.lang.String schema,
                             java.lang.String table)
                      throws java.sql.SQLException
Drop an existing full text index for a table. This method returns silently if no index for this table exists.

Parameters:
conn - the connection
schema - the schema name of the table (case sensitive)
table - the table name (case sensitive)
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:

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:

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

setIgnoreList

public static void setIgnoreList(java.sql.Connection conn,
                                 java.lang.String commaSeparatedList)
                          throws java.sql.SQLException
Change the ignore list. The ignore list is a comma separated list of common words that must not be indexed. The default ignore list is empty. If indexes already exist at the time this list is changed, reindex must be called.

Parameters:
conn - the connection
commaSeparatedList - the list
Throws:
java.sql.SQLException

asString

protected static java.lang.String asString(java.lang.Object data,
                                           int type)
                                    throws java.sql.SQLException
INTERNAL. Convert the object to a string.

Parameters:
data - the object
type - the SQL type
Returns:
the string
Throws:
java.sql.SQLException

createResultSet

protected static SimpleResultSet createResultSet(boolean data)
                                          throws java.sql.SQLException
Create an empty search result and initialize the columns.

Parameters:
data - true if the result set should contain the primary key data as an array.
Returns:
the empty result set
Throws:
java.sql.SQLException

parseKey

protected static java.lang.Object[][] parseKey(java.sql.Connection conn,
                                               java.lang.String key)
                                        throws java.sql.SQLException
Parse a primary key condition into the primary key columns.

Parameters:
conn - the database connection
key - the primary key condition as a string
Returns:
an array containing the column name list and the data list
Throws:
java.sql.SQLException

quoteSQL

protected static java.lang.String quoteSQL(java.lang.Object data,
                                           int type)
                                    throws java.sql.SQLException
INTERNAL. Convert an object to a String as used in a SQL statement.

Parameters:
data - the object
type - the SQL type
Returns:
the SQL String
Throws:
java.sql.SQLException

removeAllTriggers

protected static void removeAllTriggers(java.sql.Connection conn,
                                        java.lang.String prefix)
                                 throws java.sql.SQLException
Remove all triggers that start with the given prefix.

Parameters:
conn - the database connection
prefix - the prefix
Throws:
java.sql.SQLException

setColumns

protected static void setColumns(int[] index,
                                 java.util.ArrayList<java.lang.String> keys,
                                 java.util.ArrayList<java.lang.String> columns)
                          throws java.sql.SQLException
Set the column indices of a set of keys.

Parameters:
index - the column indices (will be modified)
keys - the key list
columns - the column list
Throws:
java.sql.SQLException