搜索去除关键字
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());
|
||||
|
||||
@@ -14,6 +14,8 @@ export interface ClcNode {
|
||||
/** 检索条件(对应后端 SearchQuery) */
|
||||
export interface SearchQuery extends ResourceQuery {
|
||||
keyword?: string
|
||||
/** 去除关键字(结果集排除,空格分隔可多个) */
|
||||
excludeKeyword?: string
|
||||
publisher?: string
|
||||
isbn?: string
|
||||
cdoi?: string
|
||||
|
||||
@@ -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<string, string>)[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<string[]>([])
|
||||
|
||||
/** 点击「去除」:把输入框内容(空格分隔可多个)加入排除词,并去重,随后重新检索 */
|
||||
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(
|
||||
</template>
|
||||
<template #append><el-button type="primary" @click="doSearch">检索</el-button></template>
|
||||
</el-input>
|
||||
|
||||
<!-- 去除关键字:在结果集中排除含指定词的记录 -->
|
||||
<div class="exclude-bar">
|
||||
<span class="exclude-label">去除关键字</span>
|
||||
<el-input
|
||||
v-model="excludeText"
|
||||
class="exclude-input"
|
||||
size="default"
|
||||
clearable
|
||||
placeholder="输入要排除的词,空格分隔可多个,如 999"
|
||||
@keyup.enter="addExclude"
|
||||
>
|
||||
<template #append><el-button @click="addExclude">去除</el-button></template>
|
||||
</el-input>
|
||||
<div v-if="excludeTerms.length" class="exclude-tags">
|
||||
<el-tag
|
||||
v-for="t in excludeTerms"
|
||||
:key="t"
|
||||
size="small"
|
||||
type="info"
|
||||
effect="plain"
|
||||
closable
|
||||
@close="removeExclude(t)"
|
||||
>{{ t }}</el-tag>
|
||||
<el-button link type="primary" size="small" @click="clearExclude">清空</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="body" v-if="searched">
|
||||
@@ -449,6 +504,22 @@ watch(
|
||||
<el-tag v-if="query.languageGroup" class="cond-tag" size="small" closable @close="clearCond('languageGroup')">
|
||||
{{ query.languageGroup === 'chi' ? '中文文献' : '外文文献' }}
|
||||
</el-tag>
|
||||
<el-tag
|
||||
v-for="t in excludeTerms"
|
||||
:key="'ex' + t"
|
||||
class="cond-tag"
|
||||
size="small"
|
||||
type="info"
|
||||
closable
|
||||
@close="removeExclude(t)"
|
||||
>去除:{{ t }}</el-tag>
|
||||
<el-tag v-if="maskedCount" type="warning" effect="plain" size="small" class="cond-tag">
|
||||
已隐藏 {{ maskedCount }} 条被屏蔽/下架的记录
|
||||
</el-tag>
|
||||
<el-tag v-if="query.mediaType" class="cond-tag" size="small" closable @close="clearCond('mediaType')">{{ query.mediaType }}</el-tag>
|
||||
<el-tag v-if="query.languageGroup" class="cond-tag" size="small" closable @close="clearCond('languageGroup')">
|
||||
{{ query.languageGroup === 'chi' ? '中文文献' : '外文文献' }}
|
||||
</el-tag>
|
||||
</div>
|
||||
<div class="ops">
|
||||
<el-checkbox
|
||||
@@ -590,6 +661,36 @@ watch(
|
||||
}
|
||||
}
|
||||
|
||||
/* 去除关键字:检索栏下方的结果集排除过滤区 */
|
||||
.exclude-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
margin-top: 12px;
|
||||
|
||||
.exclude-label {
|
||||
flex: none;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: #5b6472;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.exclude-input {
|
||||
flex: 1;
|
||||
min-width: 240px;
|
||||
max-width: 420px;
|
||||
}
|
||||
|
||||
.exclude-tags {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
||||
|
||||
.body {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
|
||||
Reference in New Issue
Block a user