修复用户收藏查询bug
This commit is contained in:
1 parent
08757d15e4
commit
f1fa0401c2
1 file changed
+7
-7
@@ -334,11 +334,11 @@ namespace Store.Modules.CloudProduct.Services
|
|||||||
.Query(q => q
|
.Query(q => q
|
||||||
.Bool(b =>
|
.Bool(b =>
|
||||||
{
|
{
|
||||||
// 只检索当前用户自己的收藏
|
|
||||||
b.Filter(f => f.Term(t => t.Field(x => x.UserName).Value(request.UserName)));
|
|
||||||
|
|
||||||
var filters = new List<Func<QueryContainerDescriptor<UserFavoritesSearchDocument>, QueryContainer>>();
|
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)
|
if (groupId.HasValue)
|
||||||
{
|
{
|
||||||
filters.Add(f => f.Term(t => t.Field(x => x.GroupId).Value(groupId.Value)));
|
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)
|
if (string.IsNullOrWhiteSpace(keyword) == false)
|
||||||
{
|
{
|
||||||
@@ -400,10 +401,9 @@ namespace Store.Modules.CloudProduct.Services
|
|||||||
})
|
})
|
||||||
.From(from)
|
.From(from)
|
||||||
.Size(pageSize)
|
.Size(pageSize)
|
||||||
.TrackTotalHits(true) // 命中数超过 10000 时默认不精确统计,需要显式开启
|
.TrackTotalHits(true)
|
||||||
.RequestConfiguration(r => r.RequestTimeout(QueryTimeout))
|
.RequestConfiguration(r => r.RequestTimeout(QueryTimeout))
|
||||||
);
|
);}
|
||||||
}
|
|
||||||
catch (OpenSearchClientException ex) when (ex.Response?.Success == false)
|
catch (OpenSearchClientException ex) when (ex.Response?.Success == false)
|
||||||
{
|
{
|
||||||
throw new AppException($"收藏检索超时或失败({QueryTimeout.TotalSeconds}秒): " + ex.Message);
|
throw new AppException($"收藏检索超时或失败({QueryTimeout.TotalSeconds}秒): " + ex.Message);
|
||||||
|
|||||||
Reference in new issue
Block a user