Dot Net Mafia

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

This Blog



Corey Roth [MVP]

A SharePoint MVP bringing you the latest time saving tips for Ionic, SharePoint, and Office 365.

How to: Query SharePoint 2013 search for trending tags

Last week, I posted on how to query items matching a hashtag.  Today, I want to extend that concept further and talk about how to determine which tags are trending.  What I am specifically talking about today is the functionality in the “Trending #tags” section of the Newsfeed page.


You can see the list there on the bottom right.  It lists each tag and provides the number of times it was used in the last week.  Once you know how to query for this information, it’s actually quite simple.  However, it took quite a bit of digging for me today to figure it out.  How did I do it?  Well I knew it was search based, so I wanted to capture the query that the built-in web part was using.  To do this, I went back to my on-premises environment and changed the diagnostic logging settings under SharePoint Server Search –> Query to Verbose.


I then started a trace with ULS Viewer and went to the Newsfeed page to see what was going on.  After some digging, I noticed a query as highlighted below.


That query specifically was something like this:

ContentTypeId:0x01FD* write>="2013-11-06 21:46:30Z" -ContentClass=urn:content-class:SPSPeople

Specifically this query is looking for specific content types (you’ll see which ones shortly) and it uses the write keyword to get everything that has happened in the last week.  Lastly, it excludes people results.  Interesting, so what does it look like when I paste the query into my Search Center?


Interesting.  Those don’t look like trending tags at all!  In fact, what we are looking at are posts and replies fro the social feed.  Interesting.  Take a look at that Tags refiner on the left though.  Those tags look familiar!  Going back and looking at what the out-of-the-box web part, it turns out that they match and they are even in the same order.  Could it be?

Edit the refinement panel and take a look at the refiners in use and you’ll see that the values in refiners match exactly to what the out-of-the-box web part gives us.


This gives us what we need to work with as a developer.  If you wanted to use it with REST, you would use a query like this:

https://server/_api/search/query?querytext='ContentTypeId:0x01FD* write>="2013-11-06 21:46:30Z" -ContentClass=urn:content-class:SPSPeople'&refiners='Tags'


Here we also need to specify that we want it to give us a refiner using the refiners query string parameter.  Specify a value of Tags and make sure it is enclosed in single quotes.  You’ll notice in the Refiners element, we get each the name of each trending tag in convenient SharePoint Term form with the GUID as well as the RefinementCount

From here, you should be able to manipulate this data to display however you want.  You can also tweak the query now to exclude or include other entries as desired.  One thing to note here is that this means that trending tags is solely based off of the newsfeed.  Tagging documents with an associated enterprise keyword as I mentioned in my previous blog post won’t affect what is trending.



Dennis said:

Good information!

"Tagging documents with an associated enterprise keyword as I mentioned in my previous blog post won’t affect what is trending."

This is the crucial part for me and what I don't really understand. I also believe that tags from other Newsfeeds (team sites) are not taken into account - really only posts on the Newsfeed itself. Makes me wonder about the whole social concept. It also doesn't get better with Yammer. Just weird, if a document were to be tagged a hundred times (say the quarterly financial report), it is simply not trending. I would have to mention it in the Newsfeed and only then it would be trending.

November 13, 2013 1:55 AM

Blog de Juan Carlos González en Geeks.MS said:

Como cada primero de mes, os dejo un nuevo recopilatorio de enlaces interesantes sobre SharePoint que

December 1, 2013 3:53 AM

SharePoint 2013: Recopilatorio de enlaces interesantes (XXVII)! | Pasi??n por la tecnolog??a... said:

Pingback from  SharePoint 2013: Recopilatorio de enlaces interesantes (XXVII)! | Pasi??n por la tecnolog??a...

December 1, 2013 3:54 AM

Tolga said:

Really nice article about a different topic.

I need to perform similar query using REST API.

Is it possible to get the "most read contents in last 10 days" using similar approach?

Thanks for your answer in advance.

December 2, 2013 8:30 AM

CoreyRoth said:

@Tolgo possibly.  You can try sending your query to the Popular result source and see what it gives you.  In theory it should only give you results that it deems as popular.

December 3, 2013 4:08 PM

Vipul Jain said:

Trending Tags shows "2 uses in the past week" even if it is used only once by a single user. How to handle this ?

January 13, 2014 4:46 AM

Kelly said:

Hi Corey,

Great article. I having issues using the REST URL in an AJAX call. It keeps tripping up because of the ' or " in the string (ex. while I can get an output by copying the URL into a browser, in the AJAX call it gives me length errors because the URL needs to be within "). Any example of how this would look in an AJAX call such as:


       async: false,

       url: URL here!,

       type: "GET",

       headers: { "Accept": "application/json;odata=verbose" },

       success: function (data) {

February 5, 2014 2:35 PM

SharePoint on-premise said:

Thanks Corey for sharing the informative post. I have performed these queries. I can see my popular results.

October 26, 2016 8:53 AM

Leave a Comment


About CoreyRoth

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