click subpath match

This commit is contained in:
2025-04-10 18:31:24 +08:00
parent b8cd3716c4
commit 85f29d8b49
2 changed files with 33 additions and 22 deletions

View File

@@ -58,22 +58,28 @@ export function buildFilter(params: Partial<EventsQueryParams>): string {
filters.push(`user_id = '${params.userId}'`);
}
// 添加子路径过滤条件
if (params.subpath) {
// 添加子路径过滤条件 - 使用更精确的匹配方式
if (params.subpath && params.subpath.trim() !== '') {
console.log('====== SUBPATH DEBUG ======');
console.log('Raw subpath param:', params.subpath);
console.log('Subpath type:', typeof params.subpath);
console.log('Subpath length:', params.subpath.length);
// 确保子路径没有前导斜杠,避免双斜杠问题
const cleanSubpath = params.subpath.startsWith('/')
? params.subpath.substring(1)
: params.subpath;
// 清理并准备subpath值
let cleanSubpath = params.subpath.trim();
// 移除开头的斜杠以便匹配
if (cleanSubpath.startsWith('/')) {
cleanSubpath = cleanSubpath.substring(1);
}
// 移除结尾的斜杠以便匹配
if (cleanSubpath.endsWith('/')) {
cleanSubpath = cleanSubpath.substring(0, cleanSubpath.length - 1);
}
console.log('Cleaned subpath:', cleanSubpath);
// 在event_attributes JSON的full_url字段中查找subpath
const condition = `JSONExtractString(event_attributes, 'full_url') LIKE '%${cleanSubpath}%'`;
// 使用正则表达式匹配URL中的第二个路径部分
// 示例: 在 "https://abc.com/slug/subpath/" 中匹配 "subpath"
const condition = `match(JSONExtractString(event_attributes, 'full_url'), '/[^/]+/${cleanSubpath}(/|\\\\?|$)')`;
console.log('Final SQL condition:', condition);
console.log('==========================');