我想在我的项目中实现一个使用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()
我找到了一个解决方案。但我知道这不是最好的一个。
我将Lucene lib降级为3.6.2,并使用普通查询而不是FullTextLucene
函数。