Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
6763ac60
authored
Apr 27, 2025
by
Archer
Committed by
GitHub
Apr 27, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix same tag in different datasets (#4673) (#4680)
Co-authored-by: heheer <heheer@sealos.io>
parent
f0a25ff9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
35 deletions
+48
-35
docSite/content/zh-cn/docs/development/upgrading/497.md
+1
-0
packages/service/core/dataset/search/controller.ts
+47
-35
No files found.
docSite/content/zh-cn/docs/development/upgrading/497.md
View file @
6763ac60
...
...
@@ -38,4 +38,5 @@ weight: 793
8.
调试知识库检索模块,提示无权操作知识库。
9.
文本内容提取节点,默认值赋值逻辑。
10.
分享链接中,会强制返回嵌套应用中的引用内容。
11.
知识库集合元数据过滤时,不同知识库的同名标签使用 $and 筛选无法获取结果。
packages/service/core/dataset/search/controller.ts
View file @
6763ac60
...
...
@@ -291,50 +291,64 @@ export async function searchDatasetData(
?
collectionFilterMatch
:
json5
.
parse
(
collectionFilterMatch
);
// Tag
let
andTags
=
jsonMatch
?.
tags
?.
$and
as
(
string
|
null
)[]
|
undefined
;
let
orTags
=
jsonMatch
?.
tags
?.
$or
as
(
string
|
null
)[]
|
undefined
;
const
andTags
=
jsonMatch
?.
tags
?.
$and
as
(
string
|
null
)[]
|
undefined
;
const
orTags
=
jsonMatch
?.
tags
?.
$or
as
(
string
|
null
)[]
|
undefined
;
// get andTagIds
if
(
andTags
&&
andTags
.
length
>
0
)
{
// tag 去重
andTags
=
Array
.
from
(
new
Set
(
andTags
));
if
(
andTags
.
includes
(
null
)
&&
andTags
.
some
((
tag
)
=>
typeof
tag
===
'string'
))
{
const
uniqueAndTags
=
Array
.
from
(
new
Set
(
andTags
));
if
(
uniqueAndTags
.
includes
(
null
)
&&
uniqueAndTags
.
some
((
tag
)
=>
typeof
tag
===
'string'
))
{
return
[];
}
if
(
andTags
.
every
((
tag
)
=>
typeof
tag
===
'string'
))
{
// Get tagId by tag string
const
andTagIdList
=
await
MongoDatasetCollectionTags
.
find
(
if
(
uniqueAndTags
.
every
((
tag
)
=>
typeof
tag
===
'string'
))
{
const
matchedTags
=
await
MongoDatasetCollectionTags
.
find
(
{
teamId
,
datasetId
:
{
$in
:
datasetIds
},
tag
:
{
$in
:
andTags
}
tag
:
{
$in
:
uniqueAndTags
as
string
[]
}
},
'_id'
,
{
...
readFromSecondary
}
'_id datasetId tag'
,
{
...
readFromSecondary
}
).
lean
();
//
If you enter a tag that does not exist, none will be found
if
(
andTagIdList
.
length
!==
andTags
.
length
)
return
[]
;
//
Group tags by dataset
const
datasetTagMap
=
new
Map
<
string
,
{
tagIds
:
string
[];
tagNames
:
Set
<
string
>
}
>
()
;
// Get collectionId by tagId
const
collections
=
await
MongoDatasetCollection
.
find
(
{
teamId
,
datasetId
:
{
$in
:
datasetIds
},
tags
:
{
$all
:
andTagIdList
.
map
((
item
)
=>
String
(
item
.
_id
))
}
},
'_id'
,
{
...
readFromSecondary
matchedTags
.
forEach
((
tag
)
=>
{
const
datasetId
=
String
(
tag
.
datasetId
);
if
(
!
datasetTagMap
.
has
(
datasetId
))
{
datasetTagMap
.
set
(
datasetId
,
{
tagIds
:
[],
tagNames
:
new
Set
()
});
}
).
lean
();
tagCollectionIdList
=
collections
.
map
((
item
)
=>
String
(
item
.
_id
));
}
else
if
(
andTags
.
every
((
tag
)
=>
tag
===
null
))
{
const
datasetData
=
datasetTagMap
.
get
(
datasetId
)
!
;
datasetData
.
tagIds
.
push
(
String
(
tag
.
_id
));
datasetData
.
tagNames
.
add
(
tag
.
tag
);
});
const
validDatasetIds
=
Array
.
from
(
datasetTagMap
.
entries
())
.
filter
(([
_
,
data
])
=>
uniqueAndTags
.
every
((
tag
)
=>
data
.
tagNames
.
has
(
tag
as
string
)))
.
map
(([
datasetId
])
=>
datasetId
);
if
(
validDatasetIds
.
length
===
0
)
return
[];
const
collectionsPromises
=
validDatasetIds
.
map
((
datasetId
)
=>
{
const
{
tagIds
}
=
datasetTagMap
.
get
(
datasetId
)
!
;
return
MongoDatasetCollection
.
find
(
{
teamId
,
datasetId
,
tags
:
{
$all
:
tagIds
}
},
'_id'
,
{
...
readFromSecondary
}
).
lean
();
});
const
collectionsResults
=
await
Promise
.
all
(
collectionsPromises
);
tagCollectionIdList
=
collectionsResults
.
flat
().
map
((
item
)
=>
String
(
item
.
_id
));
}
else
if
(
uniqueAndTags
.
every
((
tag
)
=>
tag
===
null
))
{
const
collections
=
await
MongoDatasetCollection
.
find
(
{
teamId
,
...
...
@@ -342,9 +356,7 @@ export async function searchDatasetData(
$or
:
[{
tags
:
{
$size
:
0
}
},
{
tags
:
{
$exists
:
false
}
}]
},
'_id'
,
{
...
readFromSecondary
}
{
...
readFromSecondary
}
).
lean
();
tagCollectionIdList
=
collections
.
map
((
item
)
=>
String
(
item
.
_id
));
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment