How to: Use search to query social tag (hashtag) data

Posted Tuesday, November 5, 2013 4:50 PM by CoreyRoth

I’ve been digging deeper into the SharePoint 2013 social API a bit more lately and I was particularly interested in social tags (hashtags).  In particular I wanted to find a way to see what social feed items have been tagged to a given hashtag similar to what we see on the page HashTagProfile.aspx on your personal site.

SocialHashTagProfile

This particular page does a number of things.  It shows all social feed items associated with the hashtag.  It also allows a tag administrator to associate this tag with an item in the term store.  This allows any document tagged to that particular item to be associated with the hashtag.  The SEE ALL link got me interested because I noticed it was a search query. 

SocialHashTagSearchResults

Here’s an example of what the query looks like.

NOT(ContentTypeId:0x01FD4FB0210AB50249908EAA47E6BD3CFE8B* OR ContentTypeId:0x01FD59A0DF25F1E14AB882D2C87D4874CF84* OR ContentTypeId:0x012002* OR ContentTypeId:0x0107* OR WebTemplate=COMMUNITY)owstaxIdMetadataAllTagsInfo:#03d247305-a0aa-46cc-8842-1806debbe1ae OR owstaxidmetadataalltagsinfo:#02890c1bc-0732-41b3-8466-52faf158d406

Breaking that query down, basically it excludes a few content types as well as the community site.  The key part of the query I found to be is the owstaxIdMetadataAllTagsInfo managed property.  You will notice there are two of them there.  It turns out, the first GUID returns all conversations associated with the hashtag.  The second GUID returns all documents associated with the Enterprise Keyword.  Take a look.

SocialHashTagSearchResults1

Next the results for the documents associated with the Enterprise Keywords.

SocialHashTagSearchResults2

If you want to see both together you just combine the query.

This works well, but I really wanted a simpler way to just see the social feed items associated with the hashtag itself.  I really didn’t want to have to go and retrieve the GUID for the underlying term first.  Luckily, Search is smart and you don’t have to.  Just put the human readable term in your query with owstaxIdMetadataAllTagsInfo and it does the rest.

owstaxIdMetadataAllTagsInfo:"#MarketingCampaign"

SocialHashTagSearchResults3

This actually provides more results than HashTagProfile.aspx does or when querying by GUID.  I am not really sure why there is a difference but these results seem to be more complete.  Try it out for yourself.

Comments

# re: How to: Use search to query social tag (hashtag) data

Wednesday, November 6, 2013 12:00 PM by FeliceG

Great post, thanks for sharing.

I have been trying to see if there is a way to use the content search web part to return "sites I am following" and "sites suggestions" like the web parts that can be found under the "Sites" tab.

Thoughts?

# re: How to: Use search to query social tag (hashtag) data

Thursday, November 7, 2013 8:04 AM by Kourosh

Hi and thank you realy for this very usefull information you share.

yesterday I uploaded a document on my development site on office 365 and tagged it by a tag (#myTag). today when I search owstaxIdMetadataAllTagsInfo:"#myTag", it finds only converstaions not documents.

# re: How to: Use search to query social tag (hashtag) data

Monday, November 11, 2013 11:07 AM by CoreyRoth

@FeliceG I don't think so.  For that you need to go through the Social API.  msdn.microsoft.com/.../dn194080.aspx

# re: How to: Use search to query social tag (hashtag) data

Monday, November 11, 2013 11:08 AM by CoreyRoth

@Kourosh that is correct.  This will only return the conversations not documents.  To get the documents, you have to cross reference to the Enterprise Keyword tag that the documents were tagged with.  This is how the profile page does it.

# re: How to: Use search to query social tag (hashtag) data

Friday, December 6, 2013 5:19 AM by Lars Fastrup

Thanks - very helpful post! You can also add an Alias named Tags to the owstaxIdMetadataAllTagsInfo property. This way you can search like this:

Tags:"#MarketingCampaign"

# re: How to: Use search to query social tag (hashtag) data

Friday, December 13, 2013 7:27 AM by Kourosh

Hi, I was wondering if there is possible to search for something like this:

ContentType:CTName&Sort:Created

TO get all pages with a specific CT and sort them based on the date they created.

# re: How to: Use search to query social tag (hashtag) data

Tuesday, December 17, 2013 11:44 AM by CoreyRoth

@Kourosh you can do this but you use a different parameter for sorting. See this article with the query string when sorting.  www.dotnetmafia.com/.../how-to-sort-search-results-by-query-string-with-the-resultscriptwebpart-in-sharepoint-2013.aspx

You can also configure the sort order manually on the web part.

# re: How to: Use search to query social tag (hashtag) data

Wednesday, June 14, 2017 1:39 PM by Annie

In our case, when we click See all under trending tags, no search results are populated. But if we removed NOT in front of the search query, all the newsfeed/conversation related to a search term (#something) return to search result.  Is there anything we can do to customize the search query?

Thanks,

Annie

Leave a Comment

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