二次检索
This commit is contained in:
@@ -26,6 +26,12 @@ export interface SearchQuery extends ResourceQuery {
|
||||
sourceLibraries?: string[]
|
||||
/** 来源馆(单选,左侧「来源院校」分面点选用) */
|
||||
sourceLibrary?: string
|
||||
/** 来源资源库名(多选,in) */
|
||||
sourceRepos?: string[]
|
||||
/** 媒体类型(多选,in):纸质/电子 */
|
||||
mediaTypes?: string[]
|
||||
/** 在结果中搜索:附加关键词必须同时命中(AND 收窄) */
|
||||
withinKeyword?: string
|
||||
publishYearStart?: string
|
||||
publishYearEnd?: string
|
||||
matchType?: 'EQ' | 'LEFT' | 'RIGHT' | 'LIKE'
|
||||
@@ -50,6 +56,7 @@ export interface SearchResultVO {
|
||||
page: PageResult<VersionResource>
|
||||
mediaTypeFacets: FacetItem[]
|
||||
sourceLibraryFacets: FacetItem[]
|
||||
sourceRepoFacets?: FacetItem[]
|
||||
clcFacets: FacetItem[]
|
||||
yearStats: YearStat[]
|
||||
costMs: number
|
||||
|
||||
@@ -16,6 +16,7 @@ const total = ref(0)
|
||||
const costMs = ref(0)
|
||||
const mediaFacets = ref<FacetItem[]>([])
|
||||
const libraryFacets = ref<FacetItem[]>([])
|
||||
const repoFacets = ref<FacetItem[]>([])
|
||||
const clcFacets = ref<FacetItem[]>([])
|
||||
/** 命中但被屏蔽/下架而不展示的记录数 */
|
||||
const maskedCount = ref(0)
|
||||
@@ -28,12 +29,28 @@ const selectedClc = ref('')
|
||||
const query = reactive<SearchQuery>({
|
||||
current: 1,
|
||||
size: 50,
|
||||
mediaType: ''
|
||||
mediaType: '',
|
||||
mediaTypes: [] as string[],
|
||||
sourceLibraries: [] as string[],
|
||||
sourceRepos: [] as string[],
|
||||
clcCodes: undefined,
|
||||
withinKeyword: ''
|
||||
})
|
||||
|
||||
/** 概览页每页条数选项(默认 50,可切 100/200;20 便于数据量小时演示翻页) */
|
||||
const pageSizes = [20, 50, 100, 200]
|
||||
|
||||
// ==================== 二次检索(在结果中搜索 / 添加 / 去除) ====================
|
||||
/** 二次检索模式:在结果中搜索(AND 收窄) / 在结果中添加(OR 拓宽) / 在结果中去除(排除) */
|
||||
const secMode = ref<'within' | 'add' | 'remove'>('within')
|
||||
const secInput = ref('')
|
||||
/** 在结果中搜索:必须同时命中的附加关键词 */
|
||||
const withinTerms = ref<string[]>([])
|
||||
/** 在结果中添加:与当前结果集并集的附加关键词(叠加到综合 keyword,OR 生效) */
|
||||
const addedTerms = ref<string[]>([])
|
||||
/** 综合检索词的基础部分(不含 addedTerms),用于「添加」后精确还原 */
|
||||
const baseKeyword = ref('')
|
||||
|
||||
// ==================== 检索结果展示字段(管理员在后台配置) ====================
|
||||
|
||||
/** 展示字段配置:取不到配置时用默认的 8 个字段兜底 */
|
||||
@@ -131,22 +148,50 @@ function snippets(row: VersionResource): { label: string; html: string }[] {
|
||||
return out
|
||||
}
|
||||
|
||||
async function doSearch() {
|
||||
async function doSearch(fresh = false) {
|
||||
loading.value = true
|
||||
searched.value = true
|
||||
// 按所选途径分发检索词;多词用空格分隔,词与词之间为 AND
|
||||
const kw = input.value.trim()
|
||||
query.title = query.author = query.publisher = query.isbn = query.keyword = ''
|
||||
query.clcCode = ''
|
||||
const fp = fieldParamMap[field.value]
|
||||
// 用检索框按中图分类检索时,清掉左侧分类树的点选,避免两套 CLC 条件叠加
|
||||
if (fp === 'clcCode') {
|
||||
if (fresh) {
|
||||
// 重新搜索:清空所有二次检索与分面限定,以输入框内容作为全新检索
|
||||
withinTerms.value = []
|
||||
addedTerms.value = []
|
||||
excludeTerms.value = []
|
||||
query.mediaTypes = []
|
||||
query.sourceLibraries = []
|
||||
query.sourceRepos = []
|
||||
query.clcCodes = undefined
|
||||
query.withinKeyword = ''
|
||||
query.excludeKeyword = ''
|
||||
query.mediaType = ''
|
||||
query.sourceLibrary = ''
|
||||
selectedClc.value = ''
|
||||
// 按所选途径分发检索词
|
||||
const kw = input.value.trim()
|
||||
query.title = query.author = query.publisher = query.isbn = query.keyword = ''
|
||||
query.clcCode = ''
|
||||
const fp = fieldParamMap[field.value]
|
||||
// 用检索框按中图分类检索时,清掉左侧分类树的点选,避免两套 CLC 条件叠加
|
||||
if (fp === 'clcCode') {
|
||||
query.clcCodes = undefined
|
||||
selectedClc.value = ''
|
||||
}
|
||||
;(query as unknown as Record<string, string>)[fp] = kw
|
||||
baseKeyword.value = field.value === '综合' ? kw : ''
|
||||
}
|
||||
// 叠加二次检索词
|
||||
query.withinKeyword = withinTerms.value.join(' ')
|
||||
query.excludeKeyword = excludeTerms.value.join(' ')
|
||||
// 在结果中添加:综合词 = 基础词 ∪ 附加词(OR 拓宽)
|
||||
if (field.value === '综合') {
|
||||
const base = baseKeyword.value ? baseKeyword.value.split(/\s+/).filter(Boolean) : []
|
||||
query.keyword = Array.from(new Set([...base, ...addedTerms.value])).join(' ')
|
||||
} else {
|
||||
const kf = fieldParamMap[field.value] as string
|
||||
const cur = (query as unknown as Record<string, string>)[kf] || ''
|
||||
const base = cur ? cur.split(/\s+/).filter(Boolean) : []
|
||||
;(query as unknown as Record<string, string>)[kf] =
|
||||
Array.from(new Set([...base, ...addedTerms.value])).join(' ')
|
||||
}
|
||||
;(query as unknown as Record<string, string>)[fp] = kw
|
||||
// 去除关键字:多个排除词以空格拼接提交后端统一排除
|
||||
query.excludeKeyword = excludeTerms.value.length ? excludeTerms.value.join(' ') : ''
|
||||
try {
|
||||
const res = await unifiedSearch({ ...query })
|
||||
rows.value = res.page?.records || []
|
||||
@@ -155,6 +200,7 @@ async function doSearch() {
|
||||
maskedCount.value = res.maskedCount || 0
|
||||
mediaFacets.value = res.mediaTypeFacets || []
|
||||
libraryFacets.value = res.sourceLibraryFacets || []
|
||||
repoFacets.value = res.sourceRepoFacets || []
|
||||
clcFacets.value = res.clcFacets || []
|
||||
if (res.sensitiveBlocked) {
|
||||
ElMessage.warning('检索词命中敏感词库,结果已被屏蔽')
|
||||
@@ -166,6 +212,54 @@ async function doSearch() {
|
||||
loadClcTree()
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并到综合检索词:把题名/责任者/出版者/ISBN 等途径词并入综合 keyword,
|
||||
* 避免二次检索时多字段 AND 叠加导致结果被错误收窄。
|
||||
*/
|
||||
function consolidateToKeyword() {
|
||||
const parts: string[] = []
|
||||
if (query.keyword) parts.push(query.keyword)
|
||||
if (query.title) parts.push(query.title)
|
||||
if (query.author) parts.push(query.author)
|
||||
if (query.publisher) parts.push(query.publisher)
|
||||
if (query.isbn) parts.push(query.isbn)
|
||||
baseKeyword.value = parts.filter(Boolean).join(' ')
|
||||
query.keyword = baseKeyword.value
|
||||
query.title = query.author = query.publisher = query.isbn = query.clcCode = ''
|
||||
field.value = '综合'
|
||||
}
|
||||
|
||||
/** 二次检索(在结果中搜索 / 在结果中添加 / 在结果中去除):叠加附加词后重新检索 */
|
||||
function applySecondary() {
|
||||
const parts = secInput.value.trim().split(/\s+/).filter(Boolean)
|
||||
if (!parts.length) return
|
||||
if (secMode.value === 'within') {
|
||||
const set = new Set(withinTerms.value)
|
||||
parts.forEach((p) => set.add(p))
|
||||
withinTerms.value = [...set]
|
||||
} else if (secMode.value === 'add') {
|
||||
consolidateToKeyword()
|
||||
const set = new Set(addedTerms.value)
|
||||
parts.forEach((p) => set.add(p))
|
||||
addedTerms.value = [...set]
|
||||
} else {
|
||||
const set = new Set(excludeTerms.value)
|
||||
parts.forEach((p) => set.add(p))
|
||||
excludeTerms.value = [...set]
|
||||
}
|
||||
secInput.value = ''
|
||||
doSearch()
|
||||
}
|
||||
|
||||
/** 清除全部二次检索(在结果中搜索 / 添加 / 去除) */
|
||||
function clearSecondary() {
|
||||
withinTerms.value = []
|
||||
addedTerms.value = []
|
||||
excludeTerms.value = []
|
||||
secInput.value = ''
|
||||
doSearch()
|
||||
}
|
||||
|
||||
/** 拉取中图法分类树:带上当前检索条件,数量与结果一致 */
|
||||
async function loadClcTree() {
|
||||
try {
|
||||
@@ -176,8 +270,13 @@ async function loadClcTree() {
|
||||
publisher: query.publisher,
|
||||
isbn: query.isbn,
|
||||
excludeKeyword: query.excludeKeyword,
|
||||
withinKeyword: query.withinKeyword,
|
||||
mediaType: query.mediaType,
|
||||
mediaTypes: query.mediaTypes,
|
||||
sourceLibrary: query.sourceLibrary,
|
||||
sourceLibraries: query.sourceLibraries,
|
||||
sourceRepos: query.sourceRepos,
|
||||
clcCodes: query.clcCodes,
|
||||
publishYearStart: query.publishYearStart,
|
||||
publishYearEnd: query.publishYearEnd,
|
||||
matchType: query.matchType
|
||||
@@ -197,7 +296,12 @@ function clearClc() {
|
||||
|
||||
/** 清除前置筛选条件(媒体类型 / 语种分组) */
|
||||
function clearCond(key: 'mediaType' | 'languageGroup') {
|
||||
query[key] = undefined
|
||||
if (key === 'languageGroup') {
|
||||
query.languageGroup = undefined
|
||||
} else {
|
||||
query.mediaTypes = []
|
||||
query.mediaType = ''
|
||||
}
|
||||
query.current = 1
|
||||
doSearch()
|
||||
}
|
||||
@@ -221,6 +325,14 @@ function removeExclude(t: string) {
|
||||
excludeTerms.value = excludeTerms.value.filter((x) => x !== t)
|
||||
doSearch()
|
||||
}
|
||||
function removeWithin(t: string) {
|
||||
withinTerms.value = withinTerms.value.filter((x) => x !== t)
|
||||
doSearch()
|
||||
}
|
||||
function removeAdded(t: string) {
|
||||
addedTerms.value = addedTerms.value.filter((x) => x !== t)
|
||||
doSearch()
|
||||
}
|
||||
|
||||
function clearExclude() {
|
||||
excludeTerms.value = []
|
||||
@@ -237,13 +349,22 @@ function pickClc(node: ClcNode, codes: string[]) {
|
||||
doSearch()
|
||||
}
|
||||
|
||||
/** 点选左侧分面:再点一次已选中的项即取消筛选 */
|
||||
function pick(type: 'mediaType' | 'sourceLibrary' | 'clcCode', v: string) {
|
||||
query[type] = query[type] === v ? '' : v
|
||||
/** 点选左侧分面(资源类型 / 来源院校 / 资源库名):多选组合,再次点击取消 */
|
||||
function toggleFacet(type: 'mediaType' | 'sourceLibrary' | 'sourceRepo', v: string) {
|
||||
const arr =
|
||||
type === 'mediaType' ? query.mediaTypes! : type === 'sourceLibrary' ? query.sourceLibraries! : query.sourceRepos!
|
||||
const i = arr.indexOf(v)
|
||||
if (i >= 0) arr.splice(i, 1)
|
||||
else arr.push(v)
|
||||
query.current = 1
|
||||
doSearch()
|
||||
}
|
||||
|
||||
/** 条件标签:单独移除某个已选分面 */
|
||||
function removeFacet(type: 'mediaType' | 'sourceLibrary' | 'sourceRepo', v: string) {
|
||||
toggleFacet(type, v)
|
||||
}
|
||||
|
||||
function goPage(p: number) {
|
||||
query.current = p
|
||||
doSearch()
|
||||
@@ -456,7 +577,7 @@ onMounted(() => {
|
||||
// 主页「前置筛选」勾选带来的条件:媒体类型 + 语种分组
|
||||
const mt = route.query.mediaType as string
|
||||
if (mt === '纸质' || mt === '电子') {
|
||||
query.mediaType = mt
|
||||
query.mediaTypes = [mt]
|
||||
}
|
||||
const lg = route.query.languageGroup as string
|
||||
if (lg === 'chi' || lg === 'foreign') {
|
||||
@@ -465,7 +586,7 @@ onMounted(() => {
|
||||
// 检索条件为空时也执行检索 → 后端返回全部版本资源
|
||||
input.value = kw || ''
|
||||
fetchListFields()
|
||||
doSearch()
|
||||
doSearch(true)
|
||||
})
|
||||
|
||||
// 已在检索页时,主页/热词再次带词跳转也能触发新检索
|
||||
@@ -474,7 +595,7 @@ watch(
|
||||
(kw) => {
|
||||
if (route.path !== '/search') return
|
||||
input.value = (kw as string) || ''
|
||||
doSearch()
|
||||
doSearch(true)
|
||||
}
|
||||
)
|
||||
</script>
|
||||
@@ -484,38 +605,38 @@ watch(
|
||||
<div class="bar">
|
||||
<el-input v-model="input" size="large" placeholder="请输入检索词,支持多词检索(空格分隔,命中任一词即返回)" clearable @keyup.enter="doSearch">
|
||||
<template #prepend>
|
||||
<el-select v-model="field" style="width: 96px" @change="searched && doSearch()">
|
||||
<el-select v-model="field" style="width: 96px" @change="doSearch(true)">
|
||||
<el-option v-for="f in fields" :key="f" :label="f" :value="f" />
|
||||
</el-select>
|
||||
</template>
|
||||
<template #append><el-button type="primary" @click="doSearch">检索</el-button></template>
|
||||
<template #append><el-button type="primary" @click="doSearch(true)">检索</el-button></template>
|
||||
</el-input>
|
||||
|
||||
<!-- 去除关键字:在结果集中排除含指定词的记录 -->
|
||||
<!-- 二次检索:在结果中搜索 / 在结果中添加 / 在结果中去除 -->
|
||||
<div class="exclude-bar">
|
||||
<span class="exclude-label">去除关键字</span>
|
||||
<span class="exclude-label">二次检索</span>
|
||||
<el-radio-group v-model="secMode" size="small">
|
||||
<el-radio-button value="within">在结果中搜索</el-radio-button>
|
||||
<el-radio-button value="add">在结果中添加</el-radio-button>
|
||||
<el-radio-button value="remove">在结果中去除</el-radio-button>
|
||||
</el-radio-group>
|
||||
<el-input
|
||||
v-model="excludeText"
|
||||
v-model="secInput"
|
||||
class="exclude-input"
|
||||
size="default"
|
||||
clearable
|
||||
placeholder="输入要排除的词,空格分隔可多个,如 999"
|
||||
@keyup.enter="addExclude"
|
||||
:placeholder="secMode === 'remove' ? '输入要排除的词,空格分隔可多个' : '输入检索词,空格分隔可多个'"
|
||||
@keyup.enter="applySecondary"
|
||||
>
|
||||
<template #append><el-button @click="addExclude">去除</el-button></template>
|
||||
<template #append><el-button @click="applySecondary">检索</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>
|
||||
<el-button
|
||||
v-if="withinTerms.length || addedTerms.length || excludeTerms.length"
|
||||
link
|
||||
type="primary"
|
||||
size="small"
|
||||
@click="clearSecondary"
|
||||
>清除二次检索</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -523,12 +644,17 @@ watch(
|
||||
<aside class="side">
|
||||
<div class="side-title">资源类型</div>
|
||||
<div v-for="f in mediaFacets" :key="f.name" class="side-item"
|
||||
:class="{ on: query.mediaType === f.name }" @click="pick('mediaType', f.name)">
|
||||
:class="{ on: query.mediaTypes?.includes(f.name) }" @click="toggleFacet('mediaType', f.name)">
|
||||
<span>{{ f.name }}</span><em>{{ f.value }}</em>
|
||||
</div>
|
||||
<div class="side-title">来源院校</div>
|
||||
<div v-for="f in libraryFacets" :key="f.name" class="side-item"
|
||||
:class="{ on: query.sourceLibrary === f.name }" @click="pick('sourceLibrary', f.name)">
|
||||
:class="{ on: query.sourceLibraries?.includes(f.name) }" @click="toggleFacet('sourceLibrary', f.name)">
|
||||
<span>{{ f.name }}</span><em>{{ f.value }}</em>
|
||||
</div>
|
||||
<div class="side-title">资源库名</div>
|
||||
<div v-for="f in repoFacets" :key="f.name" class="side-item"
|
||||
:class="{ on: query.sourceRepos?.includes(f.name) }" @click="toggleFacet('sourceRepo', f.name)">
|
||||
<span>{{ f.name }}</span><em>{{ f.value }}</em>
|
||||
</div>
|
||||
<div class="side-title">
|
||||
@@ -548,26 +674,36 @@ watch(
|
||||
<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>
|
||||
<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' ? '中文文献' : '外文文献' }}
|
||||
v-for="t in query.mediaTypes" :key="'mt' + t"
|
||||
class="cond-tag" size="small" closable @close="removeFacet('mediaType', t)"
|
||||
>资源类型:{{ t }}</el-tag>
|
||||
<el-tag
|
||||
v-for="t in query.sourceLibraries" :key="'sl' + t"
|
||||
class="cond-tag" size="small" closable @close="removeFacet('sourceLibrary', t)"
|
||||
>来源院校:{{ t }}</el-tag>
|
||||
<el-tag
|
||||
v-for="t in query.sourceRepos" :key="'sr' + t"
|
||||
class="cond-tag" size="small" closable @close="removeFacet('sourceRepo', t)"
|
||||
>资源库名:{{ t }}</el-tag>
|
||||
<el-tag v-if="query.clcCodes && query.clcCodes.length" class="cond-tag" size="small" closable @close="clearClc">
|
||||
中图分类:{{ query.clcCodes.join(' / ') }}
|
||||
</el-tag>
|
||||
<el-tag
|
||||
v-for="t in withinTerms" :key="'w' + t"
|
||||
class="cond-tag" size="small" type="success" closable @close="removeWithin(t)"
|
||||
>在结果中搜索:{{ t }}</el-tag>
|
||||
<el-tag
|
||||
v-for="t in addedTerms" :key="'a' + t"
|
||||
class="cond-tag" size="small" type="success" closable @close="removeAdded(t)"
|
||||
>在结果中添加:{{ t }}</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>
|
||||
</div>
|
||||
<div class="ops">
|
||||
<el-checkbox
|
||||
|
||||
Reference in New Issue
Block a user