It's a great package, but I was wondering if it's possible to exclude certain pages. I assume it's already ignoring pages that have "naviHide" set to true, but it would be great if there were a variable (e.g. "hideFromSearchResults") that could be used to suppress specific pages.
No problem at all. You would want to add a property to any document type(s) you want to filter out of the search results, just like you do with the umbracoNaviHide property. As you suggest, the 'hideFromSearchResults' property alias is a good one.
Then, modify the xsltsearch.xslt file looking for the 'possibleNodes' variable, adding the line in bold for your new property
<xsl:variable name="possibleNodes" select="$items/descendant-or-self::*[ @isDoc and string(umbracoNaviHide) != '1' and string(hideFromSearchResults) != '1' <!-- Hide documents from search --> and count(attribute::id)=1 and (umbraco.library:IsProtected(@id, @path) = false() or umbraco.library:HasAccess(@id, @path) = true()) ]"/>
This way, only pages that are not hidden from the navigation and are also not specifically hidden from the search results will appear in the results.
The default code doesn't hide things 'recursively'. By default you'd need to set the umbracoNaviHide or hideFromSearchResults property on every page you wanted to hide. I think this is reasonable but if you'd prefer to hide a page and all those below it you would modify the code to:
<xsl:variable name="possibleNodes" select="$items/descendant-or-self::*[ @isDoc and not(ancestor-or-self::*/umbracoNaviHide) = 1 and not(ancestor-or-self::*/hideFromSearchResults) = 1 <!-- Hide documents from search --> and count(attribute::id)=1 and (umbraco.library:IsProtected(@id, @path) = false() or umbraco.library:HasAccess(@id, @path) = true()) ]"/>
This checks the umbracoNaviHide and hideFromSearchResults not just on each page but all the setting on all of its ancestors as well.
Not thoroughly tested but I believe this is what you're looking for.
Do be very careful to add a complete description to the document type property alias so that your content editors realize how powerful this is. And that once set there is no way to allow a child page to be included in the search results again. At least not without more checks and logic in the possibleNodes variable.
Exclude certain pages from the results?
It's a great package, but I was wondering if it's possible to exclude certain pages. I assume it's already ignoring pages that have "naviHide" set to true, but it would be great if there were a variable (e.g. "hideFromSearchResults") that could be used to suppress specific pages.
Hi, Arie,
No problem at all. You would want to add a property to any document type(s) you want to filter out of the search results, just like you do with the umbracoNaviHide property. As you suggest, the 'hideFromSearchResults' property alias is a good one.
Then, modify the xsltsearch.xslt file looking for the 'possibleNodes' variable, adding the line in bold for your new property
doug.
Doug, Thanks for the info as well. Is it possible to exclude all childen nodes under a specific parent node?
Hi, Jeff,
The default code doesn't hide things 'recursively'. By default you'd need to set the umbracoNaviHide or hideFromSearchResults property on every page you wanted to hide. I think this is reasonable but if you'd prefer to hide a page and all those below it you would modify the code to:
This checks the umbracoNaviHide and hideFromSearchResults not just on each page but all the setting on all of its ancestors as well.
Not thoroughly tested but I believe this is what you're looking for.
Do be very careful to add a complete description to the document type property alias so that your content editors realize how powerful this is. And that once set there is no way to allow a child page to be included in the search results again. At least not without more checks and logic in the possibleNodes variable.
doug.
is working on a reply...