Skip to content

Commit c31142e

Browse files
committed
feat: add tag filtering and input support in document search functionality
1 parent 349402b commit c31142e

File tree

6 files changed

+52
-10
lines changed

6 files changed

+52
-10
lines changed

apps/knowledge/serializers/document.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ class Query(serializers.Serializer):
389389
task_type = serializers.IntegerField(required=False, label=_('task type'))
390390
status = serializers.CharField(required=False, label=_('status'), allow_null=True, allow_blank=True)
391391
order_by = serializers.CharField(required=False, label=_('order by'), allow_null=True, allow_blank=True)
392+
tag = serializers.CharField(required=False, label=_('tag'), allow_null=True, allow_blank=True)
392393

393394
def get_query_set(self):
394395
query_set = QuerySet(model=Document)
@@ -414,6 +415,12 @@ def get_query_set(self):
414415
query_set = query_set.filter(status__icontains=status)
415416
else:
416417
query_set = query_set.filter(status__iregex='^[2n]*$')
418+
if 'tag' in self.data and self.data.get('tag') not in [None, '']:
419+
tag_name = self.data.get('tag')
420+
document_id_list = QuerySet(DocumentTag).filter(
421+
Q(tag__key__icontains=tag_name) | Q(tag__value__icontains=tag_name)
422+
).values_list('document_id', flat=True)
423+
query_set = query_set.filter(id__in=document_id_list)
417424
order_by = self.data.get('order_by', '')
418425
order_by_query_set = QuerySet(model=get_dynamics_model(
419426
{'char_length': models.CharField(), 'paragraph_count': models.IntegerField(),

apps/knowledge/views/document.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ def get(self, request: Request, workspace_id: str, knowledge_id: str, current_pa
597597
'knowledge_id': knowledge_id,
598598
'folder_id': request.query_params.get('folder_id'),
599599
'name': request.query_params.get('name'),
600+
'tag': request.query_params.get('tag'),
600601
'desc': request.query_params.get("desc"),
601602
'user_id': request.query_params.get('user_id'),
602603
'status': request.query_params.get('status'),

ui/src/locales/lang/en-US/views/document.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export default {
114114
'After deletion, resources using this tag will have the tag removed. Please proceed with caution!',
115115
requiredMessage1: 'Please enter a tag',
116116
requiredMessage2: 'Please enter a value',
117+
requiredMessage3: 'Please enter a tag or value',
117118
},
118119
table: {
119120
name: 'Document Name',

ui/src/locales/lang/zh-CN/views/document.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export default {
109109
deleteTip: '删除后使用该标签的资源将会删除该标签,请谨慎操作!',
110110
requiredMessage1: '请输入标签',
111111
requiredMessage2: '请输入标签值',
112+
requiredMessage3: '请输入标签或标签值',
112113
},
113114
table: {
114115
name: '文件名称',

ui/src/locales/lang/zh-Hant/views/document.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export default {
111111
deleteTip: '刪除後使用該標籤的資源將會刪除該標籤,請謹慎操作!',
112112
requiredMessage1: '請輸入標籤',
113113
requiredMessage2: '請輸入標籤值',
114+
requiredMessage3: '請輸入標籤或標籤值',
114115
},
115116
table: {
116117
name: '文件名稱',

ui/src/views/document/index.vue

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,34 @@
104104
</el-dropdown>
105105
</template>
106106
</div>
107-
<div>
108-
<el-input
109-
v-model="filterText"
110-
:placeholder="$t('common.searchBar.placeholder')"
111-
prefix-icon="Search"
112-
class="w-240"
113-
@change="getList"
114-
clearable
115-
/>
107+
<div class="flex">
108+
<div class="flex-between complex-search">
109+
<el-select
110+
class="complex-search__left"
111+
v-model="search_type"
112+
style="width: 120px"
113+
@change="search_type_change"
114+
>
115+
<el-option :label="$t('dynamicsForm.tag.label')" value="tag" />
116+
<el-option :label="$t('views.tool.form.toolName.label')" value="name" />
117+
</el-select>
118+
<el-input
119+
v-if="search_type === 'name'"
120+
v-model="search_form.name"
121+
@change="refresh"
122+
:placeholder="$t('common.searchBar.placeholder')"
123+
style="width: 220px"
124+
clearable
125+
/>
126+
<el-input
127+
v-if="search_type === 'tag'"
128+
v-model="search_form.tag"
129+
@change="refresh"
130+
:placeholder="$t('views.document.tag.requiredMessage3')"
131+
style="width: 220px"
132+
clearable
133+
/>
134+
</div>
116135
<el-button @click="openTagDrawer" class="ml-12">
117136
{{ $t('views.document.tag.label') }}
118137
</el-button>
@@ -781,6 +800,12 @@ const getTaskState = (status: string, taskType: number) => {
781800
return taskType - 1 > statusList.length + 1 ? 'n' : statusList[taskType - 1]
782801
}
783802
803+
const search_type = ref('name')
804+
const search_form = ref<any>({
805+
name: '',
806+
tag: '',
807+
})
808+
784809
const beforePagination = computed(() => common.paginationConfig[storeKey])
785810
const beforeSearch = computed(() => common.search[storeKey])
786811
const embeddingContentDialogRef = ref<InstanceType<typeof EmbeddingContentDialog>>()
@@ -1184,11 +1209,13 @@ function handleSortChange({ prop, order }: { prop: string; order: string }) {
11841209
11851210
function getList(bool?: boolean) {
11861211
const param = {
1187-
...(filterText.value && { name: filterText.value }),
11881212
...filterMethod.value,
11891213
order_by: orderBy.value,
11901214
folder_id: folderId,
11911215
}
1216+
if (search_form.value[search_type.value]) {
1217+
param[search_type.value] = search_form.value[search_type.value]
1218+
}
11921219
loadSharedApi({ type: 'document', isShared: isShared.value, systemType: apiType.value })
11931220
.getDocumentPage(id as string, paginationConfig.value, param, bool ? undefined : loading)
11941221
.then((res: any) => {
@@ -1197,6 +1224,10 @@ function getList(bool?: boolean) {
11971224
})
11981225
}
11991226
1227+
const search_type_change = () => {
1228+
search_form.value = { name: '', tag: '' }
1229+
}
1230+
12001231
function getDetail() {
12011232
loadSharedApi({ type: 'knowledge', isShared: isShared.value, systemType: apiType.value })
12021233
.getKnowledgeDetail(id, loading)

0 commit comments

Comments
 (0)