diff --git a/backend/src/main/java/com/banben/modules/search/dto/SearchQuery.java b/backend/src/main/java/com/banben/modules/search/dto/SearchQuery.java index 4efd1b0..32eb965 100644 --- a/backend/src/main/java/com/banben/modules/search/dto/SearchQuery.java +++ b/backend/src/main/java/com/banben/modules/search/dto/SearchQuery.java @@ -24,6 +24,9 @@ public class SearchQuery { @Schema(description = "综合关键词(题名/作者/关键词/摘要/出版者 模糊匹配)") private String keyword; + @Schema(description = "去除关键字(结果集排除,空格分隔可多个;含任一排除词的记录不返回)") + private String excludeKeyword; + @Schema(description = "题名") private String title; diff --git a/backend/src/main/java/com/banben/modules/search/service/impl/SearchServiceImpl.java b/backend/src/main/java/com/banben/modules/search/service/impl/SearchServiceImpl.java index 1501c44..ebbfa4d 100644 --- a/backend/src/main/java/com/banben/modules/search/service/impl/SearchServiceImpl.java +++ b/backend/src/main/java/com/banben/modules/search/service/impl/SearchServiceImpl.java @@ -233,6 +233,21 @@ public class SearchServiceImpl implements SearchService { }); } + // 去除关键字:排除含任一排除词的记录(与综合关键词覆盖同样的文本字段) + // 字段为空(IS NULL)不计入排除,避免把缺字段的记录误删 + if (StrUtil.isNotBlank(q.getExcludeKeyword())) { + List 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()); diff --git a/frontend/src/api/search.ts b/frontend/src/api/search.ts index 4b6c554..0aeab21 100644 --- a/frontend/src/api/search.ts +++ b/frontend/src/api/search.ts @@ -14,6 +14,8 @@ export interface ClcNode { /** 检索条件(对应后端 SearchQuery) */ export interface SearchQuery extends ResourceQuery { keyword?: string + /** 去除关键字(结果集排除,空格分隔可多个) */ + excludeKeyword?: string publisher?: string isbn?: string cdoi?: string diff --git a/frontend/src/views/search/SearchView.vue b/frontend/src/views/search/SearchView.vue index 10a01a8..16f59b2 100644 --- a/frontend/src/views/search/SearchView.vue +++ b/frontend/src/views/search/SearchView.vue @@ -135,6 +135,8 @@ async function doSearch() { const kw = input.value.trim() query.title = query.author = query.publisher = query.isbn = query.keyword = '' ;(query as unknown as Record)[fieldParamMap[field.value]] = kw + // 去除关键字:多个排除词以空格拼接提交后端统一排除 + query.excludeKeyword = excludeTerms.value.length ? excludeTerms.value.join(' ') : '' try { const res = await unifiedSearch({ ...query }) rows.value = res.page?.records || [] @@ -163,6 +165,7 @@ async function loadClcTree() { author: query.author, publisher: query.publisher, isbn: query.isbn, + excludeKeyword: query.excludeKeyword, mediaType: query.mediaType, sourceLibrary: query.sourceLibrary, publishYearStart: query.publishYearStart, @@ -189,6 +192,31 @@ function clearCond(key: 'mediaType' | 'languageGroup') { doSearch() } +// ==================== 去除关键字(提交给后端做结果集排除) ==================== +const excludeText = ref('') +const excludeTerms = ref([]) + +/** 点击「去除」:把输入框内容(空格分隔可多个)加入排除词,并去重,随后重新检索 */ +function addExclude() { + const parts = excludeText.value.trim().split(/\s+/).filter(Boolean) + if (!parts.length) return + const set = new Set(excludeTerms.value) + parts.forEach((p) => set.add(p)) + excludeTerms.value = [...set] + excludeText.value = '' + doSearch() +} + +function removeExclude(t: string) { + excludeTerms.value = excludeTerms.value.filter((x) => x !== t) + doSearch() +} + +function clearExclude() { + excludeTerms.value = [] + doSearch() +} + /** 点选中图法节点:部类传其下所有大类号,大类/类目传自身号(前方一致) */ function pickClc(node: ClcNode, codes: string[]) { const same = selectedClc.value === node.code @@ -414,6 +442,33 @@ watch( + + +
+ 去除关键字 + + + +
+ {{ t }} + 清空 +
+
@@ -449,6 +504,22 @@ watch( {{ query.languageGroup === 'chi' ? '中文文献' : '外文文献' }} + 去除:{{ t }} + + 已隐藏 {{ maskedCount }} 条被屏蔽/下架的记录 + + {{ query.mediaType }} + + {{ query.languageGroup === 'chi' ? '中文文献' : '外文文献' }} +