| By Corey Roth | Article Rating: |
|
| January 9, 2013 03:21 PM EST | Reads: |
931 |
By now you may have noticed that Search has changed quite a bit in SharePoint 2013. The ResultScriptWebPart powers most of the magic behind the Search Center. It replaces the CoreResultsWebPart that we have been using since SharePoint 2007. I expected many things in it to operate the same, but this web part really has been rewritten from the ground up and that’s a good thing. One new feature (of many) it brings us is the ability to sort search results. You can specify a sort order in the query or by enabling it in the web part properties. This allows the user to pick from a list of properties. I’ll cover it in the future because it deserves a quick post. However, for you developers out there, I know that some of you will want to write some code that passes a sort order. This post explains how to do it.
Before we begin, you have to know what you can sort of. There are a lot of options out-of-the-box such as Author and Write (Modified Date) or you can use your own property. Whatever you choose, you need to check the managed properties page and make sure it has the Sortable option set to Yes - active. You do this from the Search Schema page on your site collection or Search Service Application.
Since SharePoint 2007, we have been able to pass a query using KQL using the “k” parameter to the results.aspx of your search center. We can still do this in SharePoint 2013. To add a sort order though, we do things a little differently. Using a new query string parameter called Default, we can pass in a number of properties including sort order. The format is quite a bit different though as it uses a JSON notation. To start, I am going to issue a query with out k parameter using this new JSON notation. Let’s do a search for our sales documents. To do this, I include my search center URL (/search/pages/results.aspx) and append #Default= to it followed by the JSON object with a name value pair {"k":"Sales"}. When I assemble to entire string, it looks something like this.
http://server/search/Pages/results.aspx#Default={"k":"Sales"}
Now we want to add sorting. To do that, we use the “o” parameter. It takes a collection of JSON objects. The parameter p represents the managed property to sort by and the value d is the sort direction specified as a 0 or 1. A value of 0 represents ascending and a value of 1 represents descending. For example to sort by modified date descending, we use the Write managed property. The string would look like this:
"o":[{"d":1,"p":"Write"}]
When we add it to our query string from above it looks like this.
http://server/search/Pages/results.aspx#Default={"k":"Sales","o":[{"d":1,"p":"Write"}]}
This shows us the newest documents. In SharePoint 2013, they moved the modified date to the InfoCard so you actually have to hover over a search result to see the date. To show the oldest documents, you would just specify d:'”0” instead.
As another example, we could also sort by Author.
http://server/search/Pages/results.aspx#Default={"k":"Sales","o":[{"d":0,"p":"Author"}]}
I’ve included a bigger screenshot where you can see the name of the first author in the list on the InfoCard.
We can also combine them to have multiple sort orders, but I have had mixed results with that so far. Here’s what the query string would an example look like though.
http://server/search/Pages/results.aspx#Default={"k":"Sales","o":[{"d":0,"p":"Write"},{"d":1,"p":"Author"}]}
I’m pretty excited about sorting functionality in the search center. Users have been wanting it for quite a long time and only a select few ever had it (those with FAST Search for SharePoint). If you are writing search solutions, be sure and check my post about sorting with the REST API. This technique works with both SharePoint 2013 on-premises as well as SharePoint Online Preview. All of the screenshots came from Office 365.
Read the original blog entry...
Published January 9, 2013 Reads 931
Copyright © 2013 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Corey Roth
Corey Roth, a SharePoint Server MVP, is a consultant at Infusion specializing in SharePoint for clients in the energy sector. He has more than ten years of experience delivering solutions in the energy, travel, advertising and consumer electronics verticals.
Corey specializes in delivering ECM and search solutions to clients using SharePoint. Corey has always focused on rapid adoption of new Microsoft technologies including Visual Studio 2010, .NET Framework 4.0, and Silverlight.
He is a member of the .NET Mafia (www.dotnetmafia.com) where he blogs about the latest technology and SharePoint. He is dedicated to the community and speaks regularly at user groups and SharePoint Saturdays.
- Cloud People: A Who's Who of Cloud Computing
- NIST to Sponsor FFRDC Widespread Adoption of Integrated CyberSecurity
- Cloud Business Solutions, Social Media, and Platform Systems of Engagement Market Shares, Strategies, and Forecasts, Worldwide, 2013 to 2019
- MicroStrategy Announces General Availability of MicroStrategy 9.3.1
- MicroStrategy Announces General Availability of MicroStrategy 9.3.1
- Altova Announces General Availability of RaptorXML
- Cloud Expo New York | Big Data: What It Means for Legal & Risk Management
- Reflections on the Future of Platform as a Service (PaaS)
- 2013 - 2016 : solutions stabilisées, usages innovants généralisés
- Big Data Will Revolutionize Learning
- Cloud Expo New York: Getting to the Promise of Big Data
- Cloud Expo New York: Cloud Architecture and Engineering
- Cloud People: A Who's Who of Cloud Computing
- Portable Experimenter’s Platform, Powered by Raspberry Pi
- Predixion Software Announces General Availability of the Latest Version of its Predictive Analytics Platform
- Cloud Expo New York: The Big Challenge of Big Data & Hadoop Integration
- NIST to Sponsor FFRDC Widespread Adoption of Integrated CyberSecurity
- Cloud Business Solutions, Social Media, and Platform Systems of Engagement Market Shares, Strategies, and Forecasts, Worldwide, 2013 to 2019
- Agile Solutions for Cloud, Big Data, Mobility Services
- MicroStrategy Announces General Availability of MicroStrategy 9.3.1
- Cloud Computing: Cutting Costs, Boosting Profits
- AMAX Launches StorMax(TM) CFS, powered by IBM(R) General Parallel File System(TM) (GPFS(TM))
- Benefits of Cloud Computing
- HotLink Debuts Amazon EC2 Plug-in for Microsoft SCVMM with Latest Release of HotLink Hybrid Express
- The Top 250 Players in the Cloud Computing Ecosystem
- Web Services Using ColdFusion and Apache CXF
- Cloud People: A Who's Who of Cloud Computing
- Red Hat Named "Platinum Sponsor" of Virtualization Conference & Expo
- Cloud Expo New York Call for Papers Now Open
- Eclipse "Pollinate" Project to Integrate with Apache Beehive
- An Introduction to Ant
- Cloud Expo 2011 East To Attract 10,000 Delegates and 200 Exhibitors
- Beehive Code Now Available in Apache
- 4th International Cloud Computing Conference & Expo Starts Today
- Apache's Tomcat 5.5 is First Release Ever to Use Eclipse JDT Java Compiler
- "Beehive" Now Officially an Open Source Project: Apache Beehive




















