SharePoint Blogs / SharePoint University
SharePoint Blogs and SharePoint University - all in one place!
Need SharePoint Training? Attend a SharePoint Bootcamp!

Please delete cookies related to sharepointblogs.com and sharepointu.com to resolve login issues!

Excluding Content Types from Search Results

I received a question recently about excluding certain items from the search results and thought it was worth a post. There are two main options that I thought of when asked.

Firstly, editing the XSL on the Core Results web part that controls the format of the returned results. This works fine for actually hiding the items, for example, you can wrap the results display part of the XML in an xsl:if to exclude the current item:

<xsl:if test="contenttype='Contract'">

(assuming you have contenttype included in the Selected Columns XML within the Core Results web part)

The reason why this is not such a great idea is that the web part that displays the results statistics will still include the items in the count and seeing as you cannot access the hidden control that binds the web parts together and can't change the output of the Statistics web part you cannot change that.

The best way is to limit the results based on Scope. Either by creating a separate Scope that can be used when searching or by modifying the default Scope used, ie. All Sites.

First you need to make sure that the Managed Property you want to limit the Scope with is allowed to be used in scopes. To do this go to Central Admin, Shared Services Admin for the SSP in question, Search Settings, Meta-data Property Mappings. Then edit the Managed Property and check the 'Allow this property to be used in scopes' check box:

Next, you need to add a new rule to the Scope to Exclude the items based on the value for the Managed Property. Go back to Search Settings, Click on View Scopes and then edit the scope you want to change. Click Add new Rule and create a Property Query rule that is set the to Exclude items where the property you modified above is equal to the value you want to exclude. For example to exclude Folders from search results:

(note that if you're interested in excluding folders, the above works in SharePoint, but you'll need to do something more for file shares - see Scott Jamisons's post)

Then make sure that you run the Update Scopes option so that the change to Scope takes effect.

I'm not 100% sure, but I think that if you have not had a Scope based on this Managed Property (or it might be if you enable the Managed Property for use in Scopes) you may need to do a Full Crawl to have this all work properly.

Also, if you check the 'Show Scope Picker' option in the Advanced Search Box web part, and you have created a new scope for the Exclusion to apply to, the user can select that Scope when searching. 

Be aware when doing all this that the will be a price to pay somewhere if you have a lot of Scopes defined in this way (even if it's only in confusing the user!), and that if you need really custom restrictions, perhaps you are better off with a custom search solution tailored for the way that the users need to search!

 


Posted 03-28-2007 10:46 PM by adrh

Comments

MOSS newbie wrote re: Excluding Content Types from Search Results
on 02-19-2008 4:21 PM

I'm trying to exclude Folders from search results.  I don't understand what you're doing up there and the images are missing.  Can you better explain how to exclude Folders from search results?

Justin wrote re: Excluding Content Types from Search Results
on 09-26-2008 11:26 PM

I m new to  Sharepoint, and would like to ask, if i want to exclude "Author" from being search by sharepoint, how can i do this?  What i mean is, say, when i do a search on "Administrator", all pages / document created / uploaded by the username "Administrator" will be showed. But What i expect is, only the content included  the word "Administrator" will be showed.

I have tried to set the Slope Rule -> content -> Author = Administrator. But no result were found, as all pages/document are created/uploaded by username "Administrator"  .

Thanks

(btw. i m kiwi too :) )

Dave wrote re: Excluding Content Types from Search Results
on 12-10-2008 8:44 AM

You images are missing. Showing up as red X's.

Piet wrote re: Excluding Content Types from Search Results
on 12-16-2008 3:41 PM

How can I exclude fileshare folders in searchresults, the link to Scott Jamisons's Blog is a deadlink. Can you please help me.

adrh wrote re: Excluding Content Types from Search Results
on 12-16-2008 4:08 PM

You know, that's quite frustrating because I was instrumental in that blog and thought about replicating the content! I'll have to see if I can dig out the emails about it and get back to you...

Piet wrote re: Excluding Content Types from Search Results
on 12-17-2008 1:16 AM

Thanks, did you find any emails regarding excluding fileshare folders.

Need SharePoint Training? Attend a SharePoint Bootcamp!
Posts (c) their respective authors. Everything else (c) 2009 SharePoint Experts, Inc.