I might have figured it out. What I need is a PublishedOrRedirected query like this that says either published or is unpublished and Redirected. I just need to know how to do that
public MultiDocumentQuery PublishedOrRedirected(MultiDocumentQuery query)
{
return query...
}
public IQueryResult<NavigableItemBase> GetByUrl(string url)
{
if (url.StartsWith("/"))
{
url = url.Remove(0, 1);
}
if (url.IsNullOrWhiteSpace())
{
url = PageAlias.Home;
}
var query = new MultiDocumentQuery()
.OnCurrentSite()
.LatestVersion(_isPreviewEnabled)
.Published(!_isPreviewEnabled)
.Culture(_cultureName)
.Types(_types)
.WhereEquals(nameof(PageUrlPathInfo.PageUrlPathUrlPath), url.Trim())
.WithPageUrlPaths()
.WithCoupledColumns()
.Columns("DocumentPageBuilderWidgets")
.TopN(1);
...
See how we use .Published to get the only Published documents? What we need is a PublishedOrRedirected query.