提交 5c58a48f authored 作者: Thomas Mueller's avatar Thomas Mueller

Lucene 2 is no longer supported.

上级 ea279c32
...@@ -18,10 +18,10 @@ Change Log ...@@ -18,10 +18,10 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>- <ul><li>Lucene 2 is no longer supported.
</li></ul> </li></ul>
<h2>Version 1.3.175 (2013-01-18)</h2> <h2>Version 1.3.175 (2014-01-18)</h2>
<ul><li>EXPLAIN was incorrect for queries with "ANY" or "SOME" conditions. <ul><li>EXPLAIN was incorrect for queries with "ANY" or "SOME" conditions.
</li><li>CallableStatement with "out" parameters: running the same statement twice </li><li>CallableStatement with "out" parameters: running the same statement twice
could result in an exception ("parameter not set"). could result in an exception ("parameter not set").
......
...@@ -91,7 +91,6 @@ public class Constants { ...@@ -91,7 +91,6 @@ public class Constants {
* The minor version of this database. * The minor version of this database.
*/ */
public static final int VERSION_MINOR = 3; public static final int VERSION_MINOR = 3;
// Build.getLuceneVersion() uses an ugly hack to read this value
/** /**
* The lock mode that means no locking is used at all. * The lock mode that means no locking is used at all.
......
...@@ -37,11 +37,6 @@ import org.h2.util.New; ...@@ -37,11 +37,6 @@ import org.h2.util.New;
import org.h2.util.StatementBuilder; import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
import org.h2.util.Utils; import org.h2.util.Utils;
/*## LUCENE2 ##
import org.apache.lucene.index.IndexModifier;
import org.apache.lucene.search.Hits;
//*/
//## LUCENE3 ##
import java.io.File; import java.io.File;
import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.TopDocs;
...@@ -50,7 +45,6 @@ import org.apache.lucene.store.Directory; ...@@ -50,7 +45,6 @@ import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.Version; import org.apache.lucene.util.Version;
import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriter;
//*/
/** /**
* This class implements the full text search based on Apache Lucene. * This class implements the full text search based on Apache Lucene.
...@@ -292,13 +286,6 @@ public class FullTextLucene extends FullText { ...@@ -292,13 +286,6 @@ public class FullTextLucene extends FullText {
IndexAccess access = INDEX_ACCESS.get(path); IndexAccess access = INDEX_ACCESS.get(path);
if (access == null) { if (access == null) {
try { try {
/*## LUCENE2 ##
boolean recreate = !IndexReader.indexExists(path);
Analyzer analyzer = new StandardAnalyzer();
access = new IndexAccess();
access.modifier = new IndexModifier(path, analyzer, recreate);
//*/
//## LUCENE3 ##
Directory indexDir = path.startsWith(IN_MEMORY_PREFIX) ? new RAMDirectory() : FSDirectory.open(new File(path)); Directory indexDir = path.startsWith(IN_MEMORY_PREFIX) ? new RAMDirectory() : FSDirectory.open(new File(path));
boolean recreate = !IndexReader.indexExists(indexDir); boolean recreate = !IndexReader.indexExists(indexDir);
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30); Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30);
...@@ -310,7 +297,6 @@ public class FullTextLucene extends FullText { ...@@ -310,7 +297,6 @@ public class FullTextLucene extends FullText {
access.writer = writer; access.writer = writer;
access.reader = reader; access.reader = reader;
access.searcher = new IndexSearcher(reader); access.searcher = new IndexSearcher(reader);
//*/
} catch (IOException e) { } catch (IOException e) {
throw convertException(e); throw convertException(e);
} }
...@@ -332,13 +318,7 @@ public class FullTextLucene extends FullText { ...@@ -332,13 +318,7 @@ public class FullTextLucene extends FullText {
rs.next(); rs.next();
String path = rs.getString(1); String path = rs.getString(1);
if (path == null) { if (path == null) {
/*## LUCENE2 ##
throw throwException("Fulltext search for in-memory databases " +
"is not supported with Lucene 2. Please use Lucene 3 instead.");
//*/
//## LUCENE3 ##
return IN_MEMORY_PREFIX + conn.getCatalog(); return IN_MEMORY_PREFIX + conn.getCatalog();
//*/
} }
int index = path.lastIndexOf(':'); int index = path.lastIndexOf(':');
// position 1 means a windows drive letter is used, ignore that // position 1 means a windows drive letter is used, ignore that
...@@ -393,15 +373,9 @@ public class FullTextLucene extends FullText { ...@@ -393,15 +373,9 @@ public class FullTextLucene extends FullText {
synchronized (INDEX_ACCESS) { synchronized (INDEX_ACCESS) {
try { try {
INDEX_ACCESS.remove(indexPath); INDEX_ACCESS.remove(indexPath);
/*## LUCENE2 ##
access.modifier.flush();
access.modifier.close();
//*/
//## LUCENE3 ##
access.searcher.close(); access.searcher.close();
access.reader.close(); access.reader.close();
access.writer.close(); access.writer.close();
//*/
} catch (Exception e) { } catch (Exception e) {
throw convertException(e); throw convertException(e);
} }
...@@ -430,24 +404,6 @@ public class FullTextLucene extends FullText { ...@@ -430,24 +404,6 @@ public class FullTextLucene extends FullText {
} }
try { try {
IndexAccess access = getIndexAccess(conn); IndexAccess access = getIndexAccess(conn);
/*## LUCENE2 ##
access.modifier.flush();
String path = getIndexPath(conn);
IndexReader reader = IndexReader.open(path);
Analyzer analyzer = new StandardAnalyzer();
Searcher searcher = new IndexSearcher(reader);
QueryParser parser = new QueryParser(LUCENE_FIELD_DATA, analyzer);
Query query = parser.parse(text);
Hits hits = searcher.search(query);
int max = hits.length();
if (limit == 0) {
limit = max;
}
for (int i = 0; i < limit && i + offset < max; i++) {
Document doc = hits.doc(i + offset);
float score = hits.score(i + offset);
//*/
//## LUCENE3 ##
// take a reference as the searcher may change // take a reference as the searcher may change
Searcher searcher = access.searcher; Searcher searcher = access.searcher;
// reuse the same analyzer; it's thread-safe; // reuse the same analyzer; it's thread-safe;
...@@ -471,7 +427,6 @@ public class FullTextLucene extends FullText { ...@@ -471,7 +427,6 @@ public class FullTextLucene extends FullText {
ScoreDoc sd = docs.scoreDocs[i + offset]; ScoreDoc sd = docs.scoreDocs[i + offset];
Document doc = searcher.doc(sd.doc); Document doc = searcher.doc(sd.doc);
float score = sd.score; float score = sd.score;
//*/
String q = doc.get(LUCENE_FIELD_QUERY); String q = doc.get(LUCENE_FIELD_QUERY);
if (data) { if (data) {
int idx = q.indexOf(" WHERE "); int idx = q.indexOf(" WHERE ");
...@@ -494,10 +449,6 @@ public class FullTextLucene extends FullText { ...@@ -494,10 +449,6 @@ public class FullTextLucene extends FullText {
result.addRow(q, score); result.addRow(q, score);
} }
} }
/*## LUCENE2 ##
// TODO keep it open if possible
reader.close();
//*/
} catch (Exception e) { } catch (Exception e) {
throw convertException(e); throw convertException(e);
} }
...@@ -649,40 +600,6 @@ public class FullTextLucene extends FullText { ...@@ -649,40 +600,6 @@ public class FullTextLucene extends FullText {
* @param commitIndex whether to commit the changes to the Lucene index * @param commitIndex whether to commit the changes to the Lucene index
*/ */
protected void insert(Object[] row, boolean commitIndex) throws SQLException { protected void insert(Object[] row, boolean commitIndex) throws SQLException {
/*## LUCENE2 ##
String query = getQuery(row);
Document doc = new Document();
doc.add(new Field(LUCENE_FIELD_QUERY, query,
Field.Store.YES, Field.Index.UN_TOKENIZED));
long time = System.currentTimeMillis();
doc.add(new Field(LUCENE_FIELD_MODIFIED,
DateTools.timeToString(time, DateTools.Resolution.SECOND),
Field.Store.YES, Field.Index.UN_TOKENIZED));
StatementBuilder buff = new StatementBuilder();
for (int index : indexColumns) {
String columnName = columns[index];
String data = asString(row[index], columnTypes[index]);
// column names that start with _ must be escaped to avoid conflicts
// with internal field names (_DATA, _QUERY, _modified)
if (columnName.startsWith(LUCENE_FIELD_COLUMN_PREFIX)) {
columnName = LUCENE_FIELD_COLUMN_PREFIX + columnName;
}
doc.add(new Field(columnName, data,
Field.Store.NO, Field.Index.TOKENIZED));
buff.appendExceptFirst(" ");
buff.append(data);
}
Field.Store storeText = STORE_DOCUMENT_TEXT_IN_INDEX ?
Field.Store.YES : Field.Store.NO;
doc.add(new Field(LUCENE_FIELD_DATA, buff.toString(), storeText,
Field.Index.TOKENIZED));
try {
indexAccess.modifier.addDocument(doc);
} catch (IOException e) {
throw convertException(e);
}
//*/
//## LUCENE3 ##
String query = getQuery(row); String query = getQuery(row);
Document doc = new Document(); Document doc = new Document();
doc.add(new Field(LUCENE_FIELD_QUERY, query, doc.add(new Field(LUCENE_FIELD_QUERY, query,
...@@ -718,7 +635,6 @@ public class FullTextLucene extends FullText { ...@@ -718,7 +635,6 @@ public class FullTextLucene extends FullText {
} catch (IOException e) { } catch (IOException e) {
throw convertException(e); throw convertException(e);
} }
//*/
} }
/** /**
...@@ -731,15 +647,10 @@ public class FullTextLucene extends FullText { ...@@ -731,15 +647,10 @@ public class FullTextLucene extends FullText {
String query = getQuery(row); String query = getQuery(row);
try { try {
Term term = new Term(LUCENE_FIELD_QUERY, query); Term term = new Term(LUCENE_FIELD_QUERY, query);
/*## LUCENE2 ##
indexAccess.modifier.deleteDocuments(term);
//*/
//## LUCENE3 ##
indexAccess.writer.deleteDocuments(term); indexAccess.writer.deleteDocuments(term);
if (commitIndex) { if (commitIndex) {
commitIndex(); commitIndex();
} }
//*/
} catch (IOException e) { } catch (IOException e) {
throw convertException(e); throw convertException(e);
} }
...@@ -770,33 +681,20 @@ public class FullTextLucene extends FullText { ...@@ -770,33 +681,20 @@ public class FullTextLucene extends FullText {
*/ */
static class IndexAccess { static class IndexAccess {
/**
* The index modified.
*/
/*## LUCENE2 ##
IndexModifier modifier;
//*/
/** /**
* The index writer. * The index writer.
*/ */
//## LUCENE3 ##
IndexWriter writer; IndexWriter writer;
//*/
/** /**
* The index reader. * The index reader.
*/ */
//## LUCENE3 ##
IndexReader reader; IndexReader reader;
//*/
/** /**
* The index searcher. * The index searcher.
*/ */
//## LUCENE3 ##
Searcher searcher; Searcher searcher;
//*/
} }
} }
...@@ -110,7 +110,7 @@ public class Build extends BuildBase { ...@@ -110,7 +110,7 @@ public class Build extends BuildBase {
File.pathSeparator + "ext/emma-2.0.5312.jar" + File.pathSeparator + "ext/emma-2.0.5312.jar" +
File.pathSeparator + "ext/postgresql-8.3-603.jdbc3.jar" + File.pathSeparator + "ext/postgresql-8.3-603.jdbc3.jar" +
File.pathSeparator + "ext/servlet-api-2.4.jar" + File.pathSeparator + "ext/servlet-api-2.4.jar" +
File.pathSeparator + "ext/" + getLuceneJar() + File.pathSeparator + "ext/lucene-core-3.0.2.jar" +
File.pathSeparator + "ext/h2mig_pagestore_addon.jar" + File.pathSeparator + "ext/h2mig_pagestore_addon.jar" +
File.pathSeparator + "ext/org.osgi.core-4.2.0.jar" + File.pathSeparator + "ext/org.osgi.core-4.2.0.jar" +
File.pathSeparator + "ext/org.osgi.enterprise-4.2.0.jar" + File.pathSeparator + "ext/org.osgi.enterprise-4.2.0.jar" +
...@@ -146,7 +146,6 @@ public class Build extends BuildBase { ...@@ -146,7 +146,6 @@ public class Build extends BuildBase {
} else { } else {
SwitchSource.main("-dir", "src", "-version", version, check); SwitchSource.main("-dir", "src", "-version", version, check);
} }
SwitchSource.main("-dir", "src", "-LUCENE2", "-LUCENE3", "+LUCENE" + getLuceneVersion());
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
...@@ -178,7 +177,7 @@ public class Build extends BuildBase { ...@@ -178,7 +177,7 @@ public class Build extends BuildBase {
download(); download();
String classpath = "temp" + String classpath = "temp" +
File.pathSeparator + "ext/servlet-api-2.4.jar" + File.pathSeparator + "ext/servlet-api-2.4.jar" +
File.pathSeparator + "ext/" + getLuceneJar() + File.pathSeparator + "ext/lucene-core-3.0.2.jar" +
File.pathSeparator + "ext/slf4j-api-1.6.0.jar" + File.pathSeparator + "ext/slf4j-api-1.6.0.jar" +
File.pathSeparator + "ext/org.osgi.core-4.2.0.jar" + File.pathSeparator + "ext/org.osgi.core-4.2.0.jar" +
File.pathSeparator + "ext/org.osgi.enterprise-4.2.0.jar" + File.pathSeparator + "ext/org.osgi.enterprise-4.2.0.jar" +
...@@ -262,13 +261,8 @@ public class Build extends BuildBase { ...@@ -262,13 +261,8 @@ public class Build extends BuildBase {
private void downloadOrVerify(boolean offline) { private void downloadOrVerify(boolean offline) {
downloadOrVerify("ext/servlet-api-2.4.jar", "javax/servlet", "servlet-api", "2.4", downloadOrVerify("ext/servlet-api-2.4.jar", "javax/servlet", "servlet-api", "2.4",
"3fc542fe8bb8164e8d3e840fe7403bc0518053c0", offline); "3fc542fe8bb8164e8d3e840fe7403bc0518053c0", offline);
if (getLuceneVersion() == 3) {
downloadOrVerify("ext/lucene-core-3.0.2.jar", "org/apache/lucene", "lucene-core", "3.0.2", downloadOrVerify("ext/lucene-core-3.0.2.jar", "org/apache/lucene", "lucene-core", "3.0.2",
"c2b48995ab855c1b9ea13867a0f976c994e0105d", offline); "c2b48995ab855c1b9ea13867a0f976c994e0105d", offline);
} else {
downloadOrVerify("ext/lucene-core-2.2.0.jar", "org/apache/lucene", "lucene-core", "2.2.0",
"47b6eee2e17bd68911e7045896a1c09de0b2dda8", offline);
}
downloadOrVerify("ext/slf4j-api-1.6.0.jar", "org/slf4j", "slf4j-api", "1.6.0", downloadOrVerify("ext/slf4j-api-1.6.0.jar", "org/slf4j", "slf4j-api", "1.6.0",
"b353147a7d51fcfcd818d8aa6784839783db0915", offline); "b353147a7d51fcfcd818d8aa6784839783db0915", offline);
downloadOrVerify("ext/org.osgi.core-4.2.0.jar", "org/osgi", "org.osgi.core", "4.2.0", downloadOrVerify("ext/org.osgi.core-4.2.0.jar", "org/osgi", "org.osgi.core", "4.2.0",
...@@ -314,18 +308,6 @@ public class Build extends BuildBase { ...@@ -314,18 +308,6 @@ public class Build extends BuildBase {
return getStaticValue("org.h2.engine.Constants", "getVersion"); return getStaticValue("org.h2.engine.Constants", "getVersion");
} }
private static String getLuceneJar() {
return "lucene-core-" + (getLuceneVersion() == 2 ? "2.2.0" : "3.0.2") + ".jar";
}
private static int getLuceneVersion() {
// use Lucene 2 for H2 1.2.x, and Lucene 3 for H2 1.3.x.
String s = new String(readFile(new File("src/main/org/h2/engine/Constants.java")));
int idx = s.indexOf("VERSION_MINOR") + "VERSION_MINOR".length() + 3;
int version = Integer.parseInt(s.substring(idx, idx + 1));
return Integer.parseInt(System.getProperty("lucene", "" + version));
}
private static String getJarSuffix() { private static String getJarSuffix() {
return "-" + getVersion() + ".jar"; return "-" + getVersion() + ".jar";
} }
...@@ -525,7 +507,7 @@ public class Build extends BuildBase { ...@@ -525,7 +507,7 @@ public class Build extends BuildBase {
javadoc("-sourcepath", "src/main", "org.h2.jdbc", "org.h2.jdbcx", javadoc("-sourcepath", "src/main", "org.h2.jdbc", "org.h2.jdbcx",
"org.h2.tools", "org.h2.api", "org.h2.constant", "org.h2.fulltext", "org.h2.tools", "org.h2.api", "org.h2.constant", "org.h2.fulltext",
"-classpath", "-classpath",
"ext/" + getLuceneJar() + "ext/lucene-core-3.0.2.jar" +
File.pathSeparator + "ext/jts-1.13.jar", File.pathSeparator + "ext/jts-1.13.jar",
"-docletpath", "bin" + File.pathSeparator + "temp", "-docletpath", "bin" + File.pathSeparator + "temp",
"-doclet", "org.h2.build.doclet.Doclet"); "-doclet", "org.h2.build.doclet.Doclet");
...@@ -547,7 +529,7 @@ public class Build extends BuildBase { ...@@ -547,7 +529,7 @@ public class Build extends BuildBase {
"/../lib/tools.jar" + "/../lib/tools.jar" +
File.pathSeparator + "ext/slf4j-api-1.6.0.jar" + File.pathSeparator + "ext/slf4j-api-1.6.0.jar" +
File.pathSeparator + "ext/servlet-api-2.4.jar" + File.pathSeparator + "ext/servlet-api-2.4.jar" +
File.pathSeparator + "ext/" + getLuceneJar() + File.pathSeparator + "ext/lucene-core-3.0.2.jar" +
File.pathSeparator + "ext/org.osgi.core-4.2.0.jar" + File.pathSeparator + "ext/org.osgi.core-4.2.0.jar" +
File.pathSeparator + "ext/org.osgi.enterprise-4.2.0.jar" + File.pathSeparator + "ext/org.osgi.enterprise-4.2.0.jar" +
File.pathSeparator + "ext/jts-1.13.jar", File.pathSeparator + "ext/jts-1.13.jar",
...@@ -559,7 +541,7 @@ public class Build extends BuildBase { ...@@ -559,7 +541,7 @@ public class Build extends BuildBase {
"-classpath", System.getProperty("java.home") + "/../lib/tools.jar" + "-classpath", System.getProperty("java.home") + "/../lib/tools.jar" +
File.pathSeparator + "ext/slf4j-api-1.6.0.jar" + File.pathSeparator + "ext/slf4j-api-1.6.0.jar" +
File.pathSeparator + "ext/servlet-api-2.4.jar" + File.pathSeparator + "ext/servlet-api-2.4.jar" +
File.pathSeparator + "ext/" + getLuceneJar() + File.pathSeparator + "ext/lucene-core-3.0.2.jar" +
File.pathSeparator + "ext/org.osgi.core-4.2.0.jar" + File.pathSeparator + "ext/org.osgi.core-4.2.0.jar" +
File.pathSeparator + "ext/org.osgi.enterprise-4.2.0.jar" + File.pathSeparator + "ext/org.osgi.enterprise-4.2.0.jar" +
File.pathSeparator + "ext/jts-1.13.jar", File.pathSeparator + "ext/jts-1.13.jar",
...@@ -688,7 +670,7 @@ public class Build extends BuildBase { ...@@ -688,7 +670,7 @@ public class Build extends BuildBase {
java("org.h2.build.doc.GenerateHelp", null); java("org.h2.build.doc.GenerateHelp", null);
javadoc("-sourcepath", "src/main", "org.h2.tools", "org.h2.jmx", javadoc("-sourcepath", "src/main", "org.h2.tools", "org.h2.jmx",
"-classpath", "-classpath",
"ext/" + getLuceneJar() + "ext/lucene-core-3.0.2.jar" +
File.pathSeparator + "ext/jts-1.13.jar", File.pathSeparator + "ext/jts-1.13.jar",
"-docletpath", "bin" + File.pathSeparator + "temp", "-docletpath", "bin" + File.pathSeparator + "temp",
"-doclet", "org.h2.build.doclet.ResourceDoclet"); "-doclet", "org.h2.build.doclet.ResourceDoclet");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论