搜索去除关键字
This commit is contained in:
@@ -24,6 +24,9 @@ public class SearchQuery {
|
||||
@Schema(description = "综合关键词(题名/作者/关键词/摘要/出版者 模糊匹配)")
|
||||
private String keyword;
|
||||
|
||||
@Schema(description = "去除关键字(结果集排除,空格分隔可多个;含任一排除词的记录不返回)")
|
||||
private String excludeKeyword;
|
||||
|
||||
@Schema(description = "题名")
|
||||
private String title;
|
||||
|
||||
|
||||
@@ -233,6 +233,21 @@ public class SearchServiceImpl implements SearchService {
|
||||
});
|
||||
}
|
||||
|
||||
// 去除关键字:排除含任一排除词的记录(与综合关键词覆盖同样的文本字段)
|
||||
// 字段为空(IS NULL)不计入排除,避免把缺字段的记录误删
|
||||
if (StrUtil.isNotBlank(q.getExcludeKeyword())) {
|
||||
List<String> exTerms = splitTerms(q.getExcludeKeyword());
|
||||
for (String ex : exTerms) {
|
||||
w.and(x -> x
|
||||
.and(y -> y.notLike("title", ex).or().isNull("title"))
|
||||
.and(y -> y.notLike("author", ex).or().isNull("author"))
|
||||
.and(y -> y.notLike("keywords", ex).or().isNull("keywords"))
|
||||
.and(y -> y.notLike("summary", ex).or().isNull("summary"))
|
||||
.and(y -> y.notLike("publisher", ex).or().isNull("publisher"))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
applyMatch(w, "title", q.getTitle(), q.getMatchType());
|
||||
applyMatch(w, "author", q.getAuthor(), q.getMatchType());
|
||||
applyMatch(w, "publisher", q.getPublisher(), q.getMatchType());
|
||||
|
||||
Reference in New Issue
Block a user