提交 3d361d59 authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 651cd28d
...@@ -596,6 +596,13 @@ public class FullText { ...@@ -596,6 +596,13 @@ public class FullText {
} }
} }
/**
* Add all words in the given text to the hash set.
*
* @param setting the fulltext settings
* @param set the hash set
* @param text the text
*/
static void addWords(FullTextSettings setting, HashSet set, String text) { static void addWords(FullTextSettings setting, HashSet set, String text) {
StringTokenizer tokenizer = new StringTokenizer(text, " \t\n\r\f+\"*%&/()=?'!,.;:-_#@|^~`{}[]"); StringTokenizer tokenizer = new StringTokenizer(text, " \t\n\r\f+\"*%&/()=?'!,.;:-_#@|^~`{}[]");
while (tokenizer.hasMoreTokens()) { while (tokenizer.hasMoreTokens()) {
......
...@@ -48,9 +48,13 @@ import org.h2.util.StringUtils; ...@@ -48,9 +48,13 @@ import org.h2.util.StringUtils;
*/ */
public class FullTextLucene extends FullText { public class FullTextLucene extends FullText {
//## Java 1.4 begin ## /**
static final HashMap INDEX_MODIFIERS = new HashMap(); * Whether the text content should be stored in the Lucene index.
*/
static final boolean STORE_DOCUMENT_TEXT_IN_INDEX = Boolean.getBoolean("h2.storeDocumentTextInIndex"); static final boolean STORE_DOCUMENT_TEXT_IN_INDEX = Boolean.getBoolean("h2.storeDocumentTextInIndex");
//## Java 1.4 begin ##
private static final HashMap INDEX_MODIFIERS = new HashMap();
private static final String TRIGGER_PREFIX = "FTL_"; private static final String TRIGGER_PREFIX = "FTL_";
private static final String SCHEMA = "FTL"; private static final String SCHEMA = "FTL";
private static final String FIELD_DATA = "DATA"; private static final String FIELD_DATA = "DATA";
...@@ -201,6 +205,12 @@ public class FullTextLucene extends FullText { ...@@ -201,6 +205,12 @@ public class FullTextLucene extends FullText {
return search(conn, text, limit, offset, true); return search(conn, text, limit, offset, true);
} }
/**
* Convert an exception to a fulltext exception.
*
* @param e the original exception
* @return the converted SQL exception
*/
static SQLException convertException(Exception e) { static SQLException convertException(Exception e) {
SQLException e2 = new SQLException("FULLTEXT", "Error while indexing document"); SQLException e2 = new SQLException("FULLTEXT", "Error while indexing document");
e2.initCause(e); e2.initCause(e);
...@@ -221,7 +231,7 @@ public class FullTextLucene extends FullText { ...@@ -221,7 +231,7 @@ public class FullTextLucene extends FullText {
stat.execute(buff.toString()); stat.execute(buff.toString());
} }
static IndexModifier getIndexModifier(Connection conn) throws SQLException { private static IndexModifier getIndexModifier(Connection conn) throws SQLException {
String path = getIndexPath(conn); String path = getIndexPath(conn);
IndexModifier indexer; IndexModifier indexer;
synchronized (INDEX_MODIFIERS) { synchronized (INDEX_MODIFIERS) {
...@@ -240,6 +250,12 @@ public class FullTextLucene extends FullText { ...@@ -240,6 +250,12 @@ public class FullTextLucene extends FullText {
return indexer; return indexer;
} }
/**
* Get the path of the Lucene index for this database.
*
* @param conn the database connection
* @return the path
*/
static String getIndexPath(Connection conn) throws SQLException { static String getIndexPath(Connection conn) throws SQLException {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("CALL DATABASE_PATH()"); ResultSet rs = stat.executeQuery("CALL DATABASE_PATH()");
...@@ -272,15 +288,27 @@ public class FullTextLucene extends FullText { ...@@ -272,15 +288,27 @@ public class FullTextLucene extends FullText {
String path = getIndexPath(conn); String path = getIndexPath(conn);
IndexModifier index = (IndexModifier) INDEX_MODIFIERS.get(path); IndexModifier index = (IndexModifier) INDEX_MODIFIERS.get(path);
if (index != null) { if (index != null) {
INDEX_MODIFIERS.remove(path); removeIndexModifier(index, path);
}
FileSystem.getInstance(path).deleteRecursive(path);
}
/**
* Close the index modifier and remove it from the index modifier set.
*
* @param indexModifier the index modifier
* @param indexPath the index path
*/
static void removeIndexModifier(IndexModifier indexModifier, String indexPath) throws SQLException {
synchronized (INDEX_MODIFIERS) {
try { try {
index.flush(); INDEX_MODIFIERS.remove(indexPath);
index.close(); indexModifier.flush();
} catch (IOException e) { indexModifier.close();
} catch (Exception e) {
throw convertException(e); throw convertException(e);
} }
} }
FileSystem.getInstance(path).deleteRecursive(path);
} }
private static ResultSet search(Connection conn, String text, int limit, int offset, boolean data) throws SQLException { private static ResultSet search(Connection conn, String text, int limit, int offset, boolean data) throws SQLException {
...@@ -445,14 +473,8 @@ public class FullTextLucene extends FullText { ...@@ -445,14 +473,8 @@ public class FullTextLucene extends FullText {
//## Java 1.4 begin ## //## Java 1.4 begin ##
public void close() throws SQLException { public void close() throws SQLException {
if (indexModifier != null) { if (indexModifier != null) {
try { removeIndexModifier(indexModifier, indexPath);
indexModifier.flush();
indexModifier.close();
INDEX_MODIFIERS.remove(indexPath);
indexModifier = null; indexModifier = null;
} catch (Exception e) {
throw convertException(e);
}
} }
} }
//## Java 1.4 end ## //## Java 1.4 end ##
...@@ -526,7 +548,6 @@ public class FullTextLucene extends FullText { ...@@ -526,7 +548,6 @@ public class FullTextLucene extends FullText {
String key = buff.toString(); String key = buff.toString();
return key; return key;
} }
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论