更新H2和Lucene后如何进行全文搜索

时间:2019-05-26 19:19:41

标签: clojure lucene full-text-search h2

我几年前编写的程序使用LuceneH2 database中存储的文本进行全文搜索。我一直在尝试更新程序,以使用最新版本的H2和更高版本的Lucene。

这是一个说明问题的测试。它取自有关全文搜索here的H2教程。我已尝试使此测试尽可能接近原始示例,所以它不是很惯用。

(deftest ftl-setup-test
  (testing "The ability to setup and use full text search with the H2 database 1.4.198 and later")

  ;; Delete any pre-existing versions of the test database files and
  ;; directories. Then make sure the needed parent directories are present.
  (delete-parent (get-test-db-file-name))
  (make-parents (get-test-db-file-name))

  (let [db-spec (get-test-db-spec)]
    (jdbc/execute! db-spec ["CREATE ALIAS IF NOT EXISTS FTL_INIT FOR \"org.h2.fulltext.FullTextLucene.init\""])
    (jdbc/execute! db-spec ["CALL FTL_INIT()"])
    (jdbc/execute! db-spec ["DROP TABLE IF EXISTS TEST"])
    (jdbc/execute! db-spec ["CREATE TABLE TEST(ID INT PRIMARY KEY, FIRST_NAME VARCHAR, LAST_NAME VARCHAR)"])
    (jdbc/execute! db-spec ["CALL FTL_CREATE_INDEX('PUBLIC', 'TEST', NULL)"])
    (jdbc/execute! db-spec ["INSERT INTO TEST VALUES(1, 'John', 'Wayne')"])
    (jdbc/execute! db-spec ["INSERT INTO TEST VALUES(2, 'Elton', 'John')"])
    (is (= 2 (count (jdbc/query db-spec ["SELECT * FROM FTL_SEARCH_DATA('John', 0, 0)"]))))
    (is (= 1 (count (jdbc/query db-spec ["SELECT * FROM FTL_SEARCH_DATA('LAST_NAME:John', 0, 0)"]))))
    (jdbc/execute! db-spec ["CALL FTL_DROP_ALL()"])))

当使用H2版本1.4.197和Lucene版本3.6.2构建的程序运行测试时,将报告预期的输出:

$ lein test cwiki.test.models.h2-upgrade
...

Ran 1 tests containing 2 assertions.
0 failures, 0 errors.

当项目文件中的依赖项更改为H2版本1.4.198(或1.4.199)和Lucene版本7.7.1(或5.5.5)时,将产生错误,如以下编辑的堆栈跟踪中所示。

$ lein test cwiki.test.models.h2-upgrade
...
ERROR in (ftl-setup-test) (DbException.java:573)
Uncaught exception, not in assertion.
expected: nil
  actual: org.h2.jdbc.JdbcSQLSyntaxErrorException: Error creating or initializing trigger "FTL_TEST" object, class "org.h2.fulltext.FullTextLucene$FullTextTrigger", cause: "java.lang.reflect.InvocationTargetException"; see root cause for details; SQL statement:
CREATE TRIGGER IF NOT EXISTS "PUBLIC"."FTL_TEST" AFTER INSERT, UPDATE, DELETE, ROLLBACK ON "PUBLIC"."TEST" FOR EACH ROW CALL "org.h2.fulltext.FullTextLucene$FullTextTrigger" [90043-198]
 at org.h2.message.DbException.getJdbcSQLException (DbException.java:573)
 ...
 Caused by: java.lang.reflect.InvocationTargetException: null
 at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0 (NativeConstructorAccessorImpl.java:-2)
 ...
 Caused by: java.lang.NoSuchMethodError: org.apache.lucene.document.FieldType.<init>(Lorg/apache/lucene/document/FieldType;)V
 at org.h2.fulltext.FullTextLucene$FullTextTrigger.<init> (FullTextLucene.java:503)
 ...

Ran 1 tests containing 1 assertions.
0 failures, 1 errors.
Tests failed.

使用H2数据进行的其他单元测试在更新中可以正常工作。只是我程序的全文搜索部分没有。

我已经看过所提到的H2和Lucene类的源代码,但是我看不出问题所在。

这些测试是在Java 11.0.2上使用Clojure 1.10.0运行的。

那么,关于升级H2和Lucene之后如何重新进行全文搜索的任何想法?

0 个答案:

没有答案