提交 a78addfd authored 作者: noelgrandin's avatar noelgrandin

support drop index for Lucene full-text indices

上级 78a4f621
...@@ -49,6 +49,7 @@ Change Log ...@@ -49,6 +49,7 @@ Change Log
</li><li>Improved OSGi support. H2 now registers itself as a DataSourceFactory service. Fixes issue 365. </li><li>Improved OSGi support. H2 now registers itself as a DataSourceFactory service. Fixes issue 365.
</li><li>Add a DISK_SPACE_USED system function. Fixes issue 270. </li><li>Add a DISK_SPACE_USED system function. Fixes issue 270.
</li><li>Fix a compile-time ambiguity when compiling with JDK7, thanks to a patch from Lukas Eder. </li><li>Fix a compile-time ambiguity when compiling with JDK7, thanks to a patch from Lukas Eder.
</li><li>Supporting dropping an index for Lucene full-text indexes.
</li></ul> </li></ul>
<h2>Version 1.3.170 (2012-11-30)</h2> <h2>Version 1.3.170 (2012-11-30)</h2>
......
...@@ -1215,6 +1215,12 @@ This will produce a result set that contains the query needed to retrieve the da ...@@ -1215,6 +1215,12 @@ This will produce a result set that contains the query needed to retrieve the da
QUERY: "PUBLIC"."TEST" WHERE "ID"=1 QUERY: "PUBLIC"."TEST" WHERE "ID"=1
</pre> </pre>
<p> <p>
To drop an index on a table:
</p>
<pre>
CALL FT_DROP_INDEX('PUBLIC', 'TEST');
</pre>
<p>
To get the raw data, use <code>FT_SEARCH_DATA('Hello', 0, 0);</code>. To get the raw data, use <code>FT_SEARCH_DATA('Hello', 0, 0);</code>.
The result contains the columns <code>SCHEMA</code> (the schema name), The result contains the columns <code>SCHEMA</code> (the schema name),
<code>TABLE</code> (the table name), <code>TABLE</code> (the table name),
...@@ -1270,6 +1276,13 @@ This will produce a result set that contains the query needed to retrieve the da ...@@ -1270,6 +1276,13 @@ This will produce a result set that contains the query needed to retrieve the da
QUERY: "PUBLIC"."TEST" WHERE "ID"=1 QUERY: "PUBLIC"."TEST" WHERE "ID"=1
</pre> </pre>
<p> <p>
To drop an index on a table:
(be warned that this will re-index all of the full-text indices for the entire database)
</p>
<pre>
CALL FTL_DROP_INDEX('PUBLIC', 'TEST');
</pre>
<p>
To get the raw data, use <code>FTL_SEARCH_DATA('Hello', 0, 0);</code>. To get the raw data, use <code>FTL_SEARCH_DATA('Hello', 0, 0);</code>.
The result contains the columns <code>SCHEMA</code> (the schema name), The result contains the columns <code>SCHEMA</code> (the schema name),
<code>TABLE</code> (the table name), <code>TABLE</code> (the table name),
......
...@@ -106,6 +106,7 @@ public class FullTextLucene extends FullText { ...@@ -106,6 +106,7 @@ public class FullTextLucene extends FullText {
stat.execute("CREATE TABLE IF NOT EXISTS " + SCHEMA stat.execute("CREATE TABLE IF NOT EXISTS " + SCHEMA
+ ".INDEXES(SCHEMA VARCHAR, TABLE VARCHAR, COLUMNS VARCHAR, PRIMARY KEY(SCHEMA, TABLE))"); + ".INDEXES(SCHEMA VARCHAR, TABLE VARCHAR, COLUMNS VARCHAR, PRIMARY KEY(SCHEMA, TABLE))");
stat.execute("CREATE ALIAS IF NOT EXISTS FTL_CREATE_INDEX FOR \"" + FullTextLucene.class.getName() + ".createIndex\""); stat.execute("CREATE ALIAS IF NOT EXISTS FTL_CREATE_INDEX FOR \"" + FullTextLucene.class.getName() + ".createIndex\"");
stat.execute("CREATE ALIAS IF NOT EXISTS FTL_DROP_INDEX FOR \"" + FullTextLucene.class.getName() + ".dropIndex\"");
stat.execute("CREATE ALIAS IF NOT EXISTS FTL_SEARCH FOR \"" + FullTextLucene.class.getName() + ".search\""); stat.execute("CREATE ALIAS IF NOT EXISTS FTL_SEARCH FOR \"" + FullTextLucene.class.getName() + ".search\"");
stat.execute("CREATE ALIAS IF NOT EXISTS FTL_SEARCH_DATA FOR \"" + FullTextLucene.class.getName() + ".searchData\""); stat.execute("CREATE ALIAS IF NOT EXISTS FTL_SEARCH_DATA FOR \"" + FullTextLucene.class.getName() + ".searchData\"");
stat.execute("CREATE ALIAS IF NOT EXISTS FTL_REINDEX FOR \"" + FullTextLucene.class.getName() + ".reindex\""); stat.execute("CREATE ALIAS IF NOT EXISTS FTL_REINDEX FOR \"" + FullTextLucene.class.getName() + ".reindex\"");
...@@ -138,6 +139,29 @@ public class FullTextLucene extends FullText { ...@@ -138,6 +139,29 @@ public class FullTextLucene extends FullText {
indexExistingRows(conn, schema, table); indexExistingRows(conn, schema, table);
} }
/**
* Drop an existing full text index for a table. This method returns
* silently if no index for this table exists.
*
* @param conn the connection
* @param schema the schema name of the table (case sensitive)
* @param table the table name (case sensitive)
*/
public static void dropIndex(Connection conn, String schema, String table) throws SQLException {
init(conn);
PreparedStatement prep = conn.prepareStatement("DELETE FROM " + SCHEMA
+ ".INDEXES WHERE SCHEMA=? AND TABLE=?");
prep.setString(1, schema);
prep.setString(2, table);
int rowCount = prep.executeUpdate();
if (rowCount == 0) {
return;
}
reindex(conn);
}
/** /**
* Re-creates the full text index for this database. Calling this method is * Re-creates the full text index for this database. Calling this method is
* usually not needed, as the index is kept up-to-date automatically. * usually not needed, as the index is kept up-to-date automatically.
...@@ -233,9 +257,15 @@ public class FullTextLucene extends FullText { ...@@ -233,9 +257,15 @@ public class FullTextLucene extends FullText {
* @param table the table name * @param table the table name
*/ */
protected static void createTrigger(Connection conn, String schema, String table) throws SQLException { protected static void createTrigger(Connection conn, String schema, String table) throws SQLException {
createOrDropTrigger(conn, schema, table, true);
}
private static void createOrDropTrigger(Connection conn,
String schema, String table, boolean create) throws SQLException {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
String trigger = StringUtils.quoteIdentifier(schema) + "." + StringUtils.quoteIdentifier(TRIGGER_PREFIX + table); String trigger = StringUtils.quoteIdentifier(schema) + "." + StringUtils.quoteIdentifier(TRIGGER_PREFIX + table);
stat.execute("DROP TRIGGER IF EXISTS " + trigger); stat.execute("DROP TRIGGER IF EXISTS " + trigger);
if (create) {
StringBuilder buff = new StringBuilder("CREATE TRIGGER IF NOT EXISTS "); StringBuilder buff = new StringBuilder("CREATE TRIGGER IF NOT EXISTS ");
// the trigger is also called on rollback because transaction rollback // the trigger is also called on rollback because transaction rollback
// will not undo the changes in the Lucene index // will not undo the changes in the Lucene index
...@@ -249,6 +279,7 @@ public class FullTextLucene extends FullText { ...@@ -249,6 +279,7 @@ public class FullTextLucene extends FullText {
append('\"'); append('\"');
stat.execute(buff.toString()); stat.execute(buff.toString());
} }
}
/** /**
* Get the index writer/searcher wrapper for the given connection. * Get the index writer/searcher wrapper for the given connection.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论