Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
midjourney-proxy
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
徐少华
midjourney-proxy
Commits
ba431870
Commit
ba431870
authored
Dec 01, 2020
by
李传峰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:[none] 调整小程序搜索bookName匹配方式,先中文简单分词后通配
parent
381032ee
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
175 additions
and
2 deletions
+175
-2
pom.xml
pcloud-service-book/pom.xml
+21
-0
ESBookAndAdviserBizImpl.java
.../com/pcloud/book/es/biz/impl/ESBookAndAdviserBizImpl.java
+6
-2
IKAnalyzerUtil.java
...main/java/com/pcloud/book/es/biz/impl/IKAnalyzerUtil.java
+85
-0
ESBookAndAdviserBizTest.java
...st/java/com.pcloud.book.test/ESBookAndAdviserBizTest.java
+45
-0
IKAnalyzerUtilTest.java
...rc/test/java/com.pcloud.book.test/IKAnalyzerUtilTest.java
+18
-0
No files found.
pcloud-service-book/pom.xml
View file @
ba431870
...
@@ -299,6 +299,27 @@
...
@@ -299,6 +299,27 @@
<version>
1.7.30
</version>
<version>
1.7.30
</version>
</dependency>
</dependency>
<!--中文分词-->
<dependency>
<groupId>
com.jianggujin
</groupId>
<artifactId>
IKAnalyzer-lucene
</artifactId>
<version>
8.0.0
</version>
<exclusions>
<exclusion>
<artifactId>
lucene-analyzers-common
</artifactId>
<groupId>
org.apache.lucene
</groupId>
</exclusion>
<exclusion>
<artifactId>
lucene-core
</artifactId>
<groupId>
org.apache.lucene
</groupId>
</exclusion>
<exclusion>
<artifactId>
lucene-queryparser
</artifactId>
<groupId>
org.apache.lucene
</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
pcloud-service-book/src/main/java/com/pcloud/book/es/biz/impl/ESBookAndAdviserBizImpl.java
View file @
ba431870
...
@@ -208,9 +208,13 @@ public class ESBookAndAdviserBizImpl implements ESBookAndAdviserBiz {
...
@@ -208,9 +208,13 @@ public class ESBookAndAdviserBizImpl implements ESBookAndAdviserBiz {
.
filter
(
QueryBuilders
.
termQuery
(
"isBookDelete"
,
0
))
.
filter
(
QueryBuilders
.
termQuery
(
"isBookDelete"
,
0
))
.
filter
(
Objects
.
isNull
(
templetId
)
?
QueryBuilders
.
boolQuery
()
:
QueryBuilders
.
termQuery
(
"templetId"
,
templetId
))
.
filter
(
Objects
.
isNull
(
templetId
)
?
QueryBuilders
.
boolQuery
()
:
QueryBuilders
.
termQuery
(
"templetId"
,
templetId
))
.
filter
(
Objects
.
isNull
(
secondTempletId
)
?
QueryBuilders
.
boolQuery
()
:
QueryBuilders
.
termQuery
(
"secondTempletId"
,
secondTempletId
));
.
filter
(
Objects
.
isNull
(
secondTempletId
)
?
QueryBuilders
.
boolQuery
()
:
QueryBuilders
.
termQuery
(
"secondTempletId"
,
secondTempletId
));
BoolQueryBuilder
should
=
QueryBuilders
.
boolQuery
()
BoolQueryBuilder
should
=
QueryBuilders
.
boolQuery
()
.
should
(
StringUtil
.
isEmpty
(
keyword
)
?
QueryBuilders
.
boolQuery
()
:
QueryBuilders
.
wildcardQuery
(
"bookName"
,
"*"
+
keyword
+
"*"
))
.
should
(
StringUtil
.
isEmpty
(
keyword
)
?
QueryBuilders
.
boolQuery
()
.
should
(
StringUtil
.
isEmpty
(
keyword
)
?
QueryBuilders
.
boolQuery
()
:
QueryBuilders
.
wildcardQuery
(
"isbn"
,
"*"
+
keyword
+
"*"
));
:
QueryBuilders
.
wildcardQuery
(
"bookName"
,
IKAnalyzerUtil
.
aroundWildcard
(
IKAnalyzerUtil
.
parseWildcardString
(
keyword
))))
.
should
(
StringUtil
.
isEmpty
(
keyword
)
?
QueryBuilders
.
boolQuery
()
:
QueryBuilders
.
wildcardQuery
(
"isbn"
,
IKAnalyzerUtil
.
aroundWildcard
(
keyword
)));
BoolQueryBuilder
should1
=
QueryBuilders
.
boolQuery
()
BoolQueryBuilder
should1
=
QueryBuilders
.
boolQuery
()
.
should
(
QueryBuilders
.
termQuery
(
"isBookAdviserDelete"
,
0
))
.
should
(
QueryBuilders
.
termQuery
(
"isBookAdviserDelete"
,
0
))
.
should
(
QueryBuilders
.
termQuery
(
"isAdviserBook"
,
0
));
.
should
(
QueryBuilders
.
termQuery
(
"isAdviserBook"
,
0
));
...
...
pcloud-service-book/src/main/java/com/pcloud/book/es/biz/impl/IKAnalyzerUtil.java
0 → 100644
View file @
ba431870
package
com
.
pcloud
.
book
.
es
.
biz
.
impl
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.lucene.analysis.TokenStream
;
import
org.apache.lucene.analysis.tokenattributes.CharTermAttribute
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.wltea.analyzer.lucene.IKAnalyzer
;
import
java.io.IOException
;
import
java.io.StringReader
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* 分词工具
*/
public
class
IKAnalyzerUtil
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
IKAnalyzerUtil
.
class
);
/**
* 通配符
*/
public
static
final
char
WILDCARD_CHAR
=
'*'
;
/**
* 前后加通配符
* @param text 内容
* @return
*/
public
static
String
aroundWildcard
(
String
text
)
{
return
WILDCARD_CHAR
+
text
+
WILDCARD_CHAR
;
}
/**
* 解析成分词后通配字符串
* @param text 内容
* @return String,*通配
*/
public
static
String
parseWildcardString
(
String
text
)
{
if
(
StringUtils
.
isBlank
(
text
))
{
return
text
;
}
return
StringUtils
.
join
(
analyzerText
(
text
),
WILDCARD_CHAR
);
}
/**
* 分词
* @param text 内容
* @return List<分词>
*/
public
static
List
<
String
>
analyzerText
(
String
text
)
{
List
<
String
>
result
=
new
ArrayList
<>();
TokenStream
ts
=
null
;
try
(
IKAnalyzer
analyzer
=
new
IKAnalyzer
(
true
))
{
ts
=
analyzer
.
tokenStream
(
"text"
,
new
StringReader
(
text
));
CharTermAttribute
term
=
ts
.
addAttribute
(
CharTermAttribute
.
class
);
ts
.
reset
();
while
(
ts
.
incrementToken
())
{
result
.
add
(
term
.
toString
());
}
ts
.
end
();
}
catch
(
IOException
ioe
)
{
result
.
add
(
text
);
LOGGER
.
warn
(
"analyzer text exception,text={}"
,
text
,
ioe
);
}
finally
{
closeTokenStream
(
text
,
ts
);
}
return
result
;
}
private
static
void
closeTokenStream
(
String
text
,
TokenStream
ts
)
{
if
(
ts
!=
null
)
{
try
{
ts
.
close
();
}
catch
(
IOException
ioe
)
{
LOGGER
.
warn
(
"analyzer text, close stream exception,text={}"
,
text
,
ioe
);
}
}
}
}
pcloud-service-book/src/test/java/com.pcloud.book.test/ESBookAndAdviserBizTest.java
0 → 100644
View file @
ba431870
package
com
.
pcloud
.
book
.
test
;
import
com.alibaba.fastjson.JSON
;
import
com.pcloud.book.BookApplication
;
import
com.pcloud.book.es.biz.ESBookAndAdviserBiz
;
import
com.pcloud.book.es.entity.ESBookAndAdviser
;
import
lombok.extern.slf4j.Slf4j
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.data.domain.Page
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
@Slf4j
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
(
classes
=
{
BookApplication
.
class
,
ESBookAndAdviserBizTest
.
class
})
public
class
ESBookAndAdviserBizTest
{
@Autowired
private
ESBookAndAdviserBiz
esBookAndAdviserBiz
;
@Test
public
void
testes
()
{
Page
<
ESBookAndAdviser
>
p
=
esBookAndAdviserBiz
.
getAdviserBooks4ES
(
null
,
"计算机互联网"
,
null
,
null
,
0
,
50
);
log
.
info
(
"count:{}"
,
p
.
getTotalElements
());
p
.
forEach
((
baa
)
->
log
.
info
(
JSON
.
toJSONString
(
baa
)));
p
=
esBookAndAdviserBiz
.
getAdviserBooks4ES
(
null
,
"测试书籍"
,
null
,
null
,
0
,
50
);
log
.
info
(
"count:{}"
,
p
.
getTotalElements
());
p
.
forEach
((
baa
)
->
log
.
info
(
JSON
.
toJSONString
(
baa
)));
p
=
esBookAndAdviserBiz
.
getAdviserBooks4ES
(
null
,
"学基础训练上册"
,
null
,
null
,
0
,
50
);
log
.
info
(
"count:{}"
,
p
.
getTotalElements
());
p
.
forEach
((
baa
)
->
log
.
info
(
JSON
.
toJSONString
(
baa
)));
}
}
pcloud-service-book/src/test/java/com.pcloud.book.test/IKAnalyzerUtilTest.java
0 → 100644
View file @
ba431870
package
com
.
pcloud
.
book
.
test
;
import
com.pcloud.book.es.biz.impl.IKAnalyzerUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.junit.Test
;
@Slf4j
public
class
IKAnalyzerUtilTest
{
@Test
public
void
test
()
{
log
.
info
(
IKAnalyzerUtil
.
aroundWildcard
(
"学基础训练上册"
));
log
.
info
(
IKAnalyzerUtil
.
aroundWildcard
(
"测试书籍"
));
log
.
info
(
IKAnalyzerUtil
.
aroundWildcard
(
"计算机互联网"
));
}
}
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