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:
- Create a New Search Scope
- Add Rules to Search Scope
- Create New Page for Search Results
- Set Search Core Results Web Part Scope Property
- Add New Tab to Search Center, Link the Search Page crated
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.
Step 2: Add Rules to Search Scope
Add Rules to our created scope by clicking “Add rules” link next to newly created scope.
- Choose “Property Query” in Scope Rule Type.
- Select “contentclass” in Property Query, enter “STS_ListItem_DocumentLibrary” as property value.
- Choose “Include…” under behavior.
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
Once scope updated, you can verify the scope results by checking our newly created scope.
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).
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!!
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 https://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.