提交 ace817f4 authored 作者: Thomas Mueller's avatar Thomas Mueller

Lucene fulltext index

上级 2e9d60d5
......@@ -16,7 +16,9 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>The character '$' could not be used in identifier names (table name,
<ul><li>The Lucene fulltext index was empty when opening a database with fulltext
index enabled, and re-indexing it didn't work. Fixed.
</li><li>The character '$' could not be used in identifier names (table name,
column names and so on). Fixed.
</li><li>The new method org.h2.tools.Server.startWebServer(conn) starts the H2 Console
to inspect a database while debugging.
......
......@@ -285,7 +285,7 @@ http://groups.google.com/group/h2-database/web/roadmap
</tr><tr>
<td>Updatable Result Sets</td>
<td class="compareY">Yes</td>
<td class="compareY">Yes</td>
<td class="compareY">Yes *7</td>
<td class="compareN">No</td>
<td class="compareY">Yes</td>
<td class="compareY">Yes</td>
......@@ -346,7 +346,8 @@ http://groups.google.com/group/h2-database/web/roadmap
*3 Derby support for roles based security and password checking as an option.<br />
*4 Derby only supports global temporary tables.<br />
*5 The default H2 jar file contains debug information, jar files for other databases do not.<br />
*6 PostgreSQL supports functional indexes.
*6 PostgreSQL supports functional indexes.<br />
*7 Derby only supports updatable result sets if the query is not sorted.
</p>
<h3>Derby and HSQLDB</h3>
......
......@@ -98,7 +98,8 @@ spread the word and have translated this project. Also many thanks to the donors
via PayPal:
</p>
<ul>
<li>Florent Ramiere, France
<li>Ashwin Jayaprakash, USA
</li><li>Florent Ramiere, France
</li><li>Jun Iyama, Japan
</li><li>Antonio Casqueiro, Portugal
</li><li>Oliver Computing LLC, USA
......
......@@ -161,10 +161,8 @@ implements Trigger, CloseListener
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_DROP_ALL FOR \"" + FullTextLucene.class.getName() + ".dropAll\"");
String path = getIndexPath(conn);
IndexModifier indexer = openIndexModifier(path, true);
try {
indexer.close();
getIndexModifier(conn);
} catch (Exception e) {
throw convertException(e);
}
......@@ -583,23 +581,19 @@ implements Trigger, CloseListener
synchronized (indexers) {
indexer = (IndexModifier) indexers.get(path);
if (indexer == null) {
boolean recreate = !IndexReader.indexExists(path);
indexer = openIndexModifier(path, recreate);
try {
boolean recreate = !IndexReader.indexExists(path);
Analyzer analyzer = new StandardAnalyzer();
indexer = new IndexModifier(path, analyzer, recreate);
} catch (IOException e) {
throw convertException(e);
}
indexers.put(path, indexer);
}
}
return indexer;
}
private static IndexModifier openIndexModifier(String path, boolean recreate) throws SQLException {
try {
Analyzer analyzer = new StandardAnalyzer();
return new IndexModifier(path, analyzer, recreate);
} catch (IOException e) {
throw convertException(e);
}
}
private static String getIndexPath(Connection conn) throws SQLException {
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("CALL DATABASE_PATH()");
......
......@@ -269,6 +269,8 @@ java org.h2.test.TestAll timer
/*
document FTL_SEARCH, FTL_SEARCH_DATA
JaQu
row level locking
......
......@@ -12,6 +12,7 @@ import java.sql.ResultSet;
import java.sql.Statement;
import java.util.StringTokenizer;
import org.h2.store.fs.FileSystem;
import org.h2.test.TestBase;
/**
......@@ -26,12 +27,14 @@ public class TestFullText extends TestBase {
test(false, "VARCHAR");
test(false, "CLOB");
testPerformance(false);
testReopen(false);
String luceneFullTextClassName = "org.h2.fulltext.FullTextLucene";
try {
Class.forName(luceneFullTextClassName);
test(true, "VARCHAR");
test(true, "CLOB");
testPerformance(true);
testReopen(true);
} catch (ClassNotFoundException e) {
println("Class not found, not tested: " + luceneFullTextClassName);
// ok
......@@ -41,9 +44,31 @@ public class TestFullText extends TestBase {
}
}
private void testReopen(boolean lucene) throws Exception {
String prefix = lucene ? "FTL" : "FT";
deleteDb("fullTextReopen");
FileSystem.getInstance(baseDir).deleteRecursive(baseDir + "/fullTextReopen");
Connection conn = getConnection("fullTextReopen");
Statement stat = conn.createStatement();
String className = lucene ? "FullTextLucene" : "FullText";
stat.execute("CREATE ALIAS IF NOT EXISTS " + prefix + "_INIT FOR \"org.h2.fulltext." + className + ".init\"");
stat.execute("CALL " + prefix + "_INIT()");
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)");
stat.execute("INSERT INTO TEST VALUES(1, 'Hello World')");
stat.execute("CALL " + prefix + "_CREATE_INDEX('PUBLIC', 'TEST', NULL)");
conn.close();
conn = getConnection("fullTextReopen");
stat = conn.createStatement();
ResultSet rs = stat.executeQuery("SELECT * FROM " + prefix + "_SEARCH('Hello', 0, 0)");
assertTrue(rs.next());
conn.close();
}
private void testPerformance(boolean lucene) throws Exception {
deleteDb("fullText");
FileSystem.getInstance(baseDir).deleteRecursive(baseDir + "/fullText");
Connection conn = getConnection("fullText");
String prefix = lucene ? "FTL" : "FT";
Statement stat = conn.createStatement();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论