我们在 Raven 中被这个问题难住了,无法弄清楚它对我们的生活有什么问题。我们有一个相当大的索引。它还有一个运行转换,可以根据包含标签数组的白名单文档过滤掉结果。
这是索引:
public class Entries_ByWhiteListSearchableFields
: AbstractIndexCreationTask<Entry, Entries_ByWhiteListSearchableFields.Result>
{
public class Result
{
public string Id { get; set; }
public IEnumerable<string> Search { get; set; }
public DateTimeOffset? LastPublishedAtUtc { get; set; }
public DateTimeOffset LastModifiedAtUtc { get; set; }
public DateTimeOffset DisplayAtUtc { get; set; }
public PublishStatus PublishStatus { get; set; }
public IEnumerable<string> BylineIds { get; set; }
public IEnumerable<string> TagIds { get; set; }
public IEnumerable<string> ReferenceIds { get; set; }
public string SourceStreamConfigId { get; set; }
public bool Deleted { get; set; }
public IEnumerable<string> FullyQualifiedTagIds { get; set; }
public DateTimeOffset? ExpireAtUtc { get; set; }
}
public Entries_ByWhiteListSearchableFields()
{
this.Map = entries => from entry in entries
let entrySection = entry.Tags.FirstOrDefault(tag => tag.Schema == "EntrySection")
where entrySection != null
select new
{
Id = entry.Id,
Search = entry.Tags
.Select(x => x.Label)
.Concat(new[] { entry.Headline }),
LastPublishedAtUtc = entry.LastPublishedAtUtc,
LastModifiedAtUtc = entry.LastModifiedAtUtc,
DisplayAtUtc = entry.LastPublishedAtUtc ?? entry.LastModifiedAtUtc,
PublishStatus = entry.PublishStatus,
BylineIds = entry.BylineIds,
TagIds = entry.Tags.Select(x => x.Id),
ReferenceIds = entry.References.Select(x => x.Id),
Deleted = entry.Deleted,
EntrySectionId = entrySection.Id,
FullyQualifiedTagIds = entry.Tags.Select(t => t.Schema + "." + t.Id),
ExpireAtUtc = entry.ExpireAtUtc
};
this.TransformResults =
(database, entries) => from entry in entries
let whitelist = database.Load<WhiteList>("whitelistdocid")
where database.Load<Entry>(entry.Id)
.Tags
.Select(t => t.Schema + "." + t.Id)
.Intersect(
whitelist.WhiteList.Select(s => "EntrySection." + s))
.Any()
select entry;
this.Index(x => x.Search, FieldIndexing.Analyzed);
}
}
我们已经运行了这个完全相同的索引,但没有转换,它运行良好。
这个索引似乎也可以工作,但在一个领域,我们有这样的查询:
query = this.session.Advanced.LuceneQuery<Entry, Entries_ByWhiteListSearchableFields>()
.Statistics(out stats)
.WhereEquals("Deleted", false)
.OrderBy("-DisplayAtUtc")
.Skip(queryModel.PageSize * (queryModel.Page - 1))
.Take(queryModel.PageSize)
.Include("BylineIds")
.Include("Tags,Id")
.Include("References,Id")
.Select(factory.GetEntryDashboardItemViewModel);
此查询在没有原始索引且没有转换的情况下完美运行。但是,使用新索引,当我们请求 pageSize 为 100 时,它只返回 6 个结果。当我们要求 50 时,它只返回几个。当我们要求 25 时,它返回 0。
但是,这一行:
.OrderBy("-DisplayAtUtc")
似乎引起了问题。当我们注释掉这一行时,它可以工作,但结果没有明显排序。当我们把它放回去时,同样的问题只返回了几个结果。
我重命名了一些东西以使其更有意义。如果需要更多信息,请告诉我。
任何帮助或建议表示赞赏。