mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 21:13:50 +00:00
fix collection folder tags filter (#3853)
* fix collection folder tags filter * add comment * fix
This commit is contained in:
@@ -200,6 +200,62 @@ export async function searchDatasetData(
|
|||||||
forbidCollectionIdList: collections.map((item) => String(item._id))
|
forbidCollectionIdList: collections.map((item) => String(item._id))
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function getAllCollectionIds({
|
||||||
|
teamId,
|
||||||
|
datasetIds,
|
||||||
|
parentCollectionIds
|
||||||
|
}: {
|
||||||
|
teamId: string;
|
||||||
|
datasetIds: string[];
|
||||||
|
parentCollectionIds: string[];
|
||||||
|
}): Promise<string[]> {
|
||||||
|
if (!parentCollectionIds.length) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const collections = await MongoDatasetCollection.find(
|
||||||
|
{
|
||||||
|
teamId,
|
||||||
|
datasetId: { $in: datasetIds },
|
||||||
|
_id: { $in: parentCollectionIds }
|
||||||
|
},
|
||||||
|
'_id type',
|
||||||
|
{
|
||||||
|
...readFromSecondary
|
||||||
|
}
|
||||||
|
).lean();
|
||||||
|
|
||||||
|
const resultIds = new Set(collections.map((item) => String(item._id)));
|
||||||
|
|
||||||
|
const folderIds = collections
|
||||||
|
.filter((item) => item.type === 'folder')
|
||||||
|
.map((item) => String(item._id));
|
||||||
|
|
||||||
|
// Get all child collection ids
|
||||||
|
if (folderIds.length) {
|
||||||
|
const childCollections = await MongoDatasetCollection.find(
|
||||||
|
{
|
||||||
|
teamId,
|
||||||
|
datasetId: { $in: datasetIds },
|
||||||
|
parentId: { $in: folderIds }
|
||||||
|
},
|
||||||
|
'_id',
|
||||||
|
{
|
||||||
|
...readFromSecondary
|
||||||
|
}
|
||||||
|
).lean();
|
||||||
|
|
||||||
|
const childIds = await getAllCollectionIds({
|
||||||
|
teamId,
|
||||||
|
datasetIds,
|
||||||
|
parentCollectionIds: childCollections.map((item) => String(item._id))
|
||||||
|
});
|
||||||
|
|
||||||
|
childIds.forEach((id) => resultIds.add(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array.from(resultIds);
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
Collection metadata filter
|
Collection metadata filter
|
||||||
标签过滤:
|
标签过滤:
|
||||||
@@ -326,13 +382,23 @@ export async function searchDatasetData(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Concat tag and time
|
// Concat tag and time
|
||||||
if (tagCollectionIdList && createTimeCollectionIdList) {
|
const finalIds = (() => {
|
||||||
return tagCollectionIdList.filter((id) => createTimeCollectionIdList!.includes(id));
|
if (tagCollectionIdList && createTimeCollectionIdList) {
|
||||||
} else if (tagCollectionIdList) {
|
return tagCollectionIdList.filter((id) =>
|
||||||
return tagCollectionIdList;
|
(createTimeCollectionIdList as string[]).includes(id)
|
||||||
} else if (createTimeCollectionIdList) {
|
);
|
||||||
return createTimeCollectionIdList;
|
}
|
||||||
}
|
|
||||||
|
return tagCollectionIdList || createTimeCollectionIdList;
|
||||||
|
})();
|
||||||
|
|
||||||
|
return finalIds
|
||||||
|
? await getAllCollectionIds({
|
||||||
|
teamId,
|
||||||
|
datasetIds,
|
||||||
|
parentCollectionIds: finalIds
|
||||||
|
})
|
||||||
|
: undefined;
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
};
|
};
|
||||||
const embeddingRecall = async ({
|
const embeddingRecall = async ({
|
||||||
|
Reference in New Issue
Block a user