Reputation: 891
How can I exclude pages that have been redirected to other pages using "umbracoRedirect" from displaying in the xsltSearch results?
<xsl:variable name="possibleNodes" select="$items/descendant-or-self::*[
@isDoc
and string(umbracoNaviHide) != '1'
and name() != 'ImageGalleryPhoto'
and string(umbracoRedirect) != '1' <!-- How to hide umbracoRedirect from search ?? -->
and count(attribute::id)=1
and (umbraco.library:IsProtected(@id, @path) = false()
or umbraco.library:HasAccess(@id, @path) = true())
]"/>
Upvotes: 1
Views: 181
Reputation: 891
Thanks to Chriztian Steinmeier on the Umbraco forum:
<xsl:variable name="possibleNodes" select="
$items//*[@isDoc]
[not(umbracoNaviHide = 1)]
[not(self::ImageGalleryPhoto)]
[not(normalize-space(umbracoRedirect))]
[not(umbraco.library:IsProtected(@id, @path)) or umbraco.library:HasAccess(@id, @path)]
" />
Upvotes: 0
Reputation: 10400
Instead of placing logic in the XSLT, a better approach would be to prevent items with the property umbracoRedirect (and any other non-required items) from being indexed in the first place. That way you wouldn't have to work out the logic in your macro.
If you use an event, you can catch an item being indexed and cancel the process if it has the property set.
void indexer_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
{
if (e.IndexType == IndexTypes.Content)
{
var node = e.Node;
var redirectElement = node.Element("umbracoRedirect");
if (redirectElement != null && redirectElement.Value == "1")
return;
}
}
The way an event handler is implemented has changed very slightly over the last few versions so it will be worth checking out the documentation for changes from your specific version. See here for an example for the standard approaches.
Upvotes: 1