修复用户收藏查询bug

This commit is contained in:
chfei committed 2026-10-15 17:14:52 +08:00
1 parent 08757d15e4
commit f1fa0401c2
1 file changed
+7 -7
@@ -334,11 +334,11 @@ namespace Store.Modules.CloudProduct.Services
.Query(q => q
.Bool(b =>
{
// 只检索当前用户自己的收藏
b.Filter(f => f.Term(t => t.Field(x => x.UserName).Value(request.UserName)));
var filters = new List<Func<QueryContainerDescriptor<UserFavoritesSearchDocument>, QueryContainer>>();
// 只检索当前用户自己的收藏 —— 放进 filters,避免被后面的 Filter 覆盖
filters.Add(f => f.Term(t => t.Field(x => x.UserName).Value(request.UserName)));
if (groupId.HasValue)
{
filters.Add(f => f.Term(t => t.Field(x => x.GroupId).Value(groupId.Value)));
@@ -380,7 +380,8 @@ namespace Store.Modules.CloudProduct.Services
}));
}
if (filters.Count > 0) b.Filter(filters.ToArray());
// 统一一次性应用所有 filter,避免覆盖
b.Filter(filters.ToArray());
if (string.IsNullOrWhiteSpace(keyword) == false)
{
@@ -400,10 +401,9 @@ namespace Store.Modules.CloudProduct.Services
})
.From(from)
.Size(pageSize)
.TrackTotalHits(true) // 命中数超过 10000 时默认不精确统计,需要显式开启
.TrackTotalHits(true)
.RequestConfiguration(r => r.RequestTimeout(QueryTimeout))
);
}
);}
catch (OpenSearchClientException ex) when (ex.Response?.Success == false)
{
throw new AppException($"收藏检索超时或失败({QueryTimeout.TotalSeconds}秒): " + ex.Message);