提交 560d0380 authored 作者: Thomas Mueller's avatar Thomas Mueller

Lucene 3.x support was added in the source code, however it is not yet enabled by default.

上级 55d3d9e1
......@@ -23,6 +23,11 @@ import org.h2.test.TestBase;
*/
public class TestFullText extends TestBase {
/**
* The words used in this test.
*/
static final String[] KNOWN_WORDS = { "skiing", "balance", "storage", "water", "train" };
/**
* Run just this test.
*
......@@ -38,7 +43,8 @@ public class TestFullText extends TestBase {
if (config.memory) {
return;
}
testMultiThreaded();
testMultiThreaded(true);
testMultiThreaded(false);
testStreamLob();
test(false, "VARCHAR");
test(false, "CLOB");
......@@ -79,6 +85,8 @@ public class TestFullText extends TestBase {
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)");
ResultSet rs = stat.executeQuery("SELECT * FROM " + prefix + "_SEARCH('Hello', 0, 0)");
assertTrue(rs.next());
stat.execute("UPDATE TEST SET NAME=NULL WHERE ID=1");
stat.execute("UPDATE TEST SET NAME='Hello World' WHERE ID=1");
conn.setAutoCommit(false);
......@@ -87,7 +95,7 @@ public class TestFullText extends TestBase {
conn.close();
conn = getConnection("fullTextTransaction");
stat = conn.createStatement();
ResultSet rs = stat.executeQuery("SELECT * FROM " + prefix + "_SEARCH('Hello', 0, 0)");
rs = stat.executeQuery("SELECT * FROM " + prefix + "_SEARCH('Hello', 0, 0)");
assertTrue(rs.next());
rs = stat.executeQuery("SELECT * FROM " + prefix + "_SEARCH('Moon', 0, 0)");
assertFalse(rs.next());
......@@ -97,7 +105,9 @@ public class TestFullText extends TestBase {
FileSystem.getInstance(getBaseDir()).deleteRecursive(getBaseDir() + "/fullTextTransaction", false);
}
private void testMultiThreaded() throws Exception {
private void testMultiThreaded(boolean lucene) throws Exception {
final String prefix = lucene ? "FTL" : "FT";
trace("Testing multithreaded " + prefix);
deleteDb("fullText");
final boolean[] stop = { false };
final Exception[] exception = { null };
......@@ -108,49 +118,67 @@ public class TestFullText extends TestBase {
// getConnection("fullText;MULTI_THREADED=1;LOCK_TIMEOUT=10000");
final Connection conn = getConnection("fullText");
Statement stat = conn.createStatement();
stat.execute("CREATE ALIAS IF NOT EXISTS FT_INIT FOR \"org.h2.fulltext.FullText.init\"");
stat.execute("CALL FT_INIT()");
stat.execute("CREATE ALIAS IF NOT EXISTS FT_INIT FOR \"org.h2.fulltext.FullText.init\"");
stat.execute("CALL FT_INIT()");
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 ALIAS IF NOT EXISTS " + prefix + "_INIT FOR \"org.h2.fulltext." + className + ".init\"");
stat.execute("CALL " + prefix + "_INIT()");
final String tableName = "TEST" + i;
stat.execute("CREATE TABLE " + tableName + "(ID INT PRIMARY KEY, DATA VARCHAR)");
FullText.createIndex(conn, "PUBLIC", tableName, null);
stat.execute("CALL " + prefix + "_CREATE_INDEX('PUBLIC', '" + tableName + "', NULL)");
threads[i] = new Thread() {
public void run() {
trace("starting thread " + Thread.currentThread());
try {
PreparedStatement prep = conn.prepareStatement("INSERT INTO " + tableName + " VALUES(?, ?)");
Statement stat = conn.createStatement();
Random random = new Random();
int x = 0;
while (!stop[0]) {
trace("stop[0] = " + stop[0] + " for " + Thread.currentThread());
StringBuilder buff = new StringBuilder();
for (int j = 0; j < 1000; j++) {
buff.append(" " + random.nextInt(10000));
buff.append(" x" + j);
buff.append(" ").append(random.nextInt(10000));
buff.append(" x").append(j);
buff.append(" ").append(KNOWN_WORDS[j % KNOWN_WORDS.length]);
}
prep.setInt(1, x);
prep.setString(2, buff.toString());
prep.execute();
x++;
for (String knownWord : KNOWN_WORDS) {
trace("searching for " + knownWord + " with " + Thread.currentThread());
ResultSet rs = stat.executeQuery("SELECT * FROM " + prefix + "_SEARCH('" + knownWord + "', 0, 0)");
assertTrue(rs.next());
}
}
trace("closing connection");
conn.close();
} catch (SQLException e) {
exception[0] = e;
} finally {
trace("completed thread " + Thread.currentThread());
}
}
};
}
for (Thread t : threads) {
t.setDaemon(true);
t.start();
}
trace("sleeping");
Thread.sleep(1000);
trace("setting stop to true");
stop[0] = true;
for (Thread t : threads) {
trace("joining " + t);
t.join();
trace("done joining " + t);
}
if (exception[0] != null) {
throw exception[0];
}
}
private void testStreamLob() throws SQLException {
......@@ -374,8 +402,6 @@ public class TestFullText extends TestBase {
stat = conn.createStatement();
rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('World', 0, 0)");
stat.execute("CALL " + prefix + "DROP_ALL()");
stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('World', 2, 1)");
stat.execute("CALL " + prefix + "DROP_ALL()");
conn.close();
......
......@@ -105,7 +105,7 @@ public class Build extends BuildBase {
File.pathSeparator + "ext/emma-2.0.5312.jar" +
File.pathSeparator + "ext/postgresql-8.3-603.jdbc3.jar" +
File.pathSeparator + "ext/servlet-api-2.4.jar" +
File.pathSeparator + "ext/lucene-core-2.2.0.jar" +
File.pathSeparator + "ext/" + getLuceneJar() +
File.pathSeparator + "ext/org.osgi.core-1.2.0.jar" +
File.pathSeparator + "ext/slf4j-api-1.5.0.jar";
exec("java", args("-Xmx128m", "-cp", cp, "emma", "run",
......@@ -127,6 +127,9 @@ public class Build extends BuildBase {
} else {
SwitchSource.main("-dir", "src", "-version", version);
}
if (System.getProperty("lucene") != null) {
SwitchSource.main("-dir", "src", "-LUCENE2", "-LUCENE3", "+LUCENE" + getLuceneVersion());
}
} catch (IOException e) {
throw new RuntimeException(e);
}
......@@ -139,7 +142,7 @@ public class Build extends BuildBase {
download();
String classpath = "temp" +
File.pathSeparator + "ext/servlet-api-2.4.jar" +
File.pathSeparator + "ext/lucene-core-2.2.0.jar" +
File.pathSeparator + "ext/" + getLuceneJar() +
File.pathSeparator + "ext/slf4j-api-1.5.0.jar" +
File.pathSeparator + "ext/org.osgi.core-1.2.0.jar" +
File.pathSeparator + System.getProperty("java.home") + "/../lib/tools.jar";
......@@ -218,9 +221,15 @@ public class Build extends BuildBase {
download("ext/servlet-api-2.4.jar",
"http://repo1.maven.org/maven2/javax/servlet/servlet-api/2.4/servlet-api-2.4.jar",
"3fc542fe8bb8164e8d3e840fe7403bc0518053c0");
download("ext/lucene-core-2.2.0.jar",
"http://repo1.maven.org/maven2/org/apache/lucene/lucene-core/2.2.0/lucene-core-2.2.0.jar",
"47b6eee2e17bd68911e7045896a1c09de0b2dda8");
if (getLuceneVersion() == 3) {
download("ext/lucene-core-3.0.2.jar",
"http://repo1.maven.org/maven2/org/apache/lucene/lucene-core/3.0.2/lucene-core-3.0.2.jar",
"c2b48995ab855c1b9ea13867a0f976c994e0105d");
} else {
download("ext/lucene-core-2.2.0.jar",
"http://repo1.maven.org/maven2/org/apache/lucene/lucene-core/2.2.0/lucene-core-2.2.0.jar",
"47b6eee2e17bd68911e7045896a1c09de0b2dda8");
}
download("ext/slf4j-api-1.5.0.jar",
"http://repo1.maven.org/maven2/org/slf4j/slf4j-api/1.5.0/slf4j-api-1.5.0.jar",
"b2df265d02350ecfe87b6c1773c7c4fab2b33505");
......@@ -240,6 +249,14 @@ public class Build extends BuildBase {
return getStaticValue("org.h2.engine.Constants", "getVersion");
}
private String getLuceneJar() {
return "lucene-core-" + (getLuceneVersion() == 2 ? "2.2.0" : "3.0.2") + ".jar";
}
private int getLuceneVersion() {
return Integer.parseInt(System.getProperty("lucene", "2"));
}
private String getJarSuffix() {
return "-" + getVersion() + ".jar";
}
......@@ -382,7 +399,7 @@ public class Build extends BuildBase {
mkdir("docs/javadoc");
javadoc("-sourcepath", "src/main", "org.h2.jdbc", "org.h2.jdbcx",
"org.h2.tools", "org.h2.api", "org.h2.constant", "org.h2.fulltext",
"-classpath", "ext/lucene-core-2.2.0.jar",
"-classpath", "ext/" + getLuceneJar(),
"-docletpath", "bin" + File.pathSeparator + "temp",
"-doclet", "org.h2.build.doclet.Doclet");
copy("docs/javadoc", files("src/docsrc/javadoc"), "src/docsrc/javadoc");
......@@ -402,7 +419,7 @@ public class Build extends BuildBase {
"/../lib/tools.jar" +
File.pathSeparator + "ext/slf4j-api-1.5.0.jar" +
File.pathSeparator + "ext/servlet-api-2.4.jar" +
File.pathSeparator + "ext/lucene-core-2.2.0.jar" +
File.pathSeparator + "ext/" + getLuceneJar() +
File.pathSeparator + "ext/org.osgi.core-1.2.0.jar",
"-subpackages", "org.h2",
"-exclude", "org.h2.test.jaqu:org.h2.jaqu");
......@@ -412,7 +429,7 @@ public class Build extends BuildBase {
"-classpath", System.getProperty("java.home") + "/../lib/tools.jar" +
File.pathSeparator + "ext/slf4j-api-1.5.0.jar" +
File.pathSeparator + "ext/servlet-api-2.4.jar" +
File.pathSeparator + "ext/lucene-core-2.2.0.jar" +
File.pathSeparator + "ext/" + getLuceneJar() +
File.pathSeparator + "ext/org.osgi.core-1.2.0.jar",
"-subpackages", "org.h2",
"-exclude", "org.h2.test.jaqu:org.h2.jaqu",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论