locked
"Restrict on this tag" not working in content search webpart for custom taxonomy field in SharePoint 2013 RRS feed

  • Question

  • Hi,
    
    I have created a custom taxonomy site column called "skill" as shown in below.
    
    Element.xml
     
      <Field ID="{C8150968-82DA-444C-8AB8-D852E519EDB2}"
            Type="TaxonomyFieldType"
            Name="Skill"
            DisplayName="Skill"
            Group="Custom Columns">
      </Field>
      <Field Type="Note"
            ID="{B1BE4C89-5B8A-4481-B855-94A1254DFAB0}"
            DisplayName="Skill_NOTE"
            Name="Skill_NOTE"
            StaticName="Skill_NOTE"
            ShowInViewForms="FALSE"
            Required="FALSE"
            Hidden="TRUE">
      </Field>
    Feature1.EventReceiver.cs
    
     public override void FeatureActivated(SPFeatureReceiverProperties properties)
            {
                SPSite site = properties.Feature.Parent as SPSite;
                Guid fieldId = new Guid("{C8150968-82DA-444C-8AB8-D852E519EDB2}");
    
                if (site.RootWeb.Fields.Contains(fieldId))
                {
                    TaxonomySession session = new TaxonomySession(site);
                    SPSecurity.RunWithElevatedPrivileges(delegate ()
                    {
                        if (session.TermStores.Count != 0)
                    {
                        var termStore = session.TermStores["Managed Metadata Proxy Service"];
                        var group = termStore.Groups["Technology List"];
                        var termSet = group.TermSets["Technology"];
                        TaxonomyField field = site.RootWeb.Fields[fieldId] as TaxonomyField;
                        //set the text field to the id of the OrderStatus_Note field : f47685b7-93eb-45da-8227-c59925a0d87e
                        field.TextField = new Guid("{B1BE4C89-5B8A-4481-B855-94A1254DFAB0}");
                        // Connect to MMS
                        field.SspId = termSet.TermStore.Id;
                        field.TermSetId = termSet.Id;
                        field.TargetTemplate = string.Empty;
                        field.AnchorId = Guid.Empty;
                        field.Update();
                    }
                    });
                }
            }
    The site column is created after the deployment and then adding it to a SharePoint list and populating data.
    
    Then in SharePoint page I am adding a content search webpart and click change query, selecting "Restrict on this tag" by taxonomy data as shown below.
    
    Select a query : Items matching a tag (System)
    Restrict by app : Current site
    Restrict by tag : Restrict on this tag (example : JAVA)
    Add addition filters : nothing
    
    But it is not showing anything at Search Result Preview (RelevantResults(0)).
    
    
    
    It is working fine while using Out of the Box managed metadata column. 
    
    Please let me know why it is not working for custom taxonomy field.
    
    Thanks.
    
    Wednesday, March 15, 2017 8:01 AM

All replies

  • Hi Sayak Ganguly,

    If we use “Restrict on this tag” option to limit results to content that's tagged with a term from a term set, then switch to the advanced view, we will find the managed property “owstaxIdMetadataAllTagsInfo” is added to the query text. So we can get all items that tagged with Enterprise Keywords using “Restrict on this tag” option.

    But if we use a custom site column, we should query results with the managed property of this site column instead of using “owstaxIdMetadataAllTagsInfo” managed property for Enterprise Keywords. In SharePoint Server 2013, site columns that contain values will automatically become managed properties when they are crawled. If we create a site column, SharePoint automatically creates managed properties for this site column.

    Best regards,

    Linda Zhang


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Proposed as answer by Victoria Xia Monday, March 20, 2017 5:07 AM
    Thursday, March 16, 2017 7:06 AM