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:
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:
- 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 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 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.
No comments:
Please Login and comment to get your questions answered!