Monday, 29 December 2014

Crawled properties not created for managed metadata field / Naming convention for note field associated with managed metadata column

 Hi again, today new problem and solution J and I feel this is very important one J

Background: In SharePoint 2013 when full crawl happens, Site Columns those have data for them managed and crawled properties are created automatically. For site column of type Taxonomy, SharePoint creates two types of crawled properties.

Consider my taxonomy field name is MyTaxonomyField and there is respective associated hidden Note field. In this case after full crawl SharePoint will create two crawled properties as
ows_taxid_MyTaxonomyField and
ows_MyTaxonomyField

First crawled property (ows_taxid_MyTaxonomyField) is mapped with automatically created managed property owstaxidMyTaxonomyField. This managed property we should use everywhere in our queries in Content Search web part or in Search Result web part  since it contains the Term Id and we can query based on Term Ids.
For second crawled property (ows_MyTaxonomyField), managed property is not created automatically. We can create our own custom managed property and map with this crawled property. But then this is not the best practice, we couldn’t query based on Term Ids since this property contains only Term Names and not the Ids. There might be possibility of having the special characters in term names like “-“. Some of these special characters have different meaning in Search (KQL) and which may cause the search queries failure or no result.

Problem: In our project, for our Taxonomy fields first crawled properties (ows_taxid_MyTaxonomyField) is not getting created and hence no automatically created respective managed property. We have only second crawled property (ows_MyTaxonomyField) created but we don’t want to use it. In our Content Search web part we want to do the query based on TermIds.

Solution:

We have following taxonomy field, here I kept only important attributes for the field others are removed:

<Field ID="{}"
         Type="Note"

         DisplayName="MyTaxonomyField _0"

         StaticName="MyTaxonomyField0"

         Name="MyTaxonomyField0"
  </Field>

  <Field ID="{}"
         Name=" MyTaxonomyField "

         Type="TaxonomyFieldType"

         DisplayName=" MyTaxonomyField "

         StaticName="MyTaxonomyField ">
  </Field>

First field is hidden Note field and second managed metadata field. Through feature receiver we are associating the Note field with Taxonomy field.
After digging / googling a lot it found that problem is in the naming convention of Note field. Note field associated with managed metadata field should contain the “TaxHTField” in its static name / Name.

So field should be like this
<Field ID="{}"
         Type="Note"

         DisplayName="MyTaxonomyField _0"

         StaticName="MyTaxonomyFieldTaxHTField0"

         Name="MyTaxonomyFieldTaxHTField0"
  </Field>

This is strange behaviour but it worked for our managed metadata fields. We spend lot of time in finding this, hopefully if same problem occurs it will save your time J
 
Thanks!
Enjoy Reading J

Feel free to comment / suggestion / feedback if any J

No comments: