提交 ee1c8fd2 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add support for newer Lucene versions without recompilation

上级 07a263a5
...@@ -116,7 +116,7 @@ build jarClient ...@@ -116,7 +116,7 @@ build jarClient
<h3>Using Apache Lucene</h3> <h3>Using Apache Lucene</h3>
<p> <p>
Apache Lucene 5.5.5 is used for testing. Apache Lucene 5.5.5 is used for testing.
Newer versions may work, 7.5.0 was tested with recompiled under JDK 8 version. Newer versions up to 7.5.0 can also be used.
</p> </p>
<h2 id="maven2">Using Maven 2</h2> <h2 id="maven2">Using Maven 2</h2>
......
...@@ -1234,8 +1234,8 @@ org.h2.fulltext.FullText.searchData(conn, text, limit, offset); ...@@ -1234,8 +1234,8 @@ org.h2.fulltext.FullText.searchData(conn, text, limit, offset);
<h3>Using the Apache Lucene Fulltext Search</h3> <h3>Using the Apache Lucene Fulltext Search</h3>
<p> <p>
To use the Apache Lucene full text search, you need the Lucene library in the classpath. To use the Apache Lucene full text search, you need the Lucene library in the classpath.
Currently, Apache Lucene 5.5.5 is used for testing. Apache Lucene 5.5.5 or later version up to 7.5.0 is required.
Newer versions may work, 7.5.0 was tested with recompiled under JDK 8 version. Newer versions may also work, but were not tested.
How to do that depends on the application; if you use the H2 Console, you can add the Lucene How to do that depends on the application; if you use the H2 Console, you can add the Lucene
jar file to the environment variables <code>H2DRIVERS</code> or jar file to the environment variables <code>H2DRIVERS</code> or
<code>CLASSPATH</code>. <code>CLASSPATH</code>.
......
...@@ -41,14 +41,14 @@ Import-Package: javax.crypto, ...@@ -41,14 +41,14 @@ Import-Package: javax.crypto,
org.w3c.dom;resolution:=optional, org.w3c.dom;resolution:=optional,
org.xml.sax;resolution:=optional, org.xml.sax;resolution:=optional,
org.xml.sax.helpers;resolution:=optional, org.xml.sax.helpers;resolution:=optional,
org.apache.lucene.analysis;version="[5.5.5,6.0.0)";resolution:=optional, org.apache.lucene.analysis;version="[5.5.5,8.0.0)";resolution:=optional,
org.apache.lucene.analysis.standard;version="[5.5.5,6.0.0)";resolution:=optional, org.apache.lucene.analysis.standard;version="[5.5.5,8.0.0)";resolution:=optional,
org.apache.lucene.document;version="[5.5.5,6.0.0)";resolution:=optional, org.apache.lucene.document;version="[5.5.5,8.0.0)";resolution:=optional,
org.apache.lucene.index;version="[5.5.5,6.0.0)";resolution:=optional, org.apache.lucene.index;version="[5.5.5,8.0.0)";resolution:=optional,
org.apache.lucene.queryparser;version="[5.5.5,6.0.0)";resolution:=optional, org.apache.lucene.queryparser;version="[5.5.5,8.0.0)";resolution:=optional,
org.apache.lucene.search;version="[5.5.5,6.0.0)";resolution:=optional, org.apache.lucene.search;version="[5.5.5,8.0.0)";resolution:=optional,
org.apache.lucene.store;version="[5.5.5,6.0.0)";resolution:=optional, org.apache.lucene.store;version="[5.5.5,8.0.0)";resolution:=optional,
org.apache.lucene.util;version="[5.5.5,6.0.0)";resolution:=optional, org.apache.lucene.util;version="[5.5.5,8.0.0)";resolution:=optional,
org.locationtech.jts.geom;version="1.15.0";resolution:=optional, org.locationtech.jts.geom;version="1.15.0";resolution:=optional,
org.locationtech.jts.io;version="1.15.0";resolution:=optional, org.locationtech.jts.io;version="1.15.0";resolution:=optional,
org.osgi.framework;version="1.5", org.osgi.framework;version="1.5",
......
...@@ -38,11 +38,13 @@ import org.apache.lucene.search.TopDocs; ...@@ -38,11 +38,13 @@ import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory; import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.store.RAMDirectory;
import org.h2.api.ErrorCode;
import org.h2.api.Trigger; import org.h2.api.Trigger;
import org.h2.command.Parser; import org.h2.command.Parser;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.expression.ExpressionColumn; import org.h2.expression.ExpressionColumn;
import org.h2.jdbc.JdbcConnection; import org.h2.jdbc.JdbcConnection;
import org.h2.message.DbException;
import org.h2.store.fs.FileUtils; import org.h2.store.fs.FileUtils;
import org.h2.tools.SimpleResultSet; import org.h2.tools.SimpleResultSet;
import org.h2.util.StatementBuilder; import org.h2.util.StatementBuilder;
...@@ -75,6 +77,17 @@ public class FullTextLucene extends FullText { ...@@ -75,6 +77,17 @@ public class FullTextLucene extends FullText {
*/ */
private static final String IN_MEMORY_PREFIX = "mem:"; private static final String IN_MEMORY_PREFIX = "mem:";
private static final java.lang.reflect.Field TOTAL_HITS;
static {
try {
TOTAL_HITS = TopDocs.class.getField("totalHits");
} catch (ReflectiveOperationException e) {
throw DbException.get(ErrorCode.GENERAL_ERROR_1, e,
"Field org.apache.lucene.search.TopDocs.totalHits is not found");
}
}
/** /**
* Initializes full text search functionality for this database. This adds * Initializes full text search functionality for this database. This adds
* the following Java functions to the database: * the following Java functions to the database:
...@@ -434,7 +447,7 @@ public class FullTextLucene extends FullText { ...@@ -434,7 +447,7 @@ public class FullTextLucene extends FullText {
// TopDocs.totalHits is long now // TopDocs.totalHits is long now
// (https://issues.apache.org/jira/browse/LUCENE-7872) // (https://issues.apache.org/jira/browse/LUCENE-7872)
// but in this context it's safe to cast // but in this context it's safe to cast
limit = (int)docs.totalHits; limit = (int) TOTAL_HITS.getLong(docs);
} }
for (int i = 0, len = docs.scoreDocs.length; i < limit for (int i = 0, len = docs.scoreDocs.length; i < limit
&& i + offset < docs.totalHits && i + offset < docs.totalHits
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论