Tuesday, February 12, 2013

Creating SharePoint Search Scope to Find Only Documents

Requirement: End-User wants to get only documents in search results!

Solution: In brief, create a new search scope of "ContentClass" Type "STS_ListItem_DocumentLibrary". This will filter search results with in all the documents under SharePoint document libraries.

At high level, to get filter search results by only documents, We are going to:

  1. Create a New Search Scope
  2. Add Rules to Search Scope
  3. Create New Page for Search Results
  4. Set Search Core Results Web Part Scope Property
  5. Add New Tab to Search Center, Link the Search Page crated
I assume SharePoint search service application is already in place, up and running. (if not, create it first!)

Step 1: Create a New Search Scope:

Go to Central Administration >> Manage service applications >> Search Service Application (or whatever SSA created in your environment) >> Manage >> Click on "Scopes" Link in Search Administration.
Click on New Scope to Create a New Scope.
Give a Name to the scope. Say: "Search All Documents". Click "OK" to create the scope.
sharepoint document search

Step 2: Add Rules to Search Scope

Add Rules to our created scope by clicking "Add rules" link next to newly created scope.sharepoint search only document libraries
  • Choose "Property Query" in Scope Rule Type. 
  • Select "contentclass" in Property Query, enter "STS_ListItem_DocumentLibrary" as property value. 
  • Choose "Include..." under behavior.
sharepoint 2010 documents search scope
On clicking "Ok" button, You will see SharePoint saying "Scope will be updated in 14 Minutes". Fortunately, no need to wait so. Go back to Search Administration >> Click on "Start Update Now" link next to Scope Needing Update
sharepoint search multiple document libraries
Once scope updated, you can verify the scope results by checking our newly created scope.
sharepoint search scope for document library
Alright, we have the scope ready. Lets move forward to make it available to user from search center.

Step 3:Create New Page for Search Results

Go to Search Center site, Create a New Page (Don't have Search Center created? Then create a New page in your team site of "Search Results" Page Layout type).
sharepoint search for all document library
Give it a Name. say: SearchAllDocuments.aspx

Step 4: Set Search Core Results Web Part Scope Property

Edit SearchAllDocuments.aspx page, Edit "Search Core Results" web part.
Expand the web part properties, under Location Properties >> Enter the scope as: Search All Documents (which is the name of the scope we have created in step: 1). Click "Ok" to save the changes. Publish/Check-in the page.

 Step 5: Add New Tab to Search Center, Link the Search Page crated

Go to the Search Center site >> Get the Ribbon from Site actions >> Click on "Edit" button from the ribbon

Click on "Add New Tab"
Give name to the tab, say: Search All Documents, Enter "SearchAllDocuments.aspx" (or whatever page we created in Step 3) for page field.
That's all! Search for a keyword to see our work in action!!
sharepoint search documents only

As SharePoint 2010 supports search refinements, we can refine the results further by clicking appropriate links (e.g. "Word" under result type search refinements web part).

Using the same method, We can filter search results based on other properties supported. For all available ContentClass parameters, refer http://msdn.microsoft.com/en-gb/library/dd584327%28office.11%29.aspx
E..g. You want to get all task list items. or you may want to search only surveys or picture libraries, etc.



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Five Challenges in SharePoint Security
...And How to Solve Them. Free White Paper
*Sponsored


Check out these SharePoint products:

3 comments :

  1. Great post!
    It's possible to copy those documents to a folder for example?

    Thanks in advance.

    Mauricio

    ReplyDelete
    Replies
    1. Want to download all documents from search result? Use download Managers such as FDM, DownThemAll, Orbit, etc.

      Delete
  2. This scope also returns the urls to document libraries in the search results, not just the documents... At least, that's happening to me. Is it possible to do something about that so we only get the documents and nothing else?

    ReplyDelete

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...