How to: Query SharePoint 2013 search for trending tags

Posted Tuesday, November 12, 2013 4:56 PM by CoreyRoth

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.

TrendingTagsNewsfeedPage

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.

TrendingTagsDiagnosticLogs

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.

TrendingTagsULSViewer

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?

TrendingTagsSearchResults

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.

TrendingTagsRefinementPanel

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'

TrendingTagsREST

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.

Comments

# re: How to: Query SharePoint 2013 search for trending tags

Wednesday, November 13, 2013 1:55 AM by Dennis

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.

# SharePoint 2013: Recopilatorio de enlaces interesantes (XXVII)!

Sunday, December 1, 2013 3:53 AM by Blog de Juan Carlos González en Geeks.MS

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

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

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

# re: How to: Query SharePoint 2013 search for trending tags

Monday, December 2, 2013 8:30 AM by Tolga

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.

# re: How to: Query SharePoint 2013 search for trending tags

Tuesday, December 3, 2013 4:08 PM by CoreyRoth

@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.

# re: How to: Query SharePoint 2013 search for trending tags

Monday, January 13, 2014 4:46 AM by Vipul Jain

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

# re: How to: Query SharePoint 2013 search for trending tags

Wednesday, February 5, 2014 2:35 PM by Kelly

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:

$.ajax({

       async: false,

       url: URL here!,

       type: "GET",

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

       success: function (data) {

# re: How to: Query SharePoint 2013 search for trending tags

Wednesday, October 26, 2016 8:53 AM by SharePoint on-premise

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

Leave a Comment

(required)
(required)
(optional)
(required)