SharePoint Online: Add Metadata to Search Results Page

Requirement: Add Metadata to SharePoint Online Search Results

SharePoint Online: How to Show Metadata in Search Results?
I've a requirement to add "Project Name" column value of a document in search results. Followed these steps to add metadata properties (or custom columns) to search results page of SharePoint Online:
  1. Activate Publishing Feature both at Site collection features and Site Features page.
  2. Get the Managed Property name for your list column. You can verify it from Site settings >> Click on "Search schema "under "Site Collection Administration" section. Use search to enter the name of your property, verify its mapping. In my case, I've "ProjectName" Site column added to my list and its respective managed property was created automatically as: "ProjectNameOWSTEXT".
  3. Open the site collection in SharePoint Designer, Navigate to folder "Search" folder under "Display Templates". E.g. Templates/Search/
  4. Copy paste: Item_default.html file, Rename the copied file into to something relevant. E.g. "IC_Documents.html"
  5. Edit the IC_documents.html file in SharePoint Designer
    1. Change the "Title" Tag value to: <title>IC Documents</title>
    2. Append your Metadata property to the "ManagedPropertyMapping" tag. In my case, I've added ",&#39;ProjectName&#39;:&#39;ProjectNameOWSTEXT&#39;"
      sharepoint show metadata in search results
    3. Add your custom property in <Body> section next to " _#=ctx.RenderBody(ctx)=#_ ", In my case I've added "<div> <b>Project Name:</b> _#= ctx.CurrentItem.ProjectNameOWSTEXT =#_ </div> "
      add custom column to search results in sharepoint online
    4. Save and close the file.
  6. Edit Results.aspx page, Edit "Search Results" web part, set its display template: Under properties, set "Use a single template to display items" option and select "IC Documents" from the list. Click OK and stop editing the search results page. 
    set display template for search results
  7. That's all. Now if you search something, You should see search results are populated with "Project Name" Metadata in it! Similarly, You can add any number of columns to search results.
sharepoint online add metadata property to search results

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.