fix: 使用SensitiveWordBs替代旧Helper导入
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
package com.test.musichouduan.service.impl;
|
package com.test.musichouduan.service.impl;
|
||||||
|
|
||||||
import com.github.houbb.sensitive.word.core.SensitiveWordHelper;
|
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
|
||||||
import com.test.musichouduan.exception.BusinessException;
|
import com.test.musichouduan.exception.BusinessException;
|
||||||
import com.test.musichouduan.service.SensitiveWordService;
|
import com.test.musichouduan.service.SensitiveWordService;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -13,6 +13,12 @@ import java.util.List;
|
|||||||
@Service
|
@Service
|
||||||
public class SensitiveWordServiceImpl implements SensitiveWordService {
|
public class SensitiveWordServiceImpl implements SensitiveWordService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用 SensitiveWordBs 初始化敏感词引擎。
|
||||||
|
* 说明:当前依赖版本下推荐使用该入口,避免旧版 Helper 类路径变更导致编译失败。
|
||||||
|
*/
|
||||||
|
private static final SensitiveWordBs SENSITIVE_WORD_BS = SensitiveWordBs.newInstance().init();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void validateCommentContent(String content) {
|
public void validateCommentContent(String content) {
|
||||||
if (content == null || content.trim().isEmpty()) {
|
if (content == null || content.trim().isEmpty()) {
|
||||||
@@ -22,8 +28,8 @@ public class SensitiveWordServiceImpl implements SensitiveWordService {
|
|||||||
// 使用 houbb/sensitive-word 默认内置词库进行检测。
|
// 使用 houbb/sensitive-word 默认内置词库进行检测。
|
||||||
// 当前项目保留了 sensitive-words.txt 作为后续扩展词库参考文件,
|
// 当前项目保留了 sensitive-words.txt 作为后续扩展词库参考文件,
|
||||||
// 现阶段未主动加载,避免与默认词库机制产生混淆。
|
// 现阶段未主动加载,避免与默认词库机制产生混淆。
|
||||||
if (SensitiveWordHelper.contains(content)) {
|
if (SENSITIVE_WORD_BS.contains(content)) {
|
||||||
List<String> hitWords = SensitiveWordHelper.findAll(content);
|
List<String> hitWords = SENSITIVE_WORD_BS.findAll(content);
|
||||||
if (!hitWords.isEmpty()) {
|
if (!hitWords.isEmpty()) {
|
||||||
throw new BusinessException("评论包含敏感词,请修改后再发布");
|
throw new BusinessException("评论包含敏感词,请修改后再发布");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user