【发布时间】:2018-12-07 06:52:06
【问题描述】:
我想在我的项目中使用 H2 数据库(嵌入式)实现小型全文搜索。据我所知,我必须将 Lucene 用于全文引擎来查找相关结果(不仅包含结果)。 但我不能使用它。这个块是Lucene启动:
FullTextLucene.init(connection);
FullTextLucene.createIndex(connection, "PUBLIC", Tables.COURSES_DETAIL, Columns.NAME);
我也是这样用的:
stmt.execute(
"create alias if not exists FTL_INIT for \"org.h2.fulltext.FullTextLucene.init\"");
stmt.execute("call FTL_INIT()");
stmt.execute(
String.format("CALL FTL_CREATE_INDEX('PUBLIC','%s',%s)", Tables.COURSES_DETAIL, "NULL"));
但是这个错误发生在运行时:
Error creating or initializing trigger "FTL_COURSES_DETAIL" object, class "org.h2.fulltext.FullTextLucene$FullTextTrigger", cause: "org.h2.message.DbException: Class ""org.h2.fulltext.FullTextLucene$FullTextTrigger"" not found [90086-197]"; see root cause for details; SQL statement:
CREATE TRIGGER IF NOT EXISTS "PUBLIC"."FTL_COURSES_DETAIL" AFTER INSERT, UPDATE, DELETE, ROLLBACK ON "PUBLIC"."COURSES_DETAIL" FOR EACH ROW CALL "org.h2.fulltext.FullTextLucene$FullTextTrigger"
在我将 H2 库降级到最新的“稳定”版本 (1.4.196) 后,错误已更改:
Caused by: java.lang.NoSuchMethodError: org.apache.lucene.store.FSDirectory.open(Ljava/io/File;)Lorg/apache/lucene/store/FSDirectory;
有时会出现这个错误:
Exception calling user-defined function: "init(conn1: url=jdbc:default:connection user=INFC): org.apache.lucene.store.FSDirectory.open(Ljava/io/File;)Lorg/apache/lucene/store/FSDirectory;"; SQL statement:
call FTL_INIT()
【问题讨论】: