Requirement: Add Metadata to SharePoint Online Search Results
SharePoint Online: How to Show Metadata in Search Results?
I have a requirement to add the “Project Name” column value of a document in search results. Followed these steps to add metadata properties (or custom columns) to the search results page of SharePoint Online:
- Activate Publishing Feature both at Site collection features and Site Features page.
- 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”.
- Open the site collection in SharePoint Designer, navigate to folder “Search” folder under “Display Templates”. E.g., https://crescent.sharepoint.com/sites/ICPapers/_catalogs/masterpage/Display Templates/Search/
- Copy and paste: Item_default.html file, rename the copied file into to something relevant. E.g. “IC_Documents.html”
- Edit the IC_documents.html file in SharePoint Designer
- Change the “Title” Tag value to: <title>IC Documents</title>
- Append your Metadata property to the “ManagedPropertyMapping” tag. In my case, I’ve added “,'ProjectName':'ProjectNameOWSTEXT'”
- 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> ”
- Save and close the file.
- 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.
- That’s all. Now if you search for 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.