in

Dot Net Mafia

Group site for developer blogs dealing with (usually) .NET, SharePoint 2013, SharePoint 2010, Office 365, SharePoint Online, and other Microsoft products, as well as some discussion of general programming related concepts.

This Blog

Syndication

Archives

Corey Roth [MVP]

A SharePoint MVP bringing you the latest time saving tips for SharePoint 2013, Office 365 / SharePoint Online and Visual Studio 2013.

Excluding Folders from Search Results

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.

EnterpriseSearchFolderResults

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.

EnterpriseSearchNoFolderResults

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.

EnterpriseSearchIsDocumentManagedProperty

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.

EnterpriseSearchIsDocumentScopeRule

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.

EnterpriseSearchCRWPScope

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

EnterpriseSearchFolderResultsScope

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.

Comments

 

Baris Bikmaz said:

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

April 20, 2010 9:59 AM
 

CoreyRoth said:

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

www.dotnetmafia.com/.../how-to-create-a-scope-for-a-custom-list-template-type.aspx

April 20, 2010 10:15 AM
 

Jason said:

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.

May 31, 2010 10:42 AM
 

abhishek said:

how can i f=do the same in Sharepoint2013?

February 22, 2015 11:29 PM

Leave a Comment

(required)  
(optional)
(required)  
Add

About CoreyRoth

Corey Roth is an independent SharePoint consultant specializing in ECM, Apps, and Search.
2015 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems