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
...
@@ -38,4 +38,5 @@ weight: 793
8.
调试知识库检索模块,提示无权操作知识库。
8.
调试知识库检索模块,提示无权操作知识库。
9.
文本内容提取节点,默认值赋值逻辑。
9.
文本内容提取节点,默认值赋值逻辑。
10.
分享链接中,会强制返回嵌套应用中的引用内容。
10.
分享链接中,会强制返回嵌套应用中的引用内容。
11.
知识库集合元数据过滤时,不同知识库的同名标签使用 $and 筛选无法获取结果。
packages/service/core/dataset/search/controller.ts
View file @
6763ac60
...
@@ -291,50 +291,64 @@ export async function searchDatasetData(
...
@@ -291,50 +291,64 @@ export async function searchDatasetData(
?
collectionFilterMatch
?
collectionFilterMatch
:
json5
.
parse
(
collectionFilterMatch
);
:
json5
.
parse
(
collectionFilterMatch
);
// Tag
const
andTags
=
jsonMatch
?.
tags
?.
$and
as
(
string
|
null
)[]
|
undefined
;
let
andTags
=
jsonMatch
?.
tags
?.
$and
as
(
string
|
null
)[]
|
undefined
;
const
orTags
=
jsonMatch
?.
tags
?.
$or
as
(
string
|
null
)[]
|
undefined
;
let
orTags
=
jsonMatch
?.
tags
?.
$or
as
(
string
|
null
)[]
|
undefined
;
// get andTagIds
if
(
andTags
&&
andTags
.
length
>
0
)
{
if
(
andTags
&&
andTags
.
length
>
0
)
{
// tag 去重
const
uniqueAndTags
=
Array
.
from
(
new
Set
(
andTags
));
andTags
=
Array
.
from
(
new
Set
(
andTags
));
if
(
uniqueAndTags
.
includes
(
null
)
&&
uniqueAndTags
.
some
((
tag
)
=>
typeof
tag
===
'string'
))
{
if
(
andTags
.
includes
(
null
)
&&
andTags
.
some
((
tag
)
=>
typeof
tag
===
'string'
))
{
return
[];
return
[];
}
}
if
(
uniqueAndTags
.
every
((
tag
)
=>
typeof
tag
===
'string'
))
{
if
(
andTags
.
every
((
tag
)
=>
typeof
tag
===
'string'
))
{
const
matchedTags
=
await
MongoDatasetCollectionTags
.
find
(
// Get tagId by tag string
const
andTagIdList
=
await
MongoDatasetCollectionTags
.
find
(
{
{
teamId
,
teamId
,
datasetId
:
{
$in
:
datasetIds
},
datasetId
:
{
$in
:
datasetIds
},
tag
:
{
$in
:
andTags
}
tag
:
{
$in
:
uniqueAndTags
as
string
[]
}
},
},
'_id'
,
'_id datasetId tag'
,
{
{
...
readFromSecondary
}
...
readFromSecondary
}
).
lean
();
).
lean
();
//
If you enter a tag that does not exist, none will be found
//
Group tags by dataset
if
(
andTagIdList
.
length
!==
andTags
.
length
)
return
[]
;
const
datasetTagMap
=
new
Map
<
string
,
{
tagIds
:
string
[];
tagNames
:
Set
<
string
>
}
>
()
;
// Get collectionId by tagId
matchedTags
.
forEach
((
tag
)
=>
{
const
collections
=
await
MongoDatasetCollection
.
find
(
const
datasetId
=
String
(
tag
.
datasetId
);
{
if
(
!
datasetTagMap
.
has
(
datasetId
))
{
teamId
,
datasetTagMap
.
set
(
datasetId
,
{
datasetId
:
{
$in
:
datasetIds
},
tagIds
:
[],
tags
:
{
$all
:
andTagIdList
.
map
((
item
)
=>
String
(
item
.
_id
))
}
tagNames
:
new
Set
()
},
});
'_id'
,
{
...
readFromSecondary
}
}
).
lean
();
tagCollectionIdList
=
collections
.
map
((
item
)
=>
String
(
item
.
_id
));
const
datasetData
=
datasetTagMap
.
get
(
datasetId
)
!
;
}
else
if
(
andTags
.
every
((
tag
)
=>
tag
===
null
))
{
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
(
const
collections
=
await
MongoDatasetCollection
.
find
(
{
{
teamId
,
teamId
,
...
@@ -342,9 +356,7 @@ export async function searchDatasetData(
...
@@ -342,9 +356,7 @@ export async function searchDatasetData(
$or
:
[{
tags
:
{
$size
:
0
}
},
{
tags
:
{
$exists
:
false
}
}]
$or
:
[{
tags
:
{
$size
:
0
}
},
{
tags
:
{
$exists
:
false
}
}]
},
},
'_id'
,
'_id'
,
{
{
...
readFromSecondary
}
...
readFromSecondary
}
).
lean
();
).
lean
();
tagCollectionIdList
=
collections
.
map
((
item
)
=>
String
(
item
.
_id
));
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