Wednesday, January 20, 2016

Find people based on taxonomy id’s

image
The typical scenario shown and used is where you want to list content relevant to a user based on a property on the content and a property on the user profile. For example the Ask Me About property for a user will by default store the terms as enterprise keywords. This means that if you want to list content with enterprise keywords enabled for the current user you can use a query template like:

{|owsTaxIdTaxKeyword:{User.SPS-Responsibility.Id}}

What if you want to list all people tagged with taxonomy values from a page?

Now we have the exact opposite scenario.

{|AskMeAbout:{Item.TaxKeyword} will work, as it uses the labels and not the id’s. However {|AskMeAbout:{Item.TaxKeyword.Id} will not work as the AskMeAbout field only has labels and not id’s. If you have terms with the same label in different hierarchies, or labels which can be sub-strings of other labels, then this very quickly breaks.

Is there a solution? Of course!

Here’s the magic you need to know. When you have a user profile property tied to a taxonomy, you will get a crawled property named ows_taxid_SPShPropertyName for SPS- prefixed properties and ows_taxid_PropertyName for other ones, with corresponding managed properties named owstaxIdSPShPropertyName / owstaxIdPropertyName. Just like you get for taxonomy based site columns for content.

Switch the query over to: {|owstaxIdSPShResponsibility:{Item.TaxKeyword.Id} and you’re all set. (SPS-Responsibility is the internal name for the user profile property Ask me about.)

image

The main difference for taxonomy based user profile properties is that the managed property only contains the id’s, not the labels, but it does include the property with and without the #0 prefix as well as the termset id.

image

Note: The user profile property has to be visible to everyone and marked as indexeable for it show in search.

No comments:

Post a Comment