Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
messageflow
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
虞诚毅
messageflow
Commits
46e516cf
Commit
46e516cf
authored
Jun 27, 2018
by
shentao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
主分支 提交 平台整合后版本
parent
0240116a
Show whitespace changes
Inline
Side-by-side
Showing
36 changed files
with
3349 additions
and
66 deletions
+3349
-66
pom.xml
+7
-0
src/main/java/com/zhiwei/messageflow/ES4RedisRunner.java
+2
-1
src/main/java/com/zhiwei/messageflow/ES4RedisStart.java
+13
-5
src/main/java/com/zhiwei/messageflow/ES4RedisTask.java
+180
-0
src/main/java/com/zhiwei/messageflow/ES4RedisThreadNew.java
+131
-0
src/main/java/com/zhiwei/messageflow/ESGetCommonId.java
+59
-0
src/main/java/com/zhiwei/messageflow/es/dao/ESDao.java
+9
-0
src/main/java/com/zhiwei/messageflow/es/dao/TrackESDao.java
+11
-0
src/main/java/com/zhiwei/messageflow/es/dao/impl/ESDaoImpl.java
+242
-35
src/main/java/com/zhiwei/messageflow/es/dao/impl/TrackESDaoImpl.java
+210
-0
src/main/java/com/zhiwei/messageflow/es/service/ES4BeanService.java
+22
-0
src/main/java/com/zhiwei/messageflow/es/service/EarlyWarningService.java
+4
-0
src/main/java/com/zhiwei/messageflow/es/service/HighLightFillingService.java
+9
-0
src/main/java/com/zhiwei/messageflow/es/service/NoiseProcessingService.java
+5
-0
src/main/java/com/zhiwei/messageflow/es/service/TrackHitAndWarnService.java
+11
-0
src/main/java/com/zhiwei/messageflow/es/service/impl/ES4BeanServiceImpl.java
+26
-0
src/main/java/com/zhiwei/messageflow/es/service/impl/EarlyWarningServiceImpl.java
+82
-0
src/main/java/com/zhiwei/messageflow/es/service/impl/HighLightFillingServiceImpl.java
+371
-0
src/main/java/com/zhiwei/messageflow/es/service/impl/NoiseProcessingServiceImpl.java
+529
-4
src/main/java/com/zhiwei/messageflow/es/service/impl/TrackHitAndWarnServiceImpl.java
+378
-0
src/main/java/com/zhiwei/messageflow/mongo/bean/PlatformNew.java
+84
-0
src/main/java/com/zhiwei/messageflow/mongo/bean/PlatformType.java
+75
-0
src/main/java/com/zhiwei/messageflow/mongo/bean/Project.java
+24
-1
src/main/java/com/zhiwei/messageflow/mongo/dao/PlatformDao.java
+12
-0
src/main/java/com/zhiwei/messageflow/mongo/dao/impl/PlatformDaoImpl.java
+13
-0
src/main/java/com/zhiwei/messageflow/redis/bean/RsidAndMessages.java
+5
-0
src/main/java/com/zhiwei/messageflow/redis/service/RedisService.java
+16
-0
src/main/java/com/zhiwei/messageflow/redis/service/impl/RedisServiceImpl.java
+19
-0
src/main/java/com/zhiwei/messageflow/service/DisposeMessageService.java
+24
-0
src/main/java/com/zhiwei/messageflow/service/impl/DisposeMessageServiceImpl.java
+29
-0
src/main/java/com/zhiwei/messageflow/util/ESQueryUtil.java
+610
-0
src/main/resources/application.properties
+18
-18
src/main/resources/application.properties.8092
+96
-0
src/main/resources/redis.properties
+1
-1
src/main/resources/redis.properties.6380
+21
-0
src/main/resources/redis.properties.local1
+1
-1
No files found.
pom.xml
View file @
46e516cf
...
...
@@ -115,6 +115,13 @@
<version>
1.4.7
</version>
</dependency>
<!-- fastjson -->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<version>
1.2.34
</version>
</dependency>
</dependencies>
<build>
...
...
src/main/java/com/zhiwei/messageflow/ES4RedisRunner.java
View file @
46e516cf
...
...
@@ -33,7 +33,8 @@ public class ES4RedisRunner implements ApplicationRunner {
// */
// getSet gs = ApplicationContextProvider.getBean("getSet", getSet.class);
// gs.getDataByeRedis("", "", 0, 0, 0);
ESGetCommonId
esGetCommonId
=
ApplicationContextProvider
.
getBean
(
"ESGetCommonId"
,
ESGetCommonId
.
class
);
esGetCommonId
.
getCommonId
();
/**
* redis存入缓存
...
...
src/main/java/com/zhiwei/messageflow/ES4RedisStart.java
View file @
46e516cf
...
...
@@ -11,6 +11,7 @@ import org.springframework.stereotype.Component;
import
com.fasterxml.jackson.core.JsonParseException
;
import
com.fasterxml.jackson.databind.JsonMappingException
;
import
com.zhiwei.messageflow.mongo.bean.PlatformNew
;
import
com.zhiwei.messageflow.mongo.bean.Project
;
import
com.zhiwei.messageflow.mongo.dao.PlatformDao
;
import
com.zhiwei.messageflow.mongo.dao.ProjectDao
;
...
...
@@ -38,7 +39,7 @@ public class ES4RedisStart {
List
<
Project
>
projects
=
projectDao
.
getAllProjects
();
// 公共平台名列表
List
<
String
>
platformNames
=
platformDao
.
getPublicPlatformName
();
//
List<String> platformNames = platformDao.getPublicPlatformName();
// 遍历项目
for
(
Project
project
:
projects
)
{
...
...
@@ -46,14 +47,21 @@ public class ES4RedisStart {
/**
* 项目全部平台(公共+私有)
*/
List
<
String
>
allplatformNames
=
new
ArrayList
<>();
allplatformNames
.
addAll
(
platformNames
);
allplatformNames
.
addAll
(
project
.
getDataPt
());
List
<
PlatformNew
>
allplatformNames
=
platformDao
.
findPlatformByProject
(
project
);
// System.out.println(allplatformNames);
// List<String> allplatformNames = new ArrayList<>();
// allplatformNames.addAll(platformNames);
// allplatformNames.addAll(project.getDataPt());
// 获取线程
ES4RedisThread
es4RedisThread
=
ES4RedisThread
.
getThread
(
project
.
getProjectName
(),
project
,
ES4RedisThread
New
es4RedisThread
=
ES4RedisThreadNew
.
getThread
(
project
.
getProjectName
(),
project
,
allplatformNames
,
es4RedisTask
);
// ES4RedisThread es4RedisThread = ES4RedisThread.getThread(project.getProjectName(), project,
// allplatformNames, es4RedisTask);
// 获取线程失败
if
(
es4RedisThread
==
null
)
{
log
.
warn
(
"{}项目获取线程失败"
,
project
.
getProjectName
());
...
...
src/main/java/com/zhiwei/messageflow/ES4RedisTask.java
View file @
46e516cf
...
...
@@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
com.alibaba.fastjson.JSONObject
;
import
com.fasterxml.jackson.core.JsonParseException
;
import
com.fasterxml.jackson.databind.JsonMappingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
...
...
@@ -21,6 +22,7 @@ import com.zhiwei.messageflow.bean.ZhihuMessage;
import
com.zhiwei.messageflow.es.service.EarlyWarningService
;
import
com.zhiwei.messageflow.mongo.bean.KeywordNew
;
import
com.zhiwei.messageflow.mongo.bean.NoiseRule
;
import
com.zhiwei.messageflow.mongo.bean.PlatformNew
;
import
com.zhiwei.messageflow.mongo.bean.Project
;
import
com.zhiwei.messageflow.mongo.bean.TrackRule
;
import
com.zhiwei.messageflow.mongo.dao.KeywordNewDao
;
...
...
@@ -59,6 +61,182 @@ public class ES4RedisTask {
private
static
final
int
keywordscount
=
2000
;
@SuppressWarnings
(
"unchecked"
)
public
boolean
ES4RedisNew
(
Project
project
,
List
<
PlatformNew
>
platformNames
,
int
count
)
throws
JsonParseException
,
JsonMappingException
,
IOException
{
try
{
/**
* 获取项目对应的rsid Map
*/
String
rsidjson
=
redisService
.
getRsid
(
project
.
getProjectName
());
Map
<
String
,
Integer
>
rsidMap
=
new
HashMap
<>();
if
(
rsidjson
!=
null
)
{
rsidMap
=
mapper
.
readValue
(
rsidjson
,
Map
.
class
);
}
else
{
log
.
info
(
"{}项目RSID列表过期"
,
project
.
getProjectName
());
}
// 更新rsid用的rsid Map
Map
<
String
,
Integer
>
newRsidMap
=
new
HashMap
<>();
newRsidMap
.
putAll
(
rsidMap
);
// 统计项目消息总数
int
num
=
0
;
// 项目关键词组列表
List
<
KeywordNew
>
keywordNews
=
keywordNewDao
.
getKeywordNewByProject
(
project
.
getProjectName
());
// 项目噪音规则列表
List
<
NoiseRule
>
noiseRules
=
noiseRuleDao
.
getNoiseRuleByProject
(
project
.
getProjectName
());
// 项目预警规则列表
List
<
TrackRule
>
trackRules
=
trackRuleDao
.
getTrackRuleByProject
(
project
.
getProjectName
());
/*
* //测试预警规则 List<TrackRule> trackRules=new ArrayList<>(); TrackRule tr1=new
* TrackRule(); TrackRule tr2=new TrackRule(); TrackRule tr3=new TrackRule();
* Date date = new Date(); Long createAt=date.getTime();
* tr1.setCreateAt(createAt); tr1.setAndOr(""); tr1.setWarn(false);
* tr1.setRuleType("keyWords"); tr1.setSubmitter("虞诚毅");
* tr1.setKeyWordsInputOne("知乎"); tr1.setRuleName("测试规则1");
* tr1.setRuleExplain("测试说明1"); tr1.setEarlyWarningTime("三天");
* tr1.setProject("腾讯"); tr1.setEarlyWarning("email");
* tr2.setCreateAt(createAt); tr2.setAndOr("或"); tr2.setWarn(false);
* tr2.setRuleType("keyWords"); tr2.setSubmitter("虞诚毅");
* tr2.setKeyWordsInputOne("知乎"); tr2.setKeyWordsInputTwo("微博");
* tr2.setRuleName("测试规则2"); tr2.setRuleExplain("测试说明3");
* tr2.setEarlyWarningTime("三天"); tr2.setProject("腾讯");
* tr2.setEarlyWarning("email"); tr3.setCreateAt(createAt); tr3.setAndOr("且");
* tr3.setWarn(false); tr3.setRuleType("keyWords"); tr3.setSubmitter("虞诚毅");
* tr3.setKeyWordsInputOne("知乎"); tr3.setKeyWordsInputTwo("问题");
* tr3.setRuleName("测试规则2"); tr3.setRuleExplain("测试说明3");
* tr3.setEarlyWarningTime("三天"); tr3.setProject("腾讯");
* tr3.setEarlyWarning("wechat"); trackRules.add(tr1); trackRules.add(tr2);
* trackRules.add(tr3);
*/
// 遍历平台
for
(
PlatformNew
platform
:
platformNames
)
{
String
platformName
=
platform
.
getPlatformName
();
/**
* 平台全关键词查询
*/
String
allkeytitle
=
"全部"
;
// 全关键词redis库中的key
String
allRedisKey
=
platformName
+
"-"
+
project
.
getProjectName
()
+
"-"
+
allkeytitle
;
// 获取 平台-项目-关键词组 对应的rsid作为查询范围的起始点
long
allstartrsid
=
rsidMap
.
get
(
allRedisKey
)
==
null
?
-
1L
:
Long
.
valueOf
(
rsidMap
.
get
(
allRedisKey
));
// 用于存储数据获取后新的rsid
Long
allrsid
=
-
1L
;
/**
* 将项目下的所有关键词组合成全关键词组
*/
List
<
String
>
allkeywords
=
new
ArrayList
<>();
for
(
KeywordNew
kwn
:
keywordNews
)
{
if
(
null
==
kwn
.
getKeyWords
()
||
kwn
.
getKeyWords
().
isEmpty
())
{
continue
;
}
allkeywords
.
addAll
(
kwn
.
getKeyWords
());
}
// 根据不同平台获取数据(同一方法,统一封装为消息流实体
RsidAndMessages
ram
=
disposeMessageService
.
getFilteredMessage
(
noiseRules
,
allkeywords
,
count
,
allstartrsid
,
-
1L
,
platform
,
project
.
getProjectName
(),
project
.
getMatchFields
());
// 获取查询到的信息
List
<
JSONObject
>
messages
=
ram
.
getJlist
();
// 数据量为0
if
(
messages
==
null
)
{
// log.info("{}平台{}关键字词组无消息", platformName, allkeytitle);
continue
;
}
// log.info("{}平台{}关键词数据获取{}条", platformName, "全部", messages.size());
// 记录新的rsid
allrsid
=
ram
.
getRsid
();
num
+=
messages
.
size
();
// 向redis写入数据
redisService
.
setMessage2Redis
(
allRedisKey
,
messages
,
allkeywordcount
);
newRsidMap
.
put
(
allRedisKey
,
Integer
.
valueOf
(
allrsid
.
toString
()));
// 遍历关键词组
for
(
KeywordNew
kwn
:
keywordNews
)
{
// 滤过空关键词组
if
(
null
==
kwn
.
getKeyWords
()
||
kwn
.
getKeyWords
().
isEmpty
())
{
continue
;
}
// 关键词组在redis库中的key
String
redisKey
=
platformName
+
"-"
+
project
.
getProjectName
()
+
"-"
+
kwn
.
getKeyTitle
();
// 获取 平台-项目-关键词组 对应的rsid作为查询范围的起始点
Long
startrsid
=
rsidMap
.
get
(
redisKey
)
==
null
?
-
1L
:
Long
.
valueOf
(
rsidMap
.
get
(
redisKey
));
// 用于存储数据获取后新的rsid
Long
keyrsid
=
-
1L
;
// System.out.println(kwn.toString());
// System.out.println(l++ + ":" + platformName);
// System.out.println("=============这是分界线=============");
// 获取新的rsid和信息实体
RsidAndMessages
ramkey
=
disposeMessageService
.
getFilteredMessage
(
noiseRules
,
kwn
.
getKeyWords
(),
count
,
startrsid
,
-
1L
,
platform
,
project
.
getProjectName
(),
project
.
getMatchFields
());
// 获取查询到的信息
List
<
JSONObject
>
messageskey
=
ramkey
.
getJlist
();
// 查询到数据量为0
if
(
messageskey
==
null
)
{
newRsidMap
.
put
(
redisKey
,
Integer
.
valueOf
(
startrsid
.
toString
()));
// log.info("{}平台{}关键字词组无消息", platformName, kwn.getKeyTitle());
continue
;
}
// log.info("{}平台{}关键词数据获取{}条", platformName, kwn.getKeyTitle(),
// messages.size());
num
+=
messageskey
.
size
();
// 记录新的rsid
keyrsid
=
ramkey
.
getRsid
();
// 向redis写入数据
redisService
.
setMessage2Redis
(
redisKey
,
messageskey
,
keywordscount
);
}
// 遍历关键词组
// 预警
earlyWarningService
.
earlyWarningNew
(
trackRules
,
count
,
allstartrsid
,
allrsid
,
platform
,
project
.
getProjectName
());
// 向redis库中存储新的rsid Map,覆盖原有数据
redisService
.
setRsid
(
newRsidMap
,
project
.
getProjectName
());
}
// 遍历平台
log
.
info
(
"{}项目本次获取消息数:{}"
,
project
.
getProjectName
(),
num
);
}
catch
(
Exception
e
)
{
log
.
error
(
"项目本次获取获取出错或超时{}{}"
,
e
.
getMessage
(),
e
.
getStackTrace
());
return
false
;
}
return
true
;
}
@SuppressWarnings
(
"unchecked"
)
public
boolean
ES4Redis
(
Project
project
,
List
<
String
>
platformNames
,
int
count
)
throws
JsonParseException
,
JsonMappingException
,
IOException
{
...
...
@@ -383,4 +561,5 @@ public class ES4RedisTask {
}
return
true
;
}
}
\ No newline at end of file
src/main/java/com/zhiwei/messageflow/ES4RedisThreadNew.java
0 → 100644
View file @
46e516cf
package
com
.
zhiwei
.
messageflow
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.fasterxml.jackson.core.JsonParseException
;
import
com.fasterxml.jackson.databind.JsonMappingException
;
import
com.zhiwei.messageflow.mongo.bean.PlatformNew
;
import
com.zhiwei.messageflow.mongo.bean.Project
;
public
class
ES4RedisThreadNew
extends
Thread
{
private
final
static
Logger
log
=
LoggerFactory
.
getLogger
(
ES4RedisThreadNew
.
class
);
// 线程
private
Thread
t
;
// 线程名
private
String
threadName
;
// 项目
private
Project
project
;
// 平台列表
private
List
<
PlatformNew
>
platformNames
;
private
ES4RedisTask
es4RedisTask
;
// 单个平台单个关键词组每次查询数量
private
static
final
int
count
=
300
;
// private static final int max_Thread_num = 40;
// private static int Thread_num = 0;
// private static final int max_Running_num = 3;
// private static Integer Running_num = 0;
// private static List<String> ThreadList = new ArrayList<>();
public
ES4RedisThreadNew
(
String
name
,
Project
project
,
List
<
PlatformNew
>
allplatformNames
,
ES4RedisTask
es4RedisTask
)
{
threadName
=
name
;
this
.
project
=
project
;
this
.
platformNames
=
allplatformNames
;
this
.
es4RedisTask
=
es4RedisTask
;
}
public
ES4RedisThreadNew
()
{
}
public
static
ES4RedisThreadNew
getThread
(
String
name
,
Project
project
,
List
<
PlatformNew
>
allplatformNames
,
ES4RedisTask
es4RedisTask
)
{
ES4RedisThreadNew
es4RedisThread
=
new
ES4RedisThreadNew
(
name
,
project
,
allplatformNames
,
es4RedisTask
);
return
es4RedisThread
;
}
public
void
start
()
{
// 线程开始
log
.
info
(
"Starting {}"
,
threadName
);
if
(
t
==
null
)
{
t
=
new
Thread
(
this
,
threadName
);
// 通知执行run方法
t
.
start
();
}
// 超时控制器
Timer
timer
=
new
Timer
();
timer
.
schedule
(
new
TimerTask
()
{
@Override
public
void
run
()
{
// 超时则线程中止
if
(
t
.
isAlive
())
{
t
.
interrupt
();
log
.
warn
(
"{}项目超时线程状态:{}"
,
project
.
getProjectName
(),
t
.
isInterrupted
());
}
}
},
49
*
1000L
);
}
@SuppressWarnings
(
"static-access"
)
@Override
public
void
run
()
{
try
{
Thread
.
sleep
(
10L
);
// 超时控制器
// Timer timer = new Timer();
// timer.schedule(new TimerTask() {
// @Override
// public void run() {
// // 超时则线程中止
// Thread.currentThread().interrupted();
// log.warn("{}项目超时", project.getProjectName());
// }
// }, 49 * 1000L);
// 程序运行
log
.
info
(
"Running {}"
,
threadName
);
// 该项目执行消息流获取
boolean
flag
=
es4RedisTask
.
ES4RedisNew
(
project
,
platformNames
,
count
);
if
(!
flag
)
{
// 程序执行出现异常则线程中止
// timer.cancel();
Thread
.
currentThread
().
interrupted
();
log
.
error
(
"{}项目出现异常,线程状态:{}"
,
project
.
getProjectName
(),
Thread
.
currentThread
().
isInterrupted
());
}
// else
// // 程序正常执行完毕,关闭超时控制器
// timer.cancel();
}
catch
(
JsonParseException
e
)
{
e
.
printStackTrace
();
}
catch
(
JsonMappingException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
finally
{
// 线程退出
log
.
info
(
"Thread {} exiting."
,
threadName
);
}
}
}
\ No newline at end of file
src/main/java/com/zhiwei/messageflow/ESGetCommonId.java
0 → 100644
View file @
46e516cf
package
com
.
zhiwei
.
messageflow
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
com.zhiwei.messageflow.es.dao.ESDao
;
@Component
public
class
ESGetCommonId
{
@Autowired
private
ESDao
esDao
;
public
static
int
START_COMMONID
;
public
static
long
TIME
;
public
void
getCommonId
()
{
long
nowtime
=
System
.
currentTimeMillis
();
if
(
TIME
<
nowtime
-
60
*
1000L
)
{
List
<
Integer
>
cidList
=
new
ArrayList
<>();
int
weibo
=
esDao
.
get24hoursFirstCommonid
(
"weibo"
);
cidList
.
add
(
weibo
);
int
media
=
esDao
.
get24hoursFirstCommonid
(
"media"
);
cidList
.
add
(
media
);
int
video
=
esDao
.
get24hoursFirstCommonid
(
"video"
);
cidList
.
add
(
video
);
int
zhihu
=
esDao
.
get24hoursFirstCommonid
(
"zhihu"
);
cidList
.
add
(
zhihu
);
Collections
.
sort
(
cidList
);
System
.
err
.
println
(
weibo
+
" "
+
media
+
" "
+
video
+
" "
+
zhihu
+
"\n"
+
cidList
);
START_COMMONID
=
cidList
.
get
(
0
);
TIME
=
nowtime
;
}
}
public
int
getCommonId
(
long
limit
)
{
long
nowtime
=
System
.
currentTimeMillis
();
long
endtime
=
nowtime
-
limit
;
List
<
Integer
>
cidList
=
new
ArrayList
<>();
int
weibo
=
esDao
.
getCommonidByTime
(
"weibo"
,
endtime
);
cidList
.
add
(
weibo
);
int
media
=
esDao
.
getCommonidByTime
(
"media"
,
endtime
);
cidList
.
add
(
media
);
int
video
=
esDao
.
getCommonidByTime
(
"video"
,
endtime
);
cidList
.
add
(
video
);
int
zhihu
=
esDao
.
getCommonidByTime
(
"zhihu"
,
endtime
);
cidList
.
add
(
zhihu
);
Collections
.
sort
(
cidList
);
// System.err.println(weibo + " " + media + " " + video + " " + zhihu + "\n" + cidList);
int
commonid
=
cidList
.
get
(
0
);
return
commonid
;
}
}
src/main/java/com/zhiwei/messageflow/es/dao/ESDao.java
View file @
46e516cf
...
...
@@ -4,6 +4,8 @@ import java.util.List;
import
org.elasticsearch.search.SearchHits
;
import
com.zhiwei.messageflow.mongo.bean.PlatformNew
;
//第一层 从ES获取原始数据
public
interface
ESDao
{
...
...
@@ -95,4 +97,11 @@ public interface ESDao {
public
SearchHits
getMediaDataycy
(
long
date
,
List
<
String
>
keywords
,
int
count
,
String
platform
,
String
project
);
public
SearchHits
getDataFromEs
(
List
<
String
>
keywords
,
int
count
,
long
startid
,
long
endid
,
PlatformNew
platform
,
String
project
,
String
matchFields
);
public
int
get24hoursFirstCommonid
(
String
tableName
);
public
int
getCommonidByTime
(
String
tableName
,
long
endtime
);
}
src/main/java/com/zhiwei/messageflow/es/dao/TrackESDao.java
View file @
46e516cf
...
...
@@ -2,6 +2,8 @@ package com.zhiwei.messageflow.es.dao;
import
org.elasticsearch.search.SearchHits
;
import
com.zhiwei.messageflow.mongo.bean.PlatformNew
;
public
interface
TrackESDao
{
/**
...
...
@@ -210,4 +212,13 @@ public interface TrackESDao {
*/
public
SearchHits
getarticleTrackMediaFromEs
(
String
articleTitle
,
String
color
,
int
count
,
long
start
,
long
end
,
String
platformName
);
public
SearchHits
getkeyWordsTrackFromEs
(
String
anyWord
,
String
allWords
,
String
color
,
int
count
,
long
startid
,
Long
endid
,
PlatformNew
platform
);
public
SearchHits
getchannelTrackFromEs
(
String
channel
,
String
color
,
int
count
,
long
startid
,
Long
endid
,
PlatformNew
platform
);
public
SearchHits
getarticleTrackFromEs
(
String
articleTitle
,
String
color
,
int
count
,
long
startid
,
Long
endid
,
PlatformNew
platform
);
}
src/main/java/com/zhiwei/messageflow/es/dao/impl/ESDaoImpl.java
View file @
46e516cf
...
...
@@ -14,8 +14,10 @@ import org.elasticsearch.search.sort.SortOrder;
import
org.springframework.stereotype.Component
;
import
com.zhiwei.es.util.ESIndexesUtil
;
import
com.zhiwei.messageflow.ESGetCommonId
;
import
com.zhiwei.messageflow.es.ESClient
;
import
com.zhiwei.messageflow.es.dao.ESDao
;
import
com.zhiwei.messageflow.mongo.bean.PlatformNew
;
import
com.zhiwei.messageflow.util.ESQueryUtil
;
import
com.zhiwei.messageflow.util.TimeUtil
;
...
...
@@ -24,9 +26,83 @@ public class ESDaoImpl implements ESDao {
TransportClient
transportClient
=
ESClient
.
client
;
// protected static ESIndexesUtil.ESIndexes indexes = ESIndexesUtil.create("192.168.1.75", 9200);
protected
static
ESIndexesUtil
.
ESIndexes
indexes
=
ESIndexesUtil
.
create
(
"1.119.44.201"
,
9200
);
// protected static ESIndexesUtil.ESIndexes indexes =
// ESIndexesUtil.create("192.168.1.75", 9200);
protected
static
ESIndexesUtil
.
ESIndexes
indexes
=
ESIndexesUtil
.
create
(
"1.119.44.201"
,
9200
);
@Override
public
SearchHits
getDataFromEs
(
List
<
String
>
keywords
,
int
count
,
long
startid
,
long
endid
,
PlatformNew
platform
,
String
project
,
String
matchFields
)
{
// 按ptlist获取indexlist
List
<
String
>
ptList
=
platform
.
getPt
();
ptList
.
removeAll
(
platform
.
getNoPt
());
List
<
String
>
noPlatformType
=
platform
.
getNoPlatformType
();
String
[]
indexlist
=
ESQueryUtil
.
getIndexListbyPtList
(
ptList
,
noPlatformType
);
// 按ptlist获取typelist
String
[]
typelist
=
ESQueryUtil
.
getTypeListbyPtList
(
ptList
);
// 组装查询语句
BoolQueryBuilder
queryBuilder
=
QueryBuilders
.
boolQuery
();
// 一阶段组装关键词
// 取field
String
[]
fieldlist
=
ESQueryUtil
.
getFieldListbyPtList
(
ptList
,
noPlatformType
,
matchFields
);
BoolQueryBuilder
keywordQueryBuilder
=
ESQueryUtil
.
assembleKeywordQuery
(
QueryBuilders
.
boolQuery
(),
keywords
,
fieldlist
);
queryBuilder
.
must
(
keywordQueryBuilder
);
// 二阶段组装type、source、uper
// 组装type
List
<
String
>
typeList
=
platform
.
getType
();
List
<
String
>
noTypeList
=
platform
.
getNoType
();
BoolQueryBuilder
tsuQueryBuilder
=
ESQueryUtil
.
assembleShouldNotFieldsQuery
(
QueryBuilders
.
boolQuery
(),
typeList
,
noTypeList
,
"type"
);
// 组装source
List
<
String
>
sourceList
=
platform
.
getSource
();
List
<
String
>
noSourceList
=
platform
.
getNoSource
();
tsuQueryBuilder
=
ESQueryUtil
.
assembleShouldNotFieldsQuery
(
tsuQueryBuilder
,
sourceList
,
noSourceList
,
"source"
);
// 组装uper
List
<
String
>
uperList
=
platform
.
getUper
();
List
<
String
>
noUperList
=
platform
.
getNoUper
();
tsuQueryBuilder
=
ESQueryUtil
.
assembleShouldNotFieldsQuery
(
tsuQueryBuilder
,
uperList
,
noUperList
,
"uper"
);
queryBuilder
.
must
(
tsuQueryBuilder
);
// 三阶段特殊规则 weiboSinaV weiboAlt
List
<
String
>
srList
=
platform
.
getSpecialRule
();
BoolQueryBuilder
srQueryBuilder
=
ESQueryUtil
.
assembleSpecialRuleQurey
(
QueryBuilders
.
boolQuery
(),
srList
);
queryBuilder
.
must
(
srQueryBuilder
);
// 四阶段插件过滤
BoolQueryBuilder
pluginQueryBuilder
=
ESQueryUtil
.
assemblePluginQurey
(
QueryBuilders
.
boolQuery
());
queryBuilder
.
must
(
pluginQueryBuilder
);
// 组装高亮字段
String
[]
allfieldlist
=
ESQueryUtil
.
getFieldListbyPtList
(
ptList
,
noPlatformType
,
""
);
HighlightBuilder
highlightBuilder
=
ESQueryUtil
.
getHighlightBuilder
(
allfieldlist
);
// 组配查询
SearchRequestBuilder
searchRequestBuilder
=
transportClient
.
prepareSearch
(
indexlist
).
setTypes
(
typelist
)
.
highlighter
(
highlightBuilder
).
setQuery
(
queryBuilder
).
addSort
(
"commonid"
,
SortOrder
.
DESC
).
setFrom
(
0
)
.
setSize
(
count
);
if
(
startid
>
0
&&
endid
<=
0
)
{
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"commonid"
).
from
(
startid
));
}
else
if
(
endid
>
0
&&
startid
<=
0
)
{
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"commonid"
).
to
(
endid
));
}
else
if
(
endid
>
0
&&
startid
>
0
)
{
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"commonid"
).
from
(
startid
).
to
(
endid
));
}
else
{
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"commonid"
).
from
(
ESGetCommonId
.
START_COMMONID
));
}
SearchResponse
response
=
searchRequestBuilder
.
execute
().
actionGet
();
SearchHits
searchHits
=
response
.
getHits
();
// System.err.println("totalHit"+searchHits.totalHits+"hitsnum"+searchHits.getHits().length);
return
searchHits
;
}
@Override
public
SearchHits
getWeiboDataFromEs
(
List
<
String
>
keywords
,
int
count
,
long
startid
,
long
endid
,
String
platform
,
...
...
@@ -64,7 +140,7 @@ public class ESDaoImpl implements ESDao {
mixboolQueryBuilder
.
must
(
allboolQueryBuilder
);
}
boolQueryBuilder1
.
should
(
mixboolQueryBuilder
);
}
else
if
(
word
.
indexOf
(
" "
)
!=
-
1
){
}
else
if
(
word
.
indexOf
(
" "
)
!=
-
1
)
{
BoolQueryBuilder
mixboolQueryBuilder
=
QueryBuilders
.
boolQuery
();
String
[]
words
=
word
.
split
(
" "
);
mixboolQueryBuilder
...
...
@@ -72,16 +148,17 @@ public class ESDaoImpl implements ESDao {
mixboolQueryBuilder
.
should
(
ESQueryUtil
.
matchPhraseQueryWords
(
QueryBuilders
.
boolQuery
(),
"must"
,
"roottext"
,
words
));
boolQueryBuilder1
.
should
(
mixboolQueryBuilder
);
}
else
{
}
else
{
ESQueryUtil
.
matchPhraseQueryFields
(
boolQueryBuilder1
,
"should"
,
word
,
"text"
,
"roottext"
);
}
}
//旧搜索语句
// for (int i = 0; i < keywords.size(); i++) {
// String word = keywords.get(i).replace("serach---", "");
// ESQueryUtil.matchPhraseQueryFields(boolQueryBuilder1, "should", word, "text", "roottext");
// }
// 旧搜索语句
// for (int i = 0; i < keywords.size(); i++) {
// String word = keywords.get(i).replace("serach---", "");
// ESQueryUtil.matchPhraseQueryFields(boolQueryBuilder1, "should", word, "text",
// "roottext");
// }
// 去除插件标注
boolQueryBuilder
.
mustNot
(
QueryBuilders
.
matchQuery
(
"source"
,
"插件标注"
));
...
...
@@ -179,12 +256,13 @@ public class ESDaoImpl implements ESDao {
}
}
//旧查询语句
// for (int i = 0; i < keywords.size(); i++) {
// String word = keywords.get(i).replace("serach---", "");
// ESQueryUtil.matchPhraseQueryFields(boolQueryBuilder, "should", word, "question_title",
// "question_content", "answer_content");
// }
// 旧查询语句
// for (int i = 0; i < keywords.size(); i++) {
// String word = keywords.get(i).replace("serach---", "");
// ESQueryUtil.matchPhraseQueryFields(boolQueryBuilder, "should", word,
// "question_title",
// "question_content", "answer_content");
// }
HighlightBuilder
highlightBuilder
=
ESQueryUtil
.
getHighlightBuilder
(
"question_title"
,
"question_content"
,
"answer_content"
);
// 高亮设置
...
...
@@ -273,11 +351,12 @@ public class ESDaoImpl implements ESDao {
}
}
//旧查询语句
// for (int i = 0; i < keywords.size(); i++) {
// String word = keywords.get(i).replace("serach---", "");
// ESQueryUtil.matchPhraseQueryFields(boolQueryBuilder1, "should", word, "title");
// }
// 旧查询语句
// for (int i = 0; i < keywords.size(); i++) {
// String word = keywords.get(i).replace("serach---", "");
// ESQueryUtil.matchPhraseQueryFields(boolQueryBuilder1, "should", word,
// "title");
// }
boolQueryBuilder
.
must
(
boolQueryBuilder1
);
HighlightBuilder
highlightBuilder
=
ESQueryUtil
.
getHighlightBuilder
(
"title"
);
// 高亮设置
...
...
@@ -353,23 +432,25 @@ public class ESDaoImpl implements ESDao {
mixboolQueryBuilder
.
should
(
ESQueryUtil
.
matchPhraseQueryWords
(
QueryBuilders
.
boolQuery
(),
ESQueryUtil
.
ES_QUERY_AND
,
"content"
,
words
));
// String words[] = keyword.split(" ");
// for (int i = 0; i < words.length; i++) {
// String word = words[i];
// ESQueryUtil.matchPhraseQueryFields(mixboolQueryBuilder, "must", word, "title", "content");
//// System.err.println("keyword:"+keyword);
// }
// String words[] = keyword.split(" ");
// for (int i = 0; i < words.length; i++) {
// String word = words[i];
// ESQueryUtil.matchPhraseQueryFields(mixboolQueryBuilder, "must", word,
// "title", "content");
//// System.err.println("keyword:"+keyword);
// }
boolQueryBuilder1
.
should
(
mixboolQueryBuilder
);
}
else
{
ESQueryUtil
.
matchPhraseQueryFields
(
boolQueryBuilder1
,
"should"
,
keyword
,
"title"
,
"content"
);
}
}
//旧查询语句
// for (int i = 0; i < keywords.size(); i++) {
// String word = keywords.get(i).replace("serach---", "");
// ESQueryUtil.matchPhraseQueryFields(boolQueryBuilder1, "should", word, "title", "content");
// }
// 旧查询语句
// for (int i = 0; i < keywords.size(); i++) {
// String word = keywords.get(i).replace("serach---", "");
// ESQueryUtil.matchPhraseQueryFields(boolQueryBuilder1, "should", word,
// "title", "content");
// }
HighlightBuilder
highlightBuilder
=
ESQueryUtil
.
getHighlightBuilder
(
"title"
,
"content"
);
// 高亮设置
...
...
@@ -615,9 +696,9 @@ public class ESDaoImpl implements ESDao {
.
must
(
QueryBuilders
.
existsQuery
(
"crawlerV"
));
boolQueryBuilder
.
must
(
QueryBuilders
.
boolQuery
().
should
(
booljrQueryBuilder1
).
should
(
booljrQueryBuilder2
));
//插件流
//
boolQueryBuilder.must(QueryBuilders.matchPhraseQuery("type", "今日头条"))
//
.mustNot(QueryBuilders.existsQuery("spyderInfoId")).mustNot(QueryBuilders.existsQuery("crawlerV"));
//
插件流
//
boolQueryBuilder.must(QueryBuilders.matchPhraseQuery("type", "今日头条"))
//
.mustNot(QueryBuilders.existsQuery("spyderInfoId")).mustNot(QueryBuilders.existsQuery("crawlerV"));
}
else
if
(
platform
.
equals
(
"客户端"
))
{
boolQueryBuilder
.
must
(
QueryBuilders
.
boolQuery
().
should
(
QueryBuilders
.
wildcardQuery
(
"type"
,
"*客户端"
))
.
should
(
QueryBuilders
.
matchPhraseQuery
(
"type"
,
"脉脉"
)));
...
...
@@ -641,4 +722,129 @@ public class ESDaoImpl implements ESDao {
return
searchHits
;
}
@Override
public
int
get24hoursFirstCommonid
(
String
tableName
)
{
// 获取当天最早commonid
int
commonid
=
0
;
long
date
=
System
.
currentTimeMillis
()
-
1
*
24
*
60
*
60
*
1000L
;
String
weibotime
=
TimeUtil
.
formatDateToMinute
(
new
Date
(
date
));
String
zhihutime
=
TimeUtil
.
formatEsDate
(
new
Date
(
date
-
8
*
3600
*
1000L
))
+
"Z"
;
String
vmtime
=
TimeUtil
.
formatEsDate
(
new
Date
(
date
-
8
*
3600
*
1000L
));
// weibo
if
(
tableName
.
equals
(
"weibo"
))
{
List
<
String
>
list
=
indexes
.
getLastIndexes
(
"network"
,
2
);
String
[]
indexlist
=
list
.
toArray
(
new
String
[
list
.
size
()]);
SearchRequestBuilder
searchRequestBuilder
=
transportClient
.
prepareSearch
(
indexlist
).
setTypes
(
"status"
)
.
setQuery
(
QueryBuilders
.
matchAllQuery
()).
setFetchSource
(
new
String
[]
{
"commonid"
},
null
)
.
addSort
(
"commonid"
,
SortOrder
.
ASC
).
setFrom
(
0
).
setSize
(
1
);
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"time"
).
from
(
weibotime
));
SearchResponse
response
=
searchRequestBuilder
.
execute
().
actionGet
();
SearchHits
searchHits
=
response
.
getHits
();
commonid
=
Integer
.
valueOf
(
searchHits
.
getAt
(
0
).
getSource
().
get
(
"commonid"
)
+
""
);
}
else
if
(
tableName
.
equals
(
"video"
))
{
// video
List
<
String
>
list
=
indexes
.
getLastIndexes
(
"videos"
,
2
);
String
[]
indexlist
=
list
.
toArray
(
new
String
[
list
.
size
()]);
SearchRequestBuilder
searchRequestBuilder
=
transportClient
.
prepareSearch
(
indexlist
).
setTypes
(
"video"
)
.
setQuery
(
QueryBuilders
.
matchAllQuery
()).
setFetchSource
(
new
String
[]
{
"commonid"
},
null
)
.
addSort
(
"commonid"
,
SortOrder
.
ASC
).
setFrom
(
0
).
setSize
(
1
);
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"time"
).
from
(
vmtime
));
SearchResponse
response
=
searchRequestBuilder
.
execute
().
actionGet
();
SearchHits
searchHits
=
response
.
getHits
();
commonid
=
Integer
.
valueOf
(
searchHits
.
getAt
(
0
).
getSource
().
get
(
"commonid"
)
+
""
);
}
else
if
(
tableName
.
equals
(
"media"
))
{
// media
List
<
String
>
list
=
indexes
.
getLastIndexes
(
"mediaspider"
,
2
);
String
[]
indexlist
=
list
.
toArray
(
new
String
[
list
.
size
()]);
SearchRequestBuilder
searchRequestBuilder
=
transportClient
.
prepareSearch
(
indexlist
)
.
setQuery
(
QueryBuilders
.
matchAllQuery
()).
setFetchSource
(
new
String
[]
{
"commonid"
},
null
)
.
addSort
(
"commonid"
,
SortOrder
.
ASC
).
setFrom
(
0
).
setSize
(
1
);
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"time"
).
from
(
vmtime
));
SearchResponse
response
=
searchRequestBuilder
.
execute
().
actionGet
();
SearchHits
searchHits
=
response
.
getHits
();
commonid
=
Integer
.
valueOf
(
searchHits
.
getAt
(
0
).
getSource
().
get
(
"commonid"
)
+
""
);
}
else
{
// zhihu
SearchRequestBuilder
searchRequestBuilder
=
transportClient
.
prepareSearch
(
"zhihu*"
).
setTypes
(
"zhihu"
)
.
setQuery
(
QueryBuilders
.
matchAllQuery
()).
setFetchSource
(
new
String
[]
{
"commonid"
},
null
)
.
addSort
(
"commonid"
,
SortOrder
.
ASC
).
setFrom
(
0
).
setSize
(
1
);
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"insert_at"
).
from
(
zhihutime
));
SearchResponse
response
=
searchRequestBuilder
.
execute
().
actionGet
();
SearchHits
searchHits
=
response
.
getHits
();
commonid
=
Integer
.
valueOf
(
searchHits
.
getAt
(
0
).
getSource
().
get
(
"commonid"
)
+
""
);
}
return
commonid
;
}
@Override
public
int
getCommonidByTime
(
String
tableName
,
long
endtime
)
{
// 获取当天最早commonid
int
commonid
=
0
;
long
date
=
endtime
;
String
weibotime
=
TimeUtil
.
formatDateToMinute
(
new
Date
(
date
));
String
zhihutime
=
TimeUtil
.
formatEsDate
(
new
Date
(
date
-
8
*
3600
*
1000L
))
+
"Z"
;
String
vmtime
=
TimeUtil
.
formatEsDate
(
new
Date
(
date
-
8
*
3600
*
1000L
));
// weibo
if
(
tableName
.
equals
(
"weibo"
))
{
List
<
String
>
list
=
indexes
.
getLastIndexes
(
"network"
,
2
);
String
[]
indexlist
=
list
.
toArray
(
new
String
[
list
.
size
()]);
SearchRequestBuilder
searchRequestBuilder
=
transportClient
.
prepareSearch
(
indexlist
).
setTypes
(
"status"
)
.
setQuery
(
QueryBuilders
.
matchAllQuery
()).
setFetchSource
(
new
String
[]
{
"commonid"
},
null
)
.
addSort
(
"commonid"
,
SortOrder
.
ASC
).
setFrom
(
0
).
setSize
(
1
);
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"time"
).
from
(
weibotime
));
SearchResponse
response
=
searchRequestBuilder
.
execute
().
actionGet
();
SearchHits
searchHits
=
response
.
getHits
();
commonid
=
Integer
.
valueOf
(
searchHits
.
getAt
(
0
).
getSource
().
get
(
"commonid"
)
+
""
);
}
else
if
(
tableName
.
equals
(
"video"
))
{
// video
List
<
String
>
list
=
indexes
.
getLastIndexes
(
"videos"
,
2
);
String
[]
indexlist
=
list
.
toArray
(
new
String
[
list
.
size
()]);
SearchRequestBuilder
searchRequestBuilder
=
transportClient
.
prepareSearch
(
indexlist
).
setTypes
(
"video"
)
.
setQuery
(
QueryBuilders
.
matchAllQuery
()).
setFetchSource
(
new
String
[]
{
"commonid"
},
null
)
.
addSort
(
"commonid"
,
SortOrder
.
ASC
).
setFrom
(
0
).
setSize
(
1
);
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"time"
).
from
(
vmtime
));
SearchResponse
response
=
searchRequestBuilder
.
execute
().
actionGet
();
SearchHits
searchHits
=
response
.
getHits
();
commonid
=
Integer
.
valueOf
(
searchHits
.
getAt
(
0
).
getSource
().
get
(
"commonid"
)
+
""
);
}
else
if
(
tableName
.
equals
(
"media"
))
{
// media
List
<
String
>
list
=
indexes
.
getLastIndexes
(
"mediaspider"
,
2
);
String
[]
indexlist
=
list
.
toArray
(
new
String
[
list
.
size
()]);
SearchRequestBuilder
searchRequestBuilder
=
transportClient
.
prepareSearch
(
indexlist
)
.
setQuery
(
QueryBuilders
.
matchAllQuery
()).
setFetchSource
(
new
String
[]
{
"commonid"
},
null
)
.
addSort
(
"commonid"
,
SortOrder
.
ASC
).
setFrom
(
0
).
setSize
(
1
);
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"time"
).
from
(
vmtime
));
SearchResponse
response
=
searchRequestBuilder
.
execute
().
actionGet
();
SearchHits
searchHits
=
response
.
getHits
();
commonid
=
Integer
.
valueOf
(
searchHits
.
getAt
(
0
).
getSource
().
get
(
"commonid"
)
+
""
);
}
else
{
// zhihu
SearchRequestBuilder
searchRequestBuilder
=
transportClient
.
prepareSearch
(
"zhihu*"
).
setTypes
(
"zhihu"
)
.
setQuery
(
QueryBuilders
.
matchAllQuery
()).
setFetchSource
(
new
String
[]
{
"commonid"
},
null
)
.
addSort
(
"commonid"
,
SortOrder
.
ASC
).
setFrom
(
0
).
setSize
(
1
);
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"insert_at"
).
from
(
zhihutime
));
SearchResponse
response
=
searchRequestBuilder
.
execute
().
actionGet
();
SearchHits
searchHits
=
response
.
getHits
();
commonid
=
Integer
.
valueOf
(
searchHits
.
getAt
(
0
).
getSource
().
get
(
"commonid"
)
+
""
);
}
return
commonid
;
}
}
\ No newline at end of file
src/main/java/com/zhiwei/messageflow/es/dao/impl/TrackESDaoImpl.java
View file @
46e516cf
package
com
.
zhiwei
.
messageflow
.
es
.
dao
.
impl
;
import
java.util.Date
;
import
java.util.List
;
import
org.elasticsearch.action.search.SearchRequestBuilder
;
import
org.elasticsearch.action.search.SearchResponse
;
...
...
@@ -13,9 +14,11 @@ import org.elasticsearch.search.sort.SortOrder;
import
org.springframework.stereotype.Component
;
import
com.zhiwei.es.util.ESIndexesUtil
;
import
com.zhiwei.messageflow.ESGetCommonId
;
import
com.zhiwei.messageflow.config.ESConfig
;
import
com.zhiwei.messageflow.es.ESClient
;
import
com.zhiwei.messageflow.es.dao.TrackESDao
;
import
com.zhiwei.messageflow.mongo.bean.PlatformNew
;
import
com.zhiwei.messageflow.util.ESQueryUtil
;
import
com.zhiwei.messageflow.util.TimeUtil
;
...
...
@@ -471,4 +474,211 @@ public class TrackESDaoImpl implements TrackESDao {
return
searchHits
;
}
@Override
public
SearchHits
getkeyWordsTrackFromEs
(
String
anyWord
,
String
allWords
,
String
color
,
int
count
,
long
startid
,
Long
endid
,
PlatformNew
platform
)
{
// 按ptlist获取indexlist
List
<
String
>
ptList
=
platform
.
getPt
();
ptList
.
removeAll
(
platform
.
getNoPt
());
List
<
String
>
noPlatformType
=
platform
.
getNoPlatformType
();
String
[]
indexlist
=
ESQueryUtil
.
getIndexListbyPtList
(
ptList
,
noPlatformType
);
// 按ptlist获取typelist
String
[]
typelist
=
ESQueryUtil
.
getTypeListbyPtList
(
ptList
);
// 组装查询语句
BoolQueryBuilder
queryBuilder
=
QueryBuilders
.
boolQuery
();
// 一阶段组装关键词
// 取field
String
[]
fieldlist
=
ESQueryUtil
.
getFieldListbyPtList
(
ptList
,
noPlatformType
,
""
);
BoolQueryBuilder
keywordQueryBuilder
=
ESQueryUtil
.
assembleKeywordTrackQuery
(
QueryBuilders
.
boolQuery
(),
allWords
,
anyWord
,
fieldlist
);
queryBuilder
.
must
(
keywordQueryBuilder
);
// 二阶段组装type、source、uper
// 组装type
List
<
String
>
typeList
=
platform
.
getType
();
List
<
String
>
noTypeList
=
platform
.
getNoType
();
BoolQueryBuilder
tsuQueryBuilder
=
ESQueryUtil
.
assembleShouldNotFieldsQuery
(
QueryBuilders
.
boolQuery
(),
typeList
,
noTypeList
,
"type"
);
// 组装source
List
<
String
>
sourceList
=
platform
.
getSource
();
List
<
String
>
noSourceList
=
platform
.
getNoSource
();
tsuQueryBuilder
=
ESQueryUtil
.
assembleShouldNotFieldsQuery
(
tsuQueryBuilder
,
sourceList
,
noSourceList
,
"source"
);
// 组装uper
List
<
String
>
uperList
=
platform
.
getUper
();
List
<
String
>
noUperList
=
platform
.
getNoUper
();
tsuQueryBuilder
=
ESQueryUtil
.
assembleShouldNotFieldsQuery
(
tsuQueryBuilder
,
uperList
,
noUperList
,
"uper"
);
queryBuilder
.
must
(
tsuQueryBuilder
);
// 三阶段特殊规则 weiboSinaV weiboAlt
List
<
String
>
srList
=
platform
.
getSpecialRule
();
BoolQueryBuilder
srQueryBuilder
=
ESQueryUtil
.
assembleSpecialRuleQurey
(
QueryBuilders
.
boolQuery
(),
srList
);
queryBuilder
.
must
(
srQueryBuilder
);
// 四阶段插件过滤
BoolQueryBuilder
pluginQueryBuilder
=
ESQueryUtil
.
assemblePluginQurey
(
QueryBuilders
.
boolQuery
());
queryBuilder
.
must
(
pluginQueryBuilder
);
// 组装高亮字段
HighlightBuilder
highlightBuilder
=
ESQueryUtil
.
getHighlightBuilder
(
fieldlist
);
// 组配查询
SearchRequestBuilder
searchRequestBuilder
=
transportClient
.
prepareSearch
(
indexlist
).
setTypes
(
typelist
)
.
highlighter
(
highlightBuilder
).
setQuery
(
queryBuilder
).
addSort
(
"commonid"
,
SortOrder
.
DESC
).
setFrom
(
0
)
.
setSize
(
count
);
if
(
startid
>
0
&&
endid
<=
0
)
{
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"commonid"
).
from
(
startid
));
}
else
if
(
endid
>
0
&&
startid
<=
0
)
{
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"commonid"
).
to
(
endid
));
}
else
if
(
endid
>
0
&&
startid
>
0
)
{
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"commonid"
).
from
(
startid
).
to
(
endid
));
}
else
{
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"commonid"
).
from
(
ESGetCommonId
.
START_COMMONID
));
}
SearchResponse
response
=
searchRequestBuilder
.
execute
().
actionGet
();
SearchHits
searchHits
=
response
.
getHits
();
return
searchHits
;
}
@Override
public
SearchHits
getchannelTrackFromEs
(
String
channel
,
String
color
,
int
count
,
long
startid
,
Long
endid
,
PlatformNew
platform
)
{
// 按ptlist获取indexlist
List
<
String
>
ptList
=
platform
.
getPt
();
ptList
.
removeAll
(
platform
.
getNoPt
());
List
<
String
>
noPlatformType
=
platform
.
getNoPlatformType
();
String
[]
indexlist
=
ESQueryUtil
.
getIndexListbyPtList
(
ptList
,
noPlatformType
);
// 按ptlist获取typelist
String
[]
typelist
=
ESQueryUtil
.
getTypeListbyPtList
(
ptList
);
// 组装查询语句
BoolQueryBuilder
queryBuilder
=
QueryBuilders
.
boolQuery
();
// 一阶段组装关键词
// 取field
String
[]
fieldlist
=
ESQueryUtil
.
getChannelFieldListbyPtList
(
ptList
,
noPlatformType
);
BoolQueryBuilder
keywordQueryBuilder
=
ESQueryUtil
.
assembleChannelTrackQuery
(
QueryBuilders
.
boolQuery
(),
channel
,
fieldlist
);
queryBuilder
.
must
(
keywordQueryBuilder
);
// 二阶段组装type、source、uper
// 组装type
List
<
String
>
typeList
=
platform
.
getType
();
List
<
String
>
noTypeList
=
platform
.
getNoType
();
BoolQueryBuilder
tsuQueryBuilder
=
ESQueryUtil
.
assembleShouldNotFieldsQuery
(
QueryBuilders
.
boolQuery
(),
typeList
,
noTypeList
,
"type"
);
// 组装source
List
<
String
>
sourceList
=
platform
.
getSource
();
List
<
String
>
noSourceList
=
platform
.
getNoSource
();
tsuQueryBuilder
=
ESQueryUtil
.
assembleShouldNotFieldsQuery
(
tsuQueryBuilder
,
sourceList
,
noSourceList
,
"source"
);
// 组装uper
List
<
String
>
uperList
=
platform
.
getUper
();
List
<
String
>
noUperList
=
platform
.
getNoUper
();
tsuQueryBuilder
=
ESQueryUtil
.
assembleShouldNotFieldsQuery
(
tsuQueryBuilder
,
uperList
,
noUperList
,
"uper"
);
queryBuilder
.
must
(
tsuQueryBuilder
);
// 三阶段特殊规则 weiboSinaV weiboAlt
List
<
String
>
srList
=
platform
.
getSpecialRule
();
BoolQueryBuilder
srQueryBuilder
=
ESQueryUtil
.
assembleSpecialRuleQurey
(
QueryBuilders
.
boolQuery
(),
srList
);
queryBuilder
.
must
(
srQueryBuilder
);
// 四阶段插件过滤
BoolQueryBuilder
pluginQueryBuilder
=
ESQueryUtil
.
assemblePluginQurey
(
QueryBuilders
.
boolQuery
());
queryBuilder
.
must
(
pluginQueryBuilder
);
// 组装高亮字段
HighlightBuilder
highlightBuilder
=
ESQueryUtil
.
getHighlightBuilder
(
fieldlist
);
// 组配查询
SearchRequestBuilder
searchRequestBuilder
=
transportClient
.
prepareSearch
(
indexlist
).
setTypes
(
typelist
)
.
highlighter
(
highlightBuilder
).
setQuery
(
queryBuilder
).
addSort
(
"commonid"
,
SortOrder
.
DESC
).
setFrom
(
0
)
.
setSize
(
count
);
if
(
startid
>
0
&&
endid
<=
0
)
{
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"commonid"
).
from
(
startid
));
}
else
if
(
endid
>
0
&&
startid
<=
0
)
{
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"commonid"
).
to
(
endid
));
}
else
if
(
endid
>
0
&&
startid
>
0
)
{
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"commonid"
).
from
(
startid
).
to
(
endid
));
}
else
{
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"commonid"
).
from
(
ESGetCommonId
.
START_COMMONID
));
}
SearchResponse
response
=
searchRequestBuilder
.
execute
().
actionGet
();
SearchHits
searchHits
=
response
.
getHits
();
return
searchHits
;
}
@Override
public
SearchHits
getarticleTrackFromEs
(
String
articleTitle
,
String
color
,
int
count
,
long
startid
,
Long
endid
,
PlatformNew
platform
)
{
// 按ptlist获取indexlist
List
<
String
>
ptList
=
platform
.
getPt
();
ptList
.
removeAll
(
platform
.
getNoPt
());
List
<
String
>
noPlatformType
=
platform
.
getNoPlatformType
();
String
[]
indexlist
=
ESQueryUtil
.
getIndexListbyPtList
(
ptList
,
noPlatformType
);
// 按ptlist获取typelist
String
[]
typelist
=
ESQueryUtil
.
getTypeListbyPtList
(
ptList
);
// 组装查询语句
BoolQueryBuilder
queryBuilder
=
QueryBuilders
.
boolQuery
();
// 一阶段组装关键词
// 取field
String
[]
fieldlist
=
ESQueryUtil
.
getFieldListbyPtList
(
ptList
,
noPlatformType
,
""
);
BoolQueryBuilder
keywordQueryBuilder
=
ESQueryUtil
.
assembleArticleTitleTrackQuery
(
QueryBuilders
.
boolQuery
(),
articleTitle
,
fieldlist
);
queryBuilder
.
must
(
keywordQueryBuilder
);
// 二阶段组装type、source、uper
// 组装type
List
<
String
>
typeList
=
platform
.
getType
();
List
<
String
>
noTypeList
=
platform
.
getNoType
();
BoolQueryBuilder
tsuQueryBuilder
=
ESQueryUtil
.
assembleShouldNotFieldsQuery
(
QueryBuilders
.
boolQuery
(),
typeList
,
noTypeList
,
"type"
);
// 组装source
List
<
String
>
sourceList
=
platform
.
getSource
();
List
<
String
>
noSourceList
=
platform
.
getNoSource
();
tsuQueryBuilder
=
ESQueryUtil
.
assembleShouldNotFieldsQuery
(
tsuQueryBuilder
,
sourceList
,
noSourceList
,
"source"
);
// 组装uper
List
<
String
>
uperList
=
platform
.
getUper
();
List
<
String
>
noUperList
=
platform
.
getNoUper
();
tsuQueryBuilder
=
ESQueryUtil
.
assembleShouldNotFieldsQuery
(
tsuQueryBuilder
,
uperList
,
noUperList
,
"uper"
);
queryBuilder
.
must
(
tsuQueryBuilder
);
// 三阶段特殊规则 weiboSinaV weiboAlt
List
<
String
>
srList
=
platform
.
getSpecialRule
();
BoolQueryBuilder
srQueryBuilder
=
ESQueryUtil
.
assembleSpecialRuleQurey
(
QueryBuilders
.
boolQuery
(),
srList
);
queryBuilder
.
must
(
srQueryBuilder
);
// 四阶段插件过滤
BoolQueryBuilder
pluginQueryBuilder
=
ESQueryUtil
.
assemblePluginQurey
(
QueryBuilders
.
boolQuery
());
queryBuilder
.
must
(
pluginQueryBuilder
);
// 组装高亮字段
HighlightBuilder
highlightBuilder
=
ESQueryUtil
.
getHighlightBuilder
(
fieldlist
);
// 组配查询
SearchRequestBuilder
searchRequestBuilder
=
transportClient
.
prepareSearch
(
indexlist
).
setTypes
(
typelist
)
.
highlighter
(
highlightBuilder
).
setQuery
(
queryBuilder
).
addSort
(
"commonid"
,
SortOrder
.
DESC
).
setFrom
(
0
)
.
setSize
(
count
);
if
(
startid
>
0
&&
endid
<=
0
)
{
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"commonid"
).
from
(
startid
));
}
else
if
(
endid
>
0
&&
startid
<=
0
)
{
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"commonid"
).
to
(
endid
));
}
else
if
(
endid
>
0
&&
startid
>
0
)
{
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"commonid"
).
from
(
startid
).
to
(
endid
));
}
else
{
searchRequestBuilder
.
setPostFilter
(
QueryBuilders
.
rangeQuery
(
"commonid"
).
from
(
ESGetCommonId
.
START_COMMONID
));
}
SearchResponse
response
=
searchRequestBuilder
.
execute
().
actionGet
();
SearchHits
searchHits
=
response
.
getHits
();
return
searchHits
;
}
}
src/main/java/com/zhiwei/messageflow/es/service/ES4BeanService.java
View file @
46e516cf
...
...
@@ -2,11 +2,13 @@ package com.zhiwei.messageflow.es.service;
import
java.util.List
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zhiwei.messageflow.bean.MediaMessage
;
import
com.zhiwei.messageflow.bean.VideoMessage
;
import
com.zhiwei.messageflow.bean.WeiboMessage
;
import
com.zhiwei.messageflow.bean.ZhihuMessage
;
import
com.zhiwei.messageflow.mongo.bean.NoiseRule
;
import
com.zhiwei.messageflow.mongo.bean.PlatformNew
;
//第二层 将SearchHits封装成List<Message>
public
interface
ES4BeanService
{
...
...
@@ -90,4 +92,24 @@ public interface ES4BeanService {
*/
List
<
MediaMessage
>
getMediaMessage
(
List
<
NoiseRule
>
noiseRules
,
List
<
String
>
keywords
,
int
count
,
long
startid
,
long
endid
,
String
platform
,
String
project
);
/**
* 获取各平台消息
*
* @param keys
* 关键词
* @param count
* 消息数量
* @param startid
* 开始id
* @param endid
* 结束id
* @param platform
* 平台
* @param project
* 项目
* @param matchFields
* @return
*/
List
<
JSONObject
>
getMessage
(
List
<
NoiseRule
>
noiseRules
,
List
<
String
>
keywords
,
int
count
,
long
startid
,
long
endid
,
PlatformNew
platform
,
String
project
,
String
matchFields
);
}
src/main/java/com/zhiwei/messageflow/es/service/EarlyWarningService.java
View file @
46e516cf
...
...
@@ -2,6 +2,7 @@ package com.zhiwei.messageflow.es.service;
import
java.util.List
;
import
com.zhiwei.messageflow.mongo.bean.PlatformNew
;
import
com.zhiwei.messageflow.mongo.bean.TrackRule
;
public
interface
EarlyWarningService
{
...
...
@@ -24,4 +25,7 @@ public interface EarlyWarningService {
*/
void
earlyWarning
(
List
<
TrackRule
>
trackRules
,
int
count
,
long
startid
,
long
endid
,
String
platformName
,
String
projectName
);
void
earlyWarningNew
(
List
<
TrackRule
>
trackRules
,
int
count
,
long
startid
,
Long
endid
,
PlatformNew
platform
,
String
projectName
);
}
src/main/java/com/zhiwei/messageflow/es/service/HighLightFillingService.java
View file @
46e516cf
...
...
@@ -2,6 +2,7 @@ package com.zhiwei.messageflow.es.service;
import
org.elasticsearch.search.SearchHit
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zhiwei.messageflow.bean.MediaMessage
;
import
com.zhiwei.messageflow.bean.VideoMessage
;
import
com.zhiwei.messageflow.bean.WeiboMessage
;
...
...
@@ -40,4 +41,12 @@ public interface HighLightFillingService {
* @return
*/
MediaMessage
getMediaBean
(
SearchHit
searchHit
);
/**
* 微博平台ES数据封装+高亮处理+渠道影响力
*
* @param searchHit
* @return
*/
JSONObject
getBean
(
SearchHit
searchHit
);
}
src/main/java/com/zhiwei/messageflow/es/service/NoiseProcessingService.java
View file @
46e516cf
...
...
@@ -4,11 +4,13 @@ import java.util.List;
import
org.elasticsearch.search.SearchHits
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zhiwei.messageflow.bean.MediaMessage
;
import
com.zhiwei.messageflow.bean.VideoMessage
;
import
com.zhiwei.messageflow.bean.WeiboMessage
;
import
com.zhiwei.messageflow.bean.ZhihuMessage
;
import
com.zhiwei.messageflow.mongo.bean.NoiseRule
;
import
com.zhiwei.messageflow.mongo.bean.PlatformNew
;
public
interface
NoiseProcessingService
{
...
...
@@ -19,4 +21,7 @@ public interface NoiseProcessingService {
List
<
VideoMessage
>
videoDenoising
(
List
<
NoiseRule
>
noiseRules
,
SearchHits
searchHits
,
String
platform
,
String
project
);
List
<
MediaMessage
>
mediaDenoising
(
List
<
NoiseRule
>
noiseRules
,
SearchHits
searchHits
,
String
platform
,
String
project
);
List
<
JSONObject
>
allDenoising
(
List
<
NoiseRule
>
noiseRules
,
SearchHits
searchHits
,
PlatformNew
platform
,
String
project
);
}
src/main/java/com/zhiwei/messageflow/es/service/TrackHitAndWarnService.java
View file @
46e516cf
...
...
@@ -2,6 +2,7 @@ package com.zhiwei.messageflow.es.service;
import
org.elasticsearch.search.SearchHits
;
import
com.zhiwei.messageflow.mongo.bean.PlatformNew
;
import
com.zhiwei.messageflow.mongo.bean.TrackRule
;
public
interface
TrackHitAndWarnService
{
...
...
@@ -58,4 +59,14 @@ public interface TrackHitAndWarnService {
* @param trackRule
*/
void
WarnWechat
(
SearchHits
trackHit
,
String
platformName
,
TrackRule
trackRule
,
String
projectName
);
SearchHits
keyWordsTrackHitNew
(
TrackRule
trackRule
,
int
count
,
long
startid
,
Long
endid
,
PlatformNew
platform
);
SearchHits
channelTrackHitNew
(
TrackRule
trackRule
,
int
count
,
long
startid
,
Long
endid
,
PlatformNew
platform
);
SearchHits
articleTrackHitNew
(
TrackRule
trackRule
,
int
count
,
long
startid
,
Long
endid
,
PlatformNew
platform
);
void
WarnWechatNew
(
SearchHits
trackHit
,
String
platformName
,
TrackRule
trackRule
,
String
projectName
);
void
WarnEmailNew
(
SearchHits
trackHit
,
String
platformName
,
TrackRule
trackRule
,
String
projectName
);
}
src/main/java/com/zhiwei/messageflow/es/service/impl/ES4BeanServiceImpl.java
View file @
46e516cf
...
...
@@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zhiwei.messageflow.bean.MediaMessage
;
import
com.zhiwei.messageflow.bean.VideoMessage
;
import
com.zhiwei.messageflow.bean.WeiboMessage
;
...
...
@@ -16,6 +17,7 @@ import com.zhiwei.messageflow.es.dao.ESDao;
import
com.zhiwei.messageflow.es.service.ES4BeanService
;
import
com.zhiwei.messageflow.es.service.NoiseProcessingService
;
import
com.zhiwei.messageflow.mongo.bean.NoiseRule
;
import
com.zhiwei.messageflow.mongo.bean.PlatformNew
;
@Component
public
class
ES4BeanServiceImpl
implements
ES4BeanService
{
...
...
@@ -110,4 +112,28 @@ public class ES4BeanServiceImpl implements ES4BeanService {
return
messages
;
}
@Override
public
List
<
JSONObject
>
getMessage
(
List
<
NoiseRule
>
noiseRules
,
List
<
String
>
keywords
,
int
count
,
long
startid
,
long
endid
,
PlatformNew
platform
,
String
project
,
String
matchFields
)
{
List
<
JSONObject
>
messages
=
null
;
try
{
// 查询数据库 获得searchHits
SearchHits
searchHits
=
esDao
.
getDataFromEs
(
keywords
,
count
,
startid
,
endid
,
platform
,
project
,
matchFields
);
if
(
searchHits
==
null
)
{
return
null
;
}
// 去噪并封装
messages
=
noiseProcessingService
.
allDenoising
(
noiseRules
,
searchHits
,
platform
,
project
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getStackTrace
()
+
" "
+
e
.
getMessage
());
}
return
messages
;
}
}
src/main/java/com/zhiwei/messageflow/es/service/impl/EarlyWarningServiceImpl.java
View file @
46e516cf
...
...
@@ -8,6 +8,7 @@ import org.springframework.stereotype.Component;
import
com.zhiwei.messageflow.es.service.EarlyWarningService
;
import
com.zhiwei.messageflow.es.service.TrackHitAndWarnService
;
import
com.zhiwei.messageflow.mongo.bean.PlatformNew
;
import
com.zhiwei.messageflow.mongo.bean.TrackRule
;
import
com.zhiwei.messageflow.mongo.dao.TrackRuleDao
;
...
...
@@ -95,4 +96,85 @@ public class EarlyWarningServiceImpl implements EarlyWarningService {
}
}
@Override
public
void
earlyWarningNew
(
List
<
TrackRule
>
trackRules
,
int
count
,
long
startid
,
Long
endid
,
PlatformNew
platform
,
String
projectName
)
{
String
platformName
=
platform
.
getPlatformName
();
for
(
TrackRule
trackRule
:
trackRules
)
{
// 判断是否预警
if
(
trackRule
.
isWarn
())
{
continue
;
}
/**
* 判断是否过期
*/
long
createAt
=
trackRule
.
getCreateAt
();
long
addDay
=
0
;
if
(
trackRule
.
getEarlyWarningTime
().
equals
(
"一天"
))
{
addDay
=
24
*
60
*
60
*
1000L
;
}
else
if
(
trackRule
.
getEarlyWarningTime
().
equals
(
"二天"
))
{
addDay
=
2
*
24
*
60
*
60
*
1000L
;
}
else
if
(
trackRule
.
getEarlyWarningTime
().
equals
(
"三天"
))
{
addDay
=
3
*
24
*
60
*
60
*
1000L
;
}
else
if
(
trackRule
.
getEarlyWarningTime
().
equals
(
"一月"
))
{
addDay
=
30
*
24
*
60
*
60
*
1000L
;
}
long
confirm
=
createAt
+
addDay
;
if
(
confirm
<=
System
.
currentTimeMillis
())
{
// 过期
trackRule
.
setWarn
(
true
);
trackRuleDao
.
updateTrackrule
(
trackRule
.
get_id
());
}
else
{
// 判断规则
// 首先判断预警方式
if
(
trackRule
.
getEarlyWarning
().
equals
(
"no"
))
{
}
else
if
(
trackRule
.
getEarlyWarning
().
equals
(
"wechat"
))
{
// 微信预警
// 处理规则
SearchHits
TrackHit
=
null
;
if
(
trackRule
.
getRuleType
().
equals
(
"keyWords"
))
{
// 关键词追踪
TrackHit
=
trackHitAndWarnService
.
keyWordsTrackHitNew
(
trackRule
,
count
,
startid
,
endid
,
platform
);
}
else
if
(
trackRule
.
getRuleType
().
equals
(
"channel"
))
{
// 渠道追踪
TrackHit
=
trackHitAndWarnService
.
channelTrackHitNew
(
trackRule
,
count
,
startid
,
endid
,
platform
);
}
else
if
(
trackRule
.
getRuleType
().
equals
(
"article"
))
{
// 相似新闻数追踪
TrackHit
=
trackHitAndWarnService
.
articleTrackHitNew
(
trackRule
,
count
,
startid
,
endid
,
platform
);
}
trackHitAndWarnService
.
WarnWechatNew
(
TrackHit
,
platformName
,
trackRule
,
projectName
);
}
else
if
(
trackRule
.
getEarlyWarning
().
equals
(
"email"
))
{
// 邮箱预警
// 处理规则
SearchHits
TrackHit
=
null
;
if
(
trackRule
.
getRuleType
().
equals
(
"keyWords"
))
{
// 关键词追踪
TrackHit
=
trackHitAndWarnService
.
keyWordsTrackHitNew
(
trackRule
,
count
,
startid
,
endid
,
platform
);
}
else
if
(
trackRule
.
getRuleType
().
equals
(
"channel"
))
{
// 渠道追踪
TrackHit
=
trackHitAndWarnService
.
channelTrackHitNew
(
trackRule
,
count
,
startid
,
endid
,
platform
);
}
else
if
(
trackRule
.
getRuleType
().
equals
(
"article"
))
{
// 相似新闻数追踪
TrackHit
=
trackHitAndWarnService
.
articleTrackHitNew
(
trackRule
,
count
,
startid
,
endid
,
platform
);
}
trackHitAndWarnService
.
WarnEmailNew
(
TrackHit
,
platformName
,
trackRule
,
projectName
);
}
}
}
}
}
src/main/java/com/zhiwei/messageflow/es/service/impl/HighLightFillingServiceImpl.java
View file @
46e516cf
...
...
@@ -14,6 +14,8 @@ import org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
com.alibaba.fastjson.JSONObject
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.zhiwei.messageflow.bean.MediaMessage
;
import
com.zhiwei.messageflow.bean.VideoMessage
;
...
...
@@ -40,6 +42,8 @@ public class HighLightFillingServiceImpl implements HighLightFillingService {
@Override
public
WeiboMessage
getWeiboBean
(
SearchHit
searchHit
)
{
JSONObject
wmJson
=
getBean
(
searchHit
);
/**
* ES数据读取
*/
...
...
@@ -50,6 +54,8 @@ public class HighLightFillingServiceImpl implements HighLightFillingService {
WeiboMessage
wm
=
new
WeiboMessage
();
try
{
message
=
mapper
.
writeValueAsString
(
sourceHitMap
);
// JSONObject mesJson = JSONObject.parseObject(message);
// System.out.println(searchHit.getType());
wm
=
mapper
.
readValue
(
message
,
WeiboMessage
.
class
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
...
...
@@ -90,11 +96,22 @@ public class HighLightFillingServiceImpl implements HighLightFillingService {
wm
.
setChannelIndex
(
huserInfoWeibo
==
null
?
1.0
:
huserInfoWeibo
.
getChannelIndex
());
// System.err.println("json"+wmJson);
// try {
// System.err.println("mapper"+mapper.writeValueAsString(wm));
// } catch (JsonProcessingException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
return
wm
;
}
@Override
public
ZhihuMessage
getZhihuBean
(
SearchHit
searchHit
)
{
JSONObject
wmJson
=
getBean
(
searchHit
);
Map
<
String
,
Object
>
sourceHitMap
=
searchHit
.
getSource
();
Map
<
String
,
HighlightField
>
highlightFieldsHitMap
=
searchHit
.
getHighlightFields
();
...
...
@@ -218,11 +235,24 @@ public class HighLightFillingServiceImpl implements HighLightFillingService {
zm
.
setImg
(
imgUrl
);
}
}
// System.err.println("json"+wmJson);
// try {
// System.err.println("mapper"+mapper.writeValueAsString(zm));
// } catch (JsonProcessingException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
return
zm
;
}
@Override
public
VideoMessage
getVideoBean
(
SearchHit
searchHit
)
{
JSONObject
wmJson
=
getBean
(
searchHit
);
Map
<
String
,
Object
>
sourceHitMap
=
searchHit
.
getSource
();
Map
<
String
,
HighlightField
>
highlightFieldsHitMap
=
searchHit
.
getHighlightFields
();
...
...
@@ -260,11 +290,23 @@ public class HighLightFillingServiceImpl implements HighLightFillingService {
title
=
vm
.
getTitle
();
}
vm
.
setTitle
(
title
);
// System.err.println("json"+wmJson);
// try {
// System.err.println("mapper"+mapper.writeValueAsString(vm));
// } catch (JsonProcessingException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
return
vm
;
}
@Override
public
MediaMessage
getMediaBean
(
SearchHit
searchHit
)
{
JSONObject
wmJson
=
getBean
(
searchHit
);
Map
<
String
,
Object
>
sourceHitMap
=
searchHit
.
getSource
();
Map
<
String
,
HighlightField
>
highlightFieldsHitMap
=
searchHit
.
getHighlightFields
();
...
...
@@ -343,6 +385,15 @@ public class HighLightFillingServiceImpl implements HighLightFillingService {
mm
.
setChannelIndex
(
1.0
);
}
}
// System.err.println("json"+wmJson);
// try {
// System.err.println("mapper"+mapper.writeValueAsString(mm));
// } catch (JsonProcessingException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
return
mm
;
}
...
...
@@ -354,4 +405,324 @@ public class HighLightFillingServiceImpl implements HighLightFillingService {
}
return
""
;
}
@Override
public
JSONObject
getBean
(
SearchHit
searchHit
)
{
/**
* ES数据读取
*/
Map
<
String
,
Object
>
sourceHitMap
=
searchHit
.
getSource
();
// Map<String, HighlightField> highlightFieldsHitMap = searchHit.getHighlightFields();
String
message
;
JSONObject
res
=
new
JSONObject
();
try
{
message
=
mapper
.
writeValueAsString
(
sourceHitMap
);
res
=
JSONObject
.
parseObject
(
message
);
}
catch
(
JsonProcessingException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
String
type
=
searchHit
.
getType
();
Long
rstime
=
null
!=
searchHit
.
getSource
().
get
(
"rstime"
)?
Long
.
valueOf
(
searchHit
.
getSource
().
get
(
"rstime"
)+
""
):
null
;
if
(
type
.
equals
(
"status"
)&&
null
!=
rstime
)
{
//微博
res
=
handleWeiboBean
(
searchHit
,
res
);
}
else
if
(
type
.
equals
(
"zhihu"
))
{
//zhihu
res
=
handleZhihuBean
(
searchHit
,
res
);
}
else
if
(
type
.
equals
(
"video"
))
{
//视频
res
=
handleVideoBean
(
searchHit
,
res
);
}
else
{
//网媒
res
=
handleMediaBean
(
searchHit
,
res
);
}
return
res
;
}
private
JSONObject
handleWeiboBean
(
SearchHit
searchHit
,
JSONObject
res
)
{
/**
* ES数据读取
*/
Map
<
String
,
Object
>
sourceHitMap
=
searchHit
.
getSource
();
Map
<
String
,
HighlightField
>
highlightFieldsHitMap
=
searchHit
.
getHighlightFields
();
String
text
=
""
;
String
roottext
=
""
;
Text
[]
textlist
=
highlightFieldsHitMap
.
containsKey
(
"text"
)
?
highlightFieldsHitMap
.
get
(
"text"
).
getFragments
()
:
null
;
Text
[]
roottextlist
=
highlightFieldsHitMap
.
containsKey
(
"roottext"
)
?
highlightFieldsHitMap
.
get
(
"roottext"
).
getFragments
()
:
null
;
if
(
textlist
!=
null
&&
textlist
.
length
>
0
)
{
for
(
Text
string
:
textlist
)
{
text
=
text
+
string
.
string
();
}
}
if
(
roottextlist
!=
null
&&
roottextlist
.
length
>
0
)
{
for
(
Text
string
:
roottextlist
)
{
roottext
=
roottext
+
string
.
string
();
}
}
if
(
text
.
isEmpty
())
{
text
=
String
.
valueOf
(
sourceHitMap
.
get
(
"text"
));
}
if
(
roottext
.
isEmpty
())
{
roottext
=
String
.
valueOf
(
sourceHitMap
.
get
(
"roottext"
));
}
res
.
put
(
"_id"
,
searchHit
.
getId
());
res
.
put
(
"text"
,
text
);
res
.
put
(
"roottext"
,
roottext
);
res
.
put
(
"markPt"
,
"微博"
);
// 处理渠道影响力
HuserInfoWeibo
huserInfoWeibo
=
huserInfoDao
.
getHuserInfoWeibo
(
String
.
valueOf
(
sourceHitMap
.
get
(
"user_id"
)));
res
.
put
(
"channelIndex"
,
huserInfoWeibo
==
null
?
1.0
:
huserInfoWeibo
.
getChannelIndex
());
return
res
;
}
private
JSONObject
handleZhihuBean
(
SearchHit
searchHit
,
JSONObject
res
)
{
Map
<
String
,
Object
>
sourceHitMap
=
searchHit
.
getSource
();
Map
<
String
,
HighlightField
>
highlightFieldsHitMap
=
searchHit
.
getHighlightFields
();
res
.
put
(
"_id"
,
searchHit
.
getId
());
res
.
put
(
"markPt"
,
"知乎"
);
String
insert_at
=
res
.
getString
(
"insert_at"
);
if
(
insert_at
!=
null
&&
!
insert_at
.
equals
(
""
)
&&
!
insert_at
.
replaceFirst
(
"000"
,
""
).
equals
(
""
))
{
Date
insertDate
=
TimeUtil
.
parseTime
(
insert_at
.
replaceFirst
(
"000"
,
""
),
"yyyy-MM-dd'T'HH:mm:ss.SSS"
);
if
(
insertDate
!=
null
)
res
.
put
(
"insert_at"
,
insertDate
.
toString
());
}
String
update_at
=
res
.
getString
(
"update_at"
);
if
(
update_at
!=
null
&&
!
update_at
.
equals
(
""
)
&&
!
update_at
.
replaceFirst
(
"000"
,
""
).
equals
(
""
))
{
Date
updateDate
=
TimeUtil
.
parseTime
(
update_at
.
replaceFirst
(
"000"
,
""
),
"yyyy-MM-dd'T'HH:mm:ss.SSS"
);
if
(
updateDate
!=
null
)
res
.
put
(
"update_at"
,
updateDate
.
toString
());
}
String
questionTitle
=
""
;
String
questionContent
=
""
;
String
answerContent
=
""
;
String
img
=
""
;
String
content1
=
res
.
getString
(
"question_content"
)
==
null
?
""
:
res
.
getString
(
"question_content"
);
String
content2
=
res
.
getString
(
"answer_content"
)
==
null
?
""
:
res
.
getString
(
"answer_content"
);
if
(!
""
.
equals
(
content1
))
{
img
=
regxString
(
content1
);
}
if
(!
""
.
equals
(
content2
))
{
img
=
regxString
(
content2
);
}
Text
[]
titlelist
=
highlightFieldsHitMap
.
containsKey
(
"question_title"
)
?
highlightFieldsHitMap
.
get
(
"question_title"
).
getFragments
()
:
null
;
Text
[]
questionContentlist
=
highlightFieldsHitMap
.
containsKey
(
"question_content"
)
?
highlightFieldsHitMap
.
get
(
"question_content"
).
getFragments
()
:
null
;
Text
[]
answerContentList
=
highlightFieldsHitMap
.
containsKey
(
"answer_content"
)
?
highlightFieldsHitMap
.
get
(
"answer_content"
).
getFragments
()
:
null
;
if
(
titlelist
!=
null
&&
titlelist
.
length
>
0
)
{
for
(
Text
string
:
titlelist
)
{
questionTitle
=
questionTitle
+
string
.
string
();
}
}
if
(
questionContentlist
!=
null
&&
questionContentlist
.
length
>
0
)
{
for
(
Text
string
:
questionContentlist
)
{
// 通过高亮位置截取过长字符串
String
cutStr
=
string
.
string
();
if
(
cutStr
.
length
()
>
150
)
{
int
i
=
cutStr
.
indexOf
(
"<font"
);
if
(
i
>
10
)
{
cutStr
=
cutStr
.
substring
(
i
-
10
,
cutStr
.
length
());
cutStr
=
"……"
+
cutStr
;
}
}
questionContent
=
questionContent
+
cutStr
;
}
}
if
(
answerContentList
!=
null
&&
answerContentList
.
length
>
0
)
{
for
(
Text
string
:
answerContentList
)
{
// 通过高亮位置截取过长字符串
String
cutStr
=
string
.
string
();
if
(
cutStr
.
length
()
>
150
)
{
int
i
=
cutStr
.
indexOf
(
"<font"
);
if
(
i
>
10
)
{
cutStr
=
cutStr
.
substring
(
i
-
10
,
cutStr
.
length
());
cutStr
=
"……"
+
cutStr
;
}
}
answerContent
=
answerContent
+
cutStr
;
}
}
if
(
questionTitle
.
isEmpty
())
{
questionTitle
=
res
.
getString
(
"question_title"
)+
""
;
if
(
questionTitle
.
length
()
>
300
)
{
questionTitle
=
questionTitle
.
substring
(
0
,
300
);
}
}
if
(
questionContent
.
isEmpty
())
{
questionContent
=
res
.
getString
(
"question_content"
)+
""
;
if
(
questionContent
.
length
()
>
300
)
{
questionContent
=
questionContent
.
substring
(
0
,
300
);
}
}
if
(
answerContent
.
isEmpty
())
{
answerContent
=
res
.
getString
(
"answer_content"
)+
""
;
if
(
answerContent
.
length
()
>
300
)
{
answerContent
=
answerContent
.
substring
(
0
,
300
);
}
}
res
.
put
(
"question_title"
,
questionTitle
.
replaceAll
(
"<img[^>]*>"
,
""
));
res
.
put
(
"question_content"
,
questionContent
.
replaceAll
(
"<img[^>]*>"
,
""
));
res
.
put
(
"answer_content"
,
answerContent
.
replaceAll
(
"<img[^>]*>"
,
""
));
res
.
put
(
"img"
,
img
);
if
(
res
.
getString
(
"img_url"
)
!=
null
)
{
String
imgUrl
=
res
.
getString
(
"img_url"
);
if
(
null
!=
imgUrl
&&
""
.
equals
(
imgUrl
))
{
res
.
put
(
"img"
,
imgUrl
);;
}
}
return
res
;
}
private
JSONObject
handleVideoBean
(
SearchHit
searchHit
,
JSONObject
res
)
{
Map
<
String
,
Object
>
sourceHitMap
=
searchHit
.
getSource
();
Map
<
String
,
HighlightField
>
highlightFieldsHitMap
=
searchHit
.
getHighlightFields
();
res
.
put
(
"markPt"
,
"视频"
);
res
.
put
(
"_id"
,
searchHit
.
getId
());
try
{
String
vtime
=
TimeUtil
.
parseTime
(
sourceHitMap
.
get
(
"time"
).
toString
().
replaceFirst
(
"000"
,
""
),
"yyyy-MM-dd'T'HH:mm:ss"
)
.
toString
();
res
.
put
(
"time"
,
vtime
);
}
catch
(
Exception
e
)
{
log
.
error
(
"videotime为空"
+
searchHit
.
getId
());
}
String
title
=
""
;
Text
[]
titlelist
=
highlightFieldsHitMap
.
containsKey
(
"title"
)
?
highlightFieldsHitMap
.
get
(
"title"
).
getFragments
()
:
null
;
if
(
titlelist
!=
null
&&
titlelist
.
length
>
0
)
{
for
(
Text
string
:
titlelist
)
{
// 通过高亮位置截取过长字符串
String
cutStr
=
string
.
string
();
title
=
title
+
cutStr
;
}
}
if
(
title
.
isEmpty
())
{
title
=
String
.
valueOf
(
sourceHitMap
.
get
(
"title"
));
}
res
.
put
(
"title"
,
title
);
return
res
;
}
private
JSONObject
handleMediaBean
(
SearchHit
searchHit
,
JSONObject
res
)
{
Map
<
String
,
Object
>
sourceHitMap
=
searchHit
.
getSource
();
Map
<
String
,
HighlightField
>
highlightFieldsHitMap
=
searchHit
.
getHighlightFields
();
res
.
put
(
"markPt"
,
"网媒"
);
res
.
put
(
"_id"
,
searchHit
.
getId
());
try
{
String
mtime
=
TimeUtil
.
parseTime
(
sourceHitMap
.
get
(
"time"
).
toString
().
replaceFirst
(
"000"
,
""
),
"yyyy-MM-dd'T'HH:mm:ss"
)
.
toString
();
res
.
put
(
"time"
,
mtime
);
}
catch
(
Exception
e
)
{
log
.
error
(
"mediatime为空"
+
searchHit
.
getId
());
return
null
;
}
String
content
=
""
;
String
title
=
""
;
Text
[]
titlelist
=
highlightFieldsHitMap
.
containsKey
(
"title"
)
?
highlightFieldsHitMap
.
get
(
"title"
).
getFragments
()
:
null
;
Text
[]
contentlist
=
highlightFieldsHitMap
.
containsKey
(
"content"
)
?
highlightFieldsHitMap
.
get
(
"content"
).
getFragments
()
:
null
;
if
(
titlelist
!=
null
&&
titlelist
.
length
>
0
)
{
for
(
Text
string
:
titlelist
)
{
// 通过高亮位置截取过长字符串
String
cutStr
=
string
.
string
();
title
=
title
+
cutStr
;
}
}
if
(
contentlist
!=
null
&&
contentlist
.
length
>
0
)
{
for
(
Text
string
:
contentlist
)
{
// 通过高亮位置截取过长字符串
String
cutStr
=
string
.
string
();
if
(
cutStr
.
length
()
>
150
)
{
int
i
=
cutStr
.
indexOf
(
"<font"
);
if
(
i
>
10
)
{
cutStr
=
cutStr
.
substring
(
i
-
10
,
cutStr
.
length
());
cutStr
=
"……"
+
cutStr
;
}
}
content
=
content
+
cutStr
;
}
}
if
(
content
.
isEmpty
())
{
content
=
sourceHitMap
.
containsKey
(
"content"
)
?
sourceHitMap
.
get
(
"content"
)
+
""
:
""
;
if
(
content
.
length
()
>
300
)
{
content
=
content
.
substring
(
0
,
300
);
}
}
if
(
title
.
isEmpty
())
{
title
=
sourceHitMap
.
containsKey
(
"title"
)
?
String
.
valueOf
(
sourceHitMap
.
get
(
"title"
))
:
""
;;
}
res
.
put
(
"content"
,
content
);
res
.
put
(
"title"
,
title
);
String
source
=
res
.
getString
(
"source"
)+
""
;
if
((
sourceHitMap
.
get
(
"pt"
)
+
""
).
equals
(
"微信"
))
{
HuserInfoWeixin
huserInfoWeixin
=
huserInfoDao
.
getHuserInfoWeixin
(
source
);
if
(
huserInfoWeixin
!=
null
)
{
res
.
put
(
"channelIndex"
,
huserInfoWeixin
.
getChannelIndex
());
}
else
{
res
.
put
(
"channelIndex"
,
1.0
);
}
}
else
{
HuserInfoMedia
huserInfoMedia
=
huserInfoDao
.
getHuserInfoMedia
(
source
);
if
(
huserInfoMedia
!=
null
)
{
res
.
put
(
"channelIndex"
,
huserInfoMedia
.
getChannelIndex
());
}
else
{
res
.
put
(
"channelIndex"
,
1.0
);
}
}
return
res
;
}
}
src/main/java/com/zhiwei/messageflow/es/service/impl/NoiseProcessingServiceImpl.java
View file @
46e516cf
...
...
@@ -9,6 +9,7 @@ import org.elasticsearch.search.SearchHits;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zhiwei.messageflow.bean.MediaMessage
;
import
com.zhiwei.messageflow.bean.VideoMessage
;
import
com.zhiwei.messageflow.bean.WeiboMessage
;
...
...
@@ -16,7 +17,9 @@ import com.zhiwei.messageflow.bean.ZhihuMessage;
import
com.zhiwei.messageflow.es.service.HighLightFillingService
;
import
com.zhiwei.messageflow.es.service.NoiseProcessingService
;
import
com.zhiwei.messageflow.mongo.bean.NoiseRule
;
import
com.zhiwei.messageflow.mongo.bean.PlatformNew
;
import
com.zhiwei.messageflow.mongo.dao.NoiseRuleDao
;
import
com.zhiwei.messageflow.util.ESQueryUtil
;
@Component
public
class
NoiseProcessingServiceImpl
implements
NoiseProcessingService
{
...
...
@@ -53,9 +56,9 @@ public class NoiseProcessingServiceImpl implements NoiseProcessingService {
/**
* 关键词去噪
*/
//
if (n.getKwSearch().equals("标题")) {
//
//
} else if (n.getKwSearch().equals("全文")) {
//
if (n.getKwSearch().equals("标题")) {
//
//
} else if (n.getKwSearch().equals("全文")) {
String
kone
=
n
.
getKeyWordsInputOne
();
String
ktwo
=
n
.
getKeyWordsInputTwo
();
...
...
@@ -108,7 +111,7 @@ public class NoiseProcessingServiceImpl implements NoiseProcessingService {
break
;
}
}
//
}
//
}
}
else
if
((
n
.
getRuleType
().
equals
(
"channel"
))
&&
((
n
.
getChannelPt
().
equals
(
"微博"
)
||
n
.
getChannelPt
().
equals
(
"全部"
))))
{
/**
...
...
@@ -578,4 +581,526 @@ public class NoiseProcessingServiceImpl implements NoiseProcessingService {
return
mmessages
;
}
@Override
public
List
<
JSONObject
>
allDenoising
(
List
<
NoiseRule
>
noiseRules
,
SearchHits
searchHits
,
PlatformNew
platform
,
String
project
)
{
List
<
JSONObject
>
jmessages
=
new
ArrayList
<>();
SearchHit
[]
sh
=
searchHits
.
getHits
();
for
(
SearchHit
searchHit
:
sh
)
{
// System.err.println(searchHit.getSourceAsString());
Map
<
String
,
Object
>
map
=
searchHit
.
getSource
();
if
(
map
==
null
)
{
continue
;
}
// 噪音判断参数
boolean
isnoise
=
false
;
String
type
=
searchHit
.
getType
();
Long
rstime
=
null
!=
searchHit
.
getSource
().
get
(
"rstime"
)
?
Long
.
valueOf
(
searchHit
.
getSource
().
get
(
"rstime"
)
+
""
)
:
null
;
if
(
type
.
equals
(
"status"
)
&&
null
!=
rstime
)
{
// 微博
isnoise
=
weiboIsNoise
(
noiseRules
,
map
,
platform
,
project
);
}
else
if
(
type
.
equals
(
"zhihu"
))
{
// zhihu
isnoise
=
zhihuIsNoise
(
noiseRules
,
map
,
platform
,
project
);
}
else
if
(
type
.
equals
(
"video"
))
{
// 视频
isnoise
=
videoIsNoise
(
noiseRules
,
map
,
platform
,
project
);
}
else
{
// 网媒
isnoise
=
mediaIsNoise
(
noiseRules
,
map
,
platform
,
project
);
}
if
(
isnoise
)
{
continue
;
}
// 数据转换并高亮处理
JSONObject
jo
=
highLightFillingService
.
getBean
(
searchHit
);
if
(
jo
!=
null
)
{
jmessages
.
add
(
jo
);
}
}
return
jmessages
;
}
private
boolean
weiboIsNoise
(
List
<
NoiseRule
>
noiseRules
,
Map
<
String
,
Object
>
map
,
PlatformNew
platformNew
,
String
project
)
{
String
platform
=
platformNew
.
getPlatformName
();
String
text
=
map
.
get
(
"text"
)
!=
null
?
map
.
get
(
"text"
).
toString
()
:
null
;
String
roottext
=
map
.
get
(
"roottext"
)
!=
null
?
map
.
get
(
"roottext"
).
toString
()
:
null
;
boolean
isnoise
=
false
;
if
(
noiseRules
!=
null
)
{
for
(
NoiseRule
n
:
noiseRules
)
{
/**
* 判断噪音规则
*/
if
(
n
.
getRuleType
().
equals
(
"keyWords"
)
&&
(
n
.
getKeyWordPt
().
equals
(
platform
)
||
n
.
getKeyWordPt
().
equals
(
"全部"
)))
{
/**
* 关键词去噪
*/
// if (n.getKwSearch().equals("标题")) {
//
// } else if (n.getKwSearch().equals("全文")) {
String
kone
=
n
.
getKeyWordsInputOne
();
String
ktwo
=
n
.
getKeyWordsInputTwo
();
if
(
n
.
getAndOr
().
equals
(
"且"
))
{
if
(
text
!=
null
&&
roottext
!=
null
&&
(
text
.
indexOf
(
kone
)
!=
-
1
||
roottext
.
indexOf
(
kone
)
!=
-
1
)
&&
(
text
.
indexOf
(
ktwo
)
!=
-
1
||
roottext
.
indexOf
(
ktwo
)
!=
-
1
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
!=
null
&&
roottext
==
null
&&
(
text
.
indexOf
(
kone
)
!=
-
1
)
&&
(
text
.
indexOf
(
ktwo
)
!=
-
1
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
==
null
&&
roottext
==
null
)
{
isnoise
=
true
;
break
;
}
}
else
if
(
n
.
getAndOr
().
equals
(
"或"
))
{
if
(
text
!=
null
&&
roottext
!=
null
&&
((
text
.
indexOf
(
kone
)
!=
-
1
||
roottext
.
indexOf
(
kone
)
!=
-
1
)
||
(
text
.
indexOf
(
ktwo
)
!=
-
1
||
roottext
.
indexOf
(
ktwo
)
!=
-
1
)))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
!=
null
&&
roottext
==
null
&&
((
text
.
indexOf
(
kone
)
!=
-
1
)
||
(
text
.
indexOf
(
ktwo
)
!=
-
1
)))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
==
null
&&
roottext
==
null
)
{
isnoise
=
true
;
break
;
}
}
else
{
if
(
text
!=
null
&&
roottext
!=
null
&&
(
text
.
indexOf
(
kone
)
!=
-
1
||
roottext
.
indexOf
(
kone
)
!=
-
1
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
!=
null
&&
roottext
==
null
&&
(
text
.
indexOf
(
kone
)
!=
-
1
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
==
null
&&
roottext
==
null
)
{
isnoise
=
true
;
break
;
}
}
// }
}
else
if
((
n
.
getRuleType
().
equals
(
"channel"
))
&&
((
n
.
getChannelPt
().
equals
(
platform
)
||
n
.
getChannelPt
().
equals
(
"全部"
))))
{
/**
* 渠道去噪
*/
String
channelQd
=
n
.
getChannelQd
();
String
source
=
map
.
get
(
"username"
).
toString
();
source
=
source
.
trim
();
source
=
source
.
replaceAll
(
" "
,
""
);
if
(
channelQd
.
equals
(
source
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
}
}
}
// 噪音判断完成
return
isnoise
;
}
private
boolean
zhihuIsNoise
(
List
<
NoiseRule
>
noiseRules
,
Map
<
String
,
Object
>
map
,
PlatformNew
platformNew
,
String
project
)
{
String
platform
=
platformNew
.
getPlatformName
();
String
text
=
map
.
get
(
"question_title"
)
!=
null
?
map
.
get
(
"question_title"
).
toString
()
:
null
;
String
roottext
=
map
.
get
(
"answer_content"
)
!=
null
?
map
.
get
(
"answer_content"
).
toString
()
:
null
;
// 噪音判断参数
boolean
isnoise
=
false
;
if
(
noiseRules
!=
null
)
{
for
(
NoiseRule
n
:
noiseRules
)
{
/**
* 判断噪音规则
*/
if
(
n
.
getRuleType
().
equals
(
"keyWords"
)
&&
(
n
.
getKeyWordPt
().
equals
(
platform
)
||
n
.
getKeyWordPt
().
equals
(
"全部"
)))
{
/**
* 关键词去噪
*/
// searchHit.getSource().get("text").toString().indexOf(str);
if
(
n
.
getKwSearch
().
equals
(
"标题"
))
{
String
kone
=
n
.
getKeyWordsInputOne
();
String
ktwo
=
n
.
getKeyWordsInputTwo
();
if
(
n
.
getAndOr
().
equals
(
"且"
))
{
if
(
text
!=
null
&&
(
text
.
indexOf
(
kone
)
!=
-
1
)
&&
(
text
.
indexOf
(
ktwo
)
!=
-
1
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
==
null
&&
roottext
==
null
)
{
isnoise
=
true
;
break
;
}
}
else
if
(
n
.
getAndOr
().
equals
(
"或"
))
{
if
(
text
!=
null
&&
((
text
.
indexOf
(
kone
)
!=
-
1
)
||
(
text
.
indexOf
(
ktwo
)
!=
-
1
)))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
==
null
&&
roottext
==
null
)
{
isnoise
=
true
;
break
;
}
}
else
{
if
(
text
!=
null
&&
(
text
.
indexOf
(
kone
)
!=
-
1
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
==
null
&&
roottext
==
null
)
{
isnoise
=
true
;
break
;
}
}
}
else
if
(
n
.
getKwSearch
().
equals
(
"全文"
))
{
String
kone
=
n
.
getKeyWordsInputOne
();
String
ktwo
=
n
.
getKeyWordsInputTwo
();
if
(
n
.
getAndOr
().
equals
(
"且"
))
{
if
(
text
!=
null
&&
roottext
!=
null
&&
(
text
.
indexOf
(
kone
)
!=
-
1
||
roottext
.
indexOf
(
kone
)
!=
-
1
)
&&
(
text
.
indexOf
(
ktwo
)
!=
-
1
||
roottext
.
indexOf
(
ktwo
)
!=
-
1
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
!=
null
&&
roottext
==
null
&&
(
text
.
indexOf
(
kone
)
!=
-
1
)
&&
(
text
.
indexOf
(
ktwo
)
!=
-
1
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
==
null
&&
roottext
==
null
)
{
isnoise
=
true
;
break
;
}
}
else
if
(
n
.
getAndOr
().
equals
(
"或"
))
{
if
(
text
!=
null
&&
roottext
!=
null
&&
((
text
.
indexOf
(
kone
)
!=
-
1
||
roottext
.
indexOf
(
kone
)
!=
-
1
)
||
(
text
.
indexOf
(
ktwo
)
!=
-
1
||
roottext
.
indexOf
(
ktwo
)
!=
-
1
)))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
!=
null
&&
roottext
==
null
&&
((
text
.
indexOf
(
kone
)
!=
-
1
)
||
(
text
.
indexOf
(
ktwo
)
!=
-
1
)))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
==
null
&&
roottext
==
null
)
{
isnoise
=
true
;
break
;
}
}
else
{
if
(
text
!=
null
&&
roottext
!=
null
&&
(
text
.
indexOf
(
kone
)
!=
-
1
||
roottext
.
indexOf
(
kone
)
!=
-
1
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
!=
null
&&
roottext
==
null
&&
(
text
.
indexOf
(
kone
)
!=
-
1
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
==
null
&&
roottext
==
null
)
{
isnoise
=
true
;
break
;
}
}
}
}
else
if
((
n
.
getRuleType
().
equals
(
"channel"
))
&&
((
n
.
getChannelPt
().
equals
(
platform
)
||
n
.
getChannelPt
().
equals
(
"全部"
))))
{
/**
* 渠道去噪
*/
String
channelQd
=
n
.
getChannelQd
();
String
source
=
map
.
get
(
"user_name"
)
==
null
?
"知乎提问"
:
map
.
get
(
"user_name"
).
toString
();
source
=
source
.
trim
();
source
=
source
.
replaceAll
(
" "
,
""
);
if
(
channelQd
.
equals
(
source
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
}
}
}
// 噪音判断完成
return
isnoise
;
}
private
boolean
videoIsNoise
(
List
<
NoiseRule
>
noiseRules
,
Map
<
String
,
Object
>
map
,
PlatformNew
platformNew
,
String
project
)
{
String
platform
=
platformNew
.
getPlatformName
();
String
text
=
map
.
get
(
"title"
)
!=
null
?
map
.
get
(
"title"
).
toString
()
:
null
;
String
roottext
=
null
;
// 噪音判断参数
boolean
isnoise
=
false
;
if
(
noiseRules
!=
null
)
{
for
(
NoiseRule
n
:
noiseRules
)
{
/**
* 判断噪音规则
*/
if
(
n
.
getRuleType
().
equals
(
"keyWords"
)
&&
(
n
.
getKeyWordPt
().
equals
(
platform
)
||
n
.
getKeyWordPt
().
equals
(
"全部"
)))
{
/**
* 关键词去噪
*/
if
(
n
.
getKwSearch
().
equals
(
"标题"
))
{
String
kone
=
n
.
getKeyWordsInputOne
();
String
ktwo
=
n
.
getKeyWordsInputTwo
();
if
(
n
.
getAndOr
().
equals
(
"且"
))
{
if
(
text
!=
null
&&
(
text
.
indexOf
(
kone
)
!=
-
1
)
&&
(
text
.
indexOf
(
ktwo
)
!=
-
1
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
==
null
&&
roottext
==
null
)
{
isnoise
=
true
;
break
;
}
}
else
if
(
n
.
getAndOr
().
equals
(
"或"
))
{
if
(
text
!=
null
&&
((
text
.
indexOf
(
kone
)
!=
-
1
)
||
(
text
.
indexOf
(
ktwo
)
!=
-
1
)))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
==
null
&&
roottext
==
null
)
{
isnoise
=
true
;
break
;
}
}
else
{
if
(
text
!=
null
&&
(
text
.
indexOf
(
kone
)
!=
-
1
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
==
null
&&
roottext
==
null
)
{
isnoise
=
true
;
break
;
}
}
}
else
if
(
n
.
getKwSearch
().
equals
(
"全文"
))
{
String
kone
=
n
.
getKeyWordsInputOne
();
String
ktwo
=
n
.
getKeyWordsInputTwo
();
if
(
n
.
getAndOr
().
equals
(
"且"
))
{
if
(
text
!=
null
&&
roottext
!=
null
&&
(
text
.
indexOf
(
kone
)
!=
-
1
||
roottext
.
indexOf
(
kone
)
!=
-
1
)
&&
(
text
.
indexOf
(
ktwo
)
!=
-
1
||
roottext
.
indexOf
(
ktwo
)
!=
-
1
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
!=
null
&&
roottext
==
null
&&
(
text
.
indexOf
(
kone
)
!=
-
1
)
&&
(
text
.
indexOf
(
ktwo
)
!=
-
1
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
==
null
&&
roottext
==
null
)
{
isnoise
=
true
;
break
;
}
}
else
if
(
n
.
getAndOr
().
equals
(
"或"
))
{
if
(
text
!=
null
&&
roottext
!=
null
&&
((
text
.
indexOf
(
kone
)
!=
-
1
||
roottext
.
indexOf
(
kone
)
!=
-
1
)
||
(
text
.
indexOf
(
ktwo
)
!=
-
1
||
roottext
.
indexOf
(
ktwo
)
!=
-
1
)))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
!=
null
&&
roottext
==
null
&&
((
text
.
indexOf
(
kone
)
!=
-
1
)
||
(
text
.
indexOf
(
ktwo
)
!=
-
1
)))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
==
null
&&
roottext
==
null
)
{
isnoise
=
true
;
break
;
}
}
else
{
if
(
text
!=
null
&&
roottext
!=
null
&&
(
text
.
indexOf
(
kone
)
!=
-
1
||
roottext
.
indexOf
(
kone
)
!=
-
1
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
!=
null
&&
roottext
==
null
&&
(
text
.
indexOf
(
kone
)
!=
-
1
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
==
null
&&
roottext
==
null
)
{
isnoise
=
true
;
break
;
}
}
}
}
else
if
((
n
.
getRuleType
().
equals
(
"channel"
))
&&
((
n
.
getChannelPt
().
equals
(
platform
)
||
n
.
getChannelPt
().
equals
(
"全部"
))))
{
/**
* 渠道去噪
*/
String
channelQd
=
n
.
getChannelQd
();
String
source
=
map
.
get
(
"uper"
)
!=
null
?
map
.
get
(
"uper"
).
toString
()
:
""
;
source
=
source
.
trim
();
source
=
source
.
replaceAll
(
" "
,
""
);
if
(
channelQd
.
equals
(
source
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
}
}
}
// 噪音判断完成
return
isnoise
;
}
private
boolean
mediaIsNoise
(
List
<
NoiseRule
>
noiseRules
,
Map
<
String
,
Object
>
map
,
PlatformNew
platformNew
,
String
project
)
{
String
platform
=
platformNew
.
getPlatformName
();
String
text
=
map
.
get
(
"title"
)
!=
null
?
map
.
get
(
"title"
).
toString
()
:
null
;
String
roottext
=
map
.
get
(
"content"
)
!=
null
?
map
.
get
(
"content"
).
toString
()
:
null
;
boolean
isnoise
=
false
;
if
(
noiseRules
!=
null
)
{
for
(
NoiseRule
n
:
noiseRules
)
{
/**
* 判断噪音规则
*/
if
(
n
.
getRuleType
().
equals
(
"keyWords"
)
&&
(
n
.
getKeyWordPt
().
equals
(
platform
)
||
n
.
getKeyWordPt
().
equals
(
"全部"
)))
{
/**
* 关键词去噪
*/
if
(
n
.
getKwSearch
().
equals
(
"标题"
))
{
String
kone
=
n
.
getKeyWordsInputOne
();
String
ktwo
=
n
.
getKeyWordsInputTwo
();
if
(
n
.
getAndOr
().
equals
(
"且"
))
{
if
(
text
!=
null
&&
(
text
.
indexOf
(
kone
)
!=
-
1
)
&&
(
text
.
indexOf
(
ktwo
)
!=
-
1
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
==
null
&&
roottext
==
null
)
{
isnoise
=
true
;
break
;
}
}
else
if
(
n
.
getAndOr
().
equals
(
"或"
))
{
if
(
text
!=
null
&&
((
text
.
indexOf
(
kone
)
!=
-
1
)
||
(
text
.
indexOf
(
ktwo
)
!=
-
1
)))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
==
null
&&
roottext
==
null
)
{
isnoise
=
true
;
break
;
}
}
else
{
if
(
text
!=
null
&&
(
text
.
indexOf
(
kone
)
!=
-
1
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
==
null
&&
roottext
==
null
)
{
isnoise
=
true
;
break
;
}
}
}
else
if
(
n
.
getKwSearch
().
equals
(
"全文"
))
{
String
kone
=
n
.
getKeyWordsInputOne
();
String
ktwo
=
n
.
getKeyWordsInputTwo
();
if
(
n
.
getAndOr
().
equals
(
"且"
))
{
if
(
text
!=
null
&&
roottext
!=
null
&&
(
text
.
indexOf
(
kone
)
!=
-
1
||
roottext
.
indexOf
(
kone
)
!=
-
1
)
&&
(
text
.
indexOf
(
ktwo
)
!=
-
1
||
roottext
.
indexOf
(
ktwo
)
!=
-
1
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
!=
null
&&
roottext
==
null
&&
(
text
.
indexOf
(
kone
)
!=
-
1
)
&&
(
text
.
indexOf
(
ktwo
)
!=
-
1
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
==
null
&&
roottext
==
null
)
{
isnoise
=
true
;
break
;
}
}
else
if
(
n
.
getAndOr
().
equals
(
"或"
))
{
if
(
text
!=
null
&&
roottext
!=
null
&&
((
text
.
indexOf
(
kone
)
!=
-
1
||
roottext
.
indexOf
(
kone
)
!=
-
1
)
||
(
text
.
indexOf
(
ktwo
)
!=
-
1
||
roottext
.
indexOf
(
ktwo
)
!=
-
1
)))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
!=
null
&&
roottext
==
null
&&
((
text
.
indexOf
(
kone
)
!=
-
1
)
||
(
text
.
indexOf
(
ktwo
)
!=
-
1
)))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
==
null
&&
roottext
==
null
)
{
isnoise
=
true
;
break
;
}
}
else
{
if
(
text
!=
null
&&
roottext
!=
null
&&
(
text
.
indexOf
(
kone
)
!=
-
1
||
roottext
.
indexOf
(
kone
)
!=
-
1
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
!=
null
&&
roottext
==
null
&&
(
text
.
indexOf
(
kone
)
!=
-
1
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
else
if
(
text
==
null
&&
roottext
==
null
)
{
isnoise
=
true
;
break
;
}
}
}
}
else
if
((
n
.
getRuleType
().
equals
(
"channel"
))
&&
((
n
.
getChannelPt
().
equals
(
platform
))
||
n
.
getChannelPt
().
equals
(
"全部"
)))
{
/**
* 渠道去噪
*/
String
channelQd
=
n
.
getChannelQd
();
String
source
=
map
.
get
(
"source"
).
toString
();
source
=
source
.
trim
();
source
=
source
.
replaceAll
(
" "
,
""
);
if
(
channelQd
.
equals
(
source
))
{
isnoise
=
true
;
noiseRuleDao
.
addEffectNum
(
n
);
break
;
}
}
}
}
// 噪音判断完成
return
isnoise
;
}
}
src/main/java/com/zhiwei/messageflow/es/service/impl/TrackHitAndWarnServiceImpl.java
View file @
46e516cf
...
...
@@ -13,9 +13,11 @@ import org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
com.zhiwei.messageflow.ESGetCommonId
;
import
com.zhiwei.messageflow.es.bean.TemplateData
;
import
com.zhiwei.messageflow.es.dao.TrackESDao
;
import
com.zhiwei.messageflow.es.service.TrackHitAndWarnService
;
import
com.zhiwei.messageflow.mongo.bean.PlatformNew
;
import
com.zhiwei.messageflow.mongo.bean.TrackRule
;
import
com.zhiwei.messageflow.mongo.dao.TrackRuleDao
;
import
com.zhiwei.messageflow.mongo.service.UserMailService
;
...
...
@@ -31,6 +33,9 @@ public class TrackHitAndWarnServiceImpl implements TrackHitAndWarnService {
private
TrackESDao
trackESDao
;
@Autowired
private
ESGetCommonId
esGetCommonId
;
@Autowired
TrackRuleDao
trackRuleDao
;
@Autowired
...
...
@@ -369,4 +374,377 @@ public class TrackHitAndWarnServiceImpl implements TrackHitAndWarnService {
}
}
}
@Override
public
SearchHits
keyWordsTrackHitNew
(
TrackRule
trackRule
,
int
count
,
long
startid
,
Long
endid
,
PlatformNew
platform
)
{
SearchHits
searchHits
=
null
;
String
anyWord
=
""
;
String
allWords
=
""
;
// 取关键词
if
(
trackRule
.
getAndOr
().
equals
(
"或"
))
{
anyWord
=
trackRule
.
getKeyWordsInputOne
()
+
","
+
trackRule
.
getKeyWordsInputTwo
();
}
else
if
(
trackRule
.
getAndOr
().
equals
(
"且"
))
{
allWords
=
trackRule
.
getKeyWordsInputOne
()
+
","
+
trackRule
.
getKeyWordsInputTwo
();
}
else
{
allWords
=
trackRule
.
getKeyWordsInputOne
();
}
// 取高亮颜色
String
color
=
"#ff330D"
;
if
(
null
!=
trackRule
.
getHighlighted
()
&&
""
!=
trackRule
.
getHighlighted
())
{
color
=
trackRule
.
getHighlighted
();
}
// 根据平台获取数据
searchHits
=
trackESDao
.
getkeyWordsTrackFromEs
(
anyWord
,
allWords
,
color
,
count
,
startid
,
endid
,
platform
);
// if (platformName.equals("微博")) {
// searchHits = trackESDao.getkeyWordsTrackWeiboFromEs(anyWord, allWords, color,
// count, startid, endid);
// } else if (platformName.equals("知乎")) {
// searchHits = trackESDao.getkeyWordsTrackZhihuFromEs(anyWord, allWords, color,
// count, startid, endid);
// } else if (platformName.equals("视频")) {
// searchHits = trackESDao.getkeyWordsTrackVideoFromEs(anyWord, allWords, color,
// count, startid, endid);
// } else {
// searchHits = trackESDao.getkeyWordsTrackMediaFromEs(anyWord, allWords, color,
// count, startid, endid,
// platformName);
// }
return
searchHits
;
}
@Override
public
SearchHits
channelTrackHitNew
(
TrackRule
trackRule
,
int
count
,
long
startid
,
Long
endid
,
PlatformNew
platform
)
{
SearchHits
searchHits
=
null
;
// 取渠道平台
String
pt
=
trackRule
.
getChannelPt
();
String
channel
=
trackRule
.
getChannelQd
();
// 取高亮颜色
String
color
=
"#ff330D"
;
if
(
null
!=
trackRule
.
getHighlighted
()
&&
""
!=
trackRule
.
getHighlighted
())
{
color
=
trackRule
.
getHighlighted
();
}
String
platformName
=
platform
.
getPlatformName
();
if
(
pt
.
equals
(
platformName
))
{
searchHits
=
trackESDao
.
getchannelTrackFromEs
(
channel
,
color
,
count
,
startid
,
endid
,
platform
);
}
// if (pt.equals("微博")) {
// searchHits = trackESDao.getchannelTrackWeiboFromEs(channel, color, count,
// startid, endid);
// } else if (pt.equals("知乎")) {
// searchHits = trackESDao.getchannelTrackZhihuFromEs(channel, color, count,
// startid, endid);
// } else if (pt.equals("视频")) {
// searchHits = trackESDao.getchannelTrackVideoFromEs(channel, color, count,
// startid, endid);
// } else {
// searchHits = trackESDao.getchannelTrackMediaFromEs(channel, color, count,
// startid, endid, platformName);
// }
return
searchHits
;
}
@Override
public
SearchHits
articleTrackHitNew
(
TrackRule
trackRule
,
int
count
,
long
startid
,
Long
endid
,
PlatformNew
platform
)
{
SearchHits
searchHits
=
null
;
// 取相似新闻数信息
String
articleTitle
=
trackRule
.
getArticleTitle
();
String
timeRange
=
trackRule
.
getTimeRange
();
long
createAt
=
trackRule
.
getCreateAt
();
// 算时间区段(按commonid
if
(
timeRange
.
equals
(
"3小时内"
))
{
// startid = createAt;
// endid = createAt + 3 * 60 * 60 * 1000L;
startid
=
esGetCommonId
.
getCommonId
(
3
*
60
*
60
*
1000L
);
}
else
if
(
timeRange
.
equals
(
"6小时内"
))
{
// startid = createAt;
// endid = createAt + 6 * 60 * 60 * 1000L;
startid
=
esGetCommonId
.
getCommonId
(
6
*
60
*
60
*
1000L
);
}
else
if
(
timeRange
.
equals
(
"12小时内"
))
{
// startid = createAt;
// endid = createAt + 12 * 60 * 60 * 1000L;
startid
=
esGetCommonId
.
getCommonId
(
12
*
60
*
60
*
1000L
);
}
else
if
(
timeRange
.
equals
(
"24小时内"
))
{
// startid = createAt;
// endid = createAt + 24 * 60 * 60 * 1000L;
startid
=
esGetCommonId
.
getCommonId
(
24
*
60
*
60
*
1000L
);
}
// 取高亮颜色
String
color
=
"#ff330D"
;
if
(
null
!=
trackRule
.
getHighlighted
()
&&
""
!=
trackRule
.
getHighlighted
())
{
color
=
trackRule
.
getHighlighted
();
}
searchHits
=
trackESDao
.
getarticleTrackFromEs
(
articleTitle
,
color
,
count
,
startid
,
endid
,
platform
);
// if (platformName.equals("微博")) {
// searchHits = trackESDao.getarticleTrackWeiboFromEs(articleTitle, color,
// count, startid, endid);
// } else if (platformName.equals("知乎")) {
// searchHits = null;
// } else if (platformName.equals("视频")) {
// searchHits = trackESDao.getarticleTrackVideoFromEs(articleTitle, color,
// count, startid, endid);
// ;
// } else {
// searchHits = trackESDao.getarticleTrackMediaFromEs(articleTitle, color,
// count, startid, endid,
// platformName);
// }
return
searchHits
;
}
@Override
public
void
WarnWechatNew
(
SearchHits
trackHit
,
String
platformName
,
TrackRule
trackRule
,
String
projectName
)
{
for
(
SearchHit
hit
:
trackHit
)
{
String
url
=
""
;
String
title
=
""
;
String
content
=
""
;
String
source
=
""
;
String
time
=
""
;
String
pt
=
""
;
int
fensi
=
-
1
;
String
type
=
hit
.
getType
();
Long
rstime
=
null
!=
hit
.
getSource
().
get
(
"rstime"
)
?
Long
.
valueOf
(
hit
.
getSource
().
get
(
"rstime"
)
+
""
)
:
null
;
if
(
type
.
equals
(
"status"
)
&&
null
!=
rstime
)
{
// 微博
url
=
hit
.
getSource
().
get
(
"url"
)
+
""
;
title
=
""
;
content
=
hit
.
getSource
().
get
(
"text"
)
+
""
;
source
=
hit
.
getSource
().
get
(
"username"
)
+
""
;
time
=
hit
.
getSource
().
get
(
"time"
)
+
""
;
pt
=
"微博"
;
fensi
=
Integer
.
valueOf
(
hit
.
getSource
().
get
(
"fensi"
)
+
""
);
}
else
if
(
type
.
equals
(
"zhihu"
))
{
// zhihu
url
=
hit
.
getId
()
+
""
;
title
=
hit
.
getSource
().
get
(
"question_title"
)
+
""
;
content
=
hit
.
getSource
().
get
(
"answer_content"
)
+
""
;
source
=
hit
.
getSource
().
get
(
"user_name"
)
+
""
;
time
=
hit
.
getSource
().
get
(
"created_at"
)
+
""
;
pt
=
"知乎"
;
}
else
if
(
type
.
equals
(
"video"
))
{
// 视频
url
=
hit
.
getId
()
+
""
;
title
=
hit
.
getSource
().
get
(
"title"
)
+
""
;
content
=
""
;
source
=
hit
.
getSource
().
get
(
"uper"
)
+
""
;
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
String
timein
=
String
.
valueOf
(
hit
.
getSource
().
get
(
"time"
));
String
timeout
=
timein
.
replaceAll
(
"T"
,
" "
);
try
{
Date
date
=
sdf
.
parse
(
timeout
);
try
{
// "2017-09-28 20:35:33"
Date
mediadate
=
TimeUtil
.
parseTime
(
TimeUtil
.
formatTime
(
TimeUtil
.
addTimeHour
(
date
,
8
)),
"yyyy-MM-dd HH:mm:ss"
);
time
=
sdf
.
format
(
mediadate
);
}
catch
(
Exception
e
)
{
time
=
sdf
.
format
(
System
.
currentTimeMillis
());
}
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
pt
=
"视频"
;
}
else
{
// 网媒
String
trueid
=
hit
.
getSource
().
get
(
"id"
)
!=
null
?
String
.
valueOf
(
hit
.
getSource
().
get
(
"id"
))
:
String
.
valueOf
(
hit
.
getId
());
url
=
trueid
;
title
=
hit
.
getSource
().
get
(
"title"
)
+
""
;
content
=
hit
.
getSource
().
get
(
"content"
)
+
""
;
source
=
hit
.
getSource
().
get
(
"source"
)
+
""
;
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
String
timein
=
String
.
valueOf
(
hit
.
getSource
().
get
(
"time"
));
String
timeout
=
timein
.
replaceAll
(
"T"
,
" "
);
try
{
Date
date
=
sdf
.
parse
(
timeout
);
try
{
// "2017-09-28 20:35:33"
Date
mediadate
=
TimeUtil
.
parseTime
(
TimeUtil
.
formatTime
(
TimeUtil
.
addTimeHour
(
date
,
8
)),
"yyyy-MM-dd HH:mm:ss"
);
time
=
sdf
.
format
(
mediadate
);
}
catch
(
Exception
e
)
{
time
=
sdf
.
format
(
System
.
currentTimeMillis
());
}
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
pt
=
platformName
;
}
TemplateData
templateData
=
new
TemplateData
();
if
(
trackRule
.
getRuleType
().
equals
(
"keyWords"
))
{
// 关键词追踪
templateData
.
setWordRule
(
trackRule
.
getRuleExplain
());
}
else
if
(
trackRule
.
getRuleType
().
equals
(
"channel"
))
{
// 渠道追踪
templateData
.
setChannelRule
(
trackRule
.
getRuleExplain
());
}
templateData
.
setUrl
(
url
);
templateData
.
setTitle
(
title
);
templateData
.
setContent
(
content
);
templateData
.
setSource
(
source
);
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm"
);
Date
datetime
;
try
{
datetime
=
sdf
.
parse
(
time
);
templateData
.
setTime
(
datetime
);
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
templateData
.
setTime
(
new
Date
());
}
templateData
.
setPt
(
pt
);
if
(
fensi
!=
-
1
)
{
templateData
.
setFensi
(
fensi
);
}
Map
<
String
,
Object
>
result
=
new
HashMap
<
String
,
Object
>();
result
=
userMailService
.
sendMailByProject
(
projectName
,
templateData
);
if
((
result
.
get
(
"message"
)
+
""
).
equals
(
"用户组邮件发送成功"
))
{
log
.
info
(
"发送邮件预警成功"
);
trackRule
.
setWarn
(
true
);
trackRuleDao
.
updateTrackrule
(
trackRule
.
get_id
());
break
;
}
else
if
((
result
.
get
(
"message"
)
+
""
).
equals
(
"用户组邮箱未获取到"
))
{
log
.
error
(
"发送邮件预警失败,用户获取问题"
);
}
else
{
log
.
error
(
"本次部分条发送失败"
);
trackRule
.
setWarn
(
true
);
trackRuleDao
.
updateTrackrule
(
trackRule
.
get_id
());
break
;
}
}
}
@Override
public
void
WarnEmailNew
(
SearchHits
trackHit
,
String
platformName
,
TrackRule
trackRule
,
String
projectName
)
{
for
(
SearchHit
hit
:
trackHit
)
{
String
url
=
""
;
String
title
=
""
;
String
content
=
""
;
String
source
=
""
;
String
time
=
""
;
String
pt
=
""
;
int
fensi
=
-
1
;
String
type
=
hit
.
getType
();
Long
rstime
=
null
!=
hit
.
getSource
().
get
(
"rstime"
)
?
Long
.
valueOf
(
hit
.
getSource
().
get
(
"rstime"
)
+
""
)
:
null
;
if
(
type
.
equals
(
"status"
)
&&
null
!=
rstime
)
{
// 微博
url
=
hit
.
getSource
().
get
(
"url"
)
+
""
;
title
=
""
;
content
=
hit
.
getSource
().
get
(
"text"
)
+
""
;
source
=
hit
.
getSource
().
get
(
"username"
)
+
""
;
time
=
hit
.
getSource
().
get
(
"time"
)
+
""
;
pt
=
"微博"
;
fensi
=
Integer
.
valueOf
(
hit
.
getSource
().
get
(
"fensi"
)
+
""
);
}
else
if
(
type
.
equals
(
"zhihu"
))
{
// zhihu
url
=
hit
.
getId
()
+
""
;
title
=
hit
.
getSource
().
get
(
"question_title"
)
+
""
;
content
=
hit
.
getSource
().
get
(
"answer_content"
)
+
""
;
source
=
hit
.
getSource
().
get
(
"user_name"
)
+
""
;
time
=
hit
.
getSource
().
get
(
"created_at"
)
+
""
;
pt
=
"知乎"
;
}
else
if
(
type
.
equals
(
"video"
))
{
// 视频
url
=
hit
.
getId
()
+
""
;
title
=
hit
.
getSource
().
get
(
"title"
)
+
""
;
content
=
""
;
source
=
hit
.
getSource
().
get
(
"uper"
)
+
""
;
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
String
timein
=
String
.
valueOf
(
hit
.
getSource
().
get
(
"time"
));
String
timeout
=
timein
.
replaceAll
(
"T"
,
" "
);
try
{
Date
date
=
sdf
.
parse
(
timeout
);
try
{
// "2017-09-28 20:35:33"
Date
mediadate
=
TimeUtil
.
parseTime
(
TimeUtil
.
formatTime
(
TimeUtil
.
addTimeHour
(
date
,
8
)),
"yyyy-MM-dd HH:mm:ss"
);
time
=
sdf
.
format
(
mediadate
);
}
catch
(
Exception
e
)
{
time
=
sdf
.
format
(
System
.
currentTimeMillis
());
}
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
pt
=
"视频"
;
}
else
{
// 网媒
String
trueid
=
hit
.
getSource
().
get
(
"id"
)
!=
null
?
String
.
valueOf
(
hit
.
getSource
().
get
(
"id"
))
:
String
.
valueOf
(
hit
.
getId
());
url
=
trueid
;
title
=
hit
.
getSource
().
get
(
"title"
)
+
""
;
content
=
hit
.
getSource
().
get
(
"content"
)
+
""
;
source
=
hit
.
getSource
().
get
(
"source"
)
+
""
;
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
String
timein
=
String
.
valueOf
(
hit
.
getSource
().
get
(
"time"
));
String
timeout
=
timein
.
replaceAll
(
"T"
,
" "
);
try
{
Date
date
=
sdf
.
parse
(
timeout
);
try
{
// "2017-09-28 20:35:33"
Date
mediadate
=
TimeUtil
.
parseTime
(
TimeUtil
.
formatTime
(
TimeUtil
.
addTimeHour
(
date
,
8
)),
"yyyy-MM-dd HH:mm:ss"
);
time
=
sdf
.
format
(
mediadate
);
}
catch
(
Exception
e
)
{
time
=
sdf
.
format
(
System
.
currentTimeMillis
());
}
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
pt
=
platformName
;
}
TemplateData
templateData
=
new
TemplateData
();
if
(
trackRule
.
getRuleType
().
equals
(
"keyWords"
))
{
// 关键词追踪
templateData
.
setWordRule
(
trackRule
.
getRuleExplain
());
}
else
if
(
trackRule
.
getRuleType
().
equals
(
"channel"
))
{
// 渠道追踪
templateData
.
setChannelRule
(
trackRule
.
getRuleExplain
());
}
templateData
.
setUrl
(
url
);
templateData
.
setTitle
(
title
);
templateData
.
setContent
(
content
);
templateData
.
setSource
(
source
);
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm"
);
Date
datetime
;
try
{
datetime
=
sdf
.
parse
(
time
);
templateData
.
setTime
(
datetime
);
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
templateData
.
setTime
(
new
Date
());
}
templateData
.
setPt
(
pt
);
if
(
fensi
!=
-
1
)
{
templateData
.
setFensi
(
fensi
);
}
Map
<
String
,
Object
>
result
=
new
HashMap
<
String
,
Object
>();
result
=
userMailService
.
sendMailByProject
(
projectName
,
templateData
);
if
((
result
.
get
(
"message"
)
+
""
).
equals
(
"用户组邮件发送成功"
))
{
log
.
info
(
"发送邮件预警成功"
);
trackRule
.
setWarn
(
true
);
trackRuleDao
.
updateTrackrule
(
trackRule
.
get_id
());
break
;
}
else
if
((
result
.
get
(
"message"
)
+
""
).
equals
(
"用户组邮箱未获取到"
))
{
log
.
error
(
"发送邮件预警失败,用户获取问题"
);
}
else
{
log
.
error
(
"本次部分条发送失败"
);
trackRule
.
setWarn
(
true
);
trackRuleDao
.
updateTrackrule
(
trackRule
.
get_id
());
break
;
}
}
}
}
src/main/java/com/zhiwei/messageflow/mongo/bean/PlatformNew.java
0 → 100644
View file @
46e516cf
package
com
.
zhiwei
.
messageflow
.
mongo
.
bean
;
import
java.util.List
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
lombok.Data
;
import
lombok.ToString
;
/**
* 平台新表
* @ClassName: PlatformNew
* @Description: TODO(平台bean)
* @author shentao
* @date 2017年12月15日 上午10:08:35
*/
@Data
@ToString
@Document
(
collection
=
"qbjc_platformNew"
)
public
class
PlatformNew
{
/**
* id 主键 project_platformName_createAt
*/
@Id
private
String
id
;
//id
/**
* platformName 平台名
*/
private
String
platformName
;
/**
* pt 所需pt字段
*/
private
List
<
String
>
pt
;
/**
* noPt 无需pt字段
*/
private
List
<
String
>
noPt
;
/**
* type 所需type字段
*/
private
List
<
String
>
type
;
/**
* noType 无需type字段
*/
private
List
<
String
>
noType
;
/**
* source 所需source字段
*/
private
List
<
String
>
source
;
/**
* noSource 无需source字段
*/
private
List
<
String
>
noSource
;
/**
* specialRule 特殊规则(内写方法名
*/
private
List
<
String
>
specialRule
;
/**
* platformType 已包含ptype
*/
private
List
<
String
>
platformType
;
/**
* noPlatformType 无法包含的ptype
*/
private
List
<
String
>
noPlatformType
;
/**
* uper 所需uper字段
*/
private
List
<
String
>
uper
;
/**
* noUper 无需uper字段
*/
private
List
<
String
>
noUper
;
/**
* createAt 创建时间
*/
private
Long
createAt
;
/**
* project 所属项目
*/
private
String
project
;
}
src/main/java/com/zhiwei/messageflow/mongo/bean/PlatformType.java
0 → 100644
View file @
46e516cf
package
com
.
zhiwei
.
messageflow
.
mongo
.
bean
;
import
java.util.List
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
lombok.Data
;
import
lombok.ToString
;
/**
* 平台type表
* @ClassName: PlatformType
* @Description: TODO(这里用一句话描述这个类的作用)
* @author shentao
* @date 2018年5月17日 下午5:52:41
*/
@Data
@ToString
@Document
(
collection
=
"qbjc_platformType"
)
public
class
PlatformType
{
/**
* id 主键 platformName_typeName_createAt
*/
@Id
private
String
id
;
//id
/**
* typeName 平台名
*/
private
String
typeName
;
/**
* pt 所需pt字段
*/
private
List
<
String
>
pt
;
/**
* noPt 无需pt字段
*/
private
List
<
String
>
noPt
;
/**
* type 所需type字段
*/
private
List
<
String
>
type
;
/**
* noType 无需type字段
*/
private
List
<
String
>
noType
;
/**
* source 所需source字段
*/
private
List
<
String
>
source
;
/**
* noSource 无需source字段
*/
private
List
<
String
>
noSource
;
/**
* uper 所需uper字段
*/
private
List
<
String
>
uper
;
/**
* noUper 无需uper字段
*/
private
List
<
String
>
noUper
;
/**
* specialRule 特殊规则(内写方法名
*/
private
List
<
String
>
specialRule
;
/**
* createAt 创建时间
*/
private
Long
createAt
;
/**
* 所属平台Name
*/
private
String
platformName
;
}
src/main/java/com/zhiwei/messageflow/mongo/bean/Project.java
View file @
46e516cf
...
...
@@ -38,5 +38,28 @@ public class Project {
private
boolean
weiboHotSearch
;
private
int
gatherKeyWord
;
private
boolean
download
;
/**
* "platformList" 平台列表
*/
private
List
<
String
>
platformList
;
/**
* "unplatformList" 不可选取平台列表
*/
private
List
<
String
>
unplatformList
;
/**
* matchFields 匹配方式 (标题、全文、标题+全文
*/
private
String
matchFields
;
/**
* isAutoMark 自动化标注
*/
private
Boolean
isAutoMark
;
/**
* diyMonitor 定向监测
*/
private
Boolean
diyMonitor
;
/**
* eventList 事件列表
*/
private
Boolean
eventList
;
}
src/main/java/com/zhiwei/messageflow/mongo/dao/PlatformDao.java
View file @
46e516cf
...
...
@@ -2,6 +2,9 @@ package com.zhiwei.messageflow.mongo.dao;
import
java.util.List
;
import
com.zhiwei.messageflow.mongo.bean.PlatformNew
;
import
com.zhiwei.messageflow.mongo.bean.Project
;
public
interface
PlatformDao
{
/**
* 获取公共平台名列表
...
...
@@ -16,4 +19,13 @@ public interface PlatformDao {
* @return
*/
List
<
String
>
getAllPlatformName
();
/**
* 按项目获取平台
* @Title: findPlatformByProject
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @param project
* @param @return 设定文件
* @return List<PlatformNew> 返回类型
*/
List
<
PlatformNew
>
findPlatformByProject
(
Project
project
);
}
src/main/java/com/zhiwei/messageflow/mongo/dao/impl/PlatformDaoImpl.java
View file @
46e516cf
...
...
@@ -6,9 +6,13 @@ import java.util.List;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
import
org.springframework.data.mongodb.core.query.Criteria
;
import
org.springframework.data.mongodb.core.query.Query
;
import
org.springframework.stereotype.Component
;
import
com.zhiwei.messageflow.mongo.bean.Platform
;
import
com.zhiwei.messageflow.mongo.bean.PlatformNew
;
import
com.zhiwei.messageflow.mongo.bean.Project
;
import
com.zhiwei.messageflow.mongo.dao.PlatformDao
;
@Component
...
...
@@ -51,4 +55,13 @@ public class PlatformDaoImpl implements PlatformDao {
return
platformNames
;
}
@Override
public
List
<
PlatformNew
>
findPlatformByProject
(
Project
project
)
{
List
<
String
>
pidList
=
project
.
getPlatformList
();
Query
query
=
new
Query
();
query
.
addCriteria
(
Criteria
.
where
(
"_id"
).
in
(
pidList
));
List
<
PlatformNew
>
res
=
primaryMongoTemplate
.
find
(
query
,
PlatformNew
.
class
);
return
res
;
}
}
src/main/java/com/zhiwei/messageflow/redis/bean/RsidAndMessages.java
View file @
46e516cf
...
...
@@ -2,6 +2,7 @@ package com.zhiwei.messageflow.redis.bean;
import
java.util.List
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zhiwei.messageflow.bean.MediaMessage
;
import
com.zhiwei.messageflow.bean.VideoMessage
;
import
com.zhiwei.messageflow.bean.WeiboMessage
;
...
...
@@ -30,6 +31,10 @@ public class RsidAndMessages {
*/
private
List
<
MediaMessage
>
mlist
;
/**
* 网媒消息列表
*/
private
List
<
JSONObject
>
jlist
;
/**
* 本次读取最后信息的rsid
*/
private
long
rsid
;
...
...
src/main/java/com/zhiwei/messageflow/redis/service/RedisService.java
View file @
46e516cf
...
...
@@ -3,6 +3,7 @@ package com.zhiwei.messageflow.redis.service;
import
java.util.List
;
import
java.util.Map
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zhiwei.messageflow.bean.MediaMessage
;
import
com.zhiwei.messageflow.bean.VideoMessage
;
import
com.zhiwei.messageflow.bean.WeiboMessage
;
...
...
@@ -76,4 +77,19 @@ public interface RedisService {
* redis数据存储上限
*/
void
setMediaMessageMessage
(
String
redisKey
,
List
<
MediaMessage
>
messages
,
int
maxSize
);
/**
* 向redis写入数据
*
* @Title: setMessage2Redis
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @param
* allRedisKey
* @param @param
* messages
* @param @param
* allkeywordcount 设定文件
* @return void 返回类型
*/
void
setMessage2Redis
(
String
allRedisKey
,
List
<
JSONObject
>
messages
,
int
allkeywordcount
);
}
src/main/java/com/zhiwei/messageflow/redis/service/impl/RedisServiceImpl.java
View file @
46e516cf
...
...
@@ -6,6 +6,7 @@ import java.util.Map;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
com.alibaba.fastjson.JSONObject
;
import
com.fasterxml.jackson.annotation.JsonInclude.Include
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
...
...
@@ -136,4 +137,22 @@ public class RedisServiceImpl implements RedisService {
}
@Override
public
void
setMessage2Redis
(
String
redisKey
,
List
<
JSONObject
>
messages
,
int
maxSize
)
{
for
(
JSONObject
jo
:
messages
)
{
// 写入数据
redisPoolAndTools
.
sortedSetZadd
(
redisKey
,
(
double
)
jo
.
getLongValue
(
"commonid"
),
jo
.
toJSONString
());
}
/**
* 删除超出存储上限的数据
*/
long
nowCount
=
redisPoolAndTools
.
getNowCount
(
redisKey
.
getBytes
());
// 当前数据量
int
removeIndex
=
(
int
)
(
nowCount
-
maxSize
);
// 需移除数据数量
if
(
maxSize
>
0
&&
nowCount
>
maxSize
)
{
redisPoolAndTools
.
removeDataByName
(
redisKey
.
getBytes
(),
removeIndex
);
}
}
}
src/main/java/com/zhiwei/messageflow/service/DisposeMessageService.java
View file @
46e516cf
...
...
@@ -3,6 +3,7 @@ package com.zhiwei.messageflow.service;
import
java.util.List
;
import
com.zhiwei.messageflow.mongo.bean.NoiseRule
;
import
com.zhiwei.messageflow.mongo.bean.PlatformNew
;
import
com.zhiwei.messageflow.redis.bean.RsidAndMessages
;
public
interface
DisposeMessageService
{
...
...
@@ -94,4 +95,27 @@ public interface DisposeMessageService {
*/
RsidAndMessages
getFilteredMediaMessage
(
List
<
NoiseRule
>
noiseRules
,
List
<
String
>
keywords
,
int
count
,
Long
startid
,
Long
endid
,
String
platform
,
String
project
);
/**
* 获取各平台RsidAndMessages
*
* @param noiseRules
* 去噪规则
* @param keywords
* 关键词组
* @param count
* 每次查询数量
* @param startid
* 开始rsid
* @param endid
* 结束rsid
* @param platform
* 平台
* @param matchFields
* @param project
* 项目
* @return
*/
RsidAndMessages
getFilteredMessage
(
List
<
NoiseRule
>
noiseRules
,
List
<
String
>
keywords
,
int
count
,
Long
startid
,
Long
endid
,
PlatformNew
platform
,
String
projectName
,
String
matchFields
);
}
src/main/java/com/zhiwei/messageflow/service/impl/DisposeMessageServiceImpl.java
View file @
46e516cf
...
...
@@ -8,12 +8,15 @@ import org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zhiwei.messageflow.bean.MediaMessage
;
import
com.zhiwei.messageflow.bean.VideoMessage
;
import
com.zhiwei.messageflow.bean.WeiboMessage
;
import
com.zhiwei.messageflow.bean.ZhihuMessage
;
import
com.zhiwei.messageflow.es.service.ES4BeanService
;
import
com.zhiwei.messageflow.mongo.bean.NoiseRule
;
import
com.zhiwei.messageflow.mongo.bean.PlatformNew
;
import
com.zhiwei.messageflow.redis.bean.RsidAndMessages
;
import
com.zhiwei.messageflow.service.DisposeMessageService
;
...
...
@@ -115,4 +118,30 @@ public class DisposeMessageServiceImpl implements DisposeMessageService {
return
ram
;
}
@Override
public
RsidAndMessages
getFilteredMessage
(
List
<
NoiseRule
>
noiseRules
,
List
<
String
>
keywords
,
int
count
,
Long
startid
,
Long
endid
,
PlatformNew
platform
,
String
project
,
String
matchFields
)
{
RsidAndMessages
ram
=
new
RsidAndMessages
();
// 消息列表
List
<
JSONObject
>
messages
=
new
ArrayList
<
JSONObject
>();
messages
=
es4BeanDao
.
getMessage
(
noiseRules
,
keywords
,
count
,
startid
+
1L
,
-
1L
,
platform
,
project
,
matchFields
);
/**
* 获取最后消息的rsid
*/
if
(
messages
!=
null
&&
!
messages
.
isEmpty
())
{
JSONObject
mmf
=
messages
.
get
(
0
);
JSONObject
mml
=
messages
.
get
(
messages
.
size
()
-
1
);
ram
.
setJlist
(
messages
);
long
fcomid
=
mmf
.
getLongValue
(
"commonid"
);
long
lcomid
=
mml
.
getLongValue
(
"commonid"
);
ram
.
setRsid
(
fcomid
>
lcomid
?
fcomid
:
lcomid
);
}
return
ram
;
}
}
src/main/java/com/zhiwei/messageflow/util/ESQueryUtil.java
View file @
46e516cf
package
com
.
zhiwei
.
messageflow
.
util
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.elasticsearch.index.query.BoolQueryBuilder
;
import
org.elasticsearch.index.query.QueryBuilders
;
import
org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder
;
import
com.zhiwei.es.util.ESIndexesUtil
;
/**
*
* @TODO(z es 的查询工具类)
...
...
@@ -14,12 +17,30 @@ import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
* @time 2017年7月13日下午3:08:28
*/
public
class
ESQueryUtil
{
protected
static
ESIndexesUtil
.
ESIndexes
indexes
=
ESIndexesUtil
.
create
(
"1.119.44.201"
,
9200
);
public
static
final
String
ES_QUERY_AND
=
"must"
;
public
static
final
String
ES_QUERY_OR
=
"should"
;
public
static
final
String
ES_QUERY_NOT
=
"not"
;
public
static
final
int
WEIBO_FENSI
=
0
;
/**
* 自定义获取高亮
*
* @Title: getTrackHighlightBuilder
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @param
* fields
* @param @param
* color
* @param @return
* 设定文件
* @return HighlightBuilder 返回类型
*/
public
static
HighlightBuilder
getTrackHighlightBuilder
(
String
[]
fields
,
String
color
)
{
HighlightBuilder
hiBuilder
=
new
HighlightBuilder
();
...
...
@@ -173,4 +194,593 @@ public class ESQueryUtil {
return
boolQueryBuilder
;
}
/**
* 字段不拆封,单字段 多关键词 ,带*号特殊处理
*
* @Title: fieldMatchOrWardQueryWords
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @param
* boolQuery
* @param @param
* esQueryOr
* @param @param
* field
* @param @param
* list 设定文件
* @return void 返回类型
*/
public
static
BoolQueryBuilder
fieldMatchOrWildcardQueryWords
(
BoolQueryBuilder
boolQueryBuilder
,
String
esQuery
,
String
field
,
List
<
String
>
words
)
{
if
(
ES_QUERY_AND
.
equals
(
esQuery
))
{
for
(
String
word
:
words
)
{
if
(
word
.
contains
(
"*"
))
{
BoolQueryBuilder
wQuery
=
QueryBuilders
.
boolQuery
();
wQuery
.
should
(
QueryBuilders
.
wildcardQuery
(
field
,
word
));
wQuery
.
should
(
QueryBuilders
.
matchPhraseQuery
(
field
,
word
));
boolQueryBuilder
.
must
(
wQuery
);
}
else
{
boolQueryBuilder
.
must
(
QueryBuilders
.
matchPhraseQuery
(
field
,
word
));
}
}
}
else
if
(
ES_QUERY_OR
.
equals
(
esQuery
))
{
for
(
String
word
:
words
)
{
if
(
word
.
contains
(
"*"
))
{
BoolQueryBuilder
wQuery
=
QueryBuilders
.
boolQuery
();
wQuery
.
should
(
QueryBuilders
.
wildcardQuery
(
field
,
word
));
wQuery
.
should
(
QueryBuilders
.
matchPhraseQuery
(
field
,
word
));
boolQueryBuilder
.
should
(
wQuery
);
// boolQueryBuilder.should(QueryBuilders.wildcardQuery(field, word));
}
else
{
boolQueryBuilder
.
should
(
QueryBuilders
.
matchPhraseQuery
(
field
,
word
));
}
}
}
else
if
(
ES_QUERY_NOT
.
equals
(
esQuery
))
{
for
(
String
word
:
words
)
{
if
(
word
.
contains
(
"*"
))
{
BoolQueryBuilder
wQuery
=
QueryBuilders
.
boolQuery
();
wQuery
.
should
(
QueryBuilders
.
wildcardQuery
(
field
,
word
));
wQuery
.
should
(
QueryBuilders
.
matchPhraseQuery
(
field
,
word
));
boolQueryBuilder
.
mustNot
(
wQuery
);
// boolQueryBuilder.mustNot(QueryBuilders.wildcardQuery(field, word));
}
else
{
boolQueryBuilder
.
mustNot
(
QueryBuilders
.
matchPhraseQuery
(
field
,
word
));
}
}
}
return
boolQueryBuilder
;
}
/**
* 按平台type和平台名获取indexlist
*
* @Title: getIndexListbyPtList
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @param
* ptList(status,video,zhihu,forum...
* @param @param
* platformName(平台名
* @param @return
* 设定文件
* @return String[] 返回类型
*/
public
static
String
[]
getIndexListbyPtList
(
List
<
String
>
ptList
,
List
<
String
>
noPlatformType
)
{
String
[]
indexlist
=
null
;
List
<
String
>
list
=
new
ArrayList
<>();
String
index
=
""
;
// 判断是否有微信大库
boolean
isNoWechatFull
=
false
;
for
(
String
noPt
:
noPlatformType
)
{
if
(
noPt
.
contains
(
"微信大库"
))
{
isNoWechatFull
=
true
;
}
}
for
(
String
pt
:
ptList
)
{
switch
(
pt
)
{
case
"status"
:
if
(
isNoWechatFull
)
{
index
=
"network"
;
}
else
{
index
=
"wx_tanglihua"
;
}
break
;
case
"video"
:
index
=
"videos"
;
break
;
case
"zhihu"
:
index
=
"zhihu*"
;
break
;
default
:
index
=
"mediaspider"
;
break
;
}
if
(
index
.
equals
(
"wx_tanglihua"
))
{
list
=
new
ArrayList
<>();
list
.
addAll
(
indexes
.
getLastIndexes
(
index
,
2
));
break
;
}
else
if
(!
index
.
contains
(
"*"
))
{
list
.
addAll
(
indexes
.
getLastIndexes
(
index
,
2
));
}
else
{
list
.
add
(
index
);
}
}
indexlist
=
list
.
toArray
(
new
String
[
list
.
size
()]);
return
indexlist
;
}
/**
* 按平台type和平台名获取typelist
*
* @Title: getTypeListbyPtList
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @param
* ptList
* @param @return
* 设定文件
* @return String[] 返回类型
*/
public
static
String
[]
getTypeListbyPtList
(
List
<
String
>
ptList
)
{
String
[]
typeList
=
null
;
List
<
String
>
list
=
ptList
;
typeList
=
list
.
toArray
(
new
String
[
list
.
size
()]);
return
typeList
;
}
/**
* 按平台type和平台名获取关键词fieldslist
*
* @param matchFields
* @Title: getFieldListbyPtList
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @param
* ptList
* @param @param
* noPlatformType
* @param @return
* 设定文件
* @return String[] 返回类型
*/
public
static
String
[]
getFieldListbyPtList
(
List
<
String
>
ptList
,
List
<
String
>
noPlatformType
,
String
matchFields
)
{
String
[]
fieldlist
=
null
;
List
<
String
>
fields
=
new
ArrayList
<>();
// 判断是否有微信大库
boolean
isNoWechatFull
=
false
;
for
(
String
noPt
:
noPlatformType
)
{
if
(
noPt
.
contains
(
"微信大库"
))
{
isNoWechatFull
=
true
;
}
}
// 获取搜索字段
if
(!
isNoWechatFull
)
{
fields
.
add
(
"title"
);
fields
.
add
(
"content"
);
}
else
{
for
(
String
pt
:
ptList
)
{
switch
(
pt
)
{
case
"status"
:
if
(!
fields
.
contains
(
"text"
))
{
fields
.
add
(
"text"
);
}
if
(!
fields
.
contains
(
"roottext"
))
{
fields
.
add
(
"roottext"
);
}
break
;
case
"zhihu"
:
if
(!
fields
.
contains
(
"question_title"
))
{
fields
.
add
(
"question_title"
);
}
if
(!
fields
.
contains
(
"question_content"
))
{
fields
.
add
(
"question_content"
);
}
if
(!
fields
.
contains
(
"answer_content"
))
{
fields
.
add
(
"answer_content"
);
}
break
;
default
:
if
(
matchFields
.
equals
(
"标题"
)
||
matchFields
.
equals
(
"标题+全文"
)
||
matchFields
.
equals
(
""
))
{
if
(!
fields
.
contains
(
"title"
))
{
fields
.
add
(
"title"
);
}
}
if
((
matchFields
.
equals
(
"全文"
)
||
matchFields
.
equals
(
"标题+全文"
)
||
matchFields
.
equals
(
""
))&&!
ptList
.
contains
(
"video"
))
{
if
(!
fields
.
contains
(
"content"
))
{
fields
.
add
(
"content"
);
}
}
break
;
}
}
}
fieldlist
=
fields
.
toArray
(
new
String
[
fields
.
size
()]);
return
fieldlist
;
}
/**
* 按关键词fields和关键词封装查询语句
*
* @Title: assembleKeywordQuery
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @param
* queryBuilder
* @param @param
* keywords
* @param @param
* fieldlist
* @param @return
* 设定文件
* @return BoolQueryBuilder 返回类型
*/
public
static
BoolQueryBuilder
assembleKeywordQuery
(
BoolQueryBuilder
queryBuilder
,
List
<
String
>
keywords
,
String
[]
fieldlist
)
{
// 组装查询
if
(
keywords
.
isEmpty
())
{
return
null
;
}
for
(
int
a
=
0
;
a
<
keywords
.
size
();
a
++)
{
String
keyword
=
keywords
.
get
(
a
).
replace
(
"serach---"
,
""
);
if
(
keyword
.
indexOf
(
"("
)
!=
-
1
)
{
BoolQueryBuilder
mixboolQueryBuilder
=
QueryBuilders
.
boolQuery
();
String
anyWord
=
keyword
.
substring
(
keyword
.
indexOf
(
"("
)
+
1
,
keyword
.
indexOf
(
")"
));
String
allWords
=
keyword
.
replaceAll
(
"("
+
anyWord
+
")"
,
""
);
// 或关系
BoolQueryBuilder
anyboolQueryBuilder
=
QueryBuilders
.
boolQuery
();
// 查询封装
if
(!
anyWord
.
equals
(
""
))
{
String
[]
anywords
=
anyWord
.
split
(
" "
);
for
(
int
i
=
0
;
i
<
anywords
.
length
;
i
++)
{
String
anyword
=
anywords
[
i
];
anyboolQueryBuilder
.
should
(
ESQueryUtil
.
matchPhraseQueryFields
(
QueryBuilders
.
boolQuery
(),
"should"
,
anyword
,
fieldlist
));
}
mixboolQueryBuilder
.
must
(
anyboolQueryBuilder
);
}
// 且关系
BoolQueryBuilder
allboolQueryBuilder
=
QueryBuilders
.
boolQuery
();
// 查询封装
if
(!
allWords
.
equals
(
""
))
{
String
[]
allwords
=
allWords
.
split
(
" "
);
for
(
int
i
=
0
;
i
<
allwords
.
length
;
i
++)
{
String
allword
=
allwords
[
i
];
// 意思为三字段其一满足这个关键词 用且拼接 =》
// ESQueryUtil.matchPhraseQueryFields(boolQueryBuilder, "should", word,
// "question_title", "question_content", "answer_content");
allboolQueryBuilder
.
must
(
ESQueryUtil
.
matchPhraseQueryFields
(
QueryBuilders
.
boolQuery
(),
"should"
,
allword
,
fieldlist
));
}
mixboolQueryBuilder
.
must
(
allboolQueryBuilder
);
}
queryBuilder
.
should
(
mixboolQueryBuilder
);
}
else
if
(
keyword
.
indexOf
(
" "
)
!=
-
1
)
{
BoolQueryBuilder
mixboolQueryBuilder
=
QueryBuilders
.
boolQuery
();
String
words
[]
=
keyword
.
split
(
" "
);
for
(
int
i
=
0
;
i
<
words
.
length
;
i
++)
{
String
word
=
words
[
i
];
// 意思为三字段其一满足这个关键词 用且拼接 =》
// ESQueryUtil.matchPhraseQueryFields(boolQueryBuilder, "should", word,
// "question_title", "question_content", "answer_content");
mixboolQueryBuilder
.
must
(
ESQueryUtil
.
matchPhraseQueryFields
(
QueryBuilders
.
boolQuery
(),
"should"
,
word
,
fieldlist
));
}
queryBuilder
.
should
(
mixboolQueryBuilder
);
}
else
{
ESQueryUtil
.
matchPhraseQueryFields
(
queryBuilder
,
"should"
,
keyword
,
fieldlist
);
}
}
return
queryBuilder
;
}
/**
* 组装should条件和not条件,多fields
*
* @Title: assembleShouldNotFieldsQuery
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @param
* boolQuery
* @param @param
* list
* @param @param
* noList
* @param @param
* fields
* @param @return
* 设定文件
* @return BoolQueryBuilder 返回类型
*/
public
static
BoolQueryBuilder
assembleShouldNotFieldsQuery
(
BoolQueryBuilder
boolQuery
,
List
<
String
>
list
,
List
<
String
>
noList
,
String
...
fields
)
{
if
(
null
!=
list
&&
!
list
.
isEmpty
())
{
for
(
String
field
:
fields
)
{
ESQueryUtil
.
fieldMatchOrWildcardQueryWords
(
boolQuery
,
ES_QUERY_OR
,
field
,
list
);
}
}
if
(
null
!=
noList
&&
!
noList
.
isEmpty
())
{
for
(
String
field
:
fields
)
{
ESQueryUtil
.
fieldMatchOrWildcardQueryWords
(
boolQuery
,
ES_QUERY_NOT
,
field
,
noList
);
}
}
return
boolQuery
;
}
/**
* 特殊方法配装
*
* @Title: assembleSpecialRuleQurey
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @param
* boolQuery
* @param @param
* srList
* @param @return
* 设定文件
* @return BoolQueryBuilder 返回类型
*/
public
static
BoolQueryBuilder
assembleSpecialRuleQurey
(
BoolQueryBuilder
boolQuery
,
List
<
String
>
srList
)
{
for
(
String
sr
:
srList
)
{
switch
(
sr
)
{
case
"weiboSinaV"
:
boolQuery
.
must
(
QueryBuilders
.
rangeQuery
(
"fensi"
).
gte
(
WEIBO_FENSI
));
break
;
case
"weiboAlt"
:
boolQuery
.
must
(
QueryBuilders
.
rangeQuery
(
"fensi"
).
lt
(
WEIBO_FENSI
));
break
;
default
:
break
;
}
}
return
boolQuery
;
}
/**
* 插件配装语句
*
* @Title: assemblePluginQurey
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @param
* boolQuery
* @param @return
* 设定文件
* @return BoolQueryBuilder 返回类型
*/
public
static
BoolQueryBuilder
assemblePluginQurey
(
BoolQueryBuilder
boolQuery
)
{
boolQuery
.
mustNot
(
QueryBuilders
.
matchQuery
(
"source"
,
"插件标注"
));
boolQuery
.
mustNot
(
QueryBuilders
.
existsQuery
(
"plugIn"
));
return
boolQuery
;
}
/**
* 关键词追踪规则拼装
*
* @Title: assembleKeywordTrackQuery
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @param
* boolQuery
* @param @param
* allWords
* @param @param
* anyWord
* @param @param
* fieldlist
* @param @return
* 设定文件
* @return BoolQueryBuilder 返回类型
*/
public
static
BoolQueryBuilder
assembleKeywordTrackQuery
(
BoolQueryBuilder
boolQuery
,
String
allWords
,
String
anyWord
,
String
[]
fieldlist
)
{
BoolQueryBuilder
anyboolQueryBuilder
=
QueryBuilders
.
boolQuery
();
// 查询封装
if
(
anyWord
!=
""
)
{
String
[]
anywords
=
anyWord
.
split
(
","
);
for
(
int
i
=
0
;
i
<
anywords
.
length
;
i
++)
{
String
anyword
=
anywords
[
i
];
anyboolQueryBuilder
.
should
(
ESQueryUtil
.
matchPhraseQueryFields
(
QueryBuilders
.
boolQuery
(),
"should"
,
anyword
,
fieldlist
));
}
boolQuery
.
must
(
anyboolQueryBuilder
);
}
// 且关系
BoolQueryBuilder
allboolQueryBuilder
=
QueryBuilders
.
boolQuery
();
// 查询封装
if
(
allWords
!=
""
)
{
String
[]
allwords
=
allWords
.
split
(
","
);
for
(
int
i
=
0
;
i
<
allwords
.
length
;
i
++)
{
String
allword
=
allwords
[
i
];
allboolQueryBuilder
.
must
(
ESQueryUtil
.
matchPhraseQueryFields
(
QueryBuilders
.
boolQuery
(),
"should"
,
allword
,
fieldlist
));
}
boolQuery
.
must
(
allboolQueryBuilder
);
}
return
boolQuery
;
}
/**
* 渠道追踪field获取
*
* @Title: getChannelFieldListbyPtList
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @param
* ptList
* @param @param
* noPlatformType
* @param @return
* 设定文件
* @return String[] 返回类型
*/
public
static
String
[]
getChannelFieldListbyPtList
(
List
<
String
>
ptList
,
List
<
String
>
noPlatformType
)
{
String
[]
fieldlist
=
null
;
List
<
String
>
fields
=
new
ArrayList
<>();
// 判断是否有微信大库
boolean
isNoWechatFull
=
false
;
for
(
String
noPt
:
noPlatformType
)
{
if
(
noPt
.
contains
(
"微信大库"
))
{
isNoWechatFull
=
true
;
}
}
// 获取搜索字段
if
(!
isNoWechatFull
)
{
fields
.
add
(
"source"
);
}
else
{
for
(
String
pt
:
ptList
)
{
switch
(
pt
)
{
case
"status"
:
if
(!
fields
.
contains
(
"username"
))
{
fields
.
add
(
"username"
);
}
break
;
case
"zhihu"
:
if
(!
fields
.
contains
(
"user_name"
))
{
fields
.
add
(
"user_name"
);
}
break
;
case
"video"
:
if
(!
fields
.
contains
(
"uper"
))
{
fields
.
add
(
"uper"
);
}
break
;
default
:
if
(!
fields
.
contains
(
"source"
))
{
fields
.
add
(
"source"
);
}
break
;
}
}
}
fieldlist
=
fields
.
toArray
(
new
String
[
fields
.
size
()]);
return
fieldlist
;
}
/**
* 渠道追踪拼装
* @Title: assembleChannelTrackQuery
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @param boolQuery
* @param @param channel
* @param @param fieldlist
* @param @return 设定文件
* @return BoolQueryBuilder 返回类型
*/
public
static
BoolQueryBuilder
assembleChannelTrackQuery
(
BoolQueryBuilder
boolQuery
,
String
channel
,
String
[]
fieldlist
)
{
BoolQueryBuilder
channelboolQueryBuilder
=
QueryBuilders
.
boolQuery
();
// 查询封装
channelboolQueryBuilder
.
should
(
ESQueryUtil
.
matchPhraseQueryFields
(
QueryBuilders
.
boolQuery
(),
"should"
,
channel
,
fieldlist
));
boolQuery
.
must
(
channelboolQueryBuilder
);
return
boolQuery
;
}
/**
* 相似新闻拼装
* @Title: assembleArticleTitleTrackQuery
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @param boolQuery
* @param @param articleTitle
* @param @param fieldlist
* @param @return 设定文件
* @return BoolQueryBuilder 返回类型
*/
public
static
BoolQueryBuilder
assembleArticleTitleTrackQuery
(
BoolQueryBuilder
boolQuery
,
String
articleTitle
,
String
[]
fieldlist
)
{
boolQuery
.
must
(
ESQueryUtil
.
matchPhraseQueryFields
(
QueryBuilders
.
boolQuery
(),
"should"
,
articleTitle
,
fieldlist
));
return
boolQuery
;
}
/**
* 获取搜索index
* @Title: getSearchIndexListbyPtList
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @param ptList
* @param @param noPlatformType
* @param @return 设定文件
* @return String[] 返回类型
*/
public
static
String
[]
getSearchIndexListbyPtList
(
List
<
String
>
ptList
,
List
<
String
>
noPlatformType
)
{
String
[]
indexlist
=
null
;
List
<
String
>
list
=
new
ArrayList
<>();
String
index
=
""
;
// 判断是否有微信大库
boolean
isNoWechatFull
=
false
;
for
(
String
noPt
:
noPlatformType
)
{
if
(
noPt
.
contains
(
"微信大库"
))
{
isNoWechatFull
=
true
;
}
}
for
(
String
pt
:
ptList
)
{
switch
(
pt
)
{
case
"status"
:
if
(
isNoWechatFull
)
{
index
=
"network*"
;
}
else
{
index
=
"wx_tanglihua*"
;
}
break
;
case
"video"
:
index
=
"videos*"
;
break
;
case
"zhihu"
:
index
=
"zhihu*"
;
break
;
default
:
index
=
"mediaspider*"
;
break
;
}
if
(
index
.
equals
(
"wx_tanglihua*"
))
{
list
=
new
ArrayList
<>();
list
.
add
(
index
);
break
;
}
else
if
(!
index
.
contains
(
"*"
))
{
list
.
add
(
index
);
// list.addAll(indexes.getLastIndexes(index, 2));
}
else
{
list
.
add
(
index
);
}
}
indexlist
=
list
.
toArray
(
new
String
[
list
.
size
()]);
return
indexlist
;
}
/**
* 获取高级搜索query
* @Title: assembleSeniorQuery
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param @param boolQuery
* @param @param anyWord
* @param @param allWords
* @param @param channel
* @param @param fieldlist
* @param @param sourcelist
* @param @return 设定文件
* @return BoolQueryBuilder 返回类型
*/
public
static
BoolQueryBuilder
assembleSeniorQuery
(
BoolQueryBuilder
boolQuery
,
String
anyWord
,
String
allWords
,
String
channel
,
String
[]
fieldlist
,
String
[]
sourcelist
)
{
BoolQueryBuilder
anyboolQueryBuilder
=
QueryBuilders
.
boolQuery
();
// 查询封装
if
(!
anyWord
.
equals
(
""
))
{
String
[]
anywords
=
anyWord
.
split
(
" "
);
for
(
int
i
=
0
;
i
<
anywords
.
length
;
i
++)
{
String
anyword
=
anywords
[
i
];
anyboolQueryBuilder
.
should
(
ESQueryUtil
.
matchPhraseQueryFields
(
QueryBuilders
.
boolQuery
(),
"should"
,
anyword
,
fieldlist
));
}
boolQuery
.
must
(
anyboolQueryBuilder
);
}
// 且关系
BoolQueryBuilder
allboolQueryBuilder
=
QueryBuilders
.
boolQuery
();
// 查询封装
if
(!
allWords
.
equals
(
""
))
{
String
[]
allwords
=
allWords
.
split
(
" "
);
for
(
int
i
=
0
;
i
<
allwords
.
length
;
i
++)
{
String
allword
=
allwords
[
i
];
allboolQueryBuilder
.
must
(
ESQueryUtil
.
matchPhraseQueryFields
(
QueryBuilders
.
boolQuery
(),
"should"
,
allword
,
fieldlist
));
}
boolQuery
.
must
(
allboolQueryBuilder
);
}
// 渠道
if
(!
channel
.
equals
(
""
))
{
BoolQueryBuilder
channelboolQueryBuilder
=
QueryBuilders
.
boolQuery
();
// 查询封装
channelboolQueryBuilder
.
should
(
ESQueryUtil
.
matchPhraseQueryFields
(
QueryBuilders
.
boolQuery
(),
"should"
,
channel
,
sourcelist
));
boolQuery
.
must
(
channelboolQueryBuilder
);
}
return
boolQuery
;
}
}
src/main/resources/application.properties
View file @
46e516cf
##
æå¡ç«¯
uri
##
\u009C\u008D\u008A端
uri
#spring.data.mongodb.uri=115.236.59.91:27017
#
内置tomcat端口号
server.port
=
809
2
#
\u5185\u7F6Etomcat\u7AEF\u53E3\u53F7
server.port
=
809
1
#
æå¡ç«¯æ°æ®åº
#
\u009C\u008D\u008A端\u0095\u008D\u0093
spring.data.mongodb.primary.database
=
qbjcPhoenix
#
æå¡
ip
#
\u009C\u008D\u008A
ip
spring.data.mongodb.primary.host
=
192.168.0.101
#
æå¡
port
#
\u009C\u008D\u008A
port
spring.data.mongodb.primary.port
=
27017
spring.data.mongodb.primary.username
=
stno
...
...
@@ -17,11 +17,11 @@ spring.data.mongodb.primary.password=stno1q2w3e4r
spring.data.mongodb.primary.authenticationDatabase
=
admin
#
æå¡ç«¯æ°æ®åº
#
\u009C\u008D\u008A端\u0095\u008D\u0093
spring.data.mongodb.secondary.database
=
eventMuseum
#
æå¡
ip
#
\u009C\u008D\u008A
ip
spring.data.mongodb.secondary.host
=
192.168.0.101
#
æå¡
port
#
\u009C\u008D\u008A
port
spring.data.mongodb.secondary.port
=
27017
spring.data.mongodb.secondary.username
=
stno
...
...
@@ -30,11 +30,11 @@ spring.data.mongodb.secondary.password=stno1q2w3e4r
spring.data.mongodb.secondary.authenticationDatabase
=
admin
#
æå¡ç«¯æ°æ®åº
#
\u009C\u008D\u008A端\u0095\u008D\u0093
spring.data.mongodb.thirdary.database
=
WechatPublic
#
æå¡
ip
#
\u009C\u008D\u008A
ip
spring.data.mongodb.thirdary.host
=
192.168.0.101
#
æå¡
port
#
\u009C\u008D\u008A
port
spring.data.mongodb.thirdary.port
=
27017
spring.data.mongodb.thirdary.username
=
stno
...
...
@@ -64,21 +64,21 @@ spring.data.mongodb.thirdary.authenticationDatabase=admin
#spring.data.mongodb.option.heartbeat-frequency=10000
#spring.data.mongodb.option.local-threshold=15
##
æ¬å°
ip
##
\u009C\u009C
ip
#spring.data.mongodb.host=192.168.0.241
##
æ¬å°
port
##
\u009C\u009C
port
#spring.data.mongodb.port=27017
##
æ¬å°æ°æ®åº
##
\u009C\u009C\u0095\u008D\u0093
#spring.data.mongodb.database=qbjcPhoenix
#
å ¶ä»æ°æ®åº
#
\u0085\u0096\u0095\u008D\u0093
#spring.data.mongodb.database=eventMuseum
#spring.data.mongodb.database=WechatPublic
#tag
ç¨
uri
#tag
\u0094
uri
#spring.data.mongodb.uri=1.119.44.206:30000
#spring.data.mongodb.uri=192.168.0.245:27017
#tag
æ°æ®åº
#tag
\u0095\u008D\u0093
#spring.data.mongodb.database=Testqbjc
#spring.data.mongodb.database=weibotag
...
...
src/main/resources/application.properties.8092
0 → 100644
View file @
46e516cf
##æå¡ç«¯uri
#spring.data.mongodb.uri=115.236.59.91:27017
#内置tomcat端口号
server.port=8092
#æå¡ç«¯æ°æ®åº
spring.data.mongodb.primary.database=qbjcPhoenix
#æå¡ip
spring.data.mongodb.primary.host=192.168.0.101
#æå¡port
spring.data.mongodb.primary.port=27017
spring.data.mongodb.primary.username=stno
spring.data.mongodb.primary.password=stno1q2w3e4r
spring.data.mongodb.primary.authenticationDatabase=admin
#æå¡ç«¯æ°æ®åº
spring.data.mongodb.secondary.database=eventMuseum
#æå¡ip
spring.data.mongodb.secondary.host=192.168.0.101
#æå¡port
spring.data.mongodb.secondary.port=27017
spring.data.mongodb.secondary.username=stno
spring.data.mongodb.secondary.password=stno1q2w3e4r
spring.data.mongodb.secondary.authenticationDatabase=admin
#æå¡ç«¯æ°æ®åº
spring.data.mongodb.thirdary.database=WechatPublic
#æå¡ip
spring.data.mongodb.thirdary.host=192.168.0.101
#æå¡port
spring.data.mongodb.thirdary.port=27017
spring.data.mongodb.thirdary.username=stno
spring.data.mongodb.thirdary.password=stno1q2w3e4r
spring.data.mongodb.thirdary.authenticationDatabase=admin
#spring.data.mongodb.option.min-connection-per-host=0
#spring.data.mongodb.option.max-connection-per-host=100
#spring.data.mongodb.option.threads-allowed-to-block-for-connection-multiplier=5
#spring.data.mongodb.option.server-selection-timeout=30000
#spring.data.mongodb.option.max-wait-time=120000
#spring.data.mongodb.option.max-connection-idle-time=0
#spring.data.mongodb.option.max-connection-life-time=0
#spring.data.mongodb.option.connect-timeout=10000
#spring.data.mongodb.option.socket-timeout=0
#
#spring.data.mongodb.option.socket-keep-alive=false
#spring.data.mongodb.option.ssl-enabled=false
#spring.data.mongodb.option.ssl-invalid-host-name-allowed=false
#spring.data.mongodb.option.always-use-m-beans=false
#
#spring.data.mongodb.option.heartbeat-socket-timeout=20000
#spring.data.mongodb.option.heartbeat-connect-timeout=20000
#spring.data.mongodb.option.min-heartbeat-frequency=500
#spring.data.mongodb.option.heartbeat-frequency=10000
#spring.data.mongodb.option.local-threshold=15
##æ¬å°ip
#spring.data.mongodb.host=192.168.0.241
##æ¬å°port
#spring.data.mongodb.port=27017
##æ¬å°æ°æ®åº
#spring.data.mongodb.database=qbjcPhoenix
#å ¶ä»æ°æ®åº
#spring.data.mongodb.database=eventMuseum
#spring.data.mongodb.database=WechatPublic
#tagç¨uri
#spring.data.mongodb.uri=1.119.44.206:30000
#spring.data.mongodb.uri=192.168.0.245:27017
#tagæ°æ®åº
#spring.data.mongodb.database=Testqbjc
#spring.data.mongodb.database=weibotag
#mongo.connectionsPerHost=200
#mongo.threadsAllowedToBlockForConnectionMultiplier=10
#
#mongo.connectTimeout=30000
#
#mongo.maxWaitTime=50000
#mongo.autoConnectRetry=true
#mongo.socketKeepAlive=true
#
#mongo.socketTimeout=120000
#mongo.slaveOk=true
\ No newline at end of file
src/main/resources/redis.properties
View file @
46e516cf
...
...
@@ -13,7 +13,7 @@ redis.port=6380
redis.keyMaxSize
=
5000
redis.selectDB
=
1
3
redis.selectDB
=
1
2
#redis.selectDB=2
redis.user_keyMaxSize
=
1000
redis.cacheSize
=
1000
...
...
src/main/resources/redis.properties.6380
0 → 100644
View file @
46e516cf
redis.maxTotal=2048
redis.maxIdle=200
redis.maxWaitMillis=1000
redis.testOnBorrow=true
redis.testOnReturn=true
redis.ip = 192.168.0.202
#redis.ip = 202.107.192.94
#redis.ip=127.0.0.1
redis.port=6380
#redis.ip=192.168.1.74
#redis.port=6388
#redis.password=fjouero&^%^%^$*()*)))*^$$KDFJDKJF9ruorudlfdljfldjf
redis.keyMaxSize=5000
redis.selectDB=13
#redis.selectDB=2
redis.user_keyMaxSize=1000
redis.cacheSize=1000
redis.intitCount=3000
\ No newline at end of file
src/main/resources/redis.properties.local1
View file @
46e516cf
...
...
@@ -13,7 +13,7 @@ redis.port=6379
redis.keyMaxSize=5000
redis.selectDB=1
3
redis.selectDB=1
2
#redis.selectDB=2
redis.user_keyMaxSize=1000
redis.cacheSize=1000
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment