mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 05:12:39 +00:00
Co-authored-by: heheer <heheer@sealos.io>
This commit is contained in:
@@ -38,4 +38,5 @@ weight: 793
|
|||||||
8. 调试知识库检索模块,提示无权操作知识库。
|
8. 调试知识库检索模块,提示无权操作知识库。
|
||||||
9. 文本内容提取节点,默认值赋值逻辑。
|
9. 文本内容提取节点,默认值赋值逻辑。
|
||||||
10. 分享链接中,会强制返回嵌套应用中的引用内容。
|
10. 分享链接中,会强制返回嵌套应用中的引用内容。
|
||||||
|
11. 知识库集合元数据过滤时,不同知识库的同名标签使用 $and 筛选无法获取结果。
|
||||||
|
|
||||||
|
@@ -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)) {
|
||||||
|
datasetTagMap.set(datasetId, {
|
||||||
|
tagIds: [],
|
||||||
|
tagNames: new Set()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
teamId,
|
||||||
datasetId: { $in: datasetIds },
|
datasetId,
|
||||||
tags: { $all: andTagIdList.map((item) => String(item._id)) }
|
tags: { $all: tagIds }
|
||||||
},
|
},
|
||||||
'_id',
|
'_id',
|
||||||
{
|
{ ...readFromSecondary }
|
||||||
...readFromSecondary
|
|
||||||
}
|
|
||||||
).lean();
|
).lean();
|
||||||
tagCollectionIdList = collections.map((item) => String(item._id));
|
});
|
||||||
} else if (andTags.every((tag) => tag === null)) {
|
|
||||||
|
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(
|
|||||||
$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));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user