Wednesday, October 05, 2011

Return only documents in search results

A few days ago my client came up with this new requirement where the SharePoint search should only display nothing but documents. Everything else will go ignored.

To achieve that I would recommend to create a Search Scope and then apply a set of rules that will basically prevent the unwanted items to show up.

The rules are:

*://*allitems.aspx*  Exclude
*://*webfldr.aspx*   Exclude
*://*mod-view.aspx*  Exclude
*://*my-sub.aspx*    Exclude
*://*/lists/*       Exclude
*://*lists*       Exclude

And here is how it should look once you entered them

    
For us, PowerShell entusiasts, here's how it looks  :)

write-host "Enter the Search Service Application Url where you need to apply the crawling rules:"
[string]$SearchServicerUrl = Read-Host #i.e. Enterprise Search Service Application

New-SPEnterpriseSearchCrawlRule -SearchApplication $SearchServicerUrl -Path "*://*webfldr.aspx*" -CrawlAsHttp 1 -Type ExclusionRule
New-SPEnterpriseSearchCrawlRule -SearchApplication $SearchServicerUrl -Path "*://*mod-view.aspx* " -CrawlAsHttp 1 -Type ExclusionRule
New-SPEnterpriseSearchCrawlRule -SearchApplication $SearchServicerUrl -Path "*://*my-sub.aspx*" -CrawlAsHttp 1 -Type ExclusionRule
New-SPEnterpriseSearchCrawlRule -SearchApplication $SearchServicerUrl -Path "*://*allitems.aspx*" -CrawlAsHttp 1 -Type ExclusionRule
New-SPEnterpriseSearchCrawlRule -SearchApplication $SearchServicerUrl -Path "*://*/lists/*" -CrawlAsHttp 1 -Type ExclusionRule
New-SPEnterpriseSearchCrawlRule -SearchApplication $SearchServicerUrl -Path "*://*all forms.aspx*" -CrawlAsHttp 1 -Type ExclusionRule


Happy Powershelling!

No comments: