Excluding Folders from Search Results

Posted Wednesday, August 26, 2009 1:07 PM by CoreyRoth

I see this topic come up quite a bit.  You have a set of search results, and the user just wants to see the documents, not the folder that contains the documents.  Consider the following example, when I query for accounting documents below.


As you can see in the results above, the first item returned is the folder named Accounting which contains the documents listed after it.  Many times, people do not want this showing up in the results, so we need to come up with a way to remove it.  The easiest way of course is to use the IsDocument keyword and pass it a value of 1.  This will give you results like the ones below.


As you can see, this works great, but you don’t exactly want to have to explain to the user how to type in IsDocument:1 into the search box.  However, it is quite easy to include this if you are building your own advanced search control.  One way to handle this is to create a custom scope that just returns documents.  This is quite easy to do but there are a few steps.  The first thing we need to do is allow the IsDocument managed property to be used in scope rules.  To do this, go to Search Administration –> Metadata Properties and then find IsDocument in the list.  Check the Allow this property to be used in scopes checkbox and hit ok.


After making changes to any property in search, you of course need to perform a full crawl.  This could take minutes or days depending on the size of your search index.  Once you are done, go to the Scopes page and create a new scope.  For the purpose of my example today, I’ll just call mine Documents.  After you create the new scope, you need to add a new rule.  Choose Property Query and then select IsDocument from the list.  Enter a value of 1 and choose Require.  Now whenever you query against this scope only documents will be returned.  Perform a scope update when you are finished or simply wait for the timer job to update it whenever it is scheduled.


At this point you are ready to use your new scope in the Search Center.  There are a number of ways to include this such as putting it in a scope display group and giving the user a choice of scopes to use, but for today’s example, I am just going to use the Scope parameter on the CoreResultsWebPart (CRWP).  Edit your results.aspx page and then edit the CRWP.  Under Miscellaneous, type in the name of your scope in the field and then save your changed to the web part and page.


At this point you are ready to try our your new search results.  If all works successfully, you should have search results like this.


As you can see, it’s pretty simple to set this up.  If you don’t want all of your queries to be for documents only, you can customize the search box web part to display a list of scopes or something like that.  I’ll probably cover how to do that in a future post (although it’s pretty easy).

Follow me on twitter.


# re: Excluding Folders from Search Results

Tuesday, April 20, 2010 9:59 AM by Baris Bikmaz

What if you want to display list items (e.g. News) that are also not documents? I would exclude here only the contentType folder.

# re: Excluding Folders from Search Results

Tuesday, April 20, 2010 10:15 AM by CoreyRoth

Then I would consider using a custom scope and using the list item's content class.  For example.


# re: Excluding Folders from Search Results

Monday, May 31, 2010 10:42 AM by Jason

This works great thanks! But for some reason when I do a search at the home page with the "all sites" option which has this filter it is not work. But everywhere else it seems to be work. Any ideas?

The only difference I see is the URL gets appended with &s=All+Sites.

# re: Excluding Folders from Search Results

Sunday, February 22, 2015 11:29 PM by abhishek

how can i f=do the same in Sharepoint2013?

# re: Excluding Folders from Search Results

Monday, January 2, 2017 6:02 AM by Fran

And if you want to do that but in crawl?

Not crawl this folder because you have to much of them.

I want to avoid crawl folders but include documents in this folders.

Leave a Comment