如何在java中使用H2数据库的全文检索功能?

发布于 2024-11-19 07:20:00 字数 133 浏览 2 评论 0原文

请任何人解释一下如何在java程序的帮助下使用H2嵌入式数据库的全文搜索。

执行“SELECT * FROM FT_SEARCH_DATA('word', 0, 0)”将返回一个选择查询字符串。我是否需要再次执行此操作才能获得最终结果?

Anybody please explain how to use the Full-Text search for H2 Embedded Database with the help of java program.

executing "SELECT * FROM FT_SEARCH_DATA('word', 0, 0)" is returning a select query string. Do i need to execute this one again to get the final result?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

镜花水月 2024-11-26 07:20:00

使用 H2 全文索引的 Java 程序是 单元测试程序。那里的一个例子:

    Connection conn = ...
    Statement stat = conn.createStatement();
    stat.execute("CREATE ALIAS IF NOT EXISTS FT_INIT FOR \"org.h2.fulltext.FullText.init\"");
    stat.execute("CALL FT_INIT()");
    FullText.setIgnoreList(conn, "to,this");
    FullText.setWhitespaceChars(conn, " ,.-");
    stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)");
    stat.execute("INSERT INTO TEST VALUES(1, 'Welcome to this world, One_Word')");
    stat.execute("CALL FT_CREATE_INDEX('PUBLIC', 'TEST', NULL)");
    ResultSet rs;
    rs = stat.executeQuery("SELECT * FROM FT_SEARCH('Welcome', 0, 0)");
    assertTrue(rs.next());
    assertEquals("QUERY", rs.getMetaData().getColumnLabel(1));
    assertEquals("SCORE", rs.getMetaData().getColumnLabel(2));
    assertEquals("\"PUBLIC\".\"TEST\" WHERE \"ID\"=1", rs.getString(1));
    assertEquals("1.0", rs.getString(2));
    rs = stat.executeQuery("SELECT * FROM FT_SEARCH_DATA('One', 0, 0)");
    assertFalse(rs.next());
    rs = stat.executeQuery("SELECT * FROM FT_SEARCH_DATA('One_Word', 0, 0)");
    assertTrue(rs.next());
    rs = stat.executeQuery("SELECT * FROM FT_SEARCH_DATA('Welcome', 0, 0)");
    assertTrue(rs.next());

还有一个 SQL 脚本示例。也许您对 FullText 类的 Javadocs 感兴趣 - 这将解释 FT_SEARCH_DATA / searchData 返回的内容。

A Java program that uses the H2 fulltext index is the unit test program. An example from there:

    Connection conn = ...
    Statement stat = conn.createStatement();
    stat.execute("CREATE ALIAS IF NOT EXISTS FT_INIT FOR \"org.h2.fulltext.FullText.init\"");
    stat.execute("CALL FT_INIT()");
    FullText.setIgnoreList(conn, "to,this");
    FullText.setWhitespaceChars(conn, " ,.-");
    stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)");
    stat.execute("INSERT INTO TEST VALUES(1, 'Welcome to this world, One_Word')");
    stat.execute("CALL FT_CREATE_INDEX('PUBLIC', 'TEST', NULL)");
    ResultSet rs;
    rs = stat.executeQuery("SELECT * FROM FT_SEARCH('Welcome', 0, 0)");
    assertTrue(rs.next());
    assertEquals("QUERY", rs.getMetaData().getColumnLabel(1));
    assertEquals("SCORE", rs.getMetaData().getColumnLabel(2));
    assertEquals("\"PUBLIC\".\"TEST\" WHERE \"ID\"=1", rs.getString(1));
    assertEquals("1.0", rs.getString(2));
    rs = stat.executeQuery("SELECT * FROM FT_SEARCH_DATA('One', 0, 0)");
    assertFalse(rs.next());
    rs = stat.executeQuery("SELECT * FROM FT_SEARCH_DATA('One_Word', 0, 0)");
    assertTrue(rs.next());
    rs = stat.executeQuery("SELECT * FROM FT_SEARCH_DATA('Welcome', 0, 0)");
    assertTrue(rs.next());

There is also a SQL script example. And maybe your are interested in the Javadocs for the FullText class - this will explain what FT_SEARCH_DATA / searchData returns.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文