Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
zcq
Project
Project
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
Graph
比较
统计图
议题
0
议题
0
列表
看板
标记
Milestones
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
注册表
注册表
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
svn
zcq
Commits
7d9b07f6
提交
7d9b07f6
authored
8月 06, 2019
作者:
renjiancai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
上级
f66a5333
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
178 行增加
和
0 行删除
+178
-0
SolrAdapter.java
...main/java/com/zrqx/resource/commons/solr/SolrAdapter.java
+95
-0
SolrInterface.java
...in/java/com/zrqx/resource/commons/solr/SolrInterface.java
+20
-0
SolrManage.java
.../main/java/com/zrqx/resource/commons/solr/SolrManage.java
+63
-0
没有找到文件。
com.zrqx.resource/src/main/java/com/zrqx/resource/commons/solr/SolrAdapter.java
0 → 100644
浏览文件 @
7d9b07f6
package
com
.
zrqx
.
resource
.
commons
.
solr
;
import
java.io.IOException
;
import
org.apache.solr.client.solrj.SolrQuery
;
import
org.apache.solr.client.solrj.SolrServerException
;
import
org.apache.solr.client.solrj.impl.HttpSolrClient
;
import
org.springframework.beans.factory.annotation.Value
;
public
abstract
class
SolrAdapter
implements
SolrInterface
{
@Value
(
"${spring.data.solr.host}"
)
private
String
BASE_URL
;
/**
* 创建SolrServer对象
* @return
* @author ycw
* @date: 2019年3月1日 下午4:38:00
*/
/*private static HttpSolrClient solrServer = new HttpSolrClient.Builder(BASE_URL)
.withConnectionTimeout(10000)
.withSocketTimeout(60000)
.build();*/
/**
* 创建SolrServer对象
* @return
* @author ycw
* @date: 2019年3月1日 下午4:38:00
*/
private
HttpSolrClient
getSolrClient
(){
/*
* 设置超时时间
* .withConnectionTimeout(10000)
* .withSocketTimeout(60000)
*/
return
new
HttpSolrClient
.
Builder
(
BASE_URL
)
.
withConnectionTimeout
(
10000
)
.
withSocketTimeout
(
60000
)
.
build
();
}
/**
* 更新索引
* @see com.zrqx.resource.commons.solr.SolrInterface#createIndex()
* @return
* @author ycw
* @date: 2019年4月12日 下午3:16:02
*/
@Override
public
String
createIndex
()
{
String
status
=
"0"
;
HttpSolrClient
solrServer
=
getSolrClient
();
SolrQuery
sq
=
new
SolrQuery
();
sq
.
set
(
"qt"
,
"/dataimport"
);
sq
.
set
(
"command"
,
"full-import"
);
try
{
solrServer
.
query
(
sq
);
//sq.clear();
solrServer
.
commit
();
status
=
"1"
;
}
catch
(
SolrServerException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
status
;
}
/**
* 增量更新
* @see com.zrqx.resource.commons.solr.SolrInterface#deltaImportIndex()
* @return
* @author ycw
* @date: 2019年4月12日 上午11:59:35
*/
@Override
public
String
deltaImportIndex
()
{
String
status
=
"0"
;
HttpSolrClient
solrServer
=
getSolrClient
();
SolrQuery
sq
=
new
SolrQuery
();
sq
.
set
(
"qt"
,
"/dataimport"
);
sq
.
set
(
"command"
,
"delta-import"
);
try
{
solrServer
.
query
(
sq
);
solrServer
.
commit
();
status
=
"1"
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
status
;
}
}
com.zrqx.resource/src/main/java/com/zrqx/resource/commons/solr/SolrInterface.java
0 → 100644
浏览文件 @
7d9b07f6
package
com
.
zrqx
.
resource
.
commons
.
solr
;
public
interface
SolrInterface
{
/**
* 更新索引
* @return
* @author ycw
* @date: 2019年4月12日 下午3:08:54
*/
public
String
createIndex
();
/**
* 增量索引
* @return
* @author ycw
* @date: 2019年4月12日 下午3:09:00
*/
public
String
deltaImportIndex
();
}
com.zrqx.resource/src/main/java/com/zrqx/resource/commons/solr/SolrManage.java
0 → 100644
浏览文件 @
7d9b07f6
package
com
.
zrqx
.
resource
.
commons
.
solr
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
org.jboss.logging.Logger
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
/**
* 全文检索更新索引
* @author ycw
* @date 2019年4月12日上午11:59:56
*/
@Component
public
class
SolrManage
extends
SolrAdapter
{
private
static
final
Logger
log
=
Logger
.
getLogger
(
SolrManage
.
class
);
@Value
(
"${solr-quartz}"
)
private
Boolean
offon
;
/**
* 生成索引(全部)
*
* @author ycw
* @date: 2019年4月12日 上午11:57:20
*/
@Scheduled
(
cron
=
"0 0 0/1 * * ? "
)
public
void
commandIndex
(){
if
(
offon
){
SimpleDateFormat
f
=
new
SimpleDateFormat
(
"yyyy-MM-dd hh:mm:ss"
);
log
.
info
(
"定时任务1:全文检索全部更新资源库索引开始...时间:"
+
f
.
format
(
new
Date
()));
String
result
=
this
.
createIndex
();
if
(
result
.
equals
(
"1"
)){
log
.
info
(
"定时任务1:全文检索更新成功...时间:"
+
f
.
format
(
new
Date
()));
}
else
{
log
.
info
(
"定时任务1:全文检索更新失败...时间:"
+
f
.
format
(
new
Date
()));
}
}
}
/**
* 增量更新
*
* @author ycw
* @date: 2019年4月12日 下午4:57:04
*/
//@Scheduled(cron="0 0/10 * * * ? ")
public
void
updateDeltaIndex
(){
if
(
offon
){
SimpleDateFormat
f
=
new
SimpleDateFormat
(
"yyyy-MM-dd hh:mm:ss"
);
log
.
info
(
"定时任务2:全文检索全部更新资源库索引开始...时间:"
+
f
.
format
(
new
Date
()));
String
result
=
this
.
deltaImportIndex
();
if
(
result
.
equals
(
"1"
)){
log
.
info
(
"定时任务2:全文检索更新成功...时间:"
+
f
.
format
(
new
Date
()));
}
else
{
log
.
info
(
"定时任务2:全文检索更新失败...时间:"
+
f
.
format
(
new
Date
()));
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论