Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
5841c4df
提交
5841c4df
authored
7月 25, 2017
作者:
Noel Grandin
提交者:
GitHub
7月 25, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #575 from andreitokar/full_text_mt
Support for full text search in multithreaded mode
上级
0f76639b
2053cadf
全部展开
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
423 行增加
和
284 行删除
+423
-284
tutorial.html
h2/src/docsrc/html/tutorial.html
+0
-7
FullText.java
h2/src/main/org/h2/fulltext/FullText.java
+183
-124
FullTextLucene.java
h2/src/main/org/h2/fulltext/FullTextLucene.java
+158
-119
FullTextSettings.java
h2/src/main/org/h2/fulltext/FullTextSettings.java
+77
-28
TestFullText.java
h2/src/test/org/h2/test/db/TestFullText.java
+5
-6
没有找到文件。
h2/src/docsrc/html/tutorial.html
浏览文件 @
5841c4df
...
...
@@ -1320,13 +1320,6 @@ SELECT * FROM FTL_SEARCH_DATA('John', 0, 0);
SELECT * FROM FTL_SEARCH_DATA('LAST_NAME:John', 0, 0);
CALL FTL_DROP_ALL();
</pre>
<p>
The Lucene fulltext search implementation is not synchronized internally.
If you update the database and query the fulltext search concurrently
(directly using the Java API of H2 or Lucene itself), you need to ensure
operations are properly synchronized. If this is not the case, you may get
exceptions such as
<code>
org.apache.lucene.store.AlreadyClosedException: this IndexReader is closed
</code>
.
</p>
<h2
id=
"user_defined_variables"
>
User-Defined Variables
</h2>
<p>
...
...
h2/src/main/org/h2/fulltext/FullText.java
浏览文件 @
5841c4df
差异被折叠。
点击展开。
h2/src/main/org/h2/fulltext/FullTextLucene.java
浏览文件 @
5841c4df
差异被折叠。
点击展开。
h2/src/main/org/h2/fulltext/FullTextSettings.java
浏览文件 @
5841c4df
...
...
@@ -10,20 +10,22 @@ import java.sql.PreparedStatement;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Collections
;
import
java.util.Map
;
import
java.util.Set
;
import
org.h2.util.New
;
import
org.h2.util.SoftHashMap
;
/**
* The global settings of a full text search.
*/
class
FullTextSettings
{
final
class
FullTextSettings
{
/**
* The settings of open indexes.
*/
private
static
final
Hash
Map
<
String
,
FullTextSettings
>
SETTINGS
=
New
.
hashMap
();
private
static
final
Map
<
String
,
FullTextSettings
>
SETTINGS
=
New
.
hashMap
();
/**
* Whether this instance has been initialized.
...
...
@@ -33,17 +35,17 @@ class FullTextSettings {
/**
* The set of words not to index (stop words).
*/
private
final
Hash
Set
<
String
>
ignoreList
=
New
.
hashSet
();
private
final
Set
<
String
>
ignoreList
=
New
.
hashSet
();
/**
* The set of words / terms.
*/
private
final
Hash
Map
<
String
,
Integer
>
words
=
New
.
hashMap
();
private
final
Map
<
String
,
Integer
>
words
=
New
.
hashMap
();
/**
* The set of indexes in this database.
*/
private
final
HashMap
<
Integer
,
IndexInfo
>
indexes
=
New
.
hashMap
(
);
private
final
Map
<
Integer
,
IndexInfo
>
indexes
=
Collections
.
synchronizedMap
(
New
.<
Integer
,
IndexInfo
>
hashMap
()
);
/**
* The prepared statement cache.
...
...
@@ -60,26 +62,63 @@ class FullTextSettings {
/**
* Create a new instance.
*/
pr
otected
FullTextSettings
()
{
pr
ivate
FullTextSettings
()
{
// don't allow construction
}
/**
* Get the ignore list.
*
* @return the ignore list
* Clear set of ignored words
*/
protected
HashSet
<
String
>
getIgnoreList
()
{
return
ignoreList
;
public
void
clearInored
()
{
synchronized
(
ignoreList
)
{
ignoreList
.
clear
();
}
}
/**
* Get the word list.
*
* @return the word list
* Amend set of ignored words
* @param words to add
*/
public
void
addIgnored
(
Iterable
<
String
>
words
)
{
synchronized
(
ignoreList
)
{
for
(
String
word
:
words
)
{
word
=
normalizeWord
(
word
);
ignoreList
.
add
(
word
);
}
}
}
/**
* Clear set of searchable words
*/
public
void
clearWordList
()
{
synchronized
(
words
)
{
words
.
clear
();
}
}
/**
* Get id for a searchable word
* @param word to find id for
* @return Integer id or null if word is not found
*/
protected
HashMap
<
String
,
Integer
>
getWordList
()
{
return
words
;
public
Integer
getWordId
(
String
word
)
{
synchronized
(
words
)
{
return
words
.
get
(
word
);
}
}
/**
* Register searchable word
* @param word to register
* @param id to register with
*/
public
void
addWord
(
String
word
,
Integer
id
)
{
synchronized
(
words
)
{
if
(!
words
.
containsKey
(
word
))
{
words
.
put
(
word
,
id
);
}
}
}
/**
...
...
@@ -109,11 +148,12 @@ class FullTextSettings {
* @return the uppercase version of the word or null
*/
protected
String
convertWord
(
String
word
)
{
// TODO this is locale specific, document
word
=
word
.
toUpperCase
();
word
=
normalizeWord
(
word
);
synchronized
(
ignoreList
)
{
if
(
ignoreList
.
contains
(
word
))
{
return
null
;
}
}
return
word
;
}
...
...
@@ -126,11 +166,14 @@ class FullTextSettings {
protected
static
FullTextSettings
getInstance
(
Connection
conn
)
throws
SQLException
{
String
path
=
getIndexPath
(
conn
);
FullTextSettings
setting
=
SETTINGS
.
get
(
path
);
FullTextSettings
setting
;
synchronized
(
SETTINGS
)
{
setting
=
SETTINGS
.
get
(
path
);
if
(
setting
==
null
)
{
setting
=
new
FullTextSettings
();
SETTINGS
.
put
(
path
,
setting
);
}
}
return
setting
;
}
...
...
@@ -140,7 +183,7 @@ class FullTextSettings {
* @param conn the connection
* @return the file system path
*/
pr
otected
static
String
getIndexPath
(
Connection
conn
)
throws
SQLException
{
pr
ivate
static
String
getIndexPath
(
Connection
conn
)
throws
SQLException
{
Statement
stat
=
conn
.
createStatement
();
ResultSet
rs
=
stat
.
executeQuery
(
"CALL IFNULL(DATABASE_PATH(), 'MEM:' || DATABASE())"
);
...
...
@@ -218,8 +261,10 @@ class FullTextSettings {
* Close all fulltext settings, freeing up memory.
*/
protected
static
void
closeAll
()
{
synchronized
(
SETTINGS
)
{
SETTINGS
.
clear
();
}
}
protected
void
setWhitespaceChars
(
String
whitespaceChars
)
{
this
.
whitespaceChars
=
whitespaceChars
;
...
...
@@ -229,4 +274,8 @@ class FullTextSettings {
return
whitespaceChars
;
}
private
String
normalizeWord
(
String
word
)
{
// TODO this is locale specific, document
return
word
.
toUpperCase
();
}
}
h2/src/test/org/h2/test/db/TestFullText.java
浏览文件 @
5841c4df
...
...
@@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
import
org.h2.fulltext.FullText
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.test.TestAll
;
import
org.h2.test.TestBase
;
import
org.h2.util.IOUtils
;
import
org.h2.util.Task
;
...
...
@@ -50,10 +51,6 @@ public class TestFullText extends TestBase {
@Override
public
void
test
()
throws
Exception
{
if
(
config
.
multiThreaded
)
{
// It is even mentioned in the docs that this is not supported
return
;
}
testUuidPrimaryKey
(
false
);
testAutoAnalyze
();
testNativeFeatures
();
...
...
@@ -71,7 +68,9 @@ public class TestFullText extends TestBase {
testCreateDropLucene
();
testUuidPrimaryKey
(
true
);
testMultiThreaded
(
true
);
if
(
config
.
mvStore
||
!
config
.
multiThreaded
)
{
testMultiThreaded
(
false
);
}
testTransaction
(
true
);
test
(
true
,
"VARCHAR"
);
test
(
true
,
"CLOB"
);
...
...
@@ -256,7 +255,7 @@ public class TestFullText extends TestBase {
int
len
=
2
;
Task
[]
task
=
new
Task
[
len
];
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
final
Connection
conn
=
getConnection
(
"fullText"
,
connList
);
final
Connection
conn
=
getConnection
(
"fullText
;LOCK_TIMEOUT=60000
"
,
connList
);
Statement
stat
=
conn
.
createStatement
();
initFullText
(
stat
,
lucene
);
initFullText
(
stat
,
lucene
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论