in

Dot Net Mafia

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

This Blog

Syndication

Archives

Corey Roth [MVP]

A SharePoint MVP bringing you the latest time saving tips for SharePoint 2013, Office 365 / SharePoint Online and Visual Studio 2013.

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

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

 

FeliceG said:

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?

November 6, 2013 12:00 PM
 

Kourosh said:

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.

November 7, 2013 8:04 AM
 

CoreyRoth said:

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

November 11, 2013 11:07 AM
 

CoreyRoth said:

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

November 11, 2013 11:08 AM
 

Lars Fastrup said:

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"

December 6, 2013 5:19 AM
 

Kourosh said:

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.

December 13, 2013 7:27 AM
 

CoreyRoth said:

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

December 17, 2013 11:44 AM
 

Annie said:

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

June 14, 2017 1:39 PM

Leave a Comment

(required)  
(optional)
(required)  
Add

About CoreyRoth

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