I have the following script to return search results of linked pages. I need to filter out the duplicates of the alias pages, as well as sort the results alphabetically. Currently, it returns both main page and alias page and does not sort them.
<script runat="server">
bool hasDegree;
bool hasCertificate;
bool hasLetter;
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
hasDegree = ValidationHelper.GetBoolean(CMS.DocumentEngine.DocumentHelper
.GetDocuments("FCC.Credential").Path(Eval<string>("NodeAliasPath"), CMS.DocumentEngine.PathTypeEnum.Children)
.Published().Where("CredentialType = 'D'").Count > 0, false);
hasCertificate = ValidationHelper.GetBoolean(CMS.DocumentEngine.DocumentHelper
.GetDocuments("FCC.Credential").Path(Eval<string>("NodeAliasPath"), CMS.DocumentEngine.PathTypeEnum.Children)
.Published().Where("CredentialType = 'C'").Count > 0, false);
hasLetter = ValidationHelper.GetBoolean(CMS.DocumentEngine.DocumentHelper
.GetDocuments("FCC.Credential").Path(Eval<string>("NodeAliasPath"), CMS.DocumentEngine.PathTypeEnum.Children)
.Published().Where("CredentialType = 'L'").Count > 0, false);
}
protected string imageFilePath(string cssClass, string baseImageName)
{
string fileResolution = (cssClass == "desktop") ? "320x200" : "180x180";
if (baseImageName.Trim().ToLower().EndsWith(".mp4"))
{
string baseName = baseImageName.Trim();
baseName = baseName.Substring(0, baseName.Length - 4);
return "/FCC/media/ProgramsOfStudy/Video/" + baseName + "_" + fileResolution + ".jpg";
}
return "/FCC/media/ProgramsOfStudy/" + fileResolution + "_" + baseImageName;
}
</script>
Also found this on page template called: RepeaterWithCustomQuery
WITH FOLDER_QUERY AS
(
SELECT NODEID, NODEPARENTID FROM VIEW_CMS_TREE_JOINED
WHERE CLASSNAME = 'FCC.CREDENTIALFOLDER'
),
CREDENTIAL_QUERY AS
(
SELECT CREDENTIALTYPE, NODEPARENTID FROM FCC_CREDENTIAL
JOIN VIEW_CMS_TREE_JOINED
ON [CREDENTIALID] = DOCUMENTFOREIGNKEYVALUE
WHERE CLASSNAME = 'FCC.CREDENTIAL'
-- IsPublished
AND ([DocumentCanBePublished] = 1 AND ([DocumentPublishFrom] IS NULL OR [DocumentPublishFrom] <= GETDATE()) AND ([DocumentPublishTo] IS NULL OR [DocumentPublishTo] >= GETDATE()))
),
CP_QUERY AS
(
SELECT CREDENTIALTYPE, FOLDER_QUERY.NODEPARENTID
FROM FOLDER_QUERY
JOIN CREDENTIAL_QUERY
ON FOLDER_QUERY.NODEID = CREDENTIAL_QUERY.NODEPARENTID
),
PROGRAM_QUERY AS
(
SELECT
(SELECT COUNT(*) FROM CP_QUERY WHERE CP_QUERY.NODEPARENTID = NODEID AND CP_QUERY.CREDENTIALTYPE = 'C') as Certificate,
(SELECT COUNT(*) FROM CP_QUERY WHERE CP_QUERY.NODEPARENTID = NODEID AND CP_QUERY.CREDENTIALTYPE = 'L') as Letter,
(SELECT COUNT(*) FROM CP_QUERY WHERE CP_QUERY.NODEPARENTID = NODEID AND (CP_QUERY.CREDENTIALTYPE = 'C' OR CP_QUERY.CREDENTIALTYPE = 'L')) as CertAndLetter,
(SELECT COUNT(*) FROM CP_QUERY WHERE CP_QUERY.NODEPARENTID = NODEID AND CP_QUERY.CREDENTIALTYPE = 'D') as Degree,
0 as CEWD,
NodeParentID,
DocumentName,
ClassName,
BaseImageName,
ImageAltText,
NodeAliasPath,
DocumentUrlPath,
DocumentCulture,
Description
FROM [FCC_PROGRAM] JOIN VIEW_CMS_TREE_JOINED
ON [PROGRAMID] = DOCUMENTFOREIGNKEYVALUE
WHERE CLASSNAME = 'FCC.PROGRAM'
-- IsPublished
AND ([DocumentCanBePublished] = 1 AND ([DocumentPublishFrom] IS NULL OR [DocumentPublishFrom] <= GETDATE()) AND ([DocumentPublishTo] IS NULL OR [DocumentPublishTo] >= GETDATE()))
),
CEWD_QUERY AS
(
SELECT
0 AS Certificate,
0 AS Letter,
0 AS CertAndLetter,
0 AS Degree,
1 AS CEWD,
NodeParentID,
DocumentName,
ClassName,
BaseImageName,
ImageAltText,
NodeAliasPath,
DocumentUrlPath,
DocumentCulture,
Description
FROM [FCC_CEWDPROGRAM] JOIN VIEW_CMS_TREE_JOINED
ON [CEWDPROGRAMID] = DOCUMENTFOREIGNKEYVALUE
WHERE CLASSNAME = 'FCC.CEWDPROGRAM'
-- IsPublished
AND ([DocumentCanBePublished] = 1 AND ([DocumentPublishFrom] IS NULL OR [DocumentPublishFrom] <= GETDATE()) AND ([DocumentPublishTo] IS NULL OR [DocumentPublishTo] >= GETDATE()))
),
COMBINED_QUERY as
(
SELECT * FROM PROGRAM_QUERY
UNION
SELECT * FROM CEWD_QUERY
)
SELECT * FROM COMBINED_QUERY
WHERE ##WHERE##