Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
石磊
/
cihai
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 43c7acd9
authored
Jan 18, 2018
by
侯昆
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
修改查询逻辑
1 parent
0083c3ca
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
48 deletions
serverside/cihai-app/src/main/java/com/dookay/cihai/app/controller/HomeController.java
serverside/cihai-core/src/main/java/com/dookay/cihai/core/word/query/WordQuery.java
serverside/cihai-core/src/test/java/com/dookay/cihai/core/excel/TestImportWord.java
serverside/cihai-core/src/test/resources/1.txt
serverside/cihai-core/src/test/resources/sql/clear.sql
serverside/cihai-pc/src/main/java/com/dookay/cihai/pc/controller/HomeController.java
serverside/cihai-app/src/main/java/com/dookay/cihai/app/controller/HomeController.java
View file @
43c7acd
...
@@ -15,16 +15,14 @@ package com.dookay.cihai.app.controller;
...
@@ -15,16 +15,14 @@ package com.dookay.cihai.app.controller;
****************************************/
****************************************/
import
com.baidu.aip.util.Base64Util
;
import
com.baidu.aip.util.Base64Util
;
import
com.dookay.cihai.core.word.dto.WordDTO
;
import
com.dookay.cihai.core.aip.AipDefaultClient
;
import
com.dookay.cihai.core.aip.AipDefaultClient
;
import
com.dookay.cihai.core.aip.AipWordUtilBean
;
import
com.dookay.cihai.core.aip.AipWordUtilBean
;
import
com.dookay.cihai.core.aip.model.LexerItem
;
import
com.dookay.cihai.core.aip.model.LexerItem
;
import
com.dookay.cihai.core.aip.model.ScanResult
;
import
com.dookay.cihai.core.aip.model.ScanResult
;
import
com.dookay.cihai.core.word.domain.CustomDictionaryDomain
;
import
com.dookay.cihai.core.word.domain.WordDomain
;
import
com.dookay.cihai.core.word.domain.WordDomain
;
import
com.dookay.cihai.core.word.dto.OneCharacterDTO
;
import
com.dookay.cihai.core.word.dto.OneCharacterDTO
;
import
com.dookay.cihai.core.word.dto.RecommendStatementDTO
;
import
com.dookay.cihai.core.word.dto.RecommendStatementDTO
;
import
com.dookay.cihai.core.word.
query.CustomDictionaryQuery
;
import
com.dookay.cihai.core.word.
dto.WordDTO
;
import
com.dookay.cihai.core.word.query.WordQuery
;
import
com.dookay.cihai.core.word.query.WordQuery
;
import
com.dookay.cihai.core.word.service.ICustomDictionaryService
;
import
com.dookay.cihai.core.word.service.ICustomDictionaryService
;
import
com.dookay.cihai.core.word.service.IWordRelationService
;
import
com.dookay.cihai.core.word.service.IWordRelationService
;
...
@@ -81,31 +79,21 @@ public class HomeController extends BaseController {
...
@@ -81,31 +79,21 @@ public class HomeController extends BaseController {
if
(
StringUtils
.
isBlank
(
keyword
))
{
if
(
StringUtils
.
isBlank
(
keyword
))
{
return
errorResult
(
"搜索内容不能为空"
);
return
errorResult
(
"搜索内容不能为空"
);
}
}
String
result
=
null
;
WordQuery
query
=
new
WordQuery
();
boolean
inDic
=
false
;
query
.
setKeyword
(
keyword
);
List
<
CustomDictionaryDomain
>
dictionaryDomainList
=
customDictionaryService
.
getList
(
new
CustomDictionaryQuery
());
WordDomain
first
=
wordService
.
getFirst
(
query
);
for
(
CustomDictionaryDomain
dic
:
dictionaryDomainList
)
{
if
(
first
!=
null
)
{
if
(
keyword
.
contains
(
dic
.
getWord
()))
{
return
successResult
(
"搜索结果"
,
WordDTO
.
fromDomain
(
first
,
wordRelationService
));
result
=
dic
.
getWord
();
inDic
=
true
;
}
}
}
try
{
try
{
if
(!
inDic
)
{
String
result
=
null
;
result
=
aipWordUtilBean
.
extractQueryKeyword
(
keyword
);
List
<
LexerItem
>
items
=
aipWordUtilBean
.
getLexerItems
(
result
);
}
WordQuery
wordQuery
=
new
WordQuery
();
WordQuery
wordQuery
=
new
WordQuery
();
wordQuery
.
setKeyword
(
result
);
wordQuery
.
setKeywordList
(
items
.
stream
().
map
(
LexerItem:
:
getItem
).
collect
(
Collectors
.
toList
()));
wordQuery
.
setKeyword
(
null
);
WordDomain
wordDomain
=
wordService
.
getFirst
(
wordQuery
);
WordDomain
wordDomain
=
wordService
.
getFirst
(
wordQuery
);
if
(
wordDomain
==
null
)
{
if
(
wordDomain
==
null
)
return
errorResult
(
String
.
format
(
"暂无\"%s\"检索结果"
,
keyword
));
List
<
LexerItem
>
items
=
aipWordUtilBean
.
getLexerItems
(
result
);
return
successResult
(
"搜索结果"
,
WordDTO
.
fromDomain
(
wordDomain
,
wordRelationService
));
wordQuery
.
setKeywordList
(
items
.
stream
().
map
(
LexerItem:
:
getItem
).
collect
(
Collectors
.
toList
()));
wordQuery
.
setKeyword
(
null
);
wordDomain
=
wordService
.
getFirst
(
wordQuery
);
if
(
wordDomain
==
null
)
return
errorResult
(
String
.
format
(
"暂无\"%s\"检索结果"
,
keyword
));
return
successResult
(
"搜索结果"
,
WordDTO
.
fromDomain
(
wordDomain
,
wordRelationService
));
}
return
successResult
(
"success"
,
WordDTO
.
fromDomain
(
wordDomain
,
wordRelationService
));
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
return
errorResult
(
String
.
format
(
"暂无\"%s\"检索结果"
,
keyword
));
return
errorResult
(
String
.
format
(
"暂无\"%s\"检索结果"
,
keyword
));
}
}
...
...
serverside/cihai-core/src/main/java/com/dookay/cihai/core/word/query/WordQuery.java
View file @
43c7acd
...
@@ -40,7 +40,7 @@ public class WordQuery extends Query {
...
@@ -40,7 +40,7 @@ public class WordQuery extends Query {
}
}
if
(
valid
(
keyword
))
{
if
(
valid
(
keyword
))
{
String
str
=
"%"
+
keyword
+
"%"
;
String
str
=
"%"
+
keyword
+
"%"
;
criteria
.
andCondition
(
String
.
format
(
"(word
like '%s' or word_alias like '%s')"
,
str
,
str
));
criteria
.
andCondition
(
String
.
format
(
"(word
= '%s' or word_alias like '%s')"
,
keyword
,
str
));
}
}
if
(
valid
(
keywordList
))
{
if
(
valid
(
keywordList
))
{
String
sql
=
""
;
String
sql
=
""
;
...
...
serverside/cihai-core/src/test/java/com/dookay/cihai/core/excel/TestImportWord.java
View file @
43c7acd
...
@@ -20,11 +20,9 @@ import com.dookay.cihai.core.word.domain.WordDomain;
...
@@ -20,11 +20,9 @@ import com.dookay.cihai.core.word.domain.WordDomain;
import
com.dookay.cihai.core.word.dto.WordImportDTO
;
import
com.dookay.cihai.core.word.dto.WordImportDTO
;
import
com.dookay.cihai.core.word.mapper.CustomDictionaryMapper
;
import
com.dookay.cihai.core.word.mapper.CustomDictionaryMapper
;
import
com.dookay.cihai.core.word.mapper.WordMapper
;
import
com.dookay.cihai.core.word.mapper.WordMapper
;
import
com.dookay.cihai.core.word.service.ICustomDictionaryService
;
import
com.dookay.cihai.core.word.service.IWordService
;
import
com.dookay.cihai.core.word.service.IWordService
;
import
com.dookay.coral.common.core.utils.excel.ExcelUtils
;
import
com.dookay.coral.common.core.utils.excel.ExcelUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.test.annotation.Rollback
;
import
org.springframework.test.annotation.Rollback
;
...
@@ -48,16 +46,22 @@ public class TestImportWord extends CihaiCoreApplicationTests {
...
@@ -48,16 +46,22 @@ public class TestImportWord extends CihaiCoreApplicationTests {
@Autowired
@Autowired
private
WordMapper
wordMapper
;
private
WordMapper
wordMapper
;
private
String
[]
files
=
{
"三言二拍系列"
,
"中国的相关词"
,
"二十四节气"
,
"太阳"
,
"太阳系"
,
"春节"
,
"象"
,
"银河系"
,
"马克思"
,
"鲁迅"
};
@Test
@Test
@Rollback
(
false
)
@Rollback
(
false
)
public
void
testImport
()
throws
Exception
{
public
void
testImport
()
throws
Exception
{
// String file = "辞海词语导入模版.xls";
for
(
String
file
:
files
)
{
String
file
=
"鲁迅词条_V1.xls"
;
File
excel
=
ResourceUtils
.
getFile
(
"classpath:excel/"
+
file
+
".xls"
);
File
excel
=
ResourceUtils
.
getFile
(
"classpath:"
+
file
);
try
{
List
<
WordImportDTO
>
list
=
ExcelUtils
.
importExcel
(
excel
,
WordImportDTO
.
class
);
List
<
WordImportDTO
>
list
=
ExcelUtils
.
importExcel
(
excel
,
WordImportDTO
.
class
);
List
<
WordDomain
>
wordDomains
=
list
.
stream
().
map
(
WordImportDTO:
:
toDomain
).
collect
(
Collectors
.
toList
());
List
<
WordDomain
>
wordDomains
=
list
.
stream
().
map
(
WordImportDTO:
:
toDomain
).
collect
(
Collectors
.
toList
());
List
<
CustomDictionaryDomain
>
dictionaryDomains
=
list
.
stream
().
map
(
w
->
new
CustomDictionaryDomain
(
w
.
getWord
())).
collect
(
Collectors
.
toList
());
List
<
CustomDictionaryDomain
>
dictionaryDomains
=
list
.
stream
().
map
(
w
->
new
CustomDictionaryDomain
(
w
.
getWord
())).
collect
(
Collectors
.
toList
());
int
i
=
wordMapper
.
insertList
(
wordDomains
);
int
i
=
wordMapper
.
insertList
(
wordDomains
);
int
j
=
customDictionaryMapper
.
insertList
(
dictionaryDomains
);
int
j
=
customDictionaryMapper
.
insertList
(
dictionaryDomains
);
}
catch
(
Exception
e
)
{
log
.
warn
(
file
+
"没导进去"
,
e
);
}
}
}
}
}
}
serverside/cihai-core/src/test/resources/1.txt
View file @
43c7acd
This diff is collapsed.
Click to expand it.
serverside/cihai-core/src/test/resources/sql/clear.sql
0 → 100644
View file @
43c7acd
delete
from
t_word
where
word
!=
'象'
;
delete
from
t_custom_dictionary
where
word
!=
'象'
;
truncate
table
t_word_relation
;
\ No newline at end of file
\ No newline at end of file
serverside/cihai-pc/src/main/java/com/dookay/cihai/pc/controller/HomeController.java
View file @
43c7acd
...
@@ -20,10 +20,8 @@ import com.dookay.cihai.core.aip.AipImageClassifyClient;
...
@@ -20,10 +20,8 @@ import com.dookay.cihai.core.aip.AipImageClassifyClient;
import
com.dookay.cihai.core.aip.AipWordUtilBean
;
import
com.dookay.cihai.core.aip.AipWordUtilBean
;
import
com.dookay.cihai.core.aip.model.LexerItem
;
import
com.dookay.cihai.core.aip.model.LexerItem
;
import
com.dookay.cihai.core.aip.model.ScanResult
;
import
com.dookay.cihai.core.aip.model.ScanResult
;
import
com.dookay.cihai.core.word.domain.CustomDictionaryDomain
;
import
com.dookay.cihai.core.word.domain.WordDomain
;
import
com.dookay.cihai.core.word.domain.WordDomain
;
import
com.dookay.cihai.core.word.dto.WordDTO
;
import
com.dookay.cihai.core.word.dto.WordDTO
;
import
com.dookay.cihai.core.word.query.CustomDictionaryQuery
;
import
com.dookay.cihai.core.word.query.WordQuery
;
import
com.dookay.cihai.core.word.query.WordQuery
;
import
com.dookay.cihai.core.word.service.ICustomDictionaryService
;
import
com.dookay.cihai.core.word.service.ICustomDictionaryService
;
import
com.dookay.cihai.core.word.service.IWordRelationService
;
import
com.dookay.cihai.core.word.service.IWordRelationService
;
...
@@ -99,19 +97,15 @@ public class HomeController extends BaseController {
...
@@ -99,19 +97,15 @@ public class HomeController extends BaseController {
if
(
StringUtils
.
isBlank
(
keyword
))
{
if
(
StringUtils
.
isBlank
(
keyword
))
{
return
errorResult
(
"搜索内容不能为空"
);
return
errorResult
(
"搜索内容不能为空"
);
}
}
String
result
=
null
;
WordQuery
query
=
new
WordQuery
();
boolean
inDic
=
false
;
query
.
setKeyword
(
keyword
);
List
<
CustomDictionaryDomain
>
dictionaryDomainList
=
customDictionaryService
.
getList
(
new
CustomDictionaryQuery
());
WordDomain
first
=
wordService
.
getFirst
(
query
);
for
(
CustomDictionaryDomain
dic
:
dictionaryDomainList
)
{
if
(
first
!=
null
)
{
if
(
keyword
.
contains
(
dic
.
getWord
()))
{
return
successResult
(
"搜索结果"
,
WordDTO
.
fromDomain
(
first
,
wordRelationService
));
result
=
dic
.
getWord
();
inDic
=
true
;
}
}
}
try
{
try
{
if
(!
inDic
)
{
String
result
=
null
;
result
=
aipWordUtilBean
.
extractQueryKeyword
(
keyword
);
result
=
aipWordUtilBean
.
extractQueryKeyword
(
keyword
);
}
WordQuery
wordQuery
=
new
WordQuery
();
WordQuery
wordQuery
=
new
WordQuery
();
wordQuery
.
setKeyword
(
result
);
wordQuery
.
setKeyword
(
result
);
WordDomain
wordDomain
=
wordService
.
getFirst
(
wordQuery
);
WordDomain
wordDomain
=
wordService
.
getFirst
(
wordQuery
);
...
@@ -166,6 +160,7 @@ public class HomeController extends BaseController {
...
@@ -166,6 +160,7 @@ public class HomeController extends BaseController {
/**
/**
* 历史上的今天
* 历史上的今天
*
* @author houkun
* @author houkun
* @date 2018/1/16
* @date 2018/1/16
*/
*/
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment